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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178
  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(MKS_WIFI_MODULE)
  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 *labelWifiText[NUMBER_OF_PAGE];
  38. static lv_obj_t *labelPageText;
  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 (event != LV_EVENT_RELEASED) return;
  43. if (obj->mks_obj_id == ID_WL_RETURN) {
  44. clear_cur_ui();
  45. lv_draw_set();
  46. }
  47. else if (obj->mks_obj_id == ID_WL_DOWN) {
  48. if (wifi_list.getNameNum > 0) {
  49. if ((wifi_list.nameIndex + NUMBER_OF_PAGE) >= wifi_list.getNameNum) {
  50. wifi_list.nameIndex = 0;
  51. wifi_list.currentWifipage = 1;
  52. }
  53. else {
  54. wifi_list.nameIndex += NUMBER_OF_PAGE;
  55. wifi_list.currentWifipage++;
  56. }
  57. disp_wifi_list();
  58. }
  59. }
  60. else {
  61. for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) {
  62. if (obj->mks_obj_id == i + 1) {
  63. if (wifi_list.getNameNum != 0) {
  64. 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;
  65. wifi_list.nameIndex += i;
  66. last_disp_state = WIFI_LIST_UI;
  67. lv_clear_wifi_list();
  68. if (do_wifi)
  69. lv_draw_wifi();
  70. else {
  71. keyboard_value = wifiConfig;
  72. lv_draw_keyboard();
  73. }
  74. }
  75. }
  76. }
  77. }
  78. }
  79. void lv_draw_wifi_list() {
  80. scr = lv_screen_create(WIFI_LIST_UI);
  81. lv_obj_t *buttonDown = lv_imgbtn_create(scr, "F:/bmp_pageDown.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + OTHER_BTN_YPIEL + INTERVAL_H, event_handler, ID_WL_DOWN);
  82. lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_back.bin", OTHER_BTN_XPIEL * 3 + INTERVAL_V * 4, titleHeight + (OTHER_BTN_YPIEL + INTERVAL_H) * 2, event_handler, ID_WL_RETURN);
  83. for (uint8_t i = 0; i < NUMBER_OF_PAGE; i++) {
  84. buttonWifiN[i] = lv_label_btn_create(scr, 0, NAME_BTN_Y * i + 10 + titleHeight, NAME_BTN_X, NAME_BTN_Y, event_handler, i + 1);
  85. labelWifiText[i] = lv_label_create_empty(buttonWifiN[i]);
  86. #if HAS_ROTARY_ENCODER
  87. uint8_t j = 0;
  88. if (gCfgItems.encoder_enable) {
  89. j = wifi_list.nameIndex + i;
  90. if (j < wifi_list.getNameNum) lv_group_add_obj(g, buttonWifiN[i]);
  91. }
  92. #endif
  93. }
  94. labelPageText = lv_label_create_empty(scr);
  95. lv_obj_set_style(labelPageText, &tft_style_label_rel);
  96. wifi_list.nameIndex = 0;
  97. wifi_list.currentWifipage = 1;
  98. if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode == STA_MODEL) {
  99. ZERO(wifi_list.wifiConnectedName);
  100. memcpy(wifi_list.wifiConnectedName, wifiPara.ap_name, sizeof(wifi_list.wifiConnectedName));
  101. }
  102. #if HAS_ROTARY_ENCODER
  103. if (gCfgItems.encoder_enable) {
  104. lv_group_add_obj(g, buttonDown);
  105. lv_group_add_obj(g, buttonBack);
  106. }
  107. #else
  108. UNUSED(buttonDown);
  109. UNUSED(buttonBack);
  110. #endif
  111. disp_wifi_list();
  112. }
  113. void disp_wifi_list() {
  114. int8_t tmpStr[WIFI_NAME_BUFFER_SIZE] = { 0 };
  115. uint8_t i, j;
  116. sprintf((char *)tmpStr, list_menu.file_pages, wifi_list.currentWifipage, wifi_list.getPage);
  117. lv_label_set_text(labelPageText, (const char *)tmpStr);
  118. lv_obj_align(labelPageText, nullptr, LV_ALIGN_CENTER, 50, -100);
  119. for (i = 0; i < NUMBER_OF_PAGE; i++) {
  120. ZERO(tmpStr);
  121. j = wifi_list.nameIndex + i;
  122. if (j >= wifi_list.getNameNum) {
  123. lv_label_set_text(labelWifiText[i], (const char *)tmpStr);
  124. lv_obj_align(labelWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0);
  125. }
  126. else {
  127. lv_label_set_text(labelWifiText[i], (char const *)wifi_list.wifiName[j]);
  128. lv_obj_align(labelWifiText[i], buttonWifiN[i], LV_ALIGN_IN_LEFT_MID, 20, 0);
  129. const bool btext = (wifi_link_state == WIFI_CONNECTED && strcmp((const char *)wifi_list.wifiConnectedName, (const char *)wifi_list.wifiName[j]) == 0);
  130. lv_btn_set_style(buttonWifiN[i], LV_BTN_STYLE_REL, btext ? &style_sel_text : &tft_style_label_rel);
  131. }
  132. }
  133. }
  134. void wifi_scan_handle() {
  135. if (!DIALOG_IS(WIFI_ENABLE_TIPS) || !uiCfg.command_send) return;
  136. last_disp_state = DIALOG_UI;
  137. lv_clear_dialog();
  138. if (wifi_link_state == WIFI_CONNECTED && wifiPara.mode != AP_MODEL)
  139. lv_draw_wifi();
  140. else
  141. lv_draw_wifi_list();
  142. }
  143. void lv_clear_wifi_list() {
  144. #if HAS_ROTARY_ENCODER
  145. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  146. #endif
  147. lv_obj_del(scr);
  148. }
  149. #endif // MKS_WIFI_MODULE
  150. #endif // HAS_TFT_LVGL_UI