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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  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. extern lv_group_t *g;
  29. static lv_obj_t *scr, *wifi_name_text, *wifi_key_text, *wifi_state_text, *wifi_ip_text;
  30. enum {
  31. ID_W_RETURN = 1,
  32. ID_W_CLOUD,
  33. ID_W_RECONNECT
  34. };
  35. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  36. if (event != LV_EVENT_RELEASED) return;
  37. clear_cur_ui();
  38. switch (obj->mks_obj_id) {
  39. case ID_W_RETURN:
  40. lv_draw_set();
  41. break;
  42. case ID_W_CLOUD:
  43. lv_draw_cloud_bind();
  44. break;
  45. #if ENABLED(MKS_WIFI_MODULE)
  46. case ID_W_RECONNECT: {
  47. uint8_t cmd_wifi_list[] = { 0xA5, 0x07, 0x00, 0x00, 0xFC };
  48. raw_send_to_wifi(cmd_wifi_list, COUNT(cmd_wifi_list));
  49. lv_draw_wifi_list();
  50. } break;
  51. #endif
  52. }
  53. }
  54. void lv_draw_wifi() {
  55. scr = lv_screen_create(WIFI_UI);
  56. lv_obj_t *buttonReconnect = nullptr, *label_Reconnect = nullptr;
  57. lv_obj_t *buttonCloud = nullptr, *label_Cloud = nullptr;
  58. const bool enc_ena = TERN0(HAS_ROTARY_ENCODER, gCfgItems.encoder_enable);
  59. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  60. if (gCfgItems.cloud_enable)
  61. buttonCloud = lv_imgbtn_create(scr, "F:/bmp_cloud.bin", BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_CLOUD);
  62. buttonReconnect = lv_imgbtn_create(scr, "F:/bmp_wifi.bin", BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_RECONNECT);
  63. #if HAS_ROTARY_ENCODER
  64. if (gCfgItems.cloud_enable) lv_group_add_obj(g, buttonCloud);
  65. if (enc_ena) lv_group_add_obj(g, buttonReconnect);
  66. #endif
  67. label_Reconnect = lv_label_create_empty(buttonReconnect);
  68. if (gCfgItems.cloud_enable) label_Cloud = lv_label_create_empty(buttonCloud);
  69. }
  70. // Create an Image button
  71. lv_obj_t *buttonBack = lv_imgbtn_create(scr, "F:/bmp_return.bin", BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_W_RETURN);
  72. if (enc_ena) lv_group_add_obj(g, buttonBack);
  73. lv_obj_t *label_Back = lv_label_create_empty(buttonBack);
  74. if (gCfgItems.multiple_language) {
  75. if (gCfgItems.wifi_mode_sel == STA_MODEL) {
  76. if (gCfgItems.cloud_enable) {
  77. lv_label_set_text(label_Cloud, wifi_menu.cloud);
  78. lv_obj_align(label_Cloud, buttonCloud, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  79. }
  80. lv_label_set_text(label_Reconnect, wifi_menu.reconnect);
  81. lv_obj_align(label_Reconnect, buttonReconnect, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  82. }
  83. lv_label_set_text(label_Back, common_menu.text_back);
  84. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  85. }
  86. wifi_ip_text = lv_label_create_empty(scr);
  87. lv_obj_set_style(wifi_ip_text, &tft_style_label_rel);
  88. wifi_name_text = lv_label_create_empty(scr);
  89. lv_obj_set_style(wifi_name_text, &tft_style_label_rel);
  90. wifi_key_text = lv_label_create_empty(scr);
  91. lv_obj_set_style(wifi_key_text, &tft_style_label_rel);
  92. wifi_state_text = lv_label_create_empty(scr);
  93. lv_obj_set_style(wifi_state_text, &tft_style_label_rel);
  94. disp_wifi_state();
  95. }
  96. void disp_wifi_state() {
  97. strcpy(public_buf_m, wifi_menu.ip);
  98. strcat(public_buf_m, ipPara.ip_addr);
  99. lv_label_set_text(wifi_ip_text, public_buf_m);
  100. lv_obj_align(wifi_ip_text, nullptr, LV_ALIGN_CENTER, 0, -100);
  101. strcpy(public_buf_m, wifi_menu.wifi);
  102. strcat(public_buf_m, wifiPara.ap_name);
  103. lv_label_set_text(wifi_name_text, public_buf_m);
  104. lv_obj_align(wifi_name_text, nullptr, LV_ALIGN_CENTER, 0, -70);
  105. if (wifiPara.mode == AP_MODEL) {
  106. strcpy(public_buf_m, wifi_menu.key);
  107. strcat(public_buf_m, wifiPara.keyCode);
  108. lv_label_set_text(wifi_key_text, public_buf_m);
  109. lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -40);
  110. strcpy(public_buf_m, wifi_menu.state_ap);
  111. if (wifi_link_state == WIFI_CONNECTED)
  112. strcat(public_buf_m, wifi_menu.connected);
  113. else if (wifi_link_state == WIFI_NOT_CONFIG)
  114. strcat(public_buf_m, wifi_menu.disconnected);
  115. else
  116. strcat(public_buf_m, wifi_menu.exception);
  117. lv_label_set_text(wifi_state_text, public_buf_m);
  118. lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -10);
  119. }
  120. else {
  121. strcpy(public_buf_m, wifi_menu.state_sta);
  122. if (wifi_link_state == WIFI_CONNECTED)
  123. strcat(public_buf_m, wifi_menu.connected);
  124. else if (wifi_link_state == WIFI_NOT_CONFIG)
  125. strcat(public_buf_m, wifi_menu.disconnected);
  126. else
  127. strcat(public_buf_m, wifi_menu.exception);
  128. lv_label_set_text(wifi_state_text, public_buf_m);
  129. lv_obj_align(wifi_state_text, nullptr, LV_ALIGN_CENTER, 0, -40);
  130. lv_label_set_text(wifi_key_text, "");
  131. lv_obj_align(wifi_key_text, nullptr, LV_ALIGN_CENTER, 0, -10);
  132. }
  133. }
  134. void lv_clear_wifi() {
  135. if (TERN0(HAS_ROTARY_ENCODER, gCfgItems.encoder_enable))
  136. lv_group_remove_all_objs(g);
  137. lv_obj_del(scr);
  138. }
  139. #endif // MKS_WIFI_MODULE
  140. #endif // HAS_TFT_LVGL_UI