Added a random error checking function
Not actually sure I'll use it?
This commit is contained in:
@@ -12,6 +12,15 @@ static const char* TAG = "DHT22";
|
||||
deci_percent _dht22_relative_humidity = UINT16_MAX;
|
||||
deci_degrees_c _dht22_temperature = INT16_MIN;
|
||||
|
||||
void dht22_handle_error(dht22_error e) {
|
||||
if (e == DHT22_OK) {
|
||||
ESP_LOGI(TAG, "No errors reading DHT22 value");
|
||||
} else if (e == DHT22_CHECKSUM_ERROR) {
|
||||
ESP_LOGE(TAG, "Error calculating checksum");
|
||||
} else if (e == DHT22_TIMING_ERROR) {
|
||||
ESP_LOGE(TAG, "Timing error while obtaining data");
|
||||
}
|
||||
}
|
||||
|
||||
dht22_error dht22_read() {
|
||||
uint8_t data[5] = {0};
|
||||
@@ -28,7 +37,6 @@ dht22_error dht22_read() {
|
||||
if (checksum_val != data[4]) {
|
||||
_dht22_relative_humidity = UINT16_MAX;
|
||||
_dht22_temperature = INT16_MIN;
|
||||
ESP_LOGE(TAG, "Error in final checksum check");
|
||||
return DHT22_CHECKSUM_ERROR;
|
||||
}
|
||||
|
||||
|
||||
@@ -11,6 +11,7 @@ typedef enum {
|
||||
typedef uint16_t deci_percent;
|
||||
typedef int16_t deci_degrees_c;
|
||||
|
||||
void dht22_handle_error();
|
||||
deci_percent dht22_relative_humidity();
|
||||
deci_degrees_c dht22_temperature();
|
||||
dht22_error dht22_read();
|
||||
|
||||
@@ -20,8 +20,8 @@ static const char* TAG = "YASPAM";
|
||||
static volatile bool run_dht = true;
|
||||
static volatile bool run_pms5003 = true;
|
||||
|
||||
static TaskHandle_t dht22_handle;
|
||||
static TaskHandle_t pms5003_handle;
|
||||
static TaskHandle_t dht22_handle = NULL;
|
||||
static TaskHandle_t pms5003_handle = NULL;
|
||||
|
||||
#ifdef CONFIG_PMS5003_ENABLED
|
||||
#include "pms5003.h"
|
||||
@@ -49,8 +49,12 @@ read_from_dht22()
|
||||
portDISABLE_INTERRUPTS();
|
||||
int ret = dht22_read();
|
||||
portENABLE_INTERRUPTS();
|
||||
if (ret != DHT22_OK) {
|
||||
dht22_handle_error(ret);
|
||||
} else {
|
||||
ESP_LOGI(TAG, "Got DHT22 data!");
|
||||
// TODO: Write the data out somewhere - into RAM maybe?
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(CONFIG_DHT22_PERIOD_POLL));
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user