Version 1.0.2

Updated some components.
Changed main code to support the new major version of zh_dht.
This commit is contained in:
2024-06-23 12:15:46 +03:00
parent b5f84d4320
commit ccd5403640
9 changed files with 21 additions and 27 deletions

View File

@ -151,10 +151,8 @@ menu "ZH ESP-NOW Switch Configuration"
default SENSOR_TYPE_DS18B20 default SENSOR_TYPE_DS18B20
config SENSOR_TYPE_DS18B20 config SENSOR_TYPE_DS18B20
bool "DS18B20" bool "DS18B20"
config SENSOR_TYPE_DHT11 config SENSOR_TYPE_DHT
bool "DHT11" bool "DHT"
config SENSOR_TYPE_DHT22
bool "DHT22"
endchoice endchoice
endmenu endmenu

View File

@ -91,12 +91,9 @@ void zh_load_config(switch_config_t *switch_config)
#ifdef CONFIG_SENSOR_TYPE_DS18B20 #ifdef CONFIG_SENSOR_TYPE_DS18B20
switch_config->hardware_config.sensor_pin = CONFIG_SENSOR_PIN; switch_config->hardware_config.sensor_pin = CONFIG_SENSOR_PIN;
switch_config->hardware_config.sensor_type = HAST_DS18B20; switch_config->hardware_config.sensor_type = HAST_DS18B20;
#elif CONFIG_SENSOR_TYPE_DHT11 #elif CONFIG_SENSOR_TYPE_DHT
switch_config->hardware_config.sensor_pin = CONFIG_SENSOR_PIN; switch_config->hardware_config.sensor_pin = CONFIG_SENSOR_PIN;
switch_config->hardware_config.sensor_type = HAST_DHT11; switch_config->hardware_config.sensor_type = HAST_DHT;
#elif CONFIG_SENSOR_TYPE_DHT22
switch_config->hardware_config.sensor_pin = CONFIG_SENSOR_PIN;
switch_config->hardware_config.sensor_type = HAST_DHT22;
#else #else
switch_config->hardware_config.sensor_pin = ZH_NOT_USED; switch_config->hardware_config.sensor_pin = ZH_NOT_USED;
switch_config->hardware_config.sensor_type = HAST_NONE; switch_config->hardware_config.sensor_type = HAST_NONE;
@ -238,11 +235,13 @@ void zh_gpio_init(switch_config_t *switch_config)
switch_config->hardware_config.sensor_pin = ZH_NOT_USED; switch_config->hardware_config.sensor_pin = ZH_NOT_USED;
} }
break; break;
case HAST_DHT11:; case HAST_DHT:;
case HAST_DHT22:; zh_dht_init_config_t dht_init_config = ZH_DHT_INIT_CONFIG_DEFAULT();
zh_dht_sensor_type_t sensor_type = (switch_config->hardware_config.sensor_type == HAST_DHT11) ? ZH_DHT11 : ZH_DHT22; dht_init_config.sensor_pin = switch_config->hardware_config.sensor_pin;
switch_config->dht_handle = zh_dht_init(sensor_type, switch_config->hardware_config.sensor_pin); if (zh_dht_init(&dht_init_config) != ESP_OK)
switch_config->hardware_config.sensor_pin = switch_config->dht_handle.sensor_pin; {
switch_config->hardware_config.sensor_pin = ZH_NOT_USED;
}
break; break;
default: default:
switch_config->hardware_config.sensor_type = HAST_NONE; switch_config->hardware_config.sensor_type = HAST_NONE;
@ -405,15 +404,14 @@ void zh_send_sensor_config_message(const switch_config_t *switch_config)
char *unit_of_measurement = NULL; char *unit_of_measurement = NULL;
switch (switch_config->hardware_config.sensor_type) switch (switch_config->hardware_config.sensor_type)
{ {
case HAST_DS18B20:; case HAST_DS18B20:
data.payload_data.config_message.sensor_config_message.unique_id = 2; data.payload_data.config_message.sensor_config_message.unique_id = 2;
data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE; data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
unit_of_measurement = "°C"; unit_of_measurement = "°C";
strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement); strcpy(data.payload_data.config_message.sensor_config_message.unit_of_measurement, unit_of_measurement);
zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t)); zh_send_message(switch_config->gateway_mac, (uint8_t *)&data, sizeof(zh_espnow_data_t));
break; break;
case HAST_DHT11:; case HAST_DHT:
case HAST_DHT22:;
data.payload_data.config_message.sensor_config_message.unique_id = 2; data.payload_data.config_message.sensor_config_message.unique_id = 2;
data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE; data.payload_data.config_message.sensor_config_message.sensor_device_class = HASDC_TEMPERATURE;
unit_of_measurement = "°C"; unit_of_measurement = "°C";
@ -487,10 +485,9 @@ void zh_send_sensor_status_message_task(void *pvParameter)
break; break;
} }
break; break;
case HAST_DHT11: case HAST_DHT:
case HAST_DHT22:
ZH_DHT_READ: ZH_DHT_READ:
switch (zh_dht_read(&switch_config->dht_handle, &humidity, &temperature)) switch (zh_dht_read(&humidity, &temperature))
{ {
case ESP_OK: case ESP_OK:
data.payload_data.status_message.sensor_status_message.humidity = humidity; data.payload_data.status_message.sensor_status_message.humidity = humidity;

View File

@ -78,7 +78,6 @@ typedef struct // Structure of data exchange between tasks, functions and event
volatile bool gpio_processing; // GPIO processing flag. @note Used to prevent a repeated interrupt from triggering during GPIO processing. volatile bool gpio_processing; // GPIO processing flag. @note Used to prevent a repeated interrupt from triggering during GPIO processing.
volatile bool gateway_is_available; // Gateway availability status flag. @note Used to control the tasks when the gateway connection is established / lost. volatile bool gateway_is_available; // Gateway availability status flag. @note Used to control the tasks when the gateway connection is established / lost.
uint8_t gateway_mac[6]; // Gateway MAC address. uint8_t gateway_mac[6]; // Gateway MAC address.
zh_dht_handle_t dht_handle; // Unique DTH11/22 sensor handle.
TaskHandle_t switch_attributes_message_task; // Unique task handle for zh_send_switsh_attributes_message_task(). TaskHandle_t switch_attributes_message_task; // Unique task handle for zh_send_switsh_attributes_message_task().
TaskHandle_t switch_keep_alive_message_task; // Unique task handle for zh_send_switch_keep_alive_message_task(). TaskHandle_t switch_keep_alive_message_task; // Unique task handle for zh_send_switch_keep_alive_message_task().
TaskHandle_t sensor_attributes_message_task; // Unique task handle for zh_send_sensor_attributes_message_task(). TaskHandle_t sensor_attributes_message_task; // Unique task handle for zh_send_sensor_attributes_message_task().

View File

@ -1 +1 @@
1.0.1 1.0.2