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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221
  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 "tft_lvgl_configuration.h"
  26. #if ENABLED(USE_WIFI_FUNCTION)
  27. #include "draw_ui.h"
  28. extern lv_group_t * g;
  29. static lv_obj_t *scr, *wifi_name_text, *wifi_key_text, *wifi_state_text, *wifi_ip_text;
  30. #define ID_W_RETURN 1
  31. #define ID_W_CLOUD 2
  32. #define ID_W_RECONNECT 3
  33. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  34. switch (obj->mks_obj_id) {
  35. case ID_W_RETURN:
  36. if (event == LV_EVENT_CLICKED) {
  37. }
  38. else if (event == LV_EVENT_RELEASED) {
  39. clear_cur_ui();
  40. lv_draw_set();
  41. }
  42. break;
  43. case ID_W_CLOUD:
  44. if (event == LV_EVENT_CLICKED) {
  45. }
  46. else if (event == LV_EVENT_RELEASED) {
  47. //clear_cur_ui();
  48. //draw_return_ui();
  49. }
  50. break;
  51. case ID_W_RECONNECT:
  52. if (event == LV_EVENT_CLICKED) {
  53. }
  54. else if (event == LV_EVENT_RELEASED) {
  55. clear_cur_ui();
  56. lv_draw_wifi_list();
  57. }
  58. break;
  59. }
  60. }
  61. void lv_draw_wifi(void) {
  62. lv_obj_t *buttonBack=NULL,*label_Back=NULL;
  63. lv_obj_t *buttonCloud=NULL,*label_Cloud=NULL;
  64. lv_obj_t *buttonReconnect=NULL,*label_Reconnect=NULL;
  65. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_UI) {
  66. disp_state_stack._disp_index++;
  67. disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_UI;
  68. }
  69. disp_state = WIFI_UI;
  70. scr = lv_obj_create(NULL, NULL);
  71. lv_obj_set_style(scr, &tft_style_scr);
  72. lv_scr_load(scr);
  73. lv_obj_clean(scr);
  74. lv_obj_t * title = lv_label_create(scr, NULL);
  75. lv_obj_set_style(title, &tft_style_label_rel);
  76. lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS);
  77. lv_label_set_text(title, creat_title_text());
  78. lv_refr_now(lv_refr_get_disp_refreshing());
  79. // Create an Image button
  80. buttonBack = lv_imgbtn_create(scr, NULL);
  81. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  82. //buttonCloud = lv_imgbtn_create(scr, NULL);
  83. buttonReconnect = lv_imgbtn_create(scr, NULL);
  84. }
  85. lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_W_RETURN, NULL,0);
  86. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  87. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  88. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  89. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  90. #if HAS_ROTARY_ENCODER
  91. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonBack);
  92. #endif
  93. lv_obj_set_pos(buttonBack,BTN_X_PIXEL*3+INTERVAL_V*4, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  94. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  95. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  96. lv_obj_set_event_cb_mks(buttonReconnect, event_handler,ID_W_RECONNECT, NULL,0);
  97. lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_REL, "F:/bmp_wifi.bin");
  98. lv_imgbtn_set_src(buttonReconnect, LV_BTN_STATE_PR, "F:/bmp_wifi.bin");
  99. lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_PR, &tft_style_label_pre);
  100. lv_imgbtn_set_style(buttonReconnect, LV_BTN_STATE_REL, &tft_style_label_rel);
  101. #if HAS_ROTARY_ENCODER
  102. if (gCfgItems.encoder_enable) lv_group_add_obj(g, buttonReconnect);
  103. #endif
  104. lv_obj_set_pos(buttonReconnect,BTN_X_PIXEL*2+INTERVAL_V*3, BTN_Y_PIXEL+INTERVAL_H+titleHeight);
  105. lv_btn_set_layout(buttonReconnect, LV_LAYOUT_OFF);
  106. }
  107. label_Back = lv_label_create(buttonBack, NULL);
  108. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  109. //label_Cloud = lv_label_create(buttonCloud, NULL);
  110. label_Reconnect = lv_label_create(buttonReconnect, NULL);
  111. }
  112. if (gCfgItems.multiple_language) {
  113. lv_label_set_text(label_Back, common_menu.text_back);
  114. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  115. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  116. //lv_label_set_text(label_Cloud, common_menu.text_back);
  117. //lv_obj_align(label_Cloud, buttonCloud, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  118. lv_label_set_text(label_Reconnect, wifi_menu.reconnect);
  119. lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID,0, BUTTON_TEXT_Y_OFFSET);
  120. }
  121. }
  122. wifi_ip_text = lv_label_create(scr, NULL);
  123. lv_obj_set_style(wifi_ip_text, &tft_style_label_rel);
  124. wifi_name_text = lv_label_create(scr, NULL);
  125. lv_obj_set_style(wifi_name_text, &tft_style_label_rel);
  126. wifi_key_text = lv_label_create(scr, NULL);
  127. lv_obj_set_style(wifi_key_text, &tft_style_label_rel);
  128. wifi_state_text = lv_label_create(scr, NULL);
  129. lv_obj_set_style(wifi_state_text, &tft_style_label_rel);
  130. disp_wifi_state();
  131. }
  132. void disp_wifi_state() {
  133. memset(public_buf_m, 0, sizeof(public_buf_m));
  134. strcpy(public_buf_m,wifi_menu.ip);
  135. strcat(public_buf_m,ipPara.ip_addr);
  136. lv_label_set_text(wifi_ip_text, public_buf_m);
  137. lv_obj_align(wifi_ip_text, NULL, LV_ALIGN_CENTER,0, -100);
  138. memset(public_buf_m, 0, sizeof(public_buf_m));
  139. strcpy(public_buf_m,wifi_menu.wifi);
  140. strcat(public_buf_m,wifiPara.ap_name);
  141. lv_label_set_text(wifi_name_text, public_buf_m);
  142. lv_obj_align(wifi_name_text, NULL, LV_ALIGN_CENTER,0, -70);
  143. if (wifiPara.mode == AP_MODEL) {
  144. memset(public_buf_m, 0, sizeof(public_buf_m));
  145. strcpy(public_buf_m,wifi_menu.key);
  146. strcat(public_buf_m,wifiPara.keyCode);
  147. lv_label_set_text(wifi_key_text, public_buf_m);
  148. lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -40);
  149. memset(public_buf_m, 0, sizeof(public_buf_m));
  150. strcpy(public_buf_m,wifi_menu.state_ap);
  151. if (wifi_link_state == WIFI_CONNECTED)
  152. strcat(public_buf_m,wifi_menu.connected);
  153. else if (wifi_link_state == WIFI_NOT_CONFIG)
  154. strcat(public_buf_m,wifi_menu.disconnected);
  155. else
  156. strcat(public_buf_m,wifi_menu.exception);
  157. lv_label_set_text(wifi_state_text, public_buf_m);
  158. lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -10);
  159. }
  160. else {
  161. ZERO(public_buf_m);
  162. strcpy(public_buf_m, wifi_menu.state_sta);
  163. if (wifi_link_state == WIFI_CONNECTED)
  164. strcat(public_buf_m, wifi_menu.connected);
  165. else if (wifi_link_state == WIFI_NOT_CONFIG)
  166. strcat(public_buf_m, wifi_menu.disconnected);
  167. else
  168. strcat(public_buf_m, wifi_menu.exception);
  169. lv_label_set_text(wifi_state_text, public_buf_m);
  170. lv_obj_align(wifi_state_text, NULL, LV_ALIGN_CENTER,0, -40);
  171. lv_label_set_text(wifi_key_text, "");
  172. lv_obj_align(wifi_key_text, NULL, LV_ALIGN_CENTER,0, -10);
  173. }
  174. }
  175. void lv_clear_wifi() {
  176. #if HAS_ROTARY_ENCODER
  177. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  178. #endif
  179. lv_obj_del(scr);
  180. }
  181. #endif // USE_WIFI_FUNCTION
  182. #endif // HAS_TFT_LVGL_UI