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_fan.cpp 9.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265
  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 "../../../../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. #include "../../../../gcode/gcode.h"
  35. extern lv_group_t * g;
  36. static lv_obj_t * scr;
  37. static lv_obj_t * fanText;
  38. #define ID_F_ADD 1
  39. #define ID_F_DEC 2
  40. #define ID_F_HIGH 3
  41. #define ID_F_MID 4
  42. #define ID_F_OFF 5
  43. #define ID_F_RETURN 6
  44. static uint8_t fanSpeed;
  45. static void event_handler(lv_obj_t * obj, lv_event_t event) {
  46. switch (obj->mks_obj_id) {
  47. case ID_F_ADD:
  48. if (event == LV_EVENT_CLICKED) {
  49. // nothing to do
  50. }
  51. else if (event == LV_EVENT_RELEASED) {
  52. if (fanSpeed + 1 <= 255) {
  53. fanSpeed++;
  54. ZERO(public_buf_l);
  55. sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
  56. gcode.process_subcommands_now(public_buf_l);
  57. }
  58. }
  59. break;
  60. case ID_F_DEC:
  61. if (event == LV_EVENT_CLICKED) {
  62. // nothing to do
  63. }
  64. else if (event == LV_EVENT_RELEASED) {
  65. if (fanSpeed > 0) {
  66. fanSpeed--;
  67. ZERO(public_buf_l);
  68. sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
  69. gcode.process_subcommands_now(public_buf_l);
  70. }
  71. }
  72. break;
  73. case ID_F_HIGH:
  74. if (event == LV_EVENT_CLICKED) {
  75. // nothing to do
  76. }
  77. else if (event == LV_EVENT_RELEASED) {
  78. gcode.process_subcommands_now_P(PSTR("M106 S255"));
  79. }
  80. break;
  81. case ID_F_MID:
  82. if (event == LV_EVENT_CLICKED) {
  83. // nothing to do
  84. }
  85. else if (event == LV_EVENT_RELEASED) {
  86. gcode.process_subcommands_now_P(PSTR("M106 S127"));
  87. }
  88. break;
  89. case ID_F_OFF:
  90. if (event == LV_EVENT_CLICKED) {
  91. // nothing to do
  92. }
  93. else if (event == LV_EVENT_RELEASED) {
  94. gcode.process_subcommands_now_P(PSTR("M107"));
  95. }
  96. break;
  97. case ID_F_RETURN:
  98. if (event == LV_EVENT_CLICKED) {
  99. // nothing to do
  100. }
  101. else if (event == LV_EVENT_RELEASED) {
  102. clear_cur_ui();
  103. draw_return_ui();
  104. }
  105. break;
  106. }
  107. }
  108. void lv_draw_fan(void) {
  109. lv_obj_t *buttonAdd, *buttonDec, *buttonHigh, *buttonMid;
  110. lv_obj_t *buttonOff, *buttonBack;
  111. #if HAS_FAN
  112. fanSpeed = thermalManager.fan_speed[0];
  113. #endif
  114. if (disp_state_stack._disp_state[disp_state_stack._disp_index] != FAN_UI) {
  115. disp_state_stack._disp_index++;
  116. disp_state_stack._disp_state[disp_state_stack._disp_index] = FAN_UI;
  117. }
  118. disp_state = FAN_UI;
  119. scr = lv_obj_create(NULL, NULL);
  120. lv_obj_set_style(scr, &tft_style_scr);
  121. lv_scr_load(scr);
  122. lv_obj_clean(scr);
  123. lv_obj_t * title = lv_label_create(scr, NULL);
  124. lv_obj_set_style(title, &tft_style_label_rel);
  125. lv_obj_set_pos(title, TITLE_XPOS, TITLE_YPOS);
  126. lv_label_set_text(title, creat_title_text());
  127. lv_refr_now(lv_refr_get_disp_refreshing());
  128. // Create an Image button
  129. buttonAdd = lv_imgbtn_create(scr, NULL);
  130. buttonDec = lv_imgbtn_create(scr, NULL);
  131. buttonHigh = lv_imgbtn_create(scr, NULL);
  132. buttonMid = lv_imgbtn_create(scr, NULL);
  133. buttonOff = lv_imgbtn_create(scr, NULL);
  134. buttonBack = lv_imgbtn_create(scr, NULL);
  135. lv_obj_set_event_cb_mks(buttonAdd, event_handler, ID_F_ADD, NULL, 0);
  136. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_REL, "F:/bmp_Add.bin");
  137. lv_imgbtn_set_src(buttonAdd, LV_BTN_STATE_PR, "F:/bmp_Add.bin");
  138. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_PR, &tft_style_label_pre);
  139. lv_imgbtn_set_style(buttonAdd, LV_BTN_STATE_REL, &tft_style_label_rel);
  140. lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
  141. #if 1
  142. lv_obj_set_event_cb_mks(buttonDec, event_handler, ID_F_DEC, NULL, 0);
  143. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_REL, "F:/bmp_Dec.bin");
  144. lv_imgbtn_set_src(buttonDec, LV_BTN_STATE_PR, "F:/bmp_Dec.bin");
  145. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_PR, &tft_style_label_pre);
  146. lv_imgbtn_set_style(buttonDec, LV_BTN_STATE_REL, &tft_style_label_rel);
  147. lv_obj_set_event_cb_mks(buttonHigh, event_handler,ID_F_HIGH, NULL,0);
  148. lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_REL, "F:/bmp_speed255.bin");
  149. lv_imgbtn_set_src(buttonHigh, LV_BTN_STATE_PR, "F:/bmp_speed255.bin");
  150. lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_PR, &tft_style_label_pre);
  151. lv_imgbtn_set_style(buttonHigh, LV_BTN_STATE_REL, &tft_style_label_rel);
  152. lv_obj_set_event_cb_mks(buttonMid, event_handler,ID_F_MID, NULL,0);
  153. lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_REL, "F:/bmp_speed127.bin");
  154. lv_imgbtn_set_src(buttonMid, LV_BTN_STATE_PR, "F:/bmp_speed127.bin");
  155. lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_PR, &tft_style_label_pre);
  156. lv_imgbtn_set_style(buttonMid, LV_BTN_STATE_REL, &tft_style_label_rel);
  157. lv_obj_set_event_cb_mks(buttonOff, event_handler,ID_F_OFF, NULL,0);
  158. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_REL, "F:/bmp_speed0.bin");
  159. lv_imgbtn_set_src(buttonOff, LV_BTN_STATE_PR, "F:/bmp_speed0.bin");
  160. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_PR, &tft_style_label_pre);
  161. lv_imgbtn_set_style(buttonOff, LV_BTN_STATE_REL, &tft_style_label_rel);
  162. lv_obj_set_event_cb_mks(buttonBack, event_handler,ID_F_RETURN, NULL,0);
  163. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_REL, "F:/bmp_return.bin");
  164. lv_imgbtn_set_src(buttonBack, LV_BTN_STATE_PR, "F:/bmp_return.bin");
  165. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_PR, &tft_style_label_pre);
  166. lv_imgbtn_set_style(buttonBack, LV_BTN_STATE_REL, &tft_style_label_rel);
  167. #endif
  168. lv_obj_set_pos(buttonAdd, INTERVAL_V, titleHeight);
  169. lv_obj_set_pos(buttonDec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight);
  170. lv_obj_set_pos(buttonHigh, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  171. lv_obj_set_pos(buttonMid, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  172. lv_obj_set_pos(buttonOff, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  173. lv_obj_set_pos(buttonBack, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight);
  174. // Create labels on the image buttons
  175. lv_btn_set_layout(buttonAdd, LV_LAYOUT_OFF);
  176. lv_btn_set_layout(buttonDec, LV_LAYOUT_OFF);
  177. lv_btn_set_layout(buttonHigh, LV_LAYOUT_OFF);
  178. lv_btn_set_layout(buttonMid, LV_LAYOUT_OFF);
  179. lv_btn_set_layout(buttonOff, LV_LAYOUT_OFF);
  180. lv_btn_set_layout(buttonBack, LV_LAYOUT_OFF);
  181. lv_obj_t *labelAdd = lv_label_create(buttonAdd, NULL);
  182. lv_obj_t *labelDec = lv_label_create(buttonDec, NULL);
  183. lv_obj_t *labelHigh = lv_label_create(buttonHigh, NULL);
  184. lv_obj_t *labelMid = lv_label_create(buttonMid, NULL);
  185. lv_obj_t *labelOff = lv_label_create(buttonOff, NULL);
  186. lv_obj_t *label_Back = lv_label_create(buttonBack, NULL);
  187. if (gCfgItems.multiple_language != 0) {
  188. lv_label_set_text(labelAdd, fan_menu.add);
  189. lv_obj_align(labelAdd, buttonAdd, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  190. lv_label_set_text(labelDec, fan_menu.dec);
  191. lv_obj_align(labelDec, buttonDec, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  192. lv_label_set_text(labelHigh, fan_menu.full);
  193. lv_obj_align(labelHigh, buttonHigh, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  194. lv_label_set_text(labelMid, fan_menu.half);
  195. lv_obj_align(labelMid, buttonMid, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  196. lv_label_set_text(labelOff, fan_menu.off);
  197. lv_obj_align(labelOff, buttonOff, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  198. lv_label_set_text(label_Back, common_menu.text_back);
  199. lv_obj_align(label_Back, buttonBack, LV_ALIGN_IN_BOTTOM_MID, 0, BUTTON_TEXT_Y_OFFSET);
  200. }
  201. #if HAS_ROTARY_ENCODER
  202. if (gCfgItems.encoder_enable) {
  203. lv_group_add_obj(g, buttonAdd);
  204. lv_group_add_obj(g, buttonDec);
  205. lv_group_add_obj(g, buttonHigh);
  206. lv_group_add_obj(g, buttonMid);
  207. lv_group_add_obj(g, buttonOff);
  208. lv_group_add_obj(g, buttonBack);
  209. }
  210. #endif
  211. fanText = lv_label_create(scr, NULL);
  212. lv_obj_set_style(fanText, &tft_style_label_rel);
  213. disp_fan_value();
  214. }
  215. void disp_fan_value() {
  216. char buf1[10] = {0};
  217. public_buf_l[0] = '\0';
  218. strcat(public_buf_l, fan_menu.state);
  219. strcat_P(public_buf_l, PSTR(": "));
  220. sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]);
  221. strcat(public_buf_l, buf1);
  222. lv_label_set_text(fanText, public_buf_l);
  223. lv_obj_align(fanText, NULL, LV_ALIGN_CENTER, 0, -65);
  224. }
  225. void lv_clear_fan() {
  226. #if HAS_ROTARY_ENCODER
  227. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  228. #endif
  229. lv_obj_del(scr);
  230. }
  231. #endif // HAS_TFT_LVGL_UI