actions.c 22 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591
  1. /**
  2. * @Author: 李建
  3. * @Date: 2025/3/18 11:34
  4. * Description: 定义了UI 与 逻辑的交互
  5. * Copyright: Copyright (©) 2025 永续绿建. All rights reserved.
  6. */
  7. #include <esp_log.h>
  8. #include <string.h>
  9. #include <nvs_flash.h>
  10. #include <esp_app_desc.h>
  11. #include "misc/lv_types.h"
  12. #include "widgets/tabview/lv_tabview.h"
  13. #include "gui_guider.h"
  14. #include "main.h"
  15. #include "wifi.h"
  16. #include "actions.h"
  17. #include "xf_controller.h"
  18. #include "lvgl_port.h"
  19. #include "modbus_master.h"
  20. #include "system/miscellaneous_interface.h"
  21. LV_IMAGE_DECLARE(_orange_meter_RGB565A8_84x396);
  22. LV_IMAGE_DECLARE(_green_meter_RGB565A8_84x396);
  23. LV_IMAGE_DECLARE(_power_open_RGB565A8_36x36);
  24. LV_IMAGE_DECLARE(_nxh_off_RGB565A8_80x80);
  25. LV_IMAGE_DECLARE(_js_on_RGB565A8_80x80);
  26. LV_IMAGE_DECLARE(_auto_on_RGB565A8_80x80);
  27. LV_IMAGE_DECLARE(_xf_on_RGB565A8_80x80);
  28. const static char *TAG = "actions";
  29. extern void set_xf_mode(lv_ui *ui, uint16_t mode);
  30. //
  31. /**
  32. * 点击管理密码登录按钮事件
  33. * @param e
  34. */
  35. void on_btn_check_manager_password(lv_event_t *e) {
  36. const char *password = lv_textarea_get_text(guider_ui.SettingPage_ta_1);
  37. if (strcmp(password, "0803") != 0) {
  38. // 显示密码错误标签
  39. lv_obj_remove_flag(guider_ui.SettingPage_lab_password_incorrect, LV_OBJ_FLAG_HIDDEN);
  40. } else {
  41. // 验证通过
  42. lv_obj_add_flag(guider_ui.SettingPage_lab_password_incorrect, LV_OBJ_FLAG_HIDDEN);
  43. // 隐藏密码输入 panel
  44. lv_obj_add_flag(guider_ui.SettingPage_cont_1, LV_OBJ_FLAG_HIDDEN);
  45. // 显示高级设置界面
  46. guider_ui.SettingPage_del = true;
  47. ui_load_scr_animation(&guider_ui, &guider_ui.FactorySettingPage, true,
  48. &guider_ui.SettingPage_del, setup_scr_FactorySettingPage,
  49. LV_SCR_LOAD_ANIM_MOVE_RIGHT, 200, 200, true, true);
  50. }
  51. }
  52. //void on_ac_page_set_power(lv_event_t *e) {
  53. // lv_obj_t *obj = lv_event_get_current_target(e);
  54. // if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
  55. // ac_status.power = 1;
  56. // } else {
  57. // ac_status.power = 0;
  58. // }
  59. // ac_set_power(false);
  60. //}
  61. /**
  62. * 点击设置-开关机按钮事件
  63. * @param e
  64. */
  65. void on_btn_power_click(lv_event_t *e) {
  66. lv_obj_t *obj = lv_event_get_current_target(e);
  67. if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
  68. xf_status.power = 1;
  69. } else {
  70. xf_status.power = 0;
  71. }
  72. xf_set_power(true);
  73. }
  74. /**
  75. * 滑块风挡值变化
  76. * @param e
  77. */
  78. void on_slider_speed_value_changed(lv_event_t *e) {
  79. int32_t value=lv_slider_get_value(guider_ui.screen_main_slider_speedSet_sign);
  80. if(value<=20)
  81. {
  82. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "1档");
  83. }else if(value<=40)
  84. {
  85. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "2档");
  86. }else if(value<=60)
  87. {
  88. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "3档");
  89. }else if(value<=80)
  90. {
  91. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "4档");
  92. }else if(value<=100)
  93. {
  94. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "5档");
  95. }else{
  96. }
  97. }
  98. /**
  99. * 滑块风挡释放
  100. * @param e
  101. */
  102. void on_slider_speed_released(lv_event_t *e) {
  103. int32_t value=lv_slider_get_value(guider_ui.screen_main_slider_speedSet_sign);
  104. lvgl_port_lock(-1);
  105. if(value<=20)
  106. {
  107. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "1档");
  108. lv_slider_set_value(guider_ui.screen_main_slider_speedSet_sign,20,LV_ANIM_OFF);
  109. xf_status.fan_speed=1;
  110. }else if(value<=40)
  111. {
  112. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "2档");
  113. lv_slider_set_value(guider_ui.screen_main_slider_speedSet_sign,40,LV_ANIM_OFF);
  114. xf_status.fan_speed=2;
  115. }else if(value<=60)
  116. {
  117. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "3档");
  118. lv_slider_set_value(guider_ui.screen_main_slider_speedSet_sign,60,LV_ANIM_OFF);
  119. xf_status.fan_speed=3;
  120. }else if(value<=80)
  121. {
  122. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "4档");
  123. lv_slider_set_value(guider_ui.screen_main_slider_speedSet_sign,80,LV_ANIM_OFF);
  124. xf_status.fan_speed=4;
  125. }else if(value<=100)
  126. {
  127. lv_label_set_text_static(guider_ui.screen_main_label_spedSet_vul, "5档");
  128. lv_slider_set_value(guider_ui.screen_main_slider_speedSet_sign,100,LV_ANIM_OFF);
  129. xf_status.fan_speed=5;
  130. }else{
  131. }
  132. xf_set_fan_speed(true);
  133. lvgl_port_unlock();
  134. // xf_set_fan_speed(true);
  135. // mm_set_param(CID_FAN_SPEED, (uint8_t *)&xf_status.fan_speed);
  136. }
  137. /**
  138. * 滑块最大湿度值变化
  139. * @param e
  140. */
  141. void on_slider_hum_value_changed(lv_event_t *e) {
  142. int32_t value=lv_slider_get_value(guider_ui.screen_main_slider_humSet_sign);
  143. if(value>100)
  144. {
  145. value=100;
  146. }else if(value<=system_setting.set_min_hum)
  147. {
  148. value=system_setting.set_min_hum;
  149. }
  150. lvgl_port_lock(-1);
  151. lv_label_set_text_fmt(guider_ui.screen_main_label_humSet_vul, "%ld%%",value);
  152. lvgl_port_unlock();
  153. }
  154. /**
  155. * 滑块最大湿度值释放
  156. * @param e
  157. */
  158. void on_slider_hum_released(lv_event_t *e) {
  159. int32_t value=lv_slider_get_value(guider_ui.screen_main_slider_humSet_sign);
  160. if(value>100)
  161. {
  162. value=100;
  163. }else if(value<=system_setting.set_min_hum)
  164. {
  165. value=system_setting.set_min_hum;
  166. }
  167. lvgl_port_lock(-1);
  168. lv_slider_set_value(guider_ui.screen_main_slider_humSet_sign,value,LV_ANIM_OFF);
  169. lv_label_set_text_fmt(guider_ui.screen_main_label_humSet_vul, "%ld%%",value);
  170. lvgl_port_unlock();
  171. xf_status.set_max_hum=value;
  172. xf_set_max_hum(true);
  173. }
  174. /**
  175. * 点击设置-网络-查找网络按钮事件
  176. * @param e
  177. */
  178. void on_btn_scan_wifi_click(lv_event_t *e) {
  179. lv_obj_clean(guider_ui.SettingPage_list_wifi);
  180. app_wifi_scan();
  181. }
  182. /**
  183. * 点击连接 wifi 按钮
  184. * @param e
  185. */
  186. void on_btn_connect_wifi(lv_event_t *e) {
  187. app_connect_wifi();
  188. }
  189. /**
  190. * 切换至主页面
  191. * @param e
  192. */
  193. void switch_screen_main_set(lv_event_t *e) {
  194. lv_ui * ui = lv_event_get_user_data(e);
  195. // 设置温度及滑动和风速状态
  196. lvgl_port_lock(-1);
  197. lv_label_set_text_fmt(ui->screen_main_label_humSet_vul, "%d%%", xf_status.set_max_hum);
  198. lv_slider_set_value(ui->screen_main_slider_speedSet_sign, xf_status.fan_speed*20, LV_ANIM_ON);
  199. lv_label_set_text_fmt(ui->screen_main_label_spedSet_vul, "%d档",xf_status.fan_speed);
  200. lv_slider_set_value(ui->screen_main_slider_humSet_sign, xf_status.set_max_hum, LV_ANIM_ON);
  201. set_xf_mode(ui, xf_status.mode);
  202. xf_set_power(true);
  203. // 设置电源状态
  204. lv_obj_add_state(ui->screen_main_imgbtn_power, xf_status.power == 1 ? LV_STATE_CHECKED : LV_STATE_DEFAULT);
  205. lvgl_port_unlock();
  206. }
  207. /**
  208. * 切换至设置页面
  209. * @param e
  210. */
  211. void switch_setting_page_set(lv_event_t *e) {
  212. lv_ui * ui = lv_event_get_user_data(e);
  213. lvgl_port_lock(-1);
  214. if(system_setting.sound_on_off)
  215. lv_obj_add_state(ui->SettingPage_sw_sound, LV_STATE_CHECKED);
  216. else
  217. lv_obj_remove_state(ui->SettingPage_sw_sound, LV_STATE_CHECKED);
  218. if(system_setting.screen_auto_off)
  219. lv_obj_add_state(ui->SettingPage_sw_1, LV_STATE_CHECKED);
  220. else
  221. lv_obj_remove_state(ui->SettingPage_sw_1, LV_STATE_CHECKED);
  222. lv_slider_set_value(ui->SettingPage_slider_sound_level, system_setting.sound_volume, false);
  223. lv_spinbox_set_value(ui->SettingPage_spinbox_2,system_setting.screen_off_minute);
  224. lvgl_port_unlock();
  225. }
  226. /**
  227. * 切换至高级设置页面
  228. * @param e
  229. */
  230. void switch_factory_setting_page_set(lv_event_t *e) {
  231. char str[32]={0};
  232. int index=0;
  233. lv_ui * ui = lv_event_get_user_data(e);
  234. lvgl_port_lock(-1);
  235. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply1_vol, system_setting.supply_first_vol);
  236. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply2_vol, system_setting.supply_second_vol);
  237. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply3_vol, system_setting.supply_third_vol);
  238. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply4_vol, system_setting.supply_fourth_vol);
  239. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply5_vol, system_setting.supply_fifth_vol);
  240. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust1_vol, system_setting.exhaust_first_vol);
  241. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust2_vol, system_setting.exhaust_second_vol);
  242. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust3_vol, system_setting.exhaust_third_vol);
  243. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust4_vol, system_setting.exhaust_fourth_vol);
  244. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust5_vol, system_setting.exhaust_fifth_vol);
  245. if(xf_status.error_code==0)
  246. {
  247. lv_label_set_text_static(ui->FactorySettingPage_label_detail_error, "NONE");
  248. } else{
  249. index=0;
  250. for(int i=0;i<8;i++)
  251. {
  252. if(xf_status.error_code&(1<<i))
  253. {
  254. str[index++]='E';
  255. str[index++]='0'+i;
  256. str[index++]='\n';
  257. }
  258. }
  259. str[index++]=0;
  260. lv_label_set_text(ui->FactorySettingPage_label_detail_error, str);
  261. }
  262. lvgl_port_unlock();
  263. }
  264. /**
  265. * 重置滤网剩余寿命
  266. * @param e
  267. */
  268. void on_btn_filter_life_remain_clear(lv_event_t *e) {
  269. xf_status.filter_used_time=0;
  270. xf_status.filter_life_remaining=100;
  271. xf_set_filter_life_remain(true);
  272. }
  273. void on_fan_vol_refresh(lv_event_t *e)
  274. {
  275. lv_ui * ui = lv_event_get_user_data(e);
  276. esp_err_t err = mm_get_param(CID_AIR_EXHAUST_FIRST_VOL, (uint8_t *)&system_setting.exhaust_first_vol);
  277. mm_get_param(CID_AIR_EXHAUST_SECOND_VOL, (uint8_t *)&system_setting.exhaust_second_vol);
  278. mm_get_param(CID_AIR_EXHAUST_THIRD_VOL, (uint8_t *)&system_setting.exhaust_third_vol);
  279. mm_get_param(CID_AIR_EXHAUST_FOURTH_VOL, (uint8_t *)&system_setting.exhaust_fourth_vol);
  280. mm_get_param(CID_AIR_EXHAUST_FIFTH_VOL, (uint8_t *)&system_setting.exhaust_fifth_vol);
  281. mm_get_param(CID_AIR_SUPPLY_FIRST_VOL, (uint8_t *)&system_setting.supply_first_vol);
  282. mm_get_param(CID_AIR_SUPPLY_SECOND_VOL, (uint8_t *)&system_setting.supply_second_vol);
  283. mm_get_param(CID_AIR_SUPPLY_THIRD_VOL, (uint8_t *)&system_setting.supply_third_vol);
  284. mm_get_param(CID_AIR_SUPPLY_FOURTH_VOL, (uint8_t *)&system_setting.supply_fourth_vol);
  285. mm_get_param(CID_AIR_SUPPLY_FIFTH_VOL, (uint8_t *)&system_setting.supply_fifth_vol);
  286. lvgl_port_lock(-1);
  287. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply1_vol, system_setting.supply_first_vol);
  288. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply2_vol, system_setting.supply_second_vol);
  289. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply3_vol, system_setting.supply_third_vol);
  290. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply4_vol, system_setting.supply_fourth_vol);
  291. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_supply5_vol, system_setting.supply_fifth_vol);
  292. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust1_vol, system_setting.exhaust_first_vol);
  293. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust2_vol, system_setting.exhaust_second_vol);
  294. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust3_vol, system_setting.exhaust_third_vol);
  295. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust4_vol, system_setting.exhaust_fourth_vol);
  296. lv_spinbox_set_value(ui->FactorySettingPage_spinbox_exhaust5_vol, system_setting.exhaust_fifth_vol);
  297. lvgl_port_unlock();
  298. }
  299. void on_fan_vol_save(lv_event_t *e) {
  300. lv_ui * ui = lv_event_get_user_data(e);
  301. system_setting.exhaust_first_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_exhaust1_vol);
  302. system_setting.exhaust_second_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_exhaust2_vol);
  303. system_setting.exhaust_third_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_exhaust3_vol);
  304. system_setting.exhaust_fourth_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_exhaust4_vol);
  305. system_setting.exhaust_fifth_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_exhaust5_vol);
  306. system_setting.supply_first_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_supply1_vol);
  307. system_setting.supply_second_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_supply2_vol);
  308. system_setting.supply_third_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_supply3_vol);
  309. system_setting.supply_fourth_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_supply4_vol);
  310. system_setting.supply_fifth_vol=lv_spinbox_get_value(ui->FactorySettingPage_spinbox_supply5_vol);
  311. // ESP_LOGE(TAG, "exhaust_first_vol;%d", (uint8_t) system_setting.exhaust_first_vol);
  312. mm_set_param(CID_AIR_EXHAUST_FIRST_VOL, (uint8_t *)&system_setting.exhaust_first_vol);
  313. vTaskDelay(pdTICKS_TO_MS(100));
  314. mm_set_param(CID_AIR_EXHAUST_SECOND_VOL, (uint8_t *)&system_setting.exhaust_second_vol);
  315. vTaskDelay(pdTICKS_TO_MS(100));
  316. mm_set_param(CID_AIR_EXHAUST_THIRD_VOL, (uint8_t *)&system_setting.exhaust_third_vol);
  317. vTaskDelay(pdTICKS_TO_MS(100));
  318. mm_set_param(CID_AIR_EXHAUST_FOURTH_VOL, (uint8_t *)&system_setting.exhaust_fourth_vol);
  319. vTaskDelay(pdTICKS_TO_MS(100));
  320. mm_set_param(CID_AIR_EXHAUST_FIFTH_VOL, (uint8_t *)&system_setting.exhaust_fifth_vol);
  321. vTaskDelay(pdTICKS_TO_MS(100));
  322. mm_set_param(CID_AIR_SUPPLY_FIRST_VOL, (uint8_t *)&system_setting.supply_first_vol);
  323. vTaskDelay(pdTICKS_TO_MS(100));
  324. mm_set_param(CID_AIR_SUPPLY_SECOND_VOL, (uint8_t *)&system_setting.supply_second_vol);
  325. vTaskDelay(pdTICKS_TO_MS(100));
  326. mm_set_param(CID_AIR_SUPPLY_THIRD_VOL, (uint8_t *)&system_setting.supply_third_vol);
  327. vTaskDelay(pdTICKS_TO_MS(100));
  328. mm_set_param(CID_AIR_SUPPLY_FOURTH_VOL, (uint8_t *)&system_setting.supply_fourth_vol);
  329. vTaskDelay(pdTICKS_TO_MS(100));
  330. mm_set_param(CID_AIR_SUPPLY_FIFTH_VOL, (uint8_t *)&system_setting.supply_fifth_vol);
  331. vTaskDelay(pdTICKS_TO_MS(100));
  332. save_system_setting(&system_setting);
  333. }
  334. // 设置界面切换顶部tab按钮时的事件
  335. void on_setting_tabview_changed(lv_event_t *e) {
  336. // uint32_t index = lv_tabview_get_tab_active(guider_ui.SettingPage_tabview_1);
  337. // switch (index) {
  338. // case 0: // 参数设置
  339. // break;
  340. // case 1: // 网络设置
  341. // //app_wifi_scan();
  342. // break;
  343. // case 2:
  344. // default:
  345. // break;
  346. // }
  347. }
  348. //
  349. ///**
  350. // * 高级配置-五恒模块选中事件
  351. // * @param e
  352. // */
  353. //void on_set_five_const_module(lv_event_t *e) {
  354. // lv_obj_t *cont = (lv_obj_t *) lv_event_get_current_target(e);
  355. // lv_obj_t *act_cb = lv_event_get_target(e);
  356. // if (act_cb == cont) return;
  357. // lv_obj_add_state(act_cb, LV_STATE_CHECKED);
  358. // uint32_t count = lv_obj_get_child_count(cont);
  359. // // 遍历所有子控件
  360. // for (int i = 0; i < count; i++) {
  361. // lv_obj_t *child = lv_obj_get_child(cont, i);
  362. // if (child != act_cb) {
  363. // lv_obj_remove_state(child, LV_STATE_CHECKED);
  364. // }
  365. // }
  366. // // TODO:修改本地配置
  367. //}
  368. //
  369. ///**
  370. // * 高级配置-设备风阀与分控对应关系
  371. // * @param e
  372. // * @param valve_index
  373. // */
  374. //void on_set_fan_valve(lv_event_t *e, uint8_t valve_index) {
  375. // lv_obj_t *cont = (lv_obj_t *) lv_event_get_current_target(e);
  376. // lv_obj_t *act_cb = lv_event_get_target(e);
  377. // if (act_cb == cont) return;
  378. // lv_obj_add_state(act_cb, LV_STATE_CHECKED);
  379. // uint32_t count = lv_obj_get_child_count(cont);
  380. // // 遍历所有子控件
  381. // for (int i = 0; i < count; i++) {
  382. // lv_obj_t *child = lv_obj_get_child(cont, i);
  383. // if (child != act_cb) {
  384. // lv_obj_remove_state(child, LV_STATE_CHECKED);
  385. // }
  386. // }
  387. // // TODO: 修改风阀对应配置
  388. //}
  389. /**
  390. * 高级配置-恢复出厂设置按钮事件
  391. * @param e
  392. */
  393. void on_reset_factory_setting(lv_event_t *e) {
  394. // 清空nvs
  395. nvs_flash_erase();
  396. // 重启设备
  397. esp_restart();
  398. }
  399. //
  400. //void on_ac_page_arc_value_changed(lv_event_t *e) {
  401. // lv_obj_t *arc = lv_event_get_current_target(e);
  402. // int32_t value = lv_arc_get_value(arc);
  403. // lvgl_port_lock(0);
  404. // lv_label_set_text_fmt(guider_ui.ACPage_lab_ac_temp, "%d", (uint16_t) value);
  405. // lvgl_port_unlock();
  406. //}
  407. //
  408. //void on_ac_page_arc_released(lv_event_t *e) {
  409. // lv_obj_t *arc = lv_event_get_current_target(e);
  410. // int32_t value = lv_arc_get_value(arc);
  411. // ac_status.set_temp = (uint16_t) value;
  412. // ac_set_temp(true);
  413. //}
  414. //
  415. //void on_set_inner_addr(uint8_t num) {
  416. // if (num)
  417. // addr += 1;
  418. // else
  419. // addr -= 1;
  420. // if (addr + num > 255)
  421. // addr = 254;
  422. // if (addr + num < 1)
  423. // addr = 1;
  424. // lvgl_port_lock(0);
  425. // lv_label_set_text_fmt(guider_ui.FactorySettingPage_lab_inner_addr, "%d", addr);
  426. // lvgl_port_unlock();
  427. // // 保存到 nvs
  428. // save_inner_addr(addr);
  429. //}
  430. //
  431. void on_set_xf_mode(lv_event_t *e) {
  432. lv_obj_t *cont = (lv_obj_t *) lv_event_get_current_target(e);
  433. lv_obj_t *act_cb = lv_event_get_target(e);
  434. if (act_cb == cont) return;
  435. lvgl_port_lock(-1);
  436. lv_obj_add_state(act_cb, LV_STATE_CHECKED);
  437. uint32_t count = lv_obj_get_child_count(cont);
  438. // 遍历所有子控件
  439. for (int i = 0; i < count; i++) {
  440. lv_obj_t *child = lv_obj_get_child(cont, i);
  441. if (child != act_cb) {
  442. lv_obj_remove_state(child, LV_STATE_CHECKED);
  443. }
  444. }
  445. lvgl_port_unlock();
  446. if (act_cb == guider_ui.screen_main_imgbtn_nxh) {
  447. xf_status.mode = NXH;
  448. } else if (act_cb == guider_ui.screen_main_imgbtn_js) {
  449. xf_status.mode = JS;
  450. } else if (act_cb == guider_ui.screen_main_imgbtn_xf) {
  451. xf_status.mode = XF;
  452. } else if (act_cb == guider_ui.screen_main_imgbtn_auto)
  453. xf_status.mode = AUTO;
  454. xf_set_mode(true);
  455. }
  456. //
  457. //void on_set_ac_wind_speed(lv_event_t *e) {
  458. // lv_obj_t *slider = (lv_obj_t *) lv_event_get_current_target(e);
  459. // int32_t value = lv_slider_get_value(slider);
  460. // // 设置风速文本
  461. // lvgl_port_lock(0);
  462. // lv_label_set_text_static(guider_ui.ACPage_lab_fan_speed, speed_str[value - 1]);
  463. // lvgl_port_unlock();
  464. //}
  465. //
  466. //void on_ac_set_fan_speed_released(lv_event_t *e) {
  467. // lv_obj_t *slider = (lv_obj_t *) lv_event_get_current_target(e);
  468. // int32_t value = lv_slider_get_value(slider);
  469. // ac_status.wind_speed = (uint16_t) value;
  470. // ac_set_wind_speed(true);
  471. //}
  472. //
  473. //void on_fan_valve_value_changed(lv_event_t *e) {
  474. // uint8_t *valve_index = lv_event_get_user_data(e);
  475. // lv_obj_t *slider = (lv_obj_t *) lv_event_get_current_target(e);
  476. // int32_t value = lv_slider_get_value(slider);
  477. // ac_set_fan_valve(*valve_index, value);
  478. // ESP_LOGD(TAG, "on_fan_valve_value_changed:%d", *valve_index);
  479. //}
  480. //
  481. //void on_set_fan_valve_no_changed(lv_event_t *e) {
  482. // fan_valve_set_param_t *param = lv_event_get_user_data(e);
  483. // ESP_LOGD(TAG, "%d-%d", param->ctrl_no, param->fan_valve_no);
  484. // lv_obj_t *obj = lv_event_get_current_target(e);
  485. // uint8_t v = lv_obj_has_state(obj, LV_STATE_CHECKED) ? 1 : 0;
  486. // save_fan_valve_setting(&system_setting, param->ctrl_no, param->fan_valve_no - 1, v);
  487. //}
  488. //
  489. //void on_ac_page_set_power(lv_event_t *e) {
  490. // lv_obj_t *obj = lv_event_get_current_target(e);
  491. // if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
  492. // ac_status.power = 1;
  493. // } else {
  494. // ac_status.power = 0;
  495. // }
  496. // ac_set_power(false);
  497. //}
  498. //
  499. void on_set_beep_on_off(lv_event_t * e) {
  500. lv_obj_t *obj = lv_event_get_current_target(e);
  501. if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
  502. system_setting.sound_on_off = 1;
  503. } else {
  504. system_setting.sound_on_off = 0;
  505. }
  506. save_system_setting(&system_setting);
  507. }
  508. void on_set_screen_auto_off(lv_event_t * e) {
  509. lv_obj_t *obj = lv_event_get_current_target(e);
  510. if (lv_obj_has_state(obj, LV_STATE_CHECKED)) {
  511. system_setting.screen_auto_off = 1;
  512. } else {
  513. system_setting.screen_auto_off = 0;
  514. }
  515. save_system_setting(&system_setting);
  516. }
  517. void on_set_beep_volume(lv_event_t* e) {
  518. const lv_obj_t *slider = lv_event_get_current_target(e);
  519. uint32_t value = lv_slider_get_value(slider);
  520. ESP_LOGD(TAG, "on_set_beep_volume;%d", (uint8_t) value);
  521. system_setting.sound_volume = (uint8_t) value;
  522. save_system_setting(&system_setting);
  523. }
  524. void on_set_screen_off_minute(lv_event_t * e) {
  525. lv_obj_t *spbox = lv_event_get_current_target(e);
  526. int32_t value = lv_spinbox_get_value(spbox);
  527. ESP_LOGD(TAG, "on_set_screen_off_minute;%d", (uint8_t) value);
  528. system_setting.screen_off_minute = (uint8_t) value;
  529. save_system_setting(&system_setting);
  530. }
  531. void setting_page_init(lv_ui *ui) {
  532. static lv_style_t style_SettingPage_tabview_1_extra_btnm_items_default;
  533. ui_init_style(&style_SettingPage_tabview_1_extra_btnm_items_default);
  534. lv_style_set_text_color(&style_SettingPage_tabview_1_extra_btnm_items_default, lv_color_hex(0xffb204));
  535. lv_style_set_text_font(&style_SettingPage_tabview_1_extra_btnm_items_default, &lv_font_Alibaba_PuHuiTi_Medium_16);
  536. lv_style_set_text_opa(&style_SettingPage_tabview_1_extra_btnm_items_default, 255);
  537. lv_obj_add_style(lv_tabview_get_tab_bar(ui->SettingPage_tabview_1),
  538. &style_SettingPage_tabview_1_extra_btnm_items_default, LV_PART_MAIN | LV_STATE_DEFAULT);
  539. lv_label_set_text(ui->SettingPage_lab_wifi_status, get_wifi_status() == 1 ? "已连接" : "未连接");
  540. // 填充“关于”页面信息
  541. esp_app_desc_t * desc = esp_app_get_description();
  542. lv_label_set_text(ui->SettingPage_lab_version, desc->version);
  543. char device_serial[12];
  544. get_device_serial(device_serial);
  545. lv_qrcode_update(ui->SettingPage_qr_device_code, device_serial, 12);
  546. }
  547. void on_ota_failed_restart(lv_event_t *e) {
  548. esp_restart();
  549. }
  550. void on_reset_wifi(lv_event_t *e) {
  551. yx_data_clear(NVS_SSID_KEY);
  552. yx_data_clear(NVS_PASSWORD_KEY);
  553. esp_restart();
  554. }
  555. void on_restart_device(lv_event_t *e) {
  556. esp_restart();
  557. }