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.

status_screen_DOGM.cpp 30KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916
  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. //
  23. // status_screen_DOGM.cpp
  24. // Standard Status Screen for Graphical Display
  25. //
  26. #include "../../inc/MarlinConfigPre.h"
  27. #if HAS_MARLINUI_U8GLIB && DISABLED(LIGHTWEIGHT_UI)
  28. #include "dogm_Statusscreen.h"
  29. #include "marlinui_DOGM.h"
  30. #include "../marlinui.h"
  31. #include "../lcdprint.h"
  32. #include "../../libs/numtostr.h"
  33. #include "../../module/motion.h"
  34. #include "../../module/temperature.h"
  35. #if ENABLED(FILAMENT_LCD_DISPLAY)
  36. #include "../../feature/filwidth.h"
  37. #include "../../module/planner.h"
  38. #include "../../gcode/parser.h"
  39. #endif
  40. #if HAS_CUTTER
  41. #include "../../feature/spindle_laser.h"
  42. #endif
  43. #if HAS_POWER_MONITOR
  44. #include "../../feature/power_monitor.h"
  45. #endif
  46. #if ENABLED(SDSUPPORT)
  47. #include "../../sd/cardreader.h"
  48. #endif
  49. #if HAS_PRINT_PROGRESS
  50. #include "../../module/printcounter.h"
  51. #endif
  52. #if HAS_DUAL_MIXING
  53. #include "../../feature/mixing.h"
  54. #endif
  55. #define X_LABEL_POS 3
  56. #define X_VALUE_POS 11
  57. #define XYZ_SPACING 37
  58. #define XYZ_BASELINE (30 + INFO_FONT_ASCENT)
  59. #define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
  60. #define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)
  61. #if ANIM_HBCC
  62. enum HeatBits : uint8_t {
  63. HEATBIT_HOTEND,
  64. HEATBIT_BED = HOTENDS,
  65. HEATBIT_CHAMBER,
  66. HEATBIT_CUTTER
  67. };
  68. IF<(HEATBIT_CUTTER > 7), uint16_t, uint8_t>::type heat_bits;
  69. #endif
  70. #if ANIM_HOTEND
  71. #define HOTEND_ALT(N) TEST(heat_bits, HEATBIT_HOTEND + N)
  72. #else
  73. #define HOTEND_ALT(N) false
  74. #endif
  75. #if ANIM_BED
  76. #define BED_ALT() TEST(heat_bits, HEATBIT_BED)
  77. #else
  78. #define BED_ALT() false
  79. #endif
  80. #if ANIM_CHAMBER
  81. #define CHAMBER_ALT() TEST(heat_bits, HEATBIT_CHAMBER)
  82. #else
  83. #define CHAMBER_ALT() false
  84. #endif
  85. #if ANIM_CUTTER
  86. #define CUTTER_ALT(N) TEST(heat_bits, HEATBIT_CUTTER)
  87. #else
  88. #define CUTTER_ALT() false
  89. #endif
  90. #if DO_DRAW_HOTENDS
  91. #define MAX_HOTEND_DRAW _MIN(HOTENDS, ((LCD_PIXEL_WIDTH - (STATUS_LOGO_BYTEWIDTH + STATUS_FAN_BYTEWIDTH) * 8) / (STATUS_HEATERS_XSPACE)))
  92. #define STATUS_HEATERS_BOT (STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)
  93. #endif
  94. #if HAS_POWER_MONITOR
  95. void display_power_monitor(const uint8_t x, const uint8_t y) {
  96. lcd_moveto(x, y);
  97. #if HAS_POWER_MONITOR_WATTS
  98. const bool wflag = power_monitor.power_display_enabled();
  99. #endif
  100. #if ENABLED(POWER_MONITOR_CURRENT)
  101. const bool iflag = power_monitor.current_display_enabled();
  102. #endif
  103. #if HAS_POWER_MONITOR_VREF
  104. const bool vflag = power_monitor.voltage_display_enabled();
  105. #endif
  106. #if HAS_POWER_MONITOR_WATTS
  107. // Cycle between current, voltage, and power
  108. if (ELAPSED(millis(), power_monitor.display_item_ms)) {
  109. power_monitor.display_item_ms = millis() + 1000UL;
  110. ++power_monitor.display_item;
  111. }
  112. #elif ENABLED(POWER_MONITOR_CURRENT)
  113. power_monitor.display_item = 0;
  114. #elif HAS_POWER_MONITOR_VREF
  115. power_monitor.display_item = 1;
  116. #endif
  117. // ensure we have the right one selected for display
  118. for (uint8_t i = 0; i < 3; i++) {
  119. #if ENABLED(POWER_MONITOR_CURRENT)
  120. if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
  121. #endif
  122. #if HAS_POWER_MONITOR_VREF
  123. if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
  124. #endif
  125. #if HAS_POWER_MONITOR_WATTS
  126. if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
  127. #endif
  128. if (power_monitor.display_item >= 3) power_monitor.display_item = 0;
  129. }
  130. switch (power_monitor.display_item) {
  131. #if ENABLED(POWER_MONITOR_CURRENT) // Current
  132. case 0: if (iflag) power_monitor.draw_current(); break;
  133. #endif
  134. #if HAS_POWER_MONITOR_VREF // Voltage
  135. case 1: if (vflag) power_monitor.draw_voltage(); break;
  136. #endif
  137. #if HAS_POWER_MONITOR_WATTS // Power
  138. case 2: if (wflag) power_monitor.draw_power(); break;
  139. #endif
  140. default: break;
  141. }
  142. }
  143. #endif
  144. #define PROGRESS_BAR_X 54
  145. #define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1)
  146. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  147. FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
  148. const char *str = i16tostr3rj(temp);
  149. const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
  150. lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
  151. lcd_put_wchar(LCD_STR_DEGREE[0]);
  152. }
  153. #if DO_DRAW_HOTENDS
  154. // Draw hotend bitmap with current and target temperatures
  155. FORCE_INLINE void _draw_hotend_status(const heater_id_t heater_id, const bool blink) {
  156. #if !HEATER_IDLE_HANDLER
  157. UNUSED(blink);
  158. #endif
  159. const bool isHeat = HOTEND_ALT(heater_id);
  160. const uint8_t tx = STATUS_HOTEND_TEXT_X(heater_id);
  161. const float temp = thermalManager.degHotend(heater_id),
  162. target = thermalManager.degTargetHotend(heater_id);
  163. #if DISABLED(STATUS_HOTEND_ANIM)
  164. #define STATIC_HOTEND true
  165. #define HOTEND_DOT isHeat
  166. #else
  167. #define STATIC_HOTEND false
  168. #define HOTEND_DOT false
  169. #endif
  170. #if ANIM_HOTEND && BOTH(STATUS_HOTEND_INVERTED, STATUS_HOTEND_NUMBERLESS)
  171. #define OFF_BMP(N) status_hotend_b_bmp
  172. #define ON_BMP(N) status_hotend_a_bmp
  173. #elif ANIM_HOTEND && DISABLED(STATUS_HOTEND_INVERTED) && ENABLED(STATUS_HOTEND_NUMBERLESS)
  174. #define OFF_BMP(N) status_hotend_a_bmp
  175. #define ON_BMP(N) status_hotend_b_bmp
  176. #elif BOTH(ANIM_HOTEND, STATUS_HOTEND_INVERTED)
  177. #define OFF_BMP(N) status_hotend##N##_b_bmp
  178. #define ON_BMP(N) status_hotend##N##_a_bmp
  179. #else
  180. #define OFF_BMP(N) status_hotend##N##_a_bmp
  181. #define ON_BMP(N) status_hotend##N##_b_bmp
  182. #endif
  183. #if STATUS_HOTEND_BITMAPS > 1
  184. static const unsigned char* const status_hotend_gfx[STATUS_HOTEND_BITMAPS] PROGMEM = ARRAY_N(STATUS_HOTEND_BITMAPS, OFF_BMP(1), OFF_BMP(2), OFF_BMP(3), OFF_BMP(4), OFF_BMP(5), OFF_BMP(6));
  185. #if ANIM_HOTEND
  186. static const unsigned char* const status_hotend_on_gfx[STATUS_HOTEND_BITMAPS] PROGMEM = ARRAY_N(STATUS_HOTEND_BITMAPS, ON_BMP(1), ON_BMP(2), ON_BMP(3), ON_BMP(4), ON_BMP(5), ON_BMP(6));
  187. #define HOTEND_BITMAP(N,S) (unsigned char*)pgm_read_ptr((S) ? &status_hotend_on_gfx[(N) % (STATUS_HOTEND_BITMAPS)] : &status_hotend_gfx[(N) % (STATUS_HOTEND_BITMAPS)])
  188. #else
  189. #define HOTEND_BITMAP(N,S) (unsigned char*)pgm_read_ptr(&status_hotend_gfx[(N) % (STATUS_HOTEND_BITMAPS)])
  190. #endif
  191. #elif ANIM_HOTEND
  192. #define HOTEND_BITMAP(N,S) ((S) ? ON_BMP() : OFF_BMP())
  193. #else
  194. #define HOTEND_BITMAP(N,S) status_hotend_a_bmp
  195. #endif
  196. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_BOT)) {
  197. #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2)
  198. const float prop = target - 20,
  199. perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0;
  200. uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f);
  201. NOMORE(tall, BAR_TALL);
  202. #if ANIM_HOTEND
  203. // Draw hotend bitmap, either whole or split by the heating percent
  204. const uint8_t hx = STATUS_HOTEND_X(heater_id),
  205. bw = STATUS_HOTEND_BYTEWIDTH(heater_id);
  206. #if ENABLED(STATUS_HEAT_PERCENT)
  207. if (isHeat && tall <= BAR_TALL) {
  208. const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall;
  209. u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater_id, false));
  210. u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater_id, true) + ph * bw);
  211. }
  212. else
  213. #endif
  214. u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater_id, isHeat));
  215. #endif
  216. } // PAGE_CONTAINS
  217. if (PAGE_UNDER(7)) {
  218. #if HEATER_IDLE_HANDLER
  219. const bool dodraw = (blink || !thermalManager.heater_idle[heater_id].timed_out);
  220. #else
  221. constexpr bool dodraw = true;
  222. #endif
  223. if (dodraw) _draw_centered_temp(target + 0.5, tx, 7);
  224. }
  225. if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1))
  226. _draw_centered_temp(temp + 0.5f, tx, 28);
  227. if (STATIC_HOTEND && HOTEND_DOT && PAGE_CONTAINS(17, 19)) {
  228. u8g.setColorIndex(0); // set to white on black
  229. u8g.drawBox(tx, 20 - 3, 2, 2);
  230. u8g.setColorIndex(1); // restore black on white
  231. }
  232. }
  233. #endif // DO_DRAW_HOTENDS
  234. #if DO_DRAW_BED
  235. // Draw bed bitmap with current and target temperatures
  236. FORCE_INLINE void _draw_bed_status(const bool blink) {
  237. #if !HEATER_IDLE_HANDLER
  238. UNUSED(blink);
  239. #endif
  240. const uint8_t tx = STATUS_BED_TEXT_X;
  241. const float temp = thermalManager.degBed(),
  242. target = thermalManager.degTargetBed();
  243. #if ENABLED(STATUS_HEAT_PERCENT) || DISABLED(STATUS_BED_ANIM)
  244. const bool isHeat = BED_ALT();
  245. #endif
  246. #if DISABLED(STATUS_BED_ANIM)
  247. #define STATIC_BED true
  248. #define BED_DOT isHeat
  249. #else
  250. #define STATIC_BED false
  251. #define BED_DOT false
  252. #endif
  253. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_BOT)) {
  254. #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2)
  255. const float prop = target - 20,
  256. perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0;
  257. uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f);
  258. NOMORE(tall, BAR_TALL);
  259. // Draw a heating progress bar, if specified
  260. #if ENABLED(STATUS_HEAT_PERCENT)
  261. if (isHeat) {
  262. const uint8_t bx = STATUS_BED_X + STATUS_BED_WIDTH;
  263. u8g.drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT);
  264. if (tall) {
  265. const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall;
  266. if (PAGE_OVER(STATUS_HEATERS_Y + ph))
  267. u8g.drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall);
  268. }
  269. }
  270. #endif
  271. } // PAGE_CONTAINS
  272. if (PAGE_UNDER(7)) {
  273. #if HEATER_IDLE_HANDLER
  274. const bool dodraw = (blink || !thermalManager.heater_idle[thermalManager.IDLE_INDEX_BED].timed_out);
  275. #else
  276. constexpr bool dodraw = true;
  277. #endif
  278. if (dodraw) _draw_centered_temp(target + 0.5, tx, 7);
  279. }
  280. if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1))
  281. _draw_centered_temp(temp + 0.5f, tx, 28);
  282. if (STATIC_BED && BED_DOT && PAGE_CONTAINS(17, 19)) {
  283. u8g.setColorIndex(0); // set to white on black
  284. u8g.drawBox(tx, 20 - 2, 2, 2);
  285. u8g.setColorIndex(1); // restore black on white
  286. }
  287. }
  288. #endif // DO_DRAW_BED
  289. #if DO_DRAW_CHAMBER
  290. FORCE_INLINE void _draw_chamber_status() {
  291. #if HAS_HEATED_CHAMBER
  292. if (PAGE_UNDER(7))
  293. _draw_centered_temp(thermalManager.degTargetChamber() + 0.5f, STATUS_CHAMBER_TEXT_X, 7);
  294. #endif
  295. if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1))
  296. _draw_centered_temp(thermalManager.degChamber() + 0.5f, STATUS_CHAMBER_TEXT_X, 28);
  297. }
  298. #endif // DO_DRAW_CHAMBER
  299. //
  300. // Before homing, blink '123' <-> '???'.
  301. // Homed but unknown... '123' <-> ' '.
  302. // Homed and known, display constantly.
  303. //
  304. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  305. const AxisEnum a = TERN(LCD_SHOW_E_TOTAL, axis == E_AXIS ? X_AXIS : axis, axis);
  306. const uint8_t offs = (XYZ_SPACING) * a;
  307. lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, axis_codes[axis]);
  308. lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
  309. if (blink)
  310. lcd_put_u8str(value);
  311. else {
  312. if (!TEST(axis_homed, axis))
  313. while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
  314. else {
  315. #if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
  316. if (!TEST(axis_known_position, axis))
  317. lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
  318. else
  319. #endif
  320. lcd_put_u8str(value);
  321. }
  322. }
  323. }
  324. void MarlinUI::draw_status_screen() {
  325. static char xstring[TERN(LCD_SHOW_E_TOTAL, 12, 5)], ystring[5], zstring[8];
  326. #if ENABLED(FILAMENT_LCD_DISPLAY)
  327. static char wstring[5], mstring[4];
  328. #endif
  329. #if HAS_PRINT_PROGRESS
  330. #if DISABLED(DOGM_SD_PERCENT)
  331. #define _SD_INFO_X(len) (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH) / 2 - (len) * (MENU_FONT_WIDTH) / 2)
  332. #else
  333. #define _SD_INFO_X(len) (LCD_PIXEL_WIDTH - (len) * (MENU_FONT_WIDTH))
  334. #endif
  335. #if ENABLED(DOGM_SD_PERCENT)
  336. static char progress_string[5];
  337. #endif
  338. static uint8_t lastElapsed = 0xFF, lastProgress = 0xFF;
  339. static u8g_uint_t elapsed_x_pos = 0, progress_bar_solid_width = 0;
  340. static char elapsed_string[16];
  341. #if ENABLED(SHOW_REMAINING_TIME)
  342. static u8g_uint_t estimation_x_pos = 0;
  343. static char estimation_string[10];
  344. #if BOTH(DOGM_SD_PERCENT, ROTATE_PROGRESS_DISPLAY)
  345. static u8g_uint_t progress_x_pos = 0;
  346. static uint8_t progress_state = 0;
  347. static bool prev_blink = 0;
  348. #endif
  349. #endif
  350. #endif
  351. const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive() || marlin_state == MF_SD_COMPLETE);
  352. // At the first page, generate new display values
  353. if (first_page) {
  354. #if ANIM_HBCC
  355. uint8_t new_bits = 0;
  356. #if ANIM_HOTEND
  357. HOTEND_LOOP() if (thermalManager.isHeatingHotend(e)) SBI(new_bits, HEATBIT_HOTEND + e);
  358. #endif
  359. if (TERN0(ANIM_BED, thermalManager.isHeatingBed())) SBI(new_bits, HEATBIT_BED);
  360. #if DO_DRAW_CHAMBER && HAS_HEATED_CHAMBER
  361. if (thermalManager.isHeatingChamber()) SBI(new_bits, HEATBIT_CHAMBER);
  362. #endif
  363. if (TERN0(ANIM_CUTTER, cutter.enabled())) SBI(new_bits, HEATBIT_CUTTER);
  364. heat_bits = new_bits;
  365. #endif
  366. const xyz_pos_t lpos = current_position.asLogical();
  367. strcpy(zstring, ftostr52sp(lpos.z));
  368. if (show_e_total) {
  369. #if ENABLED(LCD_SHOW_E_TOTAL)
  370. const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm
  371. sprintf_P(xstring, PSTR("%ld%cm"), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm
  372. #endif
  373. }
  374. else {
  375. strcpy(xstring, ftostr4sign(lpos.x));
  376. strcpy(ystring, ftostr4sign(lpos.y));
  377. }
  378. #if ENABLED(FILAMENT_LCD_DISPLAY)
  379. strcpy(wstring, ftostr12ns(filwidth.measured_mm));
  380. strcpy(mstring, i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
  381. #endif
  382. // Progress / elapsed / estimation updates and string formatting to avoid float math on each LCD draw
  383. #if HAS_PRINT_PROGRESS
  384. const progress_t progress = TERN(HAS_PRINT_PROGRESS_PERMYRIAD, get_progress_permyriad, get_progress_percent)();
  385. duration_t elapsed = print_job_timer.duration();
  386. const uint8_t p = progress & 0xFF, ev = elapsed.value & 0xFF;
  387. if (p != lastProgress) {
  388. lastProgress = p;
  389. progress_bar_solid_width = u8g_uint_t((PROGRESS_BAR_WIDTH - 2) * (progress / (PROGRESS_SCALE)) * 0.01f);
  390. #if ENABLED(DOGM_SD_PERCENT)
  391. if (progress == 0) {
  392. progress_string[0] = '\0';
  393. #if ENABLED(SHOW_REMAINING_TIME)
  394. estimation_string[0] = '\0';
  395. estimation_x_pos = _SD_INFO_X(0);
  396. #endif
  397. }
  398. else
  399. strcpy(progress_string, TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(progress), ui8tostr3rj(progress / (PROGRESS_SCALE))));
  400. #if BOTH(SHOW_REMAINING_TIME, ROTATE_PROGRESS_DISPLAY) // Tri-state progress display mode
  401. progress_x_pos = _SD_INFO_X(strlen(progress_string) + 1);
  402. #endif
  403. #endif
  404. }
  405. constexpr bool can_show_days = DISABLED(DOGM_SD_PERCENT) || ENABLED(ROTATE_PROGRESS_DISPLAY);
  406. if (ev != lastElapsed) {
  407. lastElapsed = ev;
  408. const uint8_t len = elapsed.toDigital(elapsed_string, can_show_days && elapsed.value >= 60*60*24L);
  409. elapsed_x_pos = _SD_INFO_X(len);
  410. #if ENABLED(SHOW_REMAINING_TIME)
  411. if (!(ev & 0x3)) {
  412. uint32_t timeval = (0
  413. #if BOTH(LCD_SET_PROGRESS_MANUALLY, USE_M73_REMAINING_TIME)
  414. + get_remaining_time()
  415. #endif
  416. );
  417. if (!timeval && progress > 0) timeval = elapsed.value * (100 * (PROGRESS_SCALE) - progress) / progress;
  418. if (!timeval) {
  419. estimation_string[0] = '\0';
  420. estimation_x_pos = _SD_INFO_X(0);
  421. }
  422. else {
  423. duration_t estimation = timeval;
  424. const uint8_t len = estimation.toDigital(estimation_string, can_show_days && estimation.value >= 60*60*24L);
  425. estimation_x_pos = _SD_INFO_X(len
  426. #if !BOTH(DOGM_SD_PERCENT, ROTATE_PROGRESS_DISPLAY)
  427. + 1
  428. #endif
  429. );
  430. }
  431. }
  432. #endif
  433. }
  434. #endif
  435. }
  436. const bool blink = get_blink();
  437. // Status Menu Font
  438. set_font(FONT_STATUSMENU);
  439. #if DO_DRAW_LOGO
  440. if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1))
  441. u8g.drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp);
  442. #endif
  443. #if STATUS_HEATERS_WIDTH
  444. // Draw all heaters (and maybe the bed) in one go
  445. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1))
  446. u8g.drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp);
  447. #endif
  448. #if DO_DRAW_CUTTER && DISABLED(STATUS_COMBINE_HEATERS)
  449. #if ANIM_CUTTER
  450. #define CUTTER_BITMAP(S) ((S) ? status_cutter_on_bmp : status_cutter_bmp)
  451. #else
  452. #define CUTTER_BITMAP(S) status_cutter_bmp
  453. #endif
  454. const uint8_t cuttery = STATUS_CUTTER_Y(CUTTER_ALT()),
  455. cutterh = STATUS_CUTTER_HEIGHT(CUTTER_ALT());
  456. if (PAGE_CONTAINS(cuttery, cuttery + cutterh - 1))
  457. u8g.drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT()));
  458. #endif
  459. #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS)
  460. #if ANIM_BED
  461. #define BED_BITMAP(S) ((S) ? status_bed_on_bmp : status_bed_bmp)
  462. #else
  463. #define BED_BITMAP(S) status_bed_bmp
  464. #endif
  465. const uint8_t bedy = STATUS_BED_Y(BED_ALT()),
  466. bedh = STATUS_BED_HEIGHT(BED_ALT());
  467. if (PAGE_CONTAINS(bedy, bedy + bedh - 1))
  468. u8g.drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT()));
  469. #endif
  470. #if DO_DRAW_CHAMBER && DISABLED(STATUS_COMBINE_HEATERS)
  471. #if ANIM_CHAMBER
  472. #define CHAMBER_BITMAP(S) ((S) ? status_chamber_on_bmp : status_chamber_bmp)
  473. #else
  474. #define CHAMBER_BITMAP(S) status_chamber_bmp
  475. #endif
  476. const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()),
  477. chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT());
  478. if (PAGE_CONTAINS(chambery, chambery + chamberh - 1))
  479. u8g.drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT()));
  480. #endif
  481. #if DO_DRAW_FAN
  482. #if STATUS_FAN_FRAMES > 2
  483. static bool old_blink;
  484. static uint8_t fan_frame;
  485. if (old_blink != blink) {
  486. old_blink = blink;
  487. if (!thermalManager.fan_speed[0] || ++fan_frame >= STATUS_FAN_FRAMES) fan_frame = 0;
  488. }
  489. #endif
  490. if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1))
  491. u8g.drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT,
  492. #if STATUS_FAN_FRAMES > 2
  493. fan_frame == 1 ? status_fan1_bmp :
  494. fan_frame == 2 ? status_fan2_bmp :
  495. #if STATUS_FAN_FRAMES > 3
  496. fan_frame == 3 ? status_fan3_bmp :
  497. #endif
  498. #elif STATUS_FAN_FRAMES > 1
  499. blink && thermalManager.fan_speed[0] ? status_fan1_bmp :
  500. #endif
  501. status_fan0_bmp
  502. );
  503. #endif
  504. //
  505. // Temperature Graphics and Info
  506. //
  507. if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
  508. // Extruders
  509. #if DO_DRAW_HOTENDS
  510. LOOP_L_N(e, MAX_HOTEND_DRAW)
  511. _draw_hotend_status((heater_id_t)e, blink);
  512. #endif
  513. // Laser / Spindle
  514. #if DO_DRAW_CUTTER
  515. if (cutter.isReady && PAGE_CONTAINS(STATUS_CUTTER_TEXT_Y - INFO_FONT_ASCENT, STATUS_CUTTER_TEXT_Y - 1)) {
  516. #if CUTTER_UNIT_IS(PERCENT)
  517. lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
  518. lcd_put_wchar('%');
  519. #elif CUTTER_UNIT_IS(RPM)
  520. lcd_put_u8str(STATUS_CUTTER_TEXT_X - 2, STATUS_CUTTER_TEXT_Y, ftostr51rj(float(cutter.unitPower) / 1000));
  521. lcd_put_wchar('K');
  522. #else
  523. lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
  524. #endif
  525. }
  526. #endif
  527. // Heated Bed
  528. TERN_(DO_DRAW_BED, _draw_bed_status(blink));
  529. // Heated Chamber
  530. TERN_(DO_DRAW_CHAMBER, _draw_chamber_status());
  531. // Fan, if a bitmap was provided
  532. #if DO_DRAW_FAN
  533. if (PAGE_CONTAINS(STATUS_FAN_TEXT_Y - INFO_FONT_ASCENT, STATUS_FAN_TEXT_Y - 1)) {
  534. char c = '%';
  535. uint16_t spd = thermalManager.fan_speed[0];
  536. if (spd) {
  537. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  538. if (!blink && thermalManager.fan_speed_scaler[0] < 128) {
  539. spd = thermalManager.scaledFanSpeed(0, spd);
  540. c = '*';
  541. }
  542. #endif
  543. lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.fanPercent(spd)));
  544. lcd_put_wchar(c);
  545. }
  546. }
  547. #endif
  548. }
  549. #if ENABLED(SDSUPPORT)
  550. //
  551. // SD Card Symbol
  552. //
  553. if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) {
  554. // Upper box
  555. u8g.drawBox(42, 42, 8, 7); // 42-48 (or 41-47)
  556. // Right edge
  557. u8g.drawBox(50, 44, 2, 5); // 44-48 (or 43-47)
  558. // Bottom hollow box
  559. u8g.drawFrame(42, 49, 10, 4); // 49-52 (or 48-51)
  560. // Corner pixel
  561. u8g.drawPixel(50, 43); // 43 (or 42)
  562. }
  563. #endif // SDSUPPORT
  564. #if HAS_PRINT_PROGRESS
  565. //
  566. // Progress bar frame
  567. //
  568. if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3))
  569. u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4);
  570. //
  571. // Progress bar solid part
  572. //
  573. if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2))
  574. u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2);
  575. if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
  576. #if ALL(DOGM_SD_PERCENT, SHOW_REMAINING_TIME, ROTATE_PROGRESS_DISPLAY)
  577. if (prev_blink != blink) {
  578. prev_blink = blink;
  579. if (++progress_state >= 3) progress_state = 0;
  580. }
  581. if (progress_state == 0) {
  582. if (progress_string[0]) {
  583. lcd_put_u8str(progress_x_pos, EXTRAS_BASELINE, progress_string);
  584. lcd_put_wchar('%');
  585. }
  586. }
  587. else if (progress_state == 2 && estimation_string[0]) {
  588. lcd_put_u8str_P(PROGRESS_BAR_X, EXTRAS_BASELINE, PSTR("R:"));
  589. lcd_put_u8str(estimation_x_pos, EXTRAS_BASELINE, estimation_string);
  590. }
  591. else if (elapsed_string[0]) {
  592. lcd_put_u8str_P(PROGRESS_BAR_X, EXTRAS_BASELINE, E_LBL);
  593. lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
  594. }
  595. #else // !DOGM_SD_PERCENT || !SHOW_REMAINING_TIME || !ROTATE_PROGRESS_DISPLAY
  596. //
  597. // SD Percent Complete
  598. //
  599. #if ENABLED(DOGM_SD_PERCENT)
  600. if (progress_string[0]) {
  601. lcd_put_u8str(55, EXTRAS_BASELINE, progress_string); // Percent complete
  602. lcd_put_wchar('%');
  603. }
  604. #endif
  605. //
  606. // Elapsed Time
  607. //
  608. #if ENABLED(SHOW_REMAINING_TIME)
  609. if (blink && estimation_string[0]) {
  610. lcd_put_wchar(estimation_x_pos, EXTRAS_BASELINE, 'R');
  611. lcd_put_u8str(estimation_string);
  612. }
  613. else
  614. #endif
  615. lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
  616. #endif // !DOGM_SD_PERCENT || !SHOW_REMAINING_TIME || !ROTATE_PROGRESS_DISPLAY
  617. }
  618. #endif // HAS_PRINT_PROGRESS
  619. //
  620. // XYZ Coordinates
  621. //
  622. #if EITHER(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME)
  623. #define XYZ_FRAME_TOP 29
  624. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 3
  625. #else
  626. #define XYZ_FRAME_TOP 30
  627. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 1
  628. #endif
  629. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  630. #if DISABLED(XYZ_NO_FRAME)
  631. #if ENABLED(XYZ_HOLLOW_FRAME)
  632. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  633. #else
  634. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  635. #endif
  636. #endif
  637. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) {
  638. #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME)
  639. u8g.setColorIndex(0); // white on black
  640. #endif
  641. #if HAS_DUAL_MIXING
  642. // Two-component mix / gradient instead of XY
  643. char mixer_messages[15];
  644. PGM_P mix_label;
  645. #if ENABLED(GRADIENT_MIX)
  646. if (mixer.gradient.enabled) {
  647. mixer.update_mix_from_gradient();
  648. mix_label = PSTR("Gr");
  649. }
  650. else
  651. #endif
  652. {
  653. mixer.update_mix_from_vtool();
  654. mix_label = PSTR("Mx");
  655. }
  656. sprintf_P(mixer_messages, PSTR(S_FMT " %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
  657. lcd_put_u8str(X_LABEL_POS, XYZ_BASELINE, mixer_messages);
  658. #else
  659. if (show_e_total) {
  660. _draw_axis_value(E_AXIS, xstring, true);
  661. lcd_put_u8str_P(PSTR(" "));
  662. }
  663. else {
  664. _draw_axis_value(X_AXIS, xstring, blink);
  665. _draw_axis_value(Y_AXIS, ystring, blink);
  666. }
  667. #endif
  668. _draw_axis_value(Z_AXIS, zstring, blink);
  669. #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME)
  670. u8g.setColorIndex(1); // black on white
  671. #endif
  672. }
  673. }
  674. //
  675. // Feedrate
  676. //
  677. #define EXTRAS_2_BASELINE (EXTRAS_BASELINE + 3)
  678. if (PAGE_CONTAINS(EXTRAS_2_BASELINE - INFO_FONT_ASCENT, EXTRAS_2_BASELINE - 1)) {
  679. set_font(FONT_MENU);
  680. lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
  681. set_font(FONT_STATUSMENU);
  682. lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3rj(feedrate_percentage));
  683. lcd_put_wchar('%');
  684. //
  685. // Filament sensor display if SD is disabled
  686. //
  687. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  688. lcd_put_u8str(56, EXTRAS_2_BASELINE, wstring);
  689. lcd_put_u8str(102, EXTRAS_2_BASELINE, mstring);
  690. lcd_put_wchar('%');
  691. set_font(FONT_MENU);
  692. lcd_put_wchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
  693. lcd_put_wchar(93, EXTRAS_2_BASELINE, LCD_STR_FILAM_MUL[0]);
  694. #endif
  695. }
  696. //
  697. // Status line
  698. //
  699. if (PAGE_CONTAINS(STATUS_BASELINE - INFO_FONT_ASCENT, STATUS_BASELINE + INFO_FONT_DESCENT)) {
  700. lcd_moveto(0, STATUS_BASELINE);
  701. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  702. // Alternate Status message and Filament display
  703. if (ELAPSED(millis(), next_filament_display)) {
  704. lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
  705. lcd_put_wchar(':');
  706. lcd_put_u8str(wstring);
  707. lcd_put_u8str_P(PSTR(" " LCD_STR_FILAM_MUL));
  708. lcd_put_wchar(':');
  709. lcd_put_u8str(mstring);
  710. lcd_put_wchar('%');
  711. return;
  712. }
  713. #endif
  714. draw_status_message(blink);
  715. }
  716. }
  717. void MarlinUI::draw_status_message(const bool blink) {
  718. // Get the UTF8 character count of the string
  719. uint8_t lcd_width = LCD_WIDTH, pixel_width = LCD_PIXEL_WIDTH,
  720. slen = utf8_strlen(status_message);
  721. #if HAS_POWER_MONITOR
  722. if (power_monitor.display_enabled()) {
  723. // make room at the end of the status line for the power monitor reading
  724. lcd_width -= 6;
  725. pixel_width -= (MENU_FONT_WIDTH) * 6;
  726. }
  727. #endif
  728. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  729. static bool last_blink = false;
  730. if (slen <= lcd_width) {
  731. // The string fits within the line. Print with no scrolling
  732. lcd_put_u8str(status_message);
  733. while (slen < lcd_width) { lcd_put_wchar(' '); ++slen; }
  734. }
  735. else {
  736. // String is longer than the available space
  737. // Get a pointer to the next valid UTF8 character
  738. // and the string remaining length
  739. uint8_t rlen;
  740. const char *stat = status_and_len(rlen);
  741. lcd_put_u8str_max(stat, pixel_width);
  742. // If the remaining string doesn't completely fill the screen
  743. if (rlen < lcd_width) {
  744. lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
  745. uint8_t chars = lcd_width - rlen; // Amount of space left in characters
  746. if (--chars) { // Draw a second dot if there's space
  747. lcd_put_wchar('.');
  748. if (--chars) { // Print a second copy of the message
  749. lcd_put_u8str_max(status_message, pixel_width - (rlen + 2) * (MENU_FONT_WIDTH));
  750. lcd_put_wchar(' ');
  751. }
  752. }
  753. }
  754. if (last_blink != blink) {
  755. last_blink = blink;
  756. advance_status_scroll();
  757. }
  758. }
  759. #else // !STATUS_MESSAGE_SCROLLING
  760. UNUSED(blink);
  761. // Just print the string to the LCD
  762. lcd_put_u8str_max(status_message, pixel_width);
  763. // Fill the rest with spaces
  764. for (; slen < lcd_width; ++slen) lcd_put_wchar(' ');
  765. #endif // !STATUS_MESSAGE_SCROLLING
  766. #if HAS_POWER_MONITOR
  767. display_power_monitor(pixel_width + MENU_FONT_WIDTH, STATUS_BASELINE);
  768. #endif
  769. }
  770. #endif // HAS_MARLINUI_U8GLIB && !LIGHTWEIGHT_UI