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.7KB

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