My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

draw_wifi.cpp 7.3KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (c) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if HAS_TFT_LVGL_UI
  24. #include "lv_conf.h"
  25. #include "draw_ui.h"
  26. #if ENABLED(USE_WIFI_FUNCTION)
  27. #include "../../../../../Configuration.h"
  28. #include "../../../../module/temperature.h"
  29. extern lv_group_t * g;
  30. static lv_obj_t *scr, *wifi_name_text, *wifi_key_text, *wifi_state_text, *wifi_ip_text;
  31. #define ID_W_RETURN 1
  32. #define ID_W_CLOUD 2
  33. #define ID_W_RECONNECT 3
  34. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  35. switch (obj->mks_obj_id) {
  36. case ID_W_RETURN:
  37. if (event == LV_EVENT_CLICKED) {
  38. }
  39. else if (event == LV_EVENT_RELEASED) {
  40. clear_cur_ui();
  41. lv_draw_set();
  42. }
  43. break;
  44. case ID_W_CLOUD:
  45. if (event == LV_EVENT_CLICKED) {
  46. }
  47. else if (event == LV_EVENT_RELEASED) {
  48. //clear_cur_ui();
  49. //draw_return_ui();
  50. }
  51. break;
  52. case ID_W_RECONNECT:
  53. if (event == LV_EVENT_CLICKED) {
  54. }
  55. else if (event == LV_EVENT_RELEASED) {
  56. clear_cur_ui();
  57. lv_draw_wifi_list();
  58. }
  59. break;
  60. }
  61. }
  62. void lv_draw_wifi(void) {
  63. lv_obj_t *buttonBack=NULL,*label_Back=NULL;
  64. lv_obj_t *buttonCloud=NULL,*label_Cloud=NULL;
  65. lv_obj_t *buttonReconnect=NULL,*label_Reconnect=NULL;
  66. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_UI) {
  67. disp_state_stack._disp_index++;
  68. disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_UI;
  69. }
  70. disp_state = WIFI_UI;
  71. scr = lv_obj_create(NULL, NULL);
  72. lv_obj_set_style(scr, &tft_style_scr);
  73. lv_scr_load(scr);
  74. lv_obj_clean(scr);
  75. lv_obj_t * title = lv_label_create(scr, NULL);
  76. lv_obj_set_style(title, &tft_style_label_rel);
  77. lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS);
  78. lv_label_set_text(title, creat_title_text());
  79. lv_refr_now(lv_refr_get_disp_refreshing());
  80. // Create an Image button
  81. buttonBack = lv_imgbtn_create(scr, NULL);
  82. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  83. //buttonCloud = lv_imgbtn_create(scr, NULL);
  84. buttonReconnect = lv_imgbtn_create(scr, NULL);
  85. }
  86. lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_W_RETURN, NULL,0);
  87. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  88. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  89. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  90. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  91. #if HAS_ROTARY_ENCODER
  92. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  93. #endif
  94. lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  95. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  96. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  97. lv_obj_set_event_cb_mks(buttonReconnect, event_handler,ID_W_RECONNECT, NULL,0);
  98. lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_REL, "F:/bmp_wifi.bin");
  99. lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_PR, "F:/bmp_wifi.bin");
  100. lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_PR, &tft_style_label_pre);
  101. lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_REL, &tft_style_label_rel);
  102. #if HAS_ROTARY_ENCODER
  103. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonReconnect);
  104. #endif
  105. lv_obj_set_pos(buttonReconnect,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  106. lv_btn_set_layout(buttonReconnect, LV_LAYOUT_OFF);
  107. }
  108. label_Back = lv_label_create(buttonBack, NULL);
  109. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  110. //label_Cloud = lv_label_create(buttonCloud, NULL);
  111. label_Reconnect = lv_label_create(buttonReconnect, NULL);
  112. }
  113. if (gCfgItems.multiple_language !=0) {
  114. lv_label_set_text(label_Back, common_menu.text_back);
  115. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  116. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  117. //lv_label_set_text(label_Cloud, common_menu.text_back);
  118. //lv_obj_align(label_Cloud, buttonCloud, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  119. lv_label_set_text(label_Reconnect, wifi_menu.reconnect);
  120. lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  121. }
  122. }
  123. wifi_ip_text = lv_label_create(scr, NULL);
  124. lv_obj_set_style(wifi_ip_text, &tft_style_label_rel);
  125. wifi_name_text = lv_label_create(scr, NULL);
  126. lv_obj_set_style(wifi_name_text, &tft_style_label_rel);
  127. wifi_key_text = lv_label_create(scr, NULL);
  128. lv_obj_set_style(wifi_key_text, &tft_style_label_rel);
  129. wifi_state_text = lv_label_create(scr, NULL);
  130. lv_obj_set_style(wifi_state_text, &tft_style_label_rel);
  131. disp_wifi_state();
  132. }
  133. void disp_wifi_state() {
  134. memset(public_buf_m, 0, sizeof(public_buf_m));
  135. strcpy(public_buf_m,wifi_menu.ip);
  136. strcat(public_buf_m,ipPara.ip_addr);
  137. lv_label_set_text(wifi_ip_text, public_buf_m);
  138. lv_obj_align(wifi_ip_text, NULL, LV_ALIGN_CENTER,0, -100);
  139. memset(public_buf_m, 0, sizeof(public_buf_m));
  140. strcpy(public_buf_m,wifi_menu.wifi);
  141. strcat(public_buf_m,wifiPara.ap_name);
  142. lv_label_set_text(wifi_name_text, public_buf_m);
  143. lv_obj_align(wifi_name_text, NULL, LV_ALIGN_CENTER,0, -70);
  144. if (wifiPara.mode == AP_MODEL) {
  145. memset(public_buf_m, 0, sizeof(public_buf_m));
  146. strcpy(public_buf_m,wifi_menu.key);
  147. strcat(public_buf_m,wifiPara.keyCode);
  148. lv_label_set_text(wifi_key_text, public_buf_m);
  149. lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -40);
  150. memset(public_buf_m, 0, sizeof(public_buf_m));
  151. strcpy(public_buf_m,wifi_menu.state_ap);
  152. if (wifi_link_state == WIFI_CONNECTED)
  153. strcat(public_buf_m,wifi_menu.connected);
  154. else if (wifi_link_state == WIFI_NOT_CONFIG)
  155. strcat(public_buf_m,wifi_menu.disconnected);
  156. else
  157. strcat(public_buf_m,wifi_menu.exception);
  158. lv_label_set_text(wifi_state_text, public_buf_m);
  159. lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -10);
  160. }
  161. else {
  162. ZERO(public_buf_m);
  163. strcpy(public_buf_m, wifi_menu.state_sta);
  164. if (wifi_link_state == WIFI_CONNECTED)
  165. strcat(public_buf_m, wifi_menu.connected);
  166. else if (wifi_link_state == WIFI_NOT_CONFIG)
  167. strcat(public_buf_m, wifi_menu.disconnected);
  168. else
  169. strcat(public_buf_m, wifi_menu.exception);
  170. lv_label_set_text(wifi_state_text, public_buf_m);
  171. lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -40);
  172. lv_label_set_text(wifi_key_text, "");
  173. lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -10);
  174. }
  175. }
  176. void lv_clear_wifi() {
  177. #if HAS_ROTARY_ENCODER
  178. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  179. #endif
  180. lv_obj_del(scr);
  181. }
  182. #endif // USE_WIFI_FUNCTION
  183. #endif // HAS_TFT_LVGL_UI