BME-Sensor / i2C mutex bugfix

This commit is contained in:
Verkehrsrot 2019-07-25 22:04:38 +02:00
parent b7b41968ab
commit 837988081e
3 changed files with 18 additions and 14 deletions

View File

@ -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()

View File

@ -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) {

View File

@ -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
}