This commit is contained in:
aZholtikov committed 2026-10-30 10:46:40 +03:00
1 parent be80536843
commit e8e32b8993
4 files changed
+64 -4

No files matched your search

+1 -1
View File
@@ -1 +1 @@
idf_component_register(SRCS "zh_sim_race_button_box.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_encoder zh_ota_server zh_menu esp_wifi nvs_flash) idf_component_register(SRCS "zh_sim_race_button_box.c" INCLUDE_DIRS "" REQUIRES zh_160x_i2c zh_encoder zh_ota_server zh_menu zh_aht esp_wifi nvs_flash)
+2
View File
@@ -14,3 +14,5 @@ dependencies:
git: "https://github.com/aZholtikov/zh_encoder.git" git: "https://github.com/aZholtikov/zh_encoder.git"
zh_menu: zh_menu:
git: "https://github.com/aZholtikov/zh_menu.git" git: "https://github.com/aZholtikov/zh_menu.git"
zh_aht:
git: "https://github.com/aZholtikov/zh_aht.git"
+54 -3
View File
@@ -45,7 +45,9 @@ static zh_menu_handle_t *_menu_handle = NULL;
// static zh_pcf8574_handle_t *_button_handle = NULL; // static zh_pcf8574_handle_t *_button_handle = NULL;
static zh_pcf8574_handle_t *_lcd_handle = NULL; static zh_pcf8574_handle_t *_lcd_handle = NULL;
static zh_160x_i2c_handle_t *_lcd_160x_handle = NULL; static zh_160x_i2c_handle_t *_lcd_160x_handle = NULL;
static zh_aht_handle_t *_aht_handle = NULL;
static TaskHandle_t _stats_task_handle = NULL; static TaskHandle_t _stats_task_handle = NULL;
static TaskHandle_t _aht_task_handle = NULL;
static void _zh_load_settings(void); static void _zh_load_settings(void);
static void _zh_save_settings(void); static void _zh_save_settings(void);
@@ -54,10 +56,12 @@ static void _zh_webserver_init(void);
static void _zh_encoder_init(void); static void _zh_encoder_init(void);
static void _zh_pcf8574_init(void); static void _zh_pcf8574_init(void);
static void _zh_menu_init(void); static void _zh_menu_init(void);
static void _zh_aht_init(void);
static void _zh_system_load(void); static void _zh_system_load(void);
static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data); static void _zh_encoder_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data);
static void _zh_stats_processing_task(void *pvParameter); static void _zh_stats_processing_task(void *pvParameter);
static void _zh_aht_processing_task(void *pvParameter);
static void _zh_menu_enter_main_menu_callback(void *arg); static void _zh_menu_enter_main_menu_callback(void *arg);
static void _zh_menu_exit_main_menu_callback(void *arg); static void _zh_menu_exit_main_menu_callback(void *arg);
static void _zh_menu_change_menu_callback(zh_menu_node_t *current_node, uint8_t current_index); static void _zh_menu_change_menu_callback(zh_menu_node_t *current_node, uint8_t current_index);
@@ -77,7 +81,7 @@ static const _zh_boot_screen_description_t _boot_screens[] = {
{"Blank", {"---", "---", "---", "---"}}, {"Blank", {"---", "---", "---", "---"}},
}; };
static char _cabin_temp_status[5] = "23C"; static char _cabin_temp_status[5] = "";
static char _air_condition_status[5] = "AUTO"; static char _air_condition_status[5] = "AUTO";
static char _side_light_status[5] = "ON"; static char _side_light_status[5] = "ON";
static char _flash_light_status[5] = "OFF"; static char _flash_light_status[5] = "OFF";
@@ -149,12 +153,12 @@ void app_main(void)
esp_event_loop_create_default(); esp_event_loop_create_default();
_zh_load_settings(); _zh_load_settings();
_zh_pcf8574_init(); _zh_pcf8574_init();
_zh_system_load(); _zh_aht_init();
_zh_encoder_init(); _zh_encoder_init();
_zh_menu_init(); _zh_menu_init();
_zh_wifi_init(); _zh_wifi_init();
_zh_webserver_init(); _zh_webserver_init();
xTaskCreatePinnedToCore(&_zh_stats_processing_task, "stats_processing_task", STATS_TASK_STACK_SIZE, NULL, STATS_TASK_PRIORITY, &_stats_task_handle, tskNO_AFFINITY); _zh_system_load();
const esp_partition_t *running = esp_ota_get_running_partition(); const esp_partition_t *running = esp_ota_get_running_partition();
esp_ota_img_states_t ota_state = {0}; esp_ota_img_states_t ota_state = {0};
esp_ota_get_state_partition(running, &ota_state); esp_ota_get_state_partition(running, &ota_state);
@@ -262,6 +266,7 @@ static void _zh_pcf8574_init(void)
i2c_master_bus_handle_t i2c_bus_handle = NULL; i2c_master_bus_handle_t i2c_bus_handle = NULL;
i2c_master_bus_config_t i2c_bus_config = { i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT, .clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = -1,
.scl_io_num = EXPANDERS_I2C_SCL_GPIO, .scl_io_num = EXPANDERS_I2C_SCL_GPIO,
.sda_io_num = EXPANDERS_I2C_SDA_GPIO, .sda_io_num = EXPANDERS_I2C_SDA_GPIO,
.glitch_ignore_cnt = 7, .glitch_ignore_cnt = 7,
@@ -301,14 +306,37 @@ static void _zh_menu_init(void)
zh_menu_init(&config, &_menu_handle); zh_menu_init(&config, &_menu_handle);
} }
static void _zh_aht_init(void)
{
i2c_master_bus_handle_t i2c_bus_handle = NULL;
i2c_master_bus_config_t i2c_bus_config = {
.clk_source = I2C_CLK_SRC_DEFAULT,
.i2c_port = -1,
.scl_io_num = AHT_I2C_SCL_GPIO,
.sda_io_num = AHT_I2C_SDA_GPIO,
.glitch_ignore_cnt = 7,
.flags.enable_internal_pullup = true,
};
i2c_new_master_bus(&i2c_bus_config, &i2c_bus_handle);
zh_aht_init_config_t config = ZH_AHT_INIT_CONFIG_DEFAULT();
config.i2c_handle = i2c_bus_handle;
zh_aht_init(&config, &_aht_handle);
}
static void _zh_system_load(void) static void _zh_system_load(void)
{ {
zh_160x_lcd_clear(&_lcd_160x_handle); zh_160x_lcd_clear(&_lcd_160x_handle);
_zh_draw_boot_screen(); _zh_draw_boot_screen();
float humidity = 0.0;
float temperature = 0.0;
zh_aht_read(&_aht_handle, &humidity, &temperature);
snprintf(_cabin_temp_status, sizeof(_cabin_temp_status), "%dC", (int)lroundf(temperature));
vTaskDelay(5000); vTaskDelay(5000);
zh_160x_lcd_clear(&_lcd_160x_handle); zh_160x_lcd_clear(&_lcd_160x_handle);
CLEAR_ROW_CACHE(); CLEAR_ROW_CACHE();
_zh_draw_main_screen(); _zh_draw_main_screen();
xTaskCreatePinnedToCore(&_zh_stats_processing_task, "stats_processing_task", STATS_TASK_STACK_SIZE, NULL, STATS_TASK_PRIORITY, &_stats_task_handle, tskNO_AFFINITY);
xTaskCreatePinnedToCore(&_zh_aht_processing_task, "aht_processing_task", AHT_TASK_STACK_SIZE, NULL, AHT_TASK_PRIORITY, &_aht_task_handle, tskNO_AFFINITY);
} }
static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data) static void _zh_pcf8574_event_handler(void *arg, esp_event_base_t event_base, int32_t event_id, void *event_data)
@@ -362,7 +390,10 @@ static void _zh_stats_processing_task(void *pvParameter)
const zh_encoder_stats_t *encoder_stats = zh_encoder_get_stats(); const zh_encoder_stats_t *encoder_stats = zh_encoder_get_stats();
const zh_pcf8574_stats_t *pcf8574_stats = zh_pcf8574_get_stats(); const zh_pcf8574_stats_t *pcf8574_stats = zh_pcf8574_get_stats();
const zh_menu_stats_t *menu_stats = zh_menu_get_stats(); const zh_menu_stats_t *menu_stats = zh_menu_get_stats();
const zh_aht_stats_t *aht_stats = zh_aht_get_stats();
printf("Stats task minimum free stack size: %lu.\n", (uint32_t)uxTaskGetStackHighWaterMark(NULL)); printf("Stats task minimum free stack size: %lu.\n", (uint32_t)uxTaskGetStackHighWaterMark(NULL));
printf("AHT task minimum free stack size: %lu.\n", (uint32_t)uxTaskGetStackHighWaterMark(_aht_task_handle));
printf("AHT i2c driver error: %lu.\n", aht_stats->i2c_driver_error);
printf("Encoder task minimum free stack size: %lu.\n", encoder_stats->min_stack_size); printf("Encoder task minimum free stack size: %lu.\n", encoder_stats->min_stack_size);
printf("Encoder event post error: %lu.\n", encoder_stats->event_post_error); printf("Encoder event post error: %lu.\n", encoder_stats->event_post_error);
printf("Encoder queue overflow error: %lu.\n", encoder_stats->queue_overflow_error); printf("Encoder queue overflow error: %lu.\n", encoder_stats->queue_overflow_error);
@@ -379,6 +410,26 @@ static void _zh_stats_processing_task(void *pvParameter)
vTaskDelete(NULL); vTaskDelete(NULL);
} }
static void _zh_aht_processing_task(void *pvParameter)
{
(void)pvParameter;
for (;;)
{
float humidity = 0.0;
float temperature = 0.0;
zh_aht_read(&_aht_handle, &humidity, &temperature);
snprintf(_cabin_temp_status, sizeof(_cabin_temp_status), "%dC", (int)lroundf(temperature));
zh_menu_status_t menu_status = {0};
zh_menu_get(&_menu_handle, &menu_status);
if (menu_status.is_active == false)
{
_zh_draw_main_screen();
}
vTaskDelay(60000 / portTICK_PERIOD_MS);
}
vTaskDelete(NULL);
}
static void _zh_menu_enter_main_menu_callback(void *arg) static void _zh_menu_enter_main_menu_callback(void *arg)
{ {
(void)arg; (void)arg;
+7
View File
@@ -2,10 +2,12 @@
#include "nvs_flash.h" #include "nvs_flash.h"
#include "esp_wifi.h" #include "esp_wifi.h"
#include "math.h"
#include "zh_menu.h" #include "zh_menu.h"
#include "zh_160x_i2c.h" #include "zh_160x_i2c.h"
#include "zh_encoder.h" #include "zh_encoder.h"
#include "zh_ota_server.h" #include "zh_ota_server.h"
#include "zh_aht.h"
#define LCD_TOTAL_ROWS 4 #define LCD_TOTAL_ROWS 4
#define LCD_TOTAL_COLS 16 #define LCD_TOTAL_COLS 16
@@ -15,6 +17,8 @@
#define STATS_TASK_PRIORITY tskIDLE_PRIORITY #define STATS_TASK_PRIORITY tskIDLE_PRIORITY
#define STATS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE #define STATS_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#define AHT_TASK_PRIORITY tskIDLE_PRIORITY + 3
#define AHT_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#define EXPANDER_TASK_PRIORITY tskIDLE_PRIORITY + 5 #define EXPANDER_TASK_PRIORITY tskIDLE_PRIORITY + 5
#define EXPANDER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE #define EXPANDER_TASK_STACK_SIZE configMINIMAL_STACK_SIZE
#define ENCODER_TASK_PRIORITY tskIDLE_PRIORITY + 4 #define ENCODER_TASK_PRIORITY tskIDLE_PRIORITY + 4
@@ -38,6 +42,9 @@
#define EXPANDERS_I2C_SDA_GPIO GPIO_NUM_25 #define EXPANDERS_I2C_SDA_GPIO GPIO_NUM_25
#define EXPANDERS_INT_GPIO GPIO_NUM_17 #define EXPANDERS_INT_GPIO GPIO_NUM_17
#define AHT_I2C_SCL_GPIO GPIO_NUM_22
#define AHT_I2C_SDA_GPIO GPIO_NUM_21
#define LCD_I2C_ADDRESS 0x27 #define LCD_I2C_ADDRESS 0x27
#define BUTTON_I2C_ADDRESS 0x24 #define BUTTON_I2C_ADDRESS 0x24