My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

draw_fan.cpp 8.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247
  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 <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../../../inc/MarlinConfigPre.h"
  23. #if ENABLED(TFT_LVGL_UI)
  24. #include "../../../../MarlinCore.h"
  25. #include "lv_conf.h"
  26. //#include "../lvgl/src/lv_objx/lv_imgbtn.h"
  27. //#include "../lvgl/src/lv_objx/lv_img.h"
  28. //#include "../lvgl/src/lv_core/lv_disp.h"
  29. //#include "../lvgl/src/lv_core/lv_refr.h"
  30. #include "../../../../../Configuration.h"
  31. #include "draw_ui.h"
  32. #include "../../../../module/temperature.h"
  33. #include "../../../../gcode/queue.h"
  34. static lv_obj_t * scr;
  35. static lv_obj_t * fanText;
  36. #define ID_F_ADD 1
  37. #define ID_F_DEC 2
  38. #define ID_F_HIGH 3
  39. #define ID_F_MID 4
  40. #define ID_F_OFF 5
  41. #define ID_F_RETURN 6
  42. static uint8_t fanSpeed;
  43. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  44. switch (obj->mks_obj_id) {
  45. case ID_F_ADD:
  46. if (event == LV_EVENT_CLICKED) {
  47. // nothing to do
  48. }
  49. else if (event == LV_EVENT_RELEASED) {
  50. if (fanSpeed + 1 <= 255) {
  51. fanSpeed++;
  52. memset(public_buf_l, 0, sizeof(public_buf_l));
  53. sprintf(public_buf_l, "M106 S%d", fanSpeed);
  54. queue.enqueue_one_now(PSTR(public_buf_l));
  55. }
  56. }
  57. break;
  58. case ID_F_DEC:
  59. if (event == LV_EVENT_CLICKED) {
  60. // nothing to do
  61. }
  62. else if (event == LV_EVENT_RELEASED) {
  63. if (fanSpeed > 0) {
  64. fanSpeed--;
  65. memset(public_buf_l, 0, sizeof(public_buf_l));
  66. sprintf(public_buf_l, "M106 S%d", fanSpeed);
  67. queue.enqueue_one_now(PSTR(public_buf_l));
  68. }
  69. }
  70. break;
  71. case ID_F_HIGH:
  72. if (event == LV_EVENT_CLICKED) {
  73. // nothing to do
  74. }
  75. else if (event == LV_EVENT_RELEASED) {
  76. queue.enqueue_one_now(PSTR("M106 S255"));
  77. }
  78. break;
  79. case ID_F_MID:
  80. if (event == LV_EVENT_CLICKED) {
  81. // nothing to do
  82. }
  83. else if (event == LV_EVENT_RELEASED) {
  84. queue.enqueue_one_now(PSTR("M106 S127"));
  85. }
  86. break;
  87. case ID_F_OFF:
  88. if (event == LV_EVENT_CLICKED) {
  89. // nothing to do
  90. }
  91. else if (event == LV_EVENT_RELEASED) {
  92. queue.enqueue_one_now(PSTR("M107"));
  93. }
  94. break;
  95. case ID_F_RETURN:
  96. if (event == LV_EVENT_CLICKED) {
  97. // nothing to do
  98. }
  99. else if (event == LV_EVENT_RELEASED) {
  100. clear_cur_ui();
  101. draw_return_ui();
  102. }
  103. break;
  104. }
  105. }
  106. void lv_draw_fan(void) {
  107. lv_obj_t *buttonAdd, *buttonDec, *buttonHigh, *buttonMid;
  108. lv_obj_t *buttonOff, *buttonBack;
  109. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FAN_UI) {
  110. disp_state_stack._disp_index++;
  111. disp_state_stack._disp_state[disp_state_stack._disp_index] = FAN_UI;
  112. }
  113. disp_state = FAN_UI;
  114. scr = lv_obj_create(NULL, NULL);
  115. lv_obj_set_style(scr, &tft_style_scr);
  116. lv_scr_load(scr);
  117. lv_obj_clean(scr);
  118. lv_obj_t * title = lv_label_create(scr, NULL);
  119. lv_obj_set_style(title, &tft_style_lable_rel);
  120. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  121. lv_label_set_text(title, creat_title_text());
  122. lv_refr_now(lv_refr_get_disp_refreshing());
  123. LV_IMG_DECLARE(bmp_pic);
  124. /*Create an Image button*/
  125. buttonAdd = lv_imgbtn_create(scr, NULL);
  126. buttonDec = lv_imgbtn_create(scr, NULL);
  127. buttonHigh = lv_imgbtn_create(scr, NULL);
  128. buttonMid = lv_imgbtn_create(scr, NULL);
  129. buttonOff = lv_imgbtn_create(scr, NULL);
  130. buttonBack = lv_imgbtn_create(scr, NULL);
  131. lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_F_ADD, "bmp_Add.bin", 0);
  132. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, &bmp_pic);
  133. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, &bmp_pic);
  134. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_lable_pre);
  135. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_lable_rel);
  136. lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
  137. #if 1
  138. lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_F_DEC, "bmp_Dec.bin", 0);
  139. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, &bmp_pic);
  140. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, &bmp_pic);
  141. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_lable_pre);
  142. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_lable_rel);
  143. lv_obj_set_event_cb_mks(buttonHigh, event_handler, ID_F_HIGH, "bmp_Speed255.bin", 0);
  144. lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_REL, &bmp_pic);
  145. lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_PR, &bmp_pic);
  146. lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_PR, &tft_style_lable_pre);
  147. lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_REL, &tft_style_lable_rel);
  148. lv_obj_set_event_cb_mks(buttonMid, event_handler, ID_F_MID, "bmp_Speed127.bin", 0);
  149. lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_REL, &bmp_pic);
  150. lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_PR, &bmp_pic);
  151. lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_PR, &tft_style_lable_pre);
  152. lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_REL, &tft_style_lable_rel);
  153. lv_obj_set_event_cb_mks(buttonOff, event_handler, ID_F_OFF, "bmp_Speed0.bin", 0);
  154. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_REL, &bmp_pic);
  155. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_PR, &bmp_pic);
  156. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_PR, &tft_style_lable_pre);
  157. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_REL, &tft_style_lable_rel);
  158. lv_obj_set_event_cb_mks(buttonBack, event_handler, ID_F_RETURN, "bmp_Return.bin", 0);
  159. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, &bmp_pic);
  160. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, &bmp_pic);
  161. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_lable_pre);
  162. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_lable_rel);
  163. #endif
  164. lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight);
  165. lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  166. lv_obj_set_pos(buttonHigh, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  167. lv_obj_set_pos(buttonMid, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  168. lv_obj_set_pos(buttonOff, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  169. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  170. /*Create a label on the Image button*/
  171. lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF);
  172. lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF);
  173. lv_btn_set_layout(buttonHigh, LV_LAYOUT_OFF);
  174. lv_btn_set_layout(buttonMid, LV_LAYOUT_OFF);
  175. lv_btn_set_layout(buttonOff, LV_LAYOUT_OFF);
  176. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  177. lv_obj_t * labelAdd = lv_label_create(buttonAdd, NULL);
  178. lv_obj_t * labelDec = lv_label_create(buttonDec, NULL);
  179. lv_obj_t * labelHigh = lv_label_create(buttonHigh, NULL);
  180. lv_obj_t * labelMid = lv_label_create(buttonMid, NULL);
  181. lv_obj_t * labelOff = lv_label_create(buttonOff, NULL);
  182. lv_obj_t * label_Back = lv_label_create(buttonBack, NULL);
  183. if (gCfgItems.multiple_language != 0) {
  184. lv_label_set_text(labelAdd, fan_menu.add);
  185. lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  186. lv_label_set_text(labelDec, fan_menu.dec);
  187. lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  188. lv_label_set_text(labelHigh, fan_menu.full);
  189. lv_obj_align(labelHigh, buttonHigh, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  190. lv_label_set_text(labelMid, fan_menu.half);
  191. lv_obj_align(labelMid, buttonMid, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  192. lv_label_set_text(labelOff, fan_menu.off);
  193. lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  194. lv_label_set_text(label_Back, common_menu.text_back);
  195. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  196. }
  197. fanText = lv_label_create(scr, NULL);
  198. lv_obj_set_style(fanText, &tft_style_lable_rel);
  199. disp_fan_value();
  200. }
  201. void disp_fan_value() {
  202. char buf1[10] = {0};
  203. public_buf_l[0] = '\0';
  204. strcat(public_buf_l, fan_menu.state);
  205. strcat(public_buf_l, ": ");
  206. sprintf(buf1, "%3d", thermalManager.fan_speed[0]);
  207. strcat(public_buf_l, buf1);
  208. lv_label_set_text(fanText, public_buf_l);
  209. lv_obj_align(fanText, NULL, LV_ALIGN_CENTER, 0, -65);
  210. }
  211. void lv_clear_fan() { lv_obj_del(scr); }
  212. #endif // TFT_LVGL_UI