继电器要飞线,先删除初始化逻辑
This commit is contained in:
@@ -22,7 +22,8 @@
|
||||
|
||||
#define TAG "MAIN"
|
||||
|
||||
typedef struct {
|
||||
typedef struct
|
||||
{
|
||||
char time_str[32];
|
||||
float lux;
|
||||
float temp;
|
||||
@@ -35,8 +36,10 @@ static SemaphoreHandle_t s_env_data_lock = NULL;
|
||||
static bool wait_for_wifi_connected(TickType_t timeout_ticks)
|
||||
{
|
||||
const TickType_t start_ticks = xTaskGetTickCount();
|
||||
while ((xTaskGetTickCount() - start_ticks) < timeout_ticks) {
|
||||
if (wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED) return true;
|
||||
while ((xTaskGetTickCount() - start_ticks) < timeout_ticks)
|
||||
{
|
||||
if (wifi_connect_get_status() == WIFI_CONNECT_STATUS_CONNECTED)
|
||||
return true;
|
||||
vTaskDelay(pdMS_TO_TICKS(200));
|
||||
}
|
||||
return false;
|
||||
@@ -44,7 +47,8 @@ static bool wait_for_wifi_connected(TickType_t timeout_ticks)
|
||||
|
||||
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;
|
||||
struct tm timeinfo;
|
||||
time(&now);
|
||||
@@ -60,7 +64,8 @@ static void env_data_update_system_info(void)
|
||||
|
||||
static void ui_task(void *arg)
|
||||
{
|
||||
for (;;) {
|
||||
for (;;)
|
||||
{
|
||||
env_data_update_system_info();
|
||||
lvgl_port_lock(0);
|
||||
ui_tick();
|
||||
@@ -86,32 +91,27 @@ extern "C" void app_main(void)
|
||||
ui_init();
|
||||
lvgl_port_unlock();
|
||||
|
||||
// 7. 创建 UI 任务
|
||||
// 7. 创建 UI 任务
|
||||
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());
|
||||
}
|
||||
|
||||
// 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 总线并注册传感器 (共享总线)
|
||||
ESP_ERROR_CHECK(bh1750_user_init());
|
||||
i2c_master_bus_handle_t i2c_bus = bh1750_get_i2c_bus_handle();
|
||||
|
||||
|
||||
// AHT30 挂载到同一条 I2C 总线上
|
||||
aht30_handle_t aht30_dev = NULL;
|
||||
ESP_ERROR_CHECK(aht30_create(i2c_bus, AHT30_I2C_ADDRESS, &aht30_dev));
|
||||
|
||||
// 6. 创建传感器读取任务
|
||||
xTaskCreate([](void *arg) {
|
||||
xTaskCreate([](void *arg)
|
||||
{
|
||||
aht30_handle_t aht30 = (aht30_handle_t)arg;
|
||||
for (;;) {
|
||||
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);
|
||||
}
|
||||
vTaskDelay(pdMS_TO_TICKS(1000));
|
||||
}
|
||||
}, "sensor_task", 4096*2, (void*)aht30_dev, 6, NULL);
|
||||
|
||||
|
||||
} }, "sensor_task", 4096 * 2, (void *)aht30_dev, 6, NULL);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user