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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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 "draw_ui.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 "../../../../module/temperature.h"
  31. #include "../../../../gcode/queue.h"
  32. #include "../../../../gcode/gcode.h"
  33. #include "../../../../inc/MarlinConfig.h"
  34. extern lv_group_t *g;
  35. static lv_obj_t *scr;
  36. static lv_obj_t *fanText;
  37. enum {
  38. ID_F_ADD = 1,
  39. ID_F_DEC,
  40. ID_F_HIGH,
  41. ID_F_MID,
  42. ID_F_OFF,
  43. ID_F_RETURN
  44. };
  45. static uint8_t fanSpeed;
  46. static void event_handler(lv_obj_t *obj, lv_event_t event) {
  47. if (event != LV_EVENT_RELEASED) return;
  48. switch (obj->mks_obj_id) {
  49. case ID_F_ADD:
  50. if (fanSpeed + 1 <= 255) {
  51. fanSpeed++;
  52. sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
  53. gcode.process_subcommands_now(public_buf_l);
  54. }
  55. break;
  56. case ID_F_DEC:
  57. if (fanSpeed > 0) {
  58. fanSpeed--;
  59. sprintf_P(public_buf_l, PSTR("M106 S%d"), fanSpeed);
  60. gcode.process_subcommands_now(public_buf_l);
  61. }
  62. break;
  63. case ID_F_HIGH:
  64. gcode.process_subcommands_now_P(PSTR("M106 S255"));
  65. break;
  66. case ID_F_MID:
  67. gcode.process_subcommands_now_P(PSTR("M106 S127"));
  68. break;
  69. case ID_F_OFF:
  70. gcode.process_subcommands_now_P(PSTR("M107"));
  71. break;
  72. case ID_F_RETURN:
  73. clear_cur_ui();
  74. draw_return_ui();
  75. break;
  76. }
  77. }
  78. void lv_draw_fan(void) {
  79. lv_obj_t *buttonAdd;
  80. #if HAS_FAN
  81. fanSpeed = thermalManager.fan_speed[0];
  82. #endif
  83. scr = lv_screen_create(FAN_UI);
  84. // Create an Image button
  85. buttonAdd = lv_big_button_create(scr, "F:/bmp_Add.bin", fan_menu.add, INTERVAL_V, titleHeight, event_handler, ID_F_ADD);
  86. lv_obj_clear_protect(buttonAdd, LV_PROTECT_FOLLOW);
  87. lv_big_button_create(scr, "F:/bmp_Dec.bin", fan_menu.dec, BTN_X_PIXEL * 3 + INTERVAL_V * 4, titleHeight, event_handler, ID_F_DEC);
  88. lv_big_button_create(scr, "F:/bmp_speed255.bin", fan_menu.full, INTERVAL_V, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_HIGH);
  89. lv_big_button_create(scr, "F:/bmp_speed127.bin", fan_menu.half, BTN_X_PIXEL + INTERVAL_V * 2, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_MID);
  90. lv_big_button_create(scr, "F:/bmp_speed0.bin", fan_menu.off, BTN_X_PIXEL * 2 + INTERVAL_V * 3, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_OFF);
  91. lv_big_button_create(scr, "F:/bmp_return.bin", common_menu.text_back, BTN_X_PIXEL * 3 + INTERVAL_V * 4, BTN_Y_PIXEL + INTERVAL_H + titleHeight, event_handler, ID_F_RETURN);
  92. fanText = lv_label_create_empty(scr);
  93. lv_obj_set_style(fanText, &tft_style_label_rel);
  94. disp_fan_value();
  95. }
  96. void disp_fan_value() {
  97. char buf1[10] = {0};
  98. public_buf_l[0] = '\0';
  99. strcat(public_buf_l, fan_menu.state);
  100. strcat_P(public_buf_l, PSTR(": "));
  101. sprintf_P(buf1, PSTR("%3d"), thermalManager.fan_speed[0]);
  102. strcat(public_buf_l, buf1);
  103. lv_label_set_text(fanText, public_buf_l);
  104. lv_obj_align(fanText, nullptr, LV_ALIGN_CENTER, 0, -65);
  105. }
  106. void lv_clear_fan() {
  107. #if HAS_ROTARY_ENCODER
  108. if (gCfgItems.encoder_enable) lv_group_remove_all_objs(g);
  109. #endif
  110. lv_obj_del(scr);
  111. }
  112. #endif // HAS_TFT_LVGL_UI