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

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