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_list.cpp 7.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235
  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. #define NAME_BTN_X 330
  30. #define NAME_BTN_Y 48
  31. #define MARK_BTN_X 0
  32. #define MARK_BTN_Y 68
  33. WIFI_LIST wifi_list;
  34. list_menu_def list_menu;
  35. extern lv_group_t * g;
  36. static lv_obj_t * scr;
  37. static lv_obj_t *buttonWifiN[NUMBER_OF_PAGE];
  38. static lv_obj_t *lableWifiText[NUMBER_OF_PAGE];
  39. static lv_obj_t *lablePageText;
  40. #define ID_WL_RETURN 11
  41. #define ID_WL_DOWN 12
  42. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  43. if (obj->mks_obj_id == ID_WL_RETURN) {
  44. if (event == LV_EVENT_CLICKED) {
  45. }
  46. else if (event == LV_EVENT_RELEASED) {
  47. clear_cur_ui();
  48. lv_draw_set();
  49. }
  50. }
  51. else if (obj->mks_obj_id == ID_WL_DOWN) {
  52. if (event == LV_EVENT_CLICKED) {
  53. }
  54. else if (event == LV_EVENT_RELEASED) {
  55. if (wifi_list.getNameNum > 0) {
  56. if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) {
  57. wifi_list.nameIndex = 0;
  58. wifi_list.currentWifipage = 1;
  59. }
  60. else {
  61. wifi_list.nameIndex += NUMBER_OF_PAGE;
  62. wifi_list.currentWifipage++;
  63. }
  64. disp_wifi_list();
  65. }
  66. }
  67. }
  68. else {
  69. for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) {
  70. if (obj->mks_obj_id == i + 1) {
  71. if (event == LV_EVENT_CLICKED) {
  72. }
  73. else if (event == LV_EVENT_RELEASED) {
  74. if (wifi_list.getNameNum != 0) {
  75. const bool do_wifi = wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[wifi_list.nameIndex + i]) == 0;
  76. wifi_list.nameIndex += i;
  77. last_disp_state = WIFI_LIST_UI;
  78. lv_clear_wifi_list();
  79. if (do_wifi)
  80. lv_draw_wifi();
  81. else {
  82. keyboard_value = wifiConfig;
  83. lv_draw_keyboard();
  84. }
  85. }
  86. }
  87. }
  88. }
  89. }
  90. }
  91. void lv_draw_wifi_list(void) {
  92. lv_obj_t *buttonBack = NULL, *buttonDown = NULL;
  93. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != WIFI_LIST_UI) {
  94. disp_state_stack._disp_index++;
  95. disp_state_stack._disp_state[disp_state_stack._disp_index] = WIFI_LIST_UI;
  96. }
  97. disp_state = WIFI_LIST_UI;
  98. scr = lv_obj_create(NULL, NULL);
  99. lv_obj_set_style(scr, &tft_style_scr);
  100. lv_scr_load(scr);
  101. lv_obj_clean(scr);
  102. lv_obj_t * title = lv_label_create(scr, NULL);
  103. lv_obj_set_style(title, &tft_style_label_rel);
  104. lv_obj_set_pos(title,TITLE_XPOS,TITLE_YPOS);
  105. lv_label_set_text(title, creat_title_text());
  106. lv_refr_now(lv_refr_get_disp_refreshing());
  107. buttonDown = lv_imgbtn_create(scr, NULL);
  108. buttonBack = lv_imgbtn_create(scr, NULL);
  109. lv_obj_set_event_cb_mks(buttonDown, event_handler,ID_WL_DOWN,NULL,0);
  110. lv_imgbtn_set_src(buttonDown, LV_BTN_STATE_REL, "F:/bmp_pageDown.bin");
  111. lv_imgbtn_set_src(buttonDown, LV_BTN_STATE_PR, "F:/bmp_pageDown.bin");
  112. lv_imgbtn_set_style(buttonDown, LV_BTN_STATE_PR, &tft_style_label_pre);
  113. lv_imgbtn_set_style(buttonDown, LV_BTN_STATE_REL, &tft_style_label_rel);
  114. lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_WL_RETURN,NULL,0);
  115. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_back.bin");
  116. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_back.bin");
  117. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  118. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  119. lv_obj_set_pos(buttonDown,OTHER_BTN_XPIEL*3+INTERVAL_V*4,titleHeight+OTHER_BTN_YPIEL+INTERVAL_H);
  120. lv_obj_set_pos(buttonBack,OTHER_BTN_XPIEL*3+INTERVAL_V*4,titleHeight+OTHER_BTN_YPIEL*2+INTERVAL_H*2);
  121. lv_btn_set_layout(buttonDown, LV_LAYOUT_OFF);
  122. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  123. for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) {
  124. buttonWifiN[i] = lv_btn_create(scr, NULL); /*Add a button the current screen*/
  125. lv_obj_set_pos(buttonWifiN[i], 0,NAME_BTN_Y*i+10+titleHeight); /*Set its position*/
  126. lv_obj_set_size(buttonWifiN[i], NAME_BTN_X,NAME_BTN_Y); /*Set its size*/
  127. lv_obj_set_event_cb_mks(buttonWifiN[i], event_handler,(i+1),NULL,0);
  128. lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &tft_style_label_rel); /*Set the button's released style*/
  129. lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_PR, &tft_style_label_pre); /*Set the button's pressed style*/
  130. lv_btn_set_layout(buttonWifiN[i], LV_LAYOUT_OFF);
  131. lableWifiText[i] = lv_label_create(buttonWifiN[i], NULL);
  132. #if HAS_ROTARY_ENCODER
  133. uint8_t j = 0;
  134. if (gCfgItems.encoder_enable) {
  135. j = wifi_list.nameIndex + i;
  136. if (j < wifi_list.getNameNum) lv_group_add_obj(g, buttonWifiN[i]);
  137. }
  138. #endif
  139. }
  140. lablePageText = lv_label_create(scr, NULL);
  141. lv_obj_set_style(lablePageText, &tft_style_label_rel);
  142. wifi_list.nameIndex = 0;
  143. wifi_list.currentWifipage = 1;
  144. if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode == STA_MODEL) {
  145. memset(wifi_list.wifiConnectedName, 0, sizeof(&wifi_list.wifiConnectedName));
  146. memcpy(wifi_list.wifiConnectedName, wifiPara.ap_name, sizeof(wifi_list.wifiConnectedName));
  147. }
  148. #if HAS_ROTARY_ENCODER
  149. if (gCfgItems.encoder_enable) {
  150. lv_group_add_obj(g, buttonDown);
  151. lv_group_add_obj(g, buttonBack);
  152. }
  153. #endif
  154. disp_wifi_list();
  155. }
  156. void disp_wifi_list(void) {
  157. int8_t tmpStr[WIFI_NAME_BUFFER_SIZE] = { 0 };
  158. uint8_t i, j;
  159. sprintf((char *)tmpStr, list_menu.file_pages, wifi_list.currentWifipage, wifi_list.getPage);
  160. lv_label_set_text(lablePageText, (const char *)tmpStr);
  161. lv_obj_align(lablePageText, NULL, LV_ALIGN_CENTER, 50, -100);
  162. for (i = 0; i < NUMBER_OF_PAGE; i++) {
  163. memset(tmpStr, 0, sizeof(tmpStr));
  164. j = wifi_list.nameIndex + i;
  165. if (j >= wifi_list.getNameNum) {
  166. lv_label_set_text(lableWifiText[i], (const char *)tmpStr);
  167. lv_obj_align(lableWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0);
  168. }
  169. else {
  170. lv_label_set_text(lableWifiText[i], (char const *)wifi_list.wifiName[j]);
  171. lv_obj_align(lableWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0);
  172. if (wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[j]) == 0) {
  173. lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &style_sel_text);
  174. }
  175. else {
  176. lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, &tft_style_label_rel);
  177. }
  178. }
  179. }
  180. }
  181. void wifi_scan_handle() {
  182. if (uiCfg.dialogType != WIFI_ENABLE_TIPS || uiCfg.command_send != 1) return;
  183. last_disp_state = DIALOG_UI;
  184. lv_clear_dialog();
  185. if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode != AP_MODEL)
  186. lv_draw_wifi();
  187. else
  188. lv_draw_wifi_list();
  189. }
  190. void lv_clear_wifi_list() {
  191. #if HAS_ROTARY_ENCODER
  192. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  193. #endif
  194. lv_obj_del(scr);
  195. }
  196. #endif // USE_WIFI_FUNCTION
  197. #endif // HAS_TFT_LVGL_UI