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.

ui_status_480x272.cpp 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2021 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 IS_DWIN_MARLINUI
  24. #include "marlinui_dwin.h"
  25. #include "dwin_lcd.h"
  26. #include "dwin_string.h"
  27. #include "lcdprint_dwin.h"
  28. #include "../../fontutils.h"
  29. #include "../../../libs/numtostr.h"
  30. #include "../../marlinui.h"
  31. #include "../../../sd/cardreader.h"
  32. #include "../../../module/motion.h"
  33. #include "../../../module/temperature.h"
  34. #include "../../../module/printcounter.h"
  35. #if ENABLED(SDSUPPORT)
  36. #include "../../../libs/duration_t.h"
  37. #endif
  38. #if ENABLED(LCD_SHOW_E_TOTAL)
  39. #include "../../../MarlinCore.h" // for printingIsActive
  40. #endif
  41. #define STATUS_HEATERS_X 15
  42. #define STATUS_HEATERS_Y 56
  43. #define STATUS_HEATERS_XSPACE 64
  44. #define STATUS_FAN_WIDTH 48
  45. #define STATUS_FAN_HEIGHT 48
  46. #define STATUS_FAN_Y STATUS_HEATERS_Y + 22
  47. #define STATUS_CHR_WIDTH 14
  48. #define STATUS_CHR_HEIGHT 28
  49. //
  50. // Before homing, blink '123' <-> '???'.
  51. // Homed but unknown... '123' <-> ' '.
  52. // Homed and known, display constantly.
  53. //
  54. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
  55. uint8_t vallen = utf8_strlen(value);
  56. if (!ui.did_first_redraw) {
  57. dwin_string.set();
  58. dwin_string.add('X' + axis);
  59. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
  60. }
  61. dwin_string.set();
  62. if (blink)
  63. dwin_string.add(value);
  64. else {
  65. if (!TEST(axis_homed, axis))
  66. while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
  67. else {
  68. #if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
  69. if (!TEST(axis_trusted, axis))
  70. dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
  71. else
  72. #endif
  73. dwin_string.add(value);
  74. }
  75. }
  76. // For E_TOTAL there may be some characters to cover up
  77. if (BOTH(DWIN_MARLINUI_PORTRAIT, LCD_SHOW_E_TOTAL) && axis == X_AXIS)
  78. dwin_string.add(" ");
  79. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
  80. }
  81. #if ENABLED(LCD_SHOW_E_TOTAL)
  82. FORCE_INLINE void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
  83. const uint8_t scale = value >= 100000.0f ? 10 : 1; // show cm after 99,999mm
  84. if (!ui.did_first_redraw) {
  85. // Extra spaces so we don't have to clear the 'Y' label separately
  86. dwin_string.set("E ");
  87. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
  88. }
  89. dwin_string.set(ui16tostr5rj(value / scale));
  90. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
  91. // Extra spaces so we don't have to clear out the Y value separately
  92. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (5 * 14), y + 32, S(scale == 1 ? "mm " : "cm "));
  93. }
  94. #endif
  95. //
  96. // Fan Icon and Percentage
  97. //
  98. FORCE_INLINE void _draw_fan_status(const uint16_t x, const uint16_t y) {
  99. const uint16_t fanx = (4 * STATUS_CHR_WIDTH - STATUS_FAN_WIDTH) / 2;
  100. const uint8_t fan_pct = thermalManager.scaledFanSpeedPercent(0);
  101. const bool fan_on = !!fan_pct;
  102. if (fan_on) {
  103. DWIN_ICON_Animation(0, fan_on, ICON, ICON_Fan0, ICON_Fan3, x + fanx, y, 25);
  104. dwin_string.set(i8tostr3rj(fan_pct));
  105. dwin_string.add('%');
  106. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
  107. }
  108. else {
  109. DWIN_ICON_Show(ICON, ICON_Fan0, x + fanx, y);
  110. dwin_string.set(PSTR(" "));
  111. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
  112. }
  113. }
  114. #if HOTENDS > 2
  115. #define HOTEND_STATS 3
  116. #elif HOTENDS > 1
  117. #define HOTEND_STATS 2
  118. #elif HAS_HOTEND
  119. #define HOTEND_STATS 1
  120. #endif
  121. /**
  122. * Draw a single heater icon with current and target temperature, at the given XY
  123. */
  124. FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x, const uint16_t y) {
  125. #if HAS_HOTEND
  126. static celsius_t old_temp[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500),
  127. old_target[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, 500);
  128. static bool old_on[HOTEND_STATS] = ARRAY_N_1(HOTEND_STATS, false);
  129. #endif
  130. #if HAS_HEATED_BED
  131. static celsius_t old_bed_temp = 500, old_bed_target = 500;
  132. static bool old_bed_on = false;
  133. #endif
  134. #if HAS_HOTEND && HAS_HEATED_BED
  135. const bool isBed = heater < 0;
  136. const float tc = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)),
  137. tt = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater));
  138. const uint8_t ta = isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater);
  139. const bool c_draw = tc != (isBed ? old_bed_temp : old_temp[heater]),
  140. t_draw = tt != (isBed ? old_bed_target : old_target[heater]),
  141. i_draw = ta != (isBed ? old_bed_on : old_on[heater]);
  142. if (isBed) { old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta; }
  143. else { old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta; }
  144. #elif HAS_HOTEND
  145. constexpr bool isBed = false;
  146. const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
  147. const uint8_t ta = thermalManager.isHeatingHotend(heater);
  148. const bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
  149. old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
  150. #elif HAS_HEATED_BED
  151. constexpr bool isBed = true;
  152. const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
  153. const uint8_t ta = thermalManager.isHeatingBed();
  154. const bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
  155. old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
  156. #endif
  157. if (!ui.did_first_redraw || t_draw) {
  158. dwin_string.set(i16tostr3rj(tt + 0.5));
  159. dwin_string.add(LCD_STR_DEGREE);
  160. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
  161. }
  162. if (!ui.did_first_redraw || i_draw)
  163. DWIN_ICON_Show(ICON, (isBed ? ICON_BedOff : ICON_HotendOff) + ta, x, y + STATUS_CHR_HEIGHT + 2);
  164. if (!ui.did_first_redraw || c_draw) {
  165. dwin_string.set(i16tostr3rj(tc + 0.5));
  166. dwin_string.add(LCD_STR_DEGREE);
  167. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 70, S(dwin_string.string()));
  168. }
  169. }
  170. /**
  171. * Draw the current "feed rate" percentage preceded by the >> character
  172. */
  173. FORCE_INLINE void _draw_feedrate_status(const char *value, uint16_t x, uint16_t y) {
  174. if (!ui.did_first_redraw) {
  175. dwin_string.set(LCD_STR_FEEDRATE);
  176. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
  177. }
  178. dwin_string.set(value);
  179. dwin_string.add(PSTR("%"));
  180. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 14, y, S(dwin_string.string()));
  181. }
  182. /**
  183. * Draw the MarlinUI Status Screen for Ender 3 V2
  184. */
  185. void MarlinUI::draw_status_screen() {
  186. const bool blink = get_blink();
  187. // Draw elements that never change
  188. if (!ui.did_first_redraw) {
  189. // Logo/Status Icon
  190. #define STATUS_LOGO_WIDTH 128
  191. #define STATUS_LOGO_HEIGHT 40
  192. DWIN_ICON_Show(ICON, ICON_LOGO_Marlin, (LCD_PIXEL_WIDTH - (STATUS_LOGO_WIDTH)) / 2, ((STATUS_HEATERS_Y - 4) - (STATUS_LOGO_HEIGHT)) / 2);
  193. // Draw a frame around the x/y/z values
  194. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  195. DWIN_Draw_Rectangle(0, Select_Color, 0, 193, LCD_PIXEL_WIDTH, 260);
  196. #else
  197. //DWIN_Draw_Rectangle(0, Select_Color, LCD_PIXEL_WIDTH - 106, 50, LCD_PIXEL_WIDTH - 1, 230);
  198. #endif
  199. }
  200. uint16_t hx = STATUS_HEATERS_X;
  201. #if HAS_HOTEND
  202. _draw_heater_status(H_E0, hx, STATUS_HEATERS_Y);
  203. hx += STATUS_HEATERS_XSPACE;
  204. #endif
  205. #if HAS_MULTI_HOTEND
  206. _draw_heater_status(H_E1, hx, STATUS_HEATERS_Y);
  207. hx += STATUS_HEATERS_XSPACE;
  208. #endif
  209. #if HAS_HEATED_BED
  210. _draw_heater_status(H_BED, hx, STATUS_HEATERS_Y);
  211. #endif
  212. #if HAS_FAN
  213. // Fan display, pinned to the right side
  214. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  215. _draw_fan_status(LCD_PIXEL_WIDTH - STATUS_CHR_WIDTH * 4, STATUS_FAN_Y);
  216. #else
  217. _draw_fan_status(212, STATUS_FAN_Y);
  218. #endif
  219. #endif
  220. // Axis values
  221. const xyz_pos_t lpos = current_position.asLogical();
  222. const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive()); UNUSED(show_e_total);
  223. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  224. constexpr int16_t cpy = 195;
  225. if (show_e_total) {
  226. TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, 6, cpy));
  227. }
  228. else {
  229. _draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink, 6, cpy);
  230. TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink, 95, cpy));
  231. }
  232. TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, 165, cpy));
  233. #else
  234. constexpr int16_t cpx = LCD_PIXEL_WIDTH - 104;
  235. _draw_axis_value(X_AXIS, ftostr52sp(lpos.x), blink, cpx, STATUS_HEATERS_Y);
  236. TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr52sp(lpos.y), blink, cpx, STATUS_HEATERS_Y + 59));
  237. TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, cpx, STATUS_HEATERS_Y + 118));
  238. #endif
  239. // Feedrate
  240. static uint16_t old_fp = 0;
  241. if (!ui.did_first_redraw || old_fp != feedrate_percentage) {
  242. old_fp = feedrate_percentage;
  243. _draw_feedrate_status(i16tostr3rj(feedrate_percentage),
  244. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  245. 5, 290
  246. #else
  247. 294, STATUS_HEATERS_Y
  248. #endif
  249. );
  250. }
  251. //
  252. // Elapsed time
  253. //
  254. char buffer[14];
  255. duration_t time;
  256. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  257. // Portrait mode only shows one value at a time, and will rotate if ROTATE_PROGRESS_DISPLAY
  258. dwin_string.set();
  259. char prefix = ' ';
  260. #if ENABLED(SHOW_REMAINING_TIME)
  261. if (TERN1(ROTATE_PROGRESS_DISPLAY, blink) && print_job_timer.isRunning()) {
  262. time = get_remaining_time();
  263. prefix = 'R';
  264. }
  265. else
  266. #endif
  267. time = print_job_timer.duration();
  268. time.toDigital(buffer);
  269. dwin_string.add(prefix);
  270. dwin_string.add(buffer);
  271. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, (LCD_PIXEL_WIDTH - ((dwin_string.length() + 1) * 14)), 290, S(dwin_string.string()));
  272. #else
  273. // landscape mode shows both elapsed and remaining (if SHOW_REMAINING_TIME)
  274. time = print_job_timer.duration();
  275. time.toDigital(buffer);
  276. dwin_string.set(" ");
  277. dwin_string.add(buffer);
  278. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 280, 100, S(dwin_string.string()));
  279. #if ENABLED(LCD_SHOW_E_TOTAL)
  280. if (show_e_total && TERN1(SHOW_REMAINING_TIME, !blink)) { // if SHOW_REMAINING_TIME is also
  281. const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // show cm after 99,000mm
  282. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S("E"));
  283. dwin_string.set(ui16tostr5rj(e_move_accumulator * escale));
  284. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 263, 135, S(dwin_string.string()));
  285. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 333, 135, S(escale==1 ? "mm" : "cm"));
  286. }
  287. #endif
  288. #if ENABLED(SHOW_REMAINING_TIME)
  289. if (!show_e_total || blink) {
  290. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 249, 135, S(" R "));
  291. time = get_remaining_time();
  292. time.toDigital(buffer);
  293. dwin_string.set(buffer);
  294. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 291, 135, S(dwin_string.string()));
  295. }
  296. #endif
  297. #endif
  298. //
  299. // Progress Bar
  300. //
  301. constexpr int16_t pb_margin = 5, pb_left = pb_margin, pb_height = 60,
  302. pb_right = LCD_PIXEL_WIDTH - TERN(DWIN_MARLINUI_PORTRAIT, 0, 107) - pb_margin,
  303. pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 230),
  304. pb_top = pb_bottom - pb_height,
  305. pb_width = pb_right - pb_left;
  306. const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
  307. if (!ui.did_first_redraw)
  308. DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
  309. static uint16_t old_solid = 50;
  310. const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
  311. const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
  312. if (p_draw) {
  313. //if (pb_solid)
  314. DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
  315. //if (pb_solid < old_solid)
  316. DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
  317. #if ENABLED(SHOW_SD_PERCENT)
  318. dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
  319. dwin_string.add(PSTR("%"));
  320. DWIN_Draw_String(
  321. false, font16x32, Percent_Color, Color_Bg_Black,
  322. pb_left + (pb_width - dwin_string.length() * 16) / 2,
  323. pb_top + (pb_height - 32) / 2,
  324. S(dwin_string.string())
  325. );
  326. #endif
  327. old_solid = pb_solid;
  328. }
  329. //
  330. // Status Message
  331. //
  332. draw_status_message(blink);
  333. ui.did_first_redraw = true;
  334. }
  335. #endif // IS_DWIN_MARLINUI