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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474
  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 <https://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. #include "../../../module/planner.h"
  36. #if ENABLED(SDSUPPORT)
  37. #include "../../../libs/duration_t.h"
  38. #endif
  39. #if ENABLED(LCD_SHOW_E_TOTAL)
  40. #include "../../../MarlinCore.h" // for printingIsActive
  41. #endif
  42. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  43. #define STATUS_HEATERS_X 15
  44. #define STATUS_HEATERS_Y 56
  45. #else
  46. #define STATUS_HEATERS_X 154
  47. #define STATUS_HEATERS_Y 10
  48. #endif
  49. #define STATUS_HEATERS_XSPACE 64
  50. #define STATUS_FAN_WIDTH 48
  51. #define STATUS_FAN_HEIGHT 48
  52. #define STATUS_FAN_Y STATUS_HEATERS_Y + 22
  53. #define STATUS_CHR_WIDTH 14
  54. #define STATUS_CHR_HEIGHT 28
  55. //
  56. // Before homing, blink '123' <-> '???'.
  57. // Homed but unknown... '123' <-> ' '.
  58. // Homed and known, display constantly.
  59. //
  60. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink, const uint16_t x, const uint16_t y) {
  61. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  62. uint8_t vallen = utf8_strlen(value);
  63. if (!ui.did_first_redraw) {
  64. dwin_string.set('X' + axis);
  65. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (vallen * 14 - 14) / 2, y + 2, S(dwin_string.string()));
  66. }
  67. dwin_string.set();
  68. if (blink)
  69. dwin_string.add(value);
  70. else if (!TEST(axes_homed, axis))
  71. while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
  72. else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !TEST(axes_trusted, axis))
  73. dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
  74. else
  75. dwin_string.add(value);
  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(F(" "));
  79. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
  80. #else // !DWIN_MARLINUI_PORTRAIT
  81. if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
  82. dwin_string.set('X' + axis);
  83. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
  84. }
  85. dwin_string.set();
  86. if (blink)
  87. dwin_string.add(value);
  88. else {
  89. if (!TEST(axes_homed, axis))
  90. while (const char c = *value++) dwin_string.add(c <= '.' ? c : '?');
  91. else {
  92. #if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
  93. if (!TEST(axes_trusted, axis))
  94. dwin_string.add(TERN1(DWIN_MARLINUI_PORTRAIT, axis == Z_AXIS) ? PSTR(" ") : PSTR(" "));
  95. else
  96. #endif
  97. dwin_string.add(value);
  98. }
  99. }
  100. // For E_TOTAL there may be some characters to cover up
  101. if (ENABLED(LCD_SHOW_E_TOTAL) && (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) && axis == X_AXIS)
  102. dwin_string.add(F(" "));
  103. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
  104. #endif // !DWIN_MARLINUI_PORTRAIT
  105. }
  106. #if ENABLED(LCD_SHOW_E_TOTAL)
  107. FORCE_INLINE void _draw_e_value(const_float_t value, const uint16_t x, const uint16_t y) {
  108. const uint8_t scale = value >= 100000.0f ? 10 : 1; // show cm after 99,999mm
  109. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  110. if (!ui.did_first_redraw) {
  111. // Extra spaces to erase previous value
  112. dwin_string.set(F("E "));
  113. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x + (4 * 14 / 2) - 7, y + 2, S(dwin_string.string()));
  114. }
  115. dwin_string.set(ui16tostr5rj(value / scale));
  116. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 32, S(dwin_string.string()));
  117. // Extra spaces to erase previous value
  118. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (5 * 14), y + 32, S(scale == 1 ? "mm " : "cm "));
  119. #else // !DWIN_MARLINUI_PORTRAIT
  120. if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
  121. dwin_string.set(F("E "));
  122. DWIN_Draw_String(true, font16x32, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
  123. }
  124. dwin_string.set(ui16tostr5rj(value / scale));
  125. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 32, y + 4, S(dwin_string.string()));
  126. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x + (32 + 70), y + 4, S(scale == 1 ? "mm " : "cm "));
  127. #endif // !DWIN_MARLINUI_PORTRAIT
  128. }
  129. #endif // LCD_SHOW_E_TOTAL
  130. //
  131. // Fan Icon and Percentage
  132. //
  133. FORCE_INLINE void _draw_fan_status(const uint16_t x, const uint16_t y) {
  134. const uint16_t fanx = (4 * STATUS_CHR_WIDTH - STATUS_FAN_WIDTH) / 2;
  135. const uint8_t fan_pct = thermalManager.scaledFanSpeedPercent(0);
  136. const bool fan_on = !!fan_pct;
  137. if (fan_on) {
  138. DWIN_ICON_Animation(0, fan_on, ICON, ICON_Fan0, ICON_Fan3, x + fanx, y, 25);
  139. dwin_string.set(i8tostr3rj(fan_pct));
  140. dwin_string.add('%');
  141. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
  142. }
  143. else {
  144. DWIN_ICON_AnimationControl(0x0000); // disable all icon animations (this is the only one)
  145. DWIN_ICON_Show(ICON, ICON_Fan0, x + fanx, y);
  146. dwin_string.set(F(" "));
  147. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + STATUS_FAN_HEIGHT, S(dwin_string.string()));
  148. }
  149. }
  150. /**
  151. * Draw a single heater icon with current and target temperature, at the given XY
  152. */
  153. FORCE_INLINE void _draw_heater_status(const heater_id_t heater, const uint16_t x, const uint16_t y) {
  154. #if HAS_HOTEND
  155. #if HOTENDS > 2
  156. #define HOTEND_STATS 3
  157. #elif HOTENDS > 1
  158. #define HOTEND_STATS 2
  159. #else
  160. #define HOTEND_STATS 1
  161. #endif
  162. static celsius_t old_temp[HOTEND_STATS] = { 0 },
  163. old_target[HOTEND_STATS] = { 0 };
  164. static bool old_on[HOTEND_STATS] = { false };
  165. #endif
  166. #if HAS_HEATED_BED
  167. static celsius_t old_bed_temp = 0, old_bed_target = 0;
  168. static bool old_bed_on = false;
  169. #if HAS_LEVELING
  170. static bool old_leveling_on = false;
  171. #endif
  172. #endif
  173. #if HAS_HOTEND && HAS_HEATED_BED
  174. float tc, tt;
  175. bool c_draw, t_draw, i_draw, ta;
  176. const bool isBed = heater < 0;
  177. if (isBed) {
  178. tc = thermalManager.degBed();
  179. tt = thermalManager.degTargetBed();
  180. ta = thermalManager.isHeatingBed();
  181. c_draw = tc != old_bed_temp;
  182. t_draw = tt != old_bed_target;
  183. i_draw = ta != old_bed_on;
  184. old_bed_temp = tc;
  185. old_bed_target = tt;
  186. old_bed_on = ta;
  187. }
  188. else {
  189. tc = thermalManager.degHotend(heater);
  190. tt = thermalManager.degTargetHotend(heater);
  191. ta = thermalManager.isHeatingHotend(heater);
  192. c_draw = tc != old_temp[heater];
  193. t_draw = tt != old_target[heater];
  194. i_draw = ta != old_on[heater];
  195. old_temp[heater] = tc;
  196. old_target[heater] = tt;
  197. old_on[heater] = ta;
  198. }
  199. #elif HAS_HOTEND
  200. constexpr bool isBed = false;
  201. const float tc = thermalManager.degHotend(heater), tt = thermalManager.degTargetHotend(heater);
  202. const uint8_t ta = thermalManager.isHeatingHotend(heater);
  203. bool c_draw = tc != old_temp[heater], t_draw = tt != old_target[heater], i_draw = ta != old_on[heater];
  204. old_temp[heater] = tc; old_target[heater] = tt; old_on[heater] = ta;
  205. #elif HAS_HEATED_BED
  206. constexpr bool isBed = true;
  207. const float tc = thermalManager.degBed(), tt = thermalManager.degTargetBed();
  208. const uint8_t ta = thermalManager.isHeatingBed();
  209. bool c_draw = tc != old_bed_temp, t_draw = tt != old_bed_target, i_draw = ta != old_bed_on;
  210. old_bed_temp = tc; old_bed_target = tt; old_bed_on = ta;
  211. #else
  212. bool c_draw = false, t_draw = false, i_draw = false;
  213. constexpr float tc = 0, tt = 0;
  214. constexpr uint8_t ta = 0;
  215. #endif
  216. #if HAS_HEATED_BED && HAS_LEVELING
  217. if (isBed) {
  218. i_draw |= (planner.leveling_active != old_leveling_on);
  219. old_leveling_on = planner.leveling_active;
  220. }
  221. #endif
  222. // Draw target temperature, if needed
  223. if (!ui.did_first_redraw || t_draw) {
  224. dwin_string.set(i16tostr3rj(tt + 0.5));
  225. dwin_string.add(LCD_STR_DEGREE);
  226. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y, S(dwin_string.string()));
  227. }
  228. // Draw heater icon with on / off / leveled states
  229. if (!ui.did_first_redraw || i_draw) {
  230. const uint8_t ico = isBed ? (TERN0(HAS_LEVELING, planner.leveling_active) ? ICON_BedLevelOff : ICON_BedOff) : ICON_HotendOff;
  231. DWIN_ICON_Show(ICON, ico + ta, x, y + STATUS_CHR_HEIGHT + 2);
  232. }
  233. // Draw current temperature, if needed
  234. if (!ui.did_first_redraw || c_draw) {
  235. dwin_string.set(i16tostr3rj(tc + 0.5));
  236. dwin_string.add(LCD_STR_DEGREE);
  237. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x, y + 70, S(dwin_string.string()));
  238. }
  239. }
  240. /**
  241. * Draw the current "feed rate" percentage preceded by the >> character
  242. */
  243. FORCE_INLINE void _draw_feedrate_status(const char *value, uint16_t x, uint16_t y) {
  244. if (!ui.did_first_redraw) {
  245. dwin_string.set(LCD_STR_FEEDRATE);
  246. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, x, y, S(dwin_string.string()));
  247. }
  248. dwin_string.set(value);
  249. dwin_string.add('%');
  250. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, x + 14, y, S(dwin_string.string()));
  251. }
  252. /**
  253. * Draw the MarlinUI Status Screen for Ender 3 V2
  254. */
  255. void MarlinUI::draw_status_screen() {
  256. const bool blink = get_blink();
  257. // Draw elements that never change
  258. if (!ui.did_first_redraw) {
  259. // Logo/Status Icon
  260. #define STATUS_LOGO_WIDTH 128
  261. #define STATUS_LOGO_HEIGHT 40
  262. DWIN_ICON_Show(ICON, ICON_LOGO_Marlin,
  263. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  264. (LCD_PIXEL_WIDTH - (STATUS_LOGO_WIDTH)) / 2, ((STATUS_HEATERS_Y - 4) - (STATUS_LOGO_HEIGHT)) / 2
  265. #else
  266. 5, 42
  267. #endif
  268. );
  269. // Draw a frame around the x/y/z values
  270. DWIN_Draw_Rectangle(0, Select_Color,
  271. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  272. 0, 193, LCD_PIXEL_WIDTH, 260
  273. #else
  274. 0, 115, LCD_PIXEL_WIDTH - 1, 152
  275. #endif
  276. );
  277. }
  278. uint16_t hx = STATUS_HEATERS_X;
  279. #if HAS_HOTEND
  280. _draw_heater_status(H_E0, hx, STATUS_HEATERS_Y);
  281. hx += STATUS_HEATERS_XSPACE;
  282. #endif
  283. #if HAS_MULTI_HOTEND
  284. _draw_heater_status(H_E1, hx, STATUS_HEATERS_Y);
  285. hx += STATUS_HEATERS_XSPACE;
  286. #endif
  287. #if HAS_HEATED_BED
  288. _draw_heater_status(H_BED, hx, STATUS_HEATERS_Y);
  289. #endif
  290. #if HAS_FAN
  291. _draw_fan_status(LCD_PIXEL_WIDTH - STATUS_CHR_WIDTH * 5, STATUS_FAN_Y);
  292. #endif
  293. // Axis values
  294. const xyz_pos_t lpos = current_position.asLogical();
  295. const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive()); UNUSED(show_e_total);
  296. constexpr int16_t cpy = TERN(DWIN_MARLINUI_PORTRAIT, 195, 117);
  297. if (show_e_total) {
  298. TERN_(LCD_SHOW_E_TOTAL, _draw_e_value(e_move_accumulator, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy));
  299. }
  300. else {
  301. _draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink, TERN(DWIN_MARLINUI_PORTRAIT, 6, 75), cpy);
  302. TERN_(HAS_Y_AXIS, _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink, TERN(DWIN_MARLINUI_PORTRAIT, 95, 184), cpy));
  303. }
  304. TERN_(HAS_Z_AXIS, _draw_axis_value(Z_AXIS, ftostr52sp(lpos.z), blink, TERN(DWIN_MARLINUI_PORTRAIT, 165, 300), cpy));
  305. // Feedrate
  306. static uint16_t old_fp = 0;
  307. if (!ui.did_first_redraw || old_fp != feedrate_percentage) {
  308. old_fp = feedrate_percentage;
  309. _draw_feedrate_status(i16tostr3rj(feedrate_percentage),
  310. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  311. 5, 290
  312. #else
  313. 14, 195
  314. #endif
  315. );
  316. }
  317. //
  318. // Elapsed time
  319. //
  320. char buffer[14];
  321. duration_t time;
  322. #if ENABLED(DWIN_MARLINUI_PORTRAIT)
  323. // Portrait mode only shows one value at a time, and will rotate if many are enabled
  324. dwin_string.set();
  325. char prefix = ' ';
  326. #if ENABLED(SHOW_REMAINING_TIME)
  327. if (blink && print_job_timer.isRunning()) {
  328. time = get_remaining_time();
  329. prefix = 'R';
  330. }
  331. else
  332. #endif
  333. time = print_job_timer.duration();
  334. time.toDigital(buffer);
  335. dwin_string.add(prefix);
  336. dwin_string.add(buffer);
  337. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, (LCD_PIXEL_WIDTH - ((dwin_string.length + 1) * 14)), 290, S(dwin_string.string()));
  338. #else
  339. // landscape mode shows both elapsed and remaining (if SHOW_REMAINING_TIME)
  340. time = print_job_timer.duration();
  341. time.toDigital(buffer);
  342. dwin_string.set(' ');
  343. dwin_string.add(buffer);
  344. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 230, 170, S(dwin_string.string()));
  345. #if ENABLED(SHOW_REMAINING_TIME)
  346. if (print_job_timer.isRunning()) {
  347. time = get_remaining_time();
  348. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(" R "));
  349. if (print_job_timer.isPaused() && blink)
  350. dwin_string.set(F(" "));
  351. else {
  352. time.toDigital(buffer);
  353. dwin_string.set(buffer);
  354. }
  355. DWIN_Draw_String(true, font14x28, Color_White, Color_Bg_Black, 378, 170, S(dwin_string.string()));
  356. }
  357. else if (!ui.did_first_redraw || ui.old_is_printing != print_job_timer.isRunning()) {
  358. dwin_string.set(F(" "));
  359. DWIN_Draw_String(true, font14x28, Color_IconBlue, Color_Bg_Black, 336, 170, S(dwin_string.string()));
  360. }
  361. #endif
  362. #endif
  363. //
  364. // Progress Bar
  365. //
  366. #if HAS_PRINT_PROGRESS
  367. constexpr int16_t pb_margin = 5,
  368. pb_left = pb_margin + TERN(DWIN_MARLINUI_PORTRAIT, 0, 90),
  369. pb_height = TERN(DWIN_MARLINUI_PORTRAIT, 60, 20),
  370. pb_right = LCD_PIXEL_WIDTH - pb_margin,
  371. pb_bottom = TERN(DWIN_MARLINUI_PORTRAIT, 410, 220),
  372. pb_top = pb_bottom - pb_height,
  373. pb_width = pb_right - pb_left;
  374. const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
  375. if (!ui.did_first_redraw)
  376. DWIN_Draw_Rectangle(0, Select_Color, pb_left, pb_top, pb_right, pb_bottom); // Outline
  377. static uint16_t old_solid = 50;
  378. const uint16_t pb_solid = (pb_width - 2) * (progress / (PROGRESS_SCALE)) * 0.01f;
  379. const bool p_draw = !ui.did_first_redraw || old_solid != pb_solid;
  380. if (p_draw) {
  381. //if (pb_solid)
  382. DWIN_Draw_Rectangle(1, Select_Color, pb_left + 1, pb_top + 1, pb_left + pb_solid, pb_bottom - 1); // Fill the solid part
  383. //if (pb_solid < old_solid)
  384. DWIN_Draw_Rectangle(1, Color_Bg_Black, pb_left + 1 + pb_solid, pb_top + 1, pb_right - 1, pb_bottom - 1); // Erase the rest
  385. #if ENABLED(SHOW_PROGRESS_PERCENT)
  386. dwin_string.set(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
  387. dwin_string.add('%');
  388. DWIN_Draw_String(
  389. false, font16x32, Percent_Color, Color_Bg_Black,
  390. pb_left + (pb_width - dwin_string.length * 16) / 2,
  391. pb_top + (pb_height - 32) / 2,
  392. S(dwin_string.string())
  393. );
  394. #endif
  395. old_solid = pb_solid;
  396. }
  397. #endif // HAS_PRINT_PROGRESS
  398. //
  399. // Status Message
  400. //
  401. draw_status_message(blink);
  402. ui.did_first_redraw = true;
  403. ui.old_is_printing = print_job_timer.isRunning();
  404. }
  405. #endif // IS_DWIN_MARLINUI