| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418 |
- /**
- * @Author: 李建
- * @Date: 2025/3/18 11:34
- * Description: 定义了UI 与 逻辑的交互
- * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
- */
- #include <esp_log.h>
- #include <string.h>
- #include <nvs_flash.h>
- #include <esp_app_desc.h>
- #include "misc/lv_types.h"
- #include "widgets/tabview/lv_tabview.h"
- #include "gui_guider.h"
- #include "main.h"
- #include "wifi.h"
- #include "actions.h"
- #include "fp_controller.h"
- #include "lvgl_port.h"
- #include "modbus_master.h"
- #include "system/miscellaneous_interface.h"
- LV_IMAGE_DECLARE(_orange_meter_RGB565A8_84x396);
- LV_IMAGE_DECLARE(_green_meter_RGB565A8_84x396);
- LV_IMAGE_DECLARE(_power_open_RGB565A8_36x36);
- LV_IMAGE_DECLARE(_nxh_off_RGB565A8_80x80);
- LV_IMAGE_DECLARE(_js_on_RGB565A8_80x80);
- LV_IMAGE_DECLARE(_auto_on_RGB565A8_80x80);
- LV_IMAGE_DECLARE(_xf_on_RGB565A8_80x80);
- const static char *TAG = "actions";
- extern void set_ac_mode(lv_ui *ui, uint16_t mode);
- //
- /**
- * 点击管理密码登录按钮事件
- * @param e
- */
- void on_btn_check_manager_password(lv_event_t *e) {
- const char *password = lv_textarea_get_text(guider_ui.SettingPage_ta_1);
- if (strcmp(password, "0803") != 0) {
- // 显示密码错误标签
- lv_obj_remove_flag(guider_ui.SettingPage_lab_password_incorrect, LV_OBJ_FLAG_HIDDEN);
- } else {
- // 验证通过
- lv_obj_add_flag(guider_ui.SettingPage_lab_password_incorrect, LV_OBJ_FLAG_HIDDEN);
- // 隐藏密码输入 panel
- lv_obj_add_flag(guider_ui.SettingPage_cont_1, LV_OBJ_FLAG_HIDDEN);
- // 显示高级设置界面
- guider_ui.SettingPage_del = true;
- ui_load_scr_animation(&guider_ui, &guider_ui.FactorySettingPage, true,
- &guider_ui.SettingPage_del, setup_scr_FactorySettingPage,
- LV_SCR_LOAD_ANIM_MOVE_RIGHT, 200, 200, true, true);
- }
- }
- /**
- * 点击设置-开关机按钮事件
- * @param e
- */
- void on_ac_page_set_power(lv_event_t *e, uint8_t power) {
- ac_status.power = power;
- ac_set_power(true);
- }
- /**
- * 点击设置-开关机按钮事件
- * @param e
- */
- void on_btn_power_click(lv_event_t *e) {
- lv_obj_t *obj = lv_event_get_current_target(e);
- if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
- ac_status.power = 1;
- } else {
- ac_status.power = 0;
- }
- ac_set_power(true);
- }
- /**
- * 点击设置-网络-查找网络按钮事件
- * @param e
- */
- void on_btn_scan_wifi_click(lv_event_t *e) {
- lv_obj_clean(guider_ui.SettingPage_list_wifi);
- app_wifi_scan();
- }
- /**
- * 点击连接 wifi 按钮
- * @param e
- */
- void on_btn_connect_wifi(lv_event_t *e) {
- app_connect_wifi();
- }
- /**
- * 切换至主页面
- * @param e
- */
- void switch_screen_main_set(lv_event_t *e) {
- lv_ui * ui = lv_event_get_user_data(e);
- // 设置温度及滑动和风速状态
- lvgl_port_lock(-1);
- // lv_label_set_text_fmt(ui->screen_main_label_humSet_vul, "%d%%", ac_status.set_max_hum);
- // lv_slider_set_value(ui->screen_main_slider_speedSet_sign, ac_status.fan_speed*20, LV_ANIM_ON);
- // lv_label_set_text_fmt(ui->screen_main_label_spedSet_vul, "%d档",ac_status.fan_speed);
- // lv_slider_set_value(ui->screen_main_slider_humSet_sign, ac_status.set_max_hum, LV_ANIM_ON);
- set_ac_mode(ui, ac_status.mode);
- ac_set_power(true);
- // 设置电源状态
- lv_obj_add_state(ui->screen_main_imgbtn_power, ac_status.power == 1 ? LV_STATE_CHECKED : LV_STATE_DEFAULT);
- lvgl_port_unlock();
- }
- /**
- * 切换至设置页面
- * @param e
- */
- void switch_setting_page_set(lv_event_t *e) {
- lv_ui * ui = lv_event_get_user_data(e);
- lvgl_port_lock(-1);
- if(system_setting.sound_on_off)
- lv_obj_add_state(ui->SettingPage_sw_sound, LV_STATE_CHECKED);
- else
- lv_obj_remove_state(ui->SettingPage_sw_sound, LV_STATE_CHECKED);
- if(system_setting.screen_auto_off)
- lv_obj_add_state(ui->SettingPage_sw_1, LV_STATE_CHECKED);
- else
- lv_obj_remove_state(ui->SettingPage_sw_1, LV_STATE_CHECKED);
- lv_slider_set_value(ui->SettingPage_slider_sound_level, system_setting.sound_volume, false);
- lv_spinbox_set_value(ui->SettingPage_spinbox_2,system_setting.screen_off_minute);
- lvgl_port_unlock();
- }
- //刷新ui
- void refresh_ui_error(lv_event_t *e)
- {
- lv_ui * ui = lv_event_get_user_data(e);
- char str[320]={0};
- int index=0;
- lvgl_port_lock(-1);
- if(ac_status.error_code==0)
- {
- lv_label_set_text_static(ui->FactorySettingPage_label_detail_error, "NONE");
- } else{
- index=0;
- for(int i=0;i<8;i++)
- {
- if(ac_status.error_code&(1<<i))
- {
- //sprintf(str,"%s:%s\n",xf_fault[i].code,xf_fault[i].description);
- str[index++]='E';
- str[index++]='0'+i+1;
- str[index++]=':';
- for(int j=0;j<strlen((const char*)xf_fault[i].description);j++)
- {
- str[index++]=xf_fault[i].description[j];
- }
- str[index++]='\n';
- }
- }
- str[index++]=0;
- lv_label_set_text(ui->FactorySettingPage_label_detail_error, str);
- }
- lvgl_port_unlock();
- }
- /**
- * 切换至高级设置页面
- * @param e
- */
- void switch_factory_setting_page_set(lv_event_t *e) {
- lv_ui * ui = lv_event_get_user_data(e);
- lvgl_port_lock(-1);
- lv_spinbox_set_value(guider_ui.FactorySettingPage_lab_inner_addr, system_setting.inner_addr);
- lvgl_port_unlock();
- //refresh_ui_error(e);
- }
- /**
- * 重置滤网剩余寿命
- * @param e
- */
- void on_btn_filter_life_remain_clear(lv_event_t *e) {
- ac_status.filter_used_time=0;
- ac_status.filter_life_remaining=100;
- xf_set_filter_life_remain(true);
- }
- void on_setting_tabview_changed(lv_event_t *e) {
- }
- void on_fan_vol_refresh(lv_event_t *e) {
- lv_label_set_text_fmt(guider_ui.FactorySettingPage_lab_inner_addr,"%d",system_setting.inner_addr);
- lv_spinbox_set_value(guider_ui.FactorySettingPage_sp_temp_recoup,system_setting.fix_temp);
- lv_spinbox_set_value(guider_ui.FactorySettingPage_sp_hum_recoup,system_setting.fix_hum);
- }
- void on_fan_vol_save(lv_event_t *e) {
- lv_ui * ui = lv_event_get_user_data(e);
- int32_t temp_fix = lv_spinbox_get_value(guider_ui.FactorySettingPage_sp_temp_recoup);
- if ((temp_fix>=0)&&(temp_fix<99)) {
- system_setting.fix_temp = (int8_t) temp_fix;
- }
- int32_t hum_fix = lv_spinbox_get_value(guider_ui.FactorySettingPage_sp_hum_recoup);
- if ((hum_fix>=0)&&(hum_fix<99)) {
- system_setting.fix_hum = (int8_t) hum_fix;
- }
- int32_t inner_addr=lv_spinbox_get_value(guider_ui.FactorySettingPage_lab_inner_addr);
- if ((inner_addr>0)&&(inner_addr<255)) {
- system_setting.inner_addr=inner_addr;
- }
- save_system_setting(&system_setting);
- }
- void on_reset_factory_setting(lv_event_t *e) {
- // 清空nvs
- nvs_flash_erase();
- // 重启设备
- esp_restart();
- }
- void on_set_xf_mode(lv_event_t *e) {
- lv_obj_t *cont = (lv_obj_t *) lv_event_get_current_target(e);
- lv_obj_t *act_cb = lv_event_get_target(e);
- if (act_cb == cont) return;
- lvgl_port_lock(-1);
- lv_obj_add_state(act_cb, LV_STATE_CHECKED);
- uint32_t count = lv_obj_get_child_count(cont);
- // 遍历所有子控件
- for (int i = 0; i < count; i++) {
- lv_obj_t *child = lv_obj_get_child(cont, i);
- if (child != act_cb) {
- lv_obj_remove_state(child, LV_STATE_CHECKED);
- }
- }
- lvgl_port_unlock();
- if (act_cb == guider_ui.screen_main_imgbtn_cold) {
- ac_status.mode = COLD;
- lv_obj_set_style_arc_color(guider_ui.screen_main_arc_temp, lv_color_hex(0x2cbccc), LV_PART_INDICATOR|LV_STATE_DEFAULT);
- lv_obj_set_style_border_color(guider_ui.screen_main_arc_temp, lv_color_hex(0x2cbccc), LV_PART_KNOB|LV_STATE_DEFAULT);
- }
- else if (act_cb == guider_ui.screen_main_imgbtn_heat) {
- lv_obj_set_style_arc_color(guider_ui.screen_main_arc_temp, lv_color_hex(0xff4200), LV_PART_INDICATOR|LV_STATE_DEFAULT);
- lv_obj_set_style_border_color(guider_ui.screen_main_arc_temp, lv_color_hex(0xff4200), LV_PART_KNOB|LV_STATE_DEFAULT);
- ac_status.mode =HEAT ;
- } else if (act_cb == guider_ui.screen_main_imgbtn_tf) {
- lv_obj_set_style_arc_color(guider_ui.screen_main_arc_temp, lv_color_hex(0x00912c), LV_PART_INDICATOR|LV_STATE_DEFAULT);
- lv_obj_set_style_border_color(guider_ui.screen_main_arc_temp, lv_color_hex(0x00912c), LV_PART_KNOB|LV_STATE_DEFAULT);
- ac_status.mode = TF;
- }
- xf_set_mode(true);
- }
- static uint8_t addr = 1;
- void on_set_inner_addr(uint8_t num) {
- if (num)
- addr += 1;
- else
- addr -= 1;
- if (addr + num > 255)
- addr = 254;
- if (addr + num < 1)
- addr = 1;
- lvgl_port_lock(0);
- lv_label_set_text_fmt(guider_ui.FactorySettingPage_lab_inner_addr, "%d", addr);
- lvgl_port_unlock();
- // 保存到 nvs
- system_setting.inner_addr = addr;
- save_inner_addr(addr);
- }
- void on_set_beep_on_off(lv_event_t * e) {
- lv_obj_t *obj = lv_event_get_current_target(e);
- if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
- system_setting.sound_on_off = 1;
- } else {
- system_setting.sound_on_off = 0;
- }
- save_system_setting(&system_setting);
- }
- void on_set_screen_auto_off(lv_event_t * e) {
- lv_obj_t *obj = lv_event_get_current_target(e);
- if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
- system_setting.screen_auto_off = 1;
- } else {
- system_setting.screen_auto_off = 0;
- }
- save_system_setting(&system_setting);
- }
- void on_set_beep_volume(lv_event_t* e) {
- const lv_obj_t *slider = lv_event_get_current_target(e);
- uint32_t value = lv_slider_get_value(slider);
- ESP_LOGD(TAG, "on_set_beep_volume;%d", (uint8_t) value);
- system_setting.sound_volume = (uint8_t) value;
- save_system_setting(&system_setting);
- }
- void on_set_screen_off_minute(lv_event_t * e) {
- lv_obj_t *spbox = lv_event_get_current_target(e);
- int32_t value = lv_spinbox_get_value(spbox);
- ESP_LOGD(TAG, "on_set_screen_off_minute;%d", (uint8_t) value);
- system_setting.screen_off_minute = (uint8_t) value;
- save_system_setting(&system_setting);
- }
- void setting_page_init(lv_ui *ui) {
- static lv_style_t style_SettingPage_tabview_1_extra_btnm_items_default;
- ui_init_style(&style_SettingPage_tabview_1_extra_btnm_items_default);
- lv_style_set_text_color(&style_SettingPage_tabview_1_extra_btnm_items_default, lv_color_hex(0xffb204));
- lv_style_set_text_font(&style_SettingPage_tabview_1_extra_btnm_items_default, &lv_font_Alibaba_PuHuiTi_Medium_16);
- lv_style_set_text_opa(&style_SettingPage_tabview_1_extra_btnm_items_default, 255);
- lv_obj_add_style(lv_tabview_get_tab_bar(ui->SettingPage_tabview_1),
- &style_SettingPage_tabview_1_extra_btnm_items_default, LV_PART_MAIN | LV_STATE_DEFAULT);
- lv_label_set_text(ui->SettingPage_lab_wifi_status, get_wifi_status() == 1 ? "已连接" : "未连接");
- // 填充“关于”页面信息
- esp_app_desc_t * desc = esp_app_get_description();
- lv_label_set_text(ui->SettingPage_lab_version, desc->version);
- char device_serial[12];
- get_device_serial(device_serial);
- lv_qrcode_update(ui->SettingPage_qr_device_code, device_serial, 12);
- }
- void on_ota_failed_restart(lv_event_t *e) {
- esp_restart();
- }
- void on_reset_wifi(lv_event_t *e) {
- yx_data_clear(NVS_SSID_KEY);
- yx_data_clear(NVS_PASSWORD_KEY);
- esp_restart();
- }
- void on_restart_device(lv_event_t *e) {
- esp_restart();
- }
- /**
- * 空调页面-温度滑动条改变
- * @param e
- */
- void on_ac_page_arc_value_changed(lv_event_t * e) {
- lv_obj_t *arc = lv_event_get_current_target(e);
- int32_t value = lv_arc_get_value(arc)/10;
- lvgl_port_lock(0);
- lv_label_set_text_fmt(guider_ui.screen_main_label_temp_set, "%d", (uint16_t) value);
- lvgl_port_unlock();
- }
- /**
- * 空调页面-温度滑动条释放
- * @param e
- */
- void on_ac_page_arc_released(lv_event_t * e) {
- lv_obj_t *arc = lv_event_get_current_target(e);
- int32_t value = lv_arc_get_value(arc)/10;
- lvgl_port_lock(0);
- lv_label_set_text_fmt(guider_ui.screen_main_label_temp_set, "%d", (uint16_t) value);
- lvgl_port_unlock();
- ac_status.set_temp = (uint16_t) value;
- ac_set_temp(true);
- }
- /**
- * 空调页面-温度加按键
- * @param e
- */
- void on_set_temp_add(lv_event_t * e) {
- if (ac_status.set_temp<30) {
- ac_status.set_temp++;
- }else {
- }
- lvgl_port_lock(0);
- lv_arc_set_value(guider_ui.screen_main_arc_temp,ac_status.set_temp*10);
- lv_label_set_text_fmt(guider_ui.screen_main_label_temp_set, "%d", (uint16_t) ac_status.set_temp);
- lvgl_port_unlock();
- ac_set_temp(true);
- }
- /**
- * 空调页面-温度减按键
- * @param e
- */
- void on_set_temp_minus(lv_event_t * e) {
- if (ac_status.set_temp>16) {
- ac_status.set_temp--;
- }else {
- }
- lvgl_port_lock(0);
- lv_arc_set_value(guider_ui.screen_main_arc_temp,ac_status.set_temp*10);
- lv_label_set_text_fmt(guider_ui.screen_main_label_temp_set, "%d", (uint16_t) ac_status.set_temp);
- lvgl_port_unlock();
- ac_set_temp(true);
- }
- /**
- * 空调页面-风速按键容器
- * @param e
- */
- void on_set_speed(lv_event_t * e) {
- lv_obj_t *cont = (lv_obj_t *) lv_event_get_current_target(e);
- lv_obj_t *act_cb = lv_event_get_target(e);
- char buf[5];
- if (act_cb == cont) return;
- lvgl_port_lock(-1);
- lv_obj_add_state(act_cb, LV_STATE_CHECKED);
- uint32_t count = lv_obj_get_child_count(cont);
- // 遍历所有子控件
- for (int i = 0; i < count; i++) {
- lv_obj_t *child = lv_obj_get_child(cont, i);
- if (child != act_cb) {
- lv_obj_remove_state(child, LV_STATE_CHECKED);
- }
- }
- lvgl_port_unlock();
- if (act_cb == guider_ui.screen_main_imgbtn_speed1) {
- ac_status.fan_speed = 1;
- }
- else if (act_cb == guider_ui.screen_main_imgbtn_speed2) {
- ac_status.fan_speed =2 ;
- } else if (act_cb == guider_ui.screen_main_imgbtn_speed3)
- { ac_status.fan_speed = 3;}
- xf_set_fan_speed(true);
- }
|