diff --git a/src/bmesensor.cpp b/src/bmesensor.cpp index 25a1e207..28bcc34b 100644 --- a/src/bmesensor.cpp +++ b/src/bmesensor.cpp @@ -41,6 +41,7 @@ Adafruit_BME280 bme; // I2C int bme_init(void) { // return = 0 -> error / return = 1 -> success + int rc = 1; #ifdef HAS_BME680 // block i2c bus access @@ -59,7 +60,8 @@ int bme_init(void) { ESP_LOGI(TAG, "BME680 sensor found and initialized"); else { ESP_LOGE(TAG, "BME680 sensor not found"); - goto error; + rc = 0; + goto finish; } loadState(); @@ -71,39 +73,40 @@ int bme_init(void) { ESP_LOGI(TAG, "BSEC subscription succesful"); else { ESP_LOGE(TAG, "BSEC subscription error"); - goto error; + rc = 0; + goto finish; } } else { ESP_LOGE(TAG, "I2c bus busy - BME680 initialization error"); - goto error; + rc = 0; + goto finish; } #elif defined HAS_BME280 bool status; - // return = 0 -> error / return = 1 -> success // block i2c bus access if (I2C_MUTEX_LOCK()) { + status = bme.begin(BME280_ADDR); if (!status) { ESP_LOGE(TAG, "BME280 sensor not found"); - goto error; + rc = 0; + goto finish; } ESP_LOGI(TAG, "BME280 sensor found and initialized"); } else { ESP_LOGE(TAG, "I2c bus busy - BME280 initialization error"); - goto error; + rc = 0; + goto finish; } #endif +finish: I2C_MUTEX_UNLOCK(); // release i2c bus access - return 1; - -error: - I2C_MUTEX_UNLOCK(); // release i2c bus access - return 0; + return rc; } // bme_init() diff --git a/src/display.cpp b/src/display.cpp index 632e0ee8..19ec7bcc 100644 --- a/src/display.cpp +++ b/src/display.cpp @@ -63,7 +63,7 @@ void init_display(const char *Productname, const char *Version) { // block i2c bus access if (!I2C_MUTEX_LOCK()) - ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); + ESP_LOGD(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { // show startup screen uint8_t buf[32]; @@ -143,7 +143,7 @@ void refreshTheDisplay(bool nextPage) { // block i2c bus access if (!I2C_MUTEX_LOCK()) - ESP_LOGW(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); + ESP_LOGD(TAG, "[%0.3f] i2c mutex lock failed", millis() / 1000.0); else { // set display on/off according to current device configuration if (DisplayIsOn != cfg.screenon) { diff --git a/src/main.cpp b/src/main.cpp index 3221a6f5..e47d71c4 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -114,6 +114,7 @@ void setup() { // create some semaphores for syncing / mutexing tasks I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus assert(I2Caccess != NULL); + I2C_MUTEX_UNLOCK(); // disable brownout detection #ifdef DISABLE_BROWNOUT @@ -377,7 +378,7 @@ void setup() { "bmeloop", // name of task 2048, // stack size of task (void *)1, // parameter of the task - 1, // priority of the task + 2, // priority of the task &BmeTask, // task handle 1); // CPU core }