Merge pull request #400 from cyberman54/development
BME-Sensor / i2C mutex bugfix
This commit is contained in:
commit
b127c2c8c6
@ -41,6 +41,7 @@ Adafruit_BME280 bme; // I2C
|
|||||||
int bme_init(void) {
|
int bme_init(void) {
|
||||||
|
|
||||||
// return = 0 -> error / return = 1 -> success
|
// return = 0 -> error / return = 1 -> success
|
||||||
|
int rc = 1;
|
||||||
|
|
||||||
#ifdef HAS_BME680
|
#ifdef HAS_BME680
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
@ -59,7 +60,8 @@ int bme_init(void) {
|
|||||||
ESP_LOGI(TAG, "BME680 sensor found and initialized");
|
ESP_LOGI(TAG, "BME680 sensor found and initialized");
|
||||||
else {
|
else {
|
||||||
ESP_LOGE(TAG, "BME680 sensor not found");
|
ESP_LOGE(TAG, "BME680 sensor not found");
|
||||||
goto error;
|
rc = 0;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
loadState();
|
loadState();
|
||||||
@ -71,39 +73,40 @@ int bme_init(void) {
|
|||||||
ESP_LOGI(TAG, "BSEC subscription succesful");
|
ESP_LOGI(TAG, "BSEC subscription succesful");
|
||||||
else {
|
else {
|
||||||
ESP_LOGE(TAG, "BSEC subscription error");
|
ESP_LOGE(TAG, "BSEC subscription error");
|
||||||
goto error;
|
rc = 0;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "I2c bus busy - BME680 initialization error");
|
ESP_LOGE(TAG, "I2c bus busy - BME680 initialization error");
|
||||||
goto error;
|
rc = 0;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
#elif defined HAS_BME280
|
#elif defined HAS_BME280
|
||||||
|
|
||||||
bool status;
|
bool status;
|
||||||
// return = 0 -> error / return = 1 -> success
|
|
||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (I2C_MUTEX_LOCK()) {
|
if (I2C_MUTEX_LOCK()) {
|
||||||
|
|
||||||
status = bme.begin(BME280_ADDR);
|
status = bme.begin(BME280_ADDR);
|
||||||
if (!status) {
|
if (!status) {
|
||||||
ESP_LOGE(TAG, "BME280 sensor not found");
|
ESP_LOGE(TAG, "BME280 sensor not found");
|
||||||
goto error;
|
rc = 0;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
ESP_LOGI(TAG, "BME280 sensor found and initialized");
|
ESP_LOGI(TAG, "BME280 sensor found and initialized");
|
||||||
} else {
|
} else {
|
||||||
ESP_LOGE(TAG, "I2c bus busy - BME280 initialization error");
|
ESP_LOGE(TAG, "I2c bus busy - BME280 initialization error");
|
||||||
goto error;
|
rc = 0;
|
||||||
|
goto finish;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
finish:
|
||||||
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
||||||
return 1;
|
return rc;
|
||||||
|
|
||||||
error:
|
|
||||||
I2C_MUTEX_UNLOCK(); // release i2c bus access
|
|
||||||
return 0;
|
|
||||||
|
|
||||||
} // bme_init()
|
} // bme_init()
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ void init_display(const char *Productname, const char *Version) {
|
|||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (!I2C_MUTEX_LOCK())
|
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 {
|
else {
|
||||||
// show startup screen
|
// show startup screen
|
||||||
uint8_t buf[32];
|
uint8_t buf[32];
|
||||||
@ -143,7 +143,7 @@ void refreshTheDisplay(bool nextPage) {
|
|||||||
|
|
||||||
// block i2c bus access
|
// block i2c bus access
|
||||||
if (!I2C_MUTEX_LOCK())
|
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 {
|
else {
|
||||||
// set display on/off according to current device configuration
|
// set display on/off according to current device configuration
|
||||||
if (DisplayIsOn != cfg.screenon) {
|
if (DisplayIsOn != cfg.screenon) {
|
||||||
|
@ -114,6 +114,7 @@ void setup() {
|
|||||||
// create some semaphores for syncing / mutexing tasks
|
// create some semaphores for syncing / mutexing tasks
|
||||||
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
I2Caccess = xSemaphoreCreateMutex(); // for access management of i2c bus
|
||||||
assert(I2Caccess != NULL);
|
assert(I2Caccess != NULL);
|
||||||
|
I2C_MUTEX_UNLOCK();
|
||||||
|
|
||||||
// disable brownout detection
|
// disable brownout detection
|
||||||
#ifdef DISABLE_BROWNOUT
|
#ifdef DISABLE_BROWNOUT
|
||||||
@ -377,7 +378,7 @@ void setup() {
|
|||||||
"bmeloop", // name of task
|
"bmeloop", // name of task
|
||||||
2048, // stack size of task
|
2048, // stack size of task
|
||||||
(void *)1, // parameter of the task
|
(void *)1, // parameter of the task
|
||||||
1, // priority of the task
|
2, // priority of the task
|
||||||
&BmeTask, // task handle
|
&BmeTask, // task handle
|
||||||
1); // CPU core
|
1); // CPU core
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user