123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116 |
- #include <sys/cdefs.h>
- #include <stdio.h>
- #include <nvs_flash.h>
- #include <esp_netif.h>
- #include "esp_log.h"
- #include "freertos/FreeRTOS.h"
- #include "freertos/task.h"
- #include "app/include/wifi.h"
- #include "lcd_st7701.h"
- #include "lvgl_port.h"
- #include "framework_compat.h"
- #include "time_sync.h"
- #include "ota.h"
- #include "custom.h"
- #include "beep.h"
- #include "sht30.h"
- #include "modbus_master.h"
- #include "system/miscellaneous_interface.h"
- #include "setting.h"
- #include "heatpump_controller.h"
- static const char *TAG = "main";
- lv_ui guider_ui;
- system_setting_t system_setting = {};
- bool cloud_connected = false;
- void iot_event_monitor(int event) {
- switch (event) {
- case IOT_CONNECT_CLOUD_FAILT:
- ESP_LOGI(TAG, "IOT_CONNECT_CLOUD_FAILT");
- cloud_connected = false;
- lvgl_port_lock(-1);
- lv_obj_add_flag(guider_ui.screen_lab_icon_cloud, LV_OBJ_FLAG_HIDDEN);
- lvgl_port_unlock();
- break;
- case IOT_CONNECT_CLOUD_SUCCESS:
- ESP_LOGI(TAG, "IOT_CONNECT_CLOUD_SUCCESS");
- cloud_connected = true;
- lvgl_port_lock(-1);
- lv_obj_clear_flag(guider_ui.screen_lab_icon_cloud, LV_OBJ_FLAG_HIDDEN);
- lv_obj_clear_flag(guider_ui.screen_img_wifi, LV_OBJ_FLAG_HIDDEN);
- lvgl_port_unlock();
- break;
- case IOT_LOGIN_FAILT:
- ESP_LOGI(TAG, "IOT_LOGIN_FAILT");
- break;
- case IOT_LOGIN_SUCCESS:
- ESP_LOGI(TAG, "IOT_LOGIN_SUCCESS");
- break;
- case IOT_REGISTER_FAILT:
- ESP_LOGI(TAG, "IOT_REGISTER_FAILT");
- break;
- case IOT_REGISTER_SUCCESS:
- ESP_LOGI(TAG, "IOT_REGISTER_SUCCESS");
- break;
- default:
- break;
- }
- }
- /**
- * wifi连接成功后执行的回调函数
- */
- void on_wifi_connected(void) {
- // //request_weather();
- // 开启时间同步
- time_sync_start();
- }
- _Noreturn void app_main(void) {
- // esp_log_level_set("*", ESP_LOG_ERROR);
- // esp_log_level_set("wifi-setting", ESP_LOG_DEBUG);
- // esp_log_level_set("ac_controller", ESP_LOG_DEBUG);
- // esp_log_level_set("mqtt_client", ESP_LOG_DEBUG);
- // esp_log_level_set("UI", ESP_LOG_DEBUG);
- // esp_log_level_set("system_setting", ESP_LOG_DEBUG);
- // 初始化NVS
- esp_err_t err = nvs_flash_init(); //nvs初始化
- if (err == ESP_ERR_NVS_NO_FREE_PAGES) {
- ESP_ERROR_CHECK(nvs_flash_erase()); //擦除nvs
- nvs_flash_init(); //重新初始化
- }
- modbus_master_init(); // 初始化 modbus master
- ESP_ERROR_CHECK(esp_netif_init());
- read_system_setting(&system_setting); // 读取nvs中存储的系统设置
- heatpump_controller_init(&system_setting);
- iotx_event_regist_cb(&iot_event_monitor); // 注册网关事件
- beep_init(); // 蜂鸣器初始化
- ESP_ERROR_CHECK(lcd_st7701_init());
- // 如果上次为熄屏状态
- uint8_t *s_on_off = nvs_get_uint8(NVS_SCREEN_ON_OFF);
- if (s_on_off != NULL) {
- if (*s_on_off == 1) {
- ESP_ERROR_CHECK(lcd_st7701_backlight_off());
- } else {
- ESP_ERROR_CHECK(lcd_st7701_backlight_on());
- }
- } else {
- ESP_ERROR_CHECK(lcd_st7701_backlight_on());
- }
- setup_ui(&guider_ui);
- app_wifi_init(on_wifi_connected);
- sht30_init(); // 初始化温湿度传感器
- // 初始化OTA功能
- ota_init();
- // 熄屏定时器初始化
- screen_off_timer_init(&system_setting);
- for (;;) {
- vTaskDelay(10 / portTICK_PERIOD_MS);
- }
- }
|