继电器要飞线,先删除初始化逻辑

This commit is contained in:
Wang Beihong
2026-04-21 01:04:41 +08:00
parent 08acf1b58b
commit 85cde3687f

View File

@@ -22,7 +22,8 @@
#define TAG "MAIN" #define TAG "MAIN"
typedef struct { typedef struct
{
char time_str[32]; char time_str[32];
float lux; float lux;
float temp; float temp;
@@ -35,8 +36,10 @@ static SemaphoreHandle_t s_env_data_lock = NULL;
static bool wait_for_wifi_connected(TickType_t timeout_ticks) static bool wait_for_wifi_connected(TickType_t timeout_ticks)
{ {
const TickType_t start_ticks = xTaskGetTickCount(); const TickType_t start_ticks = xTaskGetTickCount();
while ((xTaskGetTickCount() - start_ticks) < timeout_ticks) { while ((xTaskGetTickCount() - start_ticks) < timeout_ticks)
if (wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED) return true; {
if (wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED)
return true;
vTaskDelay(pdMS_TO_TICKS(200)); vTaskDelay(pdMS_TO_TICKS(200));
} }
return false; return false;
@@ -44,7 +47,8 @@ static bool wait_for_wifi_connected(TickType_t timeout_ticks)
static void env_data_update_system_info(void) static void env_data_update_system_info(void)
{ {
if (s_env_data_lock == NULL) return; if (s_env_data_lock == NULL)
return;
time_t now; time_t now;
struct tm timeinfo; struct tm timeinfo;
time(&now); time(&now);
@@ -60,7 +64,8 @@ static void env_data_update_system_info(void)
static void ui_task(void *arg) static void ui_task(void *arg)
{ {
for (;;) { for (;;)
{
env_data_update_system_info(); env_data_update_system_info();
lvgl_port_lock(0); lvgl_port_lock(0);
ui_tick(); ui_tick();
@@ -89,18 +94,12 @@ extern "C" void app_main(void)
// 7. 创建 UI 任务 // 7. 创建 UI 任务
xTaskCreate(ui_task, "ui_task", 8192, NULL, 5, NULL); xTaskCreate(ui_task, "ui_task", 8192, NULL, 5, NULL);
if (wait_for_wifi_connected(pdMS_TO_TICKS(15000))) { if (wait_for_wifi_connected(pdMS_TO_TICKS(15000)))
{
set_var_system_ip(wifi_connect_get_ip()); set_var_system_ip(wifi_connect_get_ip());
} }
// 4. 初始化继电器 (避开 PSRAM 引脚)
static const relay_config_t relay_cfg[RELAY_CTRL_ID_MAX] = {
{.pin = GPIO_NUM_38, .active_high = true},
{.pin = GPIO_NUM_39, .active_high = false},
{.pin = GPIO_NUM_40, .active_high = false},
};
relay_ctrl_init(relay_cfg);
// 5. 初始化 I2C 总线并注册传感器 (共享总线) // 5. 初始化 I2C 总线并注册传感器 (共享总线)
ESP_ERROR_CHECK(bh1750_user_init()); ESP_ERROR_CHECK(bh1750_user_init());
@@ -111,7 +110,8 @@ extern "C" void app_main(void)
ESP_ERROR_CHECK(aht30_create(i2c_bus, AHT30_I2C_ADDRESS, &aht30_dev)); ESP_ERROR_CHECK(aht30_create(i2c_bus, AHT30_I2C_ADDRESS, &aht30_dev));
// 6. 创建传感器读取任务 // 6. 创建传感器读取任务
xTaskCreate([](void *arg) { xTaskCreate([](void *arg)
{
aht30_handle_t aht30 = (aht30_handle_t)arg; aht30_handle_t aht30 = (aht30_handle_t)arg;
for (;;) { for (;;) {
float lux = 0.0f, temp = 0.0f, hum = 0.0f; float lux = 0.0f, temp = 0.0f, hum = 0.0f;
@@ -135,8 +135,5 @@ extern "C" void app_main(void)
xSemaphoreGive(s_env_data_lock); xSemaphoreGive(s_env_data_lock);
} }
vTaskDelay(pdMS_TO_TICKS(1000)); vTaskDelay(pdMS_TO_TICKS(1000));
} } }, "sensor_task", 4096 * 2, (void *)aht30_dev, 6, NULL);
}, "sensor_task", 4096*2, (void*)aht30_dev, 6, NULL);
} }