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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031
  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_LEVELING
  44. #include "../../module/planner.h"
  45. #endif
  46. #if HAS_CUTTER
  47. #include "../../feature/spindle_laser.h"
  48. #endif
  49. #if EITHER(HAS_COOLER, LASER_COOLANT_FLOW_METER)
  50. #include "../../feature/cooler.h"
  51. #endif
  52. #if DO_DRAW_AMMETER
  53. #include "../../feature/ammeter.h"
  54. #endif
  55. #if HAS_POWER_MONITOR
  56. #include "../../feature/power_monitor.h"
  57. #endif
  58. #if ENABLED(SDSUPPORT)
  59. #include "../../sd/cardreader.h"
  60. #endif
  61. #if HAS_PRINT_PROGRESS
  62. #include "../../module/printcounter.h"
  63. #endif
  64. #if HAS_DUAL_MIXING
  65. #include "../../feature/mixing.h"
  66. #endif
  67. #define X_LABEL_POS 3
  68. #define X_VALUE_POS 11
  69. #define XYZ_SPACING 37
  70. #define X_LABEL_POS_IN (X_LABEL_POS - 2)
  71. #define X_VALUE_POS_IN (X_VALUE_POS - 5)
  72. #define XYZ_SPACING_IN (XYZ_SPACING + 9)
  73. #define XYZ_BASELINE (30 + INFO_FONT_ASCENT)
  74. #define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
  75. #define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)
  76. #if ANIM_HBCC
  77. enum HeatBits : uint8_t {
  78. DRAWBIT_HOTEND,
  79. DRAWBIT_BED = HOTENDS,
  80. DRAWBIT_CHAMBER,
  81. DRAWBIT_CUTTER
  82. };
  83. IF<(DRAWBIT_CUTTER > 7), uint16_t, uint8_t>::type draw_bits;
  84. #endif
  85. #if ANIM_HOTEND
  86. #define HOTEND_ALT(N) TEST(draw_bits, DRAWBIT_HOTEND + N)
  87. #else
  88. #define HOTEND_ALT(N) false
  89. #endif
  90. #if ANIM_BED
  91. #define BED_ALT() TEST(draw_bits, DRAWBIT_BED)
  92. #else
  93. #define BED_ALT() false
  94. #endif
  95. #if ANIM_CHAMBER
  96. #define CHAMBER_ALT() TEST(draw_bits, DRAWBIT_CHAMBER)
  97. #else
  98. #define CHAMBER_ALT() false
  99. #endif
  100. #if ANIM_CUTTER
  101. #define CUTTER_ALT(N) TEST(draw_bits, DRAWBIT_CUTTER)
  102. #else
  103. #define CUTTER_ALT() false
  104. #endif
  105. #if DO_DRAW_HOTENDS
  106. #define MAX_HOTEND_DRAW _MIN(HOTENDS, ((LCD_PIXEL_WIDTH - (STATUS_LOGO_BYTEWIDTH + STATUS_FAN_BYTEWIDTH) * 8) / (STATUS_HEATERS_XSPACE)))
  107. #endif
  108. #if EITHER(DO_DRAW_BED, DO_DRAW_HOTENDS)
  109. #define STATUS_HEATERS_BOT (STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)
  110. #endif
  111. #if HAS_POWER_MONITOR
  112. void display_power_monitor(const uint8_t x, const uint8_t y) {
  113. lcd_moveto(x, y);
  114. #if HAS_POWER_MONITOR_WATTS
  115. const bool wflag = power_monitor.power_display_enabled();
  116. #endif
  117. #if ENABLED(POWER_MONITOR_CURRENT)
  118. const bool iflag = power_monitor.current_display_enabled();
  119. #endif
  120. #if ENABLED(POWER_MONITOR_VOLTAGE)
  121. const bool vflag = power_monitor.voltage_display_enabled();
  122. #endif
  123. #if HAS_POWER_MONITOR_WATTS
  124. // Cycle between current, voltage, and power
  125. if (ELAPSED(millis(), power_monitor.display_item_ms)) {
  126. power_monitor.display_item_ms = millis() + 1000UL;
  127. ++power_monitor.display_item;
  128. }
  129. #elif ENABLED(POWER_MONITOR_CURRENT)
  130. power_monitor.display_item = 0;
  131. #elif ENABLED(POWER_MONITOR_VOLTAGE)
  132. power_monitor.display_item = 1;
  133. #endif
  134. // ensure we have the right one selected for display
  135. for (uint8_t i = 0; i < 3; i++) {
  136. #if ENABLED(POWER_MONITOR_CURRENT)
  137. if (power_monitor.display_item == 0 && !iflag) ++power_monitor.display_item;
  138. #endif
  139. #if ENABLED(POWER_MONITOR_VOLTAGE)
  140. if (power_monitor.display_item == 1 && !vflag) ++power_monitor.display_item;
  141. #endif
  142. #if HAS_POWER_MONITOR_WATTS
  143. if (power_monitor.display_item == 2 && !wflag) ++power_monitor.display_item;
  144. #endif
  145. if (power_monitor.display_item >= 3) power_monitor.display_item = 0;
  146. }
  147. switch (power_monitor.display_item) {
  148. #if ENABLED(POWER_MONITOR_CURRENT) // Current
  149. case 0: if (iflag) power_monitor.draw_current(); break;
  150. #endif
  151. #if ENABLED(POWER_MONITOR_VOLTAGE) // Voltage
  152. case 1: if (vflag) power_monitor.draw_voltage(); break;
  153. #endif
  154. #if HAS_POWER_MONITOR_WATTS // Power
  155. case 2: if (wflag) power_monitor.draw_power(); break;
  156. #endif
  157. default: break;
  158. }
  159. }
  160. #endif
  161. #define PROGRESS_BAR_X 54
  162. #define PROGRESS_BAR_Y (EXTRAS_BASELINE + 1)
  163. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  164. FORCE_INLINE void _draw_centered_temp(const celsius_t temp, const uint8_t tx, const uint8_t ty) {
  165. if (temp < 0)
  166. lcd_put_u8str(tx - 3 * (INFO_FONT_WIDTH) / 2 + 1, ty, F("err"));
  167. else {
  168. const char *str = i16tostr3rj(temp);
  169. const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
  170. lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
  171. lcd_put_lchar(LCD_STR_DEGREE[0]);
  172. }
  173. }
  174. #if DO_DRAW_FLOWMETER
  175. FORCE_INLINE void _draw_centered_flowrate(const float flow, const uint8_t tx, const uint8_t ty) {
  176. const char *str = ftostr11ns(flow);
  177. const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
  178. lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
  179. lcd_put_u8str("L");
  180. }
  181. #endif
  182. #if DO_DRAW_AMMETER
  183. FORCE_INLINE void _draw_centered_current(const float current, const uint8_t tx, const uint8_t ty) {
  184. const char *str = ftostr31ns(current);
  185. const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
  186. lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
  187. }
  188. #endif
  189. #if DO_DRAW_HOTENDS
  190. // Draw hotend bitmap with current and target temperatures
  191. FORCE_INLINE void _draw_hotend_status(const heater_id_t heater_id, const bool blink) {
  192. #if !HEATER_IDLE_HANDLER
  193. UNUSED(blink);
  194. #endif
  195. const bool isHeat = HOTEND_ALT(heater_id);
  196. const uint8_t tx = STATUS_HOTEND_TEXT_X(heater_id);
  197. const celsius_t temp = thermalManager.wholeDegHotend(heater_id),
  198. target = thermalManager.degTargetHotend(heater_id);
  199. #if DISABLED(STATUS_HOTEND_ANIM)
  200. #define STATIC_HOTEND true
  201. #define HOTEND_DOT isHeat
  202. #else
  203. #define STATIC_HOTEND false
  204. #define HOTEND_DOT false
  205. #endif
  206. #if ENABLED(STATUS_HOTEND_NUMBERLESS)
  207. #define OFF_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend_b_bmp, status_hotend_a_bmp)
  208. #define ON_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend_a_bmp, status_hotend_b_bmp)
  209. #else
  210. #define OFF_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend##N##_b_bmp, status_hotend##N##_a_bmp)
  211. #define ON_BMP(N) TERN(STATUS_HOTEND_INVERTED, status_hotend##N##_a_bmp, 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 DISABLED(STATUS_COMBINE_HEATERS)
  229. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_BOT)) {
  230. #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2)
  231. const float prop = target - 20,
  232. perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0;
  233. uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f);
  234. NOMORE(tall, BAR_TALL);
  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. } // PAGE_CONTAINS
  248. #endif // !STATUS_COMBINE_HEATERS
  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_lchar((is_inch ? X_LABEL_POS_IN : X_LABEL_POS) + offs, XYZ_BASELINE, AXIS_CHAR(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_lchar(c <= '.' ? c : '?');
  364. else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
  365. lcd_put_u8str(axis == Z_AXIS ? F(" ") : F(" "));
  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(SHOW_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(SHOW_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(SHOW_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(SHOW_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(SHOW_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 + !BOTH(SHOW_SD_PERCENT, ROTATE_PROGRESS_DISPLAY));
  479. }
  480. }
  481. #endif
  482. }
  483. #endif
  484. }
  485. const bool blink = get_blink();
  486. // Status Menu Font
  487. set_font(FONT_STATUSMENU);
  488. #if DO_DRAW_LOGO
  489. if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1))
  490. u8g.drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp);
  491. #endif
  492. #if STATUS_HEATERS_WIDTH
  493. // Draw all heaters (and maybe the bed) in one go
  494. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1))
  495. u8g.drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp);
  496. #endif
  497. #if DO_DRAW_CUTTER && DISABLED(STATUS_COMBINE_HEATERS)
  498. #if ANIM_CUTTER
  499. #define CUTTER_BITMAP(S) ((S) ? status_cutter_on_bmp : status_cutter_bmp)
  500. #else
  501. #define CUTTER_BITMAP(S) status_cutter_bmp
  502. #endif
  503. const uint8_t cuttery = STATUS_CUTTER_Y(CUTTER_ALT()),
  504. cutterh = STATUS_CUTTER_HEIGHT(CUTTER_ALT());
  505. if (PAGE_CONTAINS(cuttery, cuttery + cutterh - 1))
  506. u8g.drawBitmapP(STATUS_CUTTER_X, cuttery, STATUS_CUTTER_BYTEWIDTH, cutterh, CUTTER_BITMAP(CUTTER_ALT()));
  507. #endif
  508. #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS)
  509. #if ANIM_BED
  510. #if BOTH(HAS_LEVELING, STATUS_ALT_BED_BITMAP)
  511. #define BED_BITMAP(S) ((S) \
  512. ? (planner.leveling_active ? status_bed_leveled_on_bmp : status_bed_on_bmp) \
  513. : (planner.leveling_active ? status_bed_leveled_bmp : status_bed_bmp))
  514. #else
  515. #define BED_BITMAP(S) ((S) ? status_bed_on_bmp : status_bed_bmp)
  516. #endif
  517. #else
  518. #define BED_BITMAP(S) status_bed_bmp
  519. #endif
  520. const uint8_t bedy = STATUS_BED_Y(BED_ALT()),
  521. bedh = STATUS_BED_HEIGHT(BED_ALT());
  522. if (PAGE_CONTAINS(bedy, bedy + bedh - 1))
  523. u8g.drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT()));
  524. #endif
  525. #if DO_DRAW_CHAMBER && DISABLED(STATUS_COMBINE_HEATERS)
  526. #if ANIM_CHAMBER
  527. #define CHAMBER_BITMAP(S) ((S) ? status_chamber_on_bmp : status_chamber_bmp)
  528. #else
  529. #define CHAMBER_BITMAP(S) status_chamber_bmp
  530. #endif
  531. const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()),
  532. chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT());
  533. if (PAGE_CONTAINS(chambery, chambery + chamberh - 1))
  534. u8g.drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT()));
  535. #endif
  536. #if DO_DRAW_FAN
  537. #if STATUS_FAN_FRAMES > 2
  538. static bool old_blink;
  539. static uint8_t fan_frame;
  540. if (old_blink != blink) {
  541. old_blink = blink;
  542. if (!thermalManager.fan_speed[0] || ++fan_frame >= STATUS_FAN_FRAMES) fan_frame = 0;
  543. }
  544. #endif
  545. if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1))
  546. u8g.drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT,
  547. #if STATUS_FAN_FRAMES > 2
  548. fan_frame == 1 ? status_fan1_bmp :
  549. fan_frame == 2 ? status_fan2_bmp :
  550. #if STATUS_FAN_FRAMES > 3
  551. fan_frame == 3 ? status_fan3_bmp :
  552. #endif
  553. #elif STATUS_FAN_FRAMES > 1
  554. blink && thermalManager.fan_speed[0] ? status_fan1_bmp :
  555. #endif
  556. status_fan0_bmp
  557. );
  558. #endif
  559. //
  560. // Temperature Graphics and Info
  561. //
  562. if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
  563. // Extruders
  564. #if DO_DRAW_HOTENDS
  565. LOOP_L_N(e, MAX_HOTEND_DRAW)
  566. _draw_hotend_status((heater_id_t)e, blink);
  567. #endif
  568. // Laser / Spindle
  569. #if DO_DRAW_CUTTER
  570. if (cutter.isReadyForUI && PAGE_CONTAINS(STATUS_CUTTER_TEXT_Y - INFO_FONT_ASCENT, STATUS_CUTTER_TEXT_Y - 1)) {
  571. #if CUTTER_UNIT_IS(PERCENT)
  572. lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
  573. #elif CUTTER_UNIT_IS(RPM)
  574. lcd_put_u8str(STATUS_CUTTER_TEXT_X - 2, STATUS_CUTTER_TEXT_Y, ftostr61rj(float(cutter.unitPower) / 1000));
  575. lcd_put_lchar('K');
  576. #else
  577. lcd_put_u8str(STATUS_CUTTER_TEXT_X, STATUS_CUTTER_TEXT_Y, cutter_power2str(cutter.unitPower));
  578. #endif
  579. }
  580. #endif
  581. // Laser Cooler
  582. #if DO_DRAW_COOLER
  583. const uint8_t coolery = STATUS_COOLER_Y(status_cooler_bmp1),
  584. coolerh = STATUS_COOLER_HEIGHT(status_cooler_bmp1);
  585. if (PAGE_CONTAINS(coolery, coolery + coolerh - 1))
  586. u8g.drawBitmapP(STATUS_COOLER_X, coolery, STATUS_COOLER_BYTEWIDTH, coolerh, blink && cooler.enabled ? status_cooler_bmp2 : status_cooler_bmp1);
  587. #endif
  588. // Laser Cooler Flow Meter
  589. #if DO_DRAW_FLOWMETER
  590. const uint8_t flowmetery = STATUS_FLOWMETER_Y(status_flowmeter_bmp1),
  591. flowmeterh = STATUS_FLOWMETER_HEIGHT(status_flowmeter_bmp1);
  592. if (PAGE_CONTAINS(flowmetery, flowmetery + flowmeterh - 1))
  593. u8g.drawBitmapP(STATUS_FLOWMETER_X, flowmetery, STATUS_FLOWMETER_BYTEWIDTH, flowmeterh, blink && cooler.flowpulses ? status_flowmeter_bmp2 : status_flowmeter_bmp1);
  594. #endif
  595. // Laser Ammeter
  596. #if DO_DRAW_AMMETER
  597. const uint8_t ammetery = STATUS_AMMETER_Y(status_ammeter_bmp_mA),
  598. ammeterh = STATUS_AMMETER_HEIGHT(status_ammeter_bmp_mA);
  599. if (PAGE_CONTAINS(ammetery, ammetery + ammeterh - 1))
  600. u8g.drawBitmapP(STATUS_AMMETER_X, ammetery, STATUS_AMMETER_BYTEWIDTH, ammeterh, (ammeter.current < 0.1f) ? status_ammeter_bmp_mA : status_ammeter_bmp_A);
  601. #endif
  602. // Heated Bed
  603. TERN_(DO_DRAW_BED, _draw_bed_status(blink));
  604. // Heated Chamber
  605. TERN_(DO_DRAW_CHAMBER, _draw_chamber_status());
  606. // Cooler
  607. TERN_(DO_DRAW_COOLER, _draw_cooler_status());
  608. // Flowmeter
  609. TERN_(DO_DRAW_FLOWMETER, _draw_flowmeter_status());
  610. // Flowmeter
  611. TERN_(DO_DRAW_AMMETER, _draw_ammeter_status());
  612. // Fan, if a bitmap was provided
  613. #if DO_DRAW_FAN
  614. if (PAGE_CONTAINS(STATUS_FAN_TEXT_Y - INFO_FONT_ASCENT, STATUS_FAN_TEXT_Y - 1)) {
  615. char c = '%';
  616. uint16_t spd = thermalManager.fan_speed[0];
  617. if (spd) {
  618. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  619. if (!blink && thermalManager.fan_speed_scaler[0] < 128) {
  620. spd = thermalManager.scaledFanSpeed(0, spd);
  621. c = '*';
  622. }
  623. #endif
  624. lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3rj(thermalManager.pwmToPercent(spd)));
  625. lcd_put_lchar(c);
  626. }
  627. }
  628. #endif
  629. }
  630. #if ENABLED(SDSUPPORT)
  631. //
  632. // SD Card Symbol
  633. //
  634. if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) {
  635. // Upper box
  636. u8g.drawBox(42, 42, 8, 7); // 42-48 (or 41-47)
  637. // Right edge
  638. u8g.drawBox(50, 44, 2, 5); // 44-48 (or 43-47)
  639. // Bottom hollow box
  640. u8g.drawFrame(42, 49, 10, 4); // 49-52 (or 48-51)
  641. // Corner pixel
  642. u8g.drawPixel(50, 43); // 43 (or 42)
  643. }
  644. #endif // SDSUPPORT
  645. #if HAS_PRINT_PROGRESS
  646. //
  647. // Progress bar frame
  648. //
  649. if (PAGE_CONTAINS(PROGRESS_BAR_Y, PROGRESS_BAR_Y + 3))
  650. u8g.drawFrame(PROGRESS_BAR_X, PROGRESS_BAR_Y, PROGRESS_BAR_WIDTH, 4);
  651. //
  652. // Progress bar solid part
  653. //
  654. if (PAGE_CONTAINS(PROGRESS_BAR_Y + 1, PROGRESS_BAR_Y + 2))
  655. u8g.drawBox(PROGRESS_BAR_X + 1, PROGRESS_BAR_Y + 1, progress_bar_solid_width, 2);
  656. if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
  657. #if ALL(SHOW_SD_PERCENT, SHOW_REMAINING_TIME, ROTATE_PROGRESS_DISPLAY)
  658. if (prev_blink != blink) {
  659. prev_blink = blink;
  660. if (++progress_state >= 3) progress_state = 0;
  661. }
  662. if (progress_state == 0) {
  663. if (progress_string[0]) {
  664. lcd_put_u8str(progress_x_pos, EXTRAS_BASELINE, progress_string);
  665. lcd_put_lchar('%');
  666. }
  667. }
  668. else if (progress_state == 2 && estimation_string[0]) {
  669. lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, F("R:"));
  670. lcd_put_u8str(estimation_x_pos, EXTRAS_BASELINE, estimation_string);
  671. }
  672. else if (elapsed_string[0]) {
  673. lcd_put_u8str(PROGRESS_BAR_X, EXTRAS_BASELINE, F("E:"));
  674. lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
  675. }
  676. #else // !SHOW_SD_PERCENT || !SHOW_REMAINING_TIME || !ROTATE_PROGRESS_DISPLAY
  677. //
  678. // SD Percent Complete
  679. //
  680. #if ENABLED(SHOW_SD_PERCENT)
  681. if (progress_string[0]) {
  682. lcd_put_u8str(55, EXTRAS_BASELINE, progress_string); // Percent complete
  683. lcd_put_lchar('%');
  684. }
  685. #endif
  686. //
  687. // Elapsed Time
  688. //
  689. #if ENABLED(SHOW_REMAINING_TIME)
  690. if (blink && estimation_string[0]) {
  691. lcd_put_lchar(estimation_x_pos, EXTRAS_BASELINE, 'R');
  692. lcd_put_u8str(estimation_string);
  693. }
  694. else
  695. #endif
  696. lcd_put_u8str(elapsed_x_pos, EXTRAS_BASELINE, elapsed_string);
  697. #endif // !SHOW_SD_PERCENT || !SHOW_REMAINING_TIME || !ROTATE_PROGRESS_DISPLAY
  698. }
  699. #endif // HAS_PRINT_PROGRESS
  700. //
  701. // XYZ Coordinates
  702. //
  703. #if EITHER(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME)
  704. #define XYZ_FRAME_TOP 29
  705. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 3
  706. #else
  707. #define XYZ_FRAME_TOP 30
  708. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 1
  709. #endif
  710. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  711. #if DISABLED(XYZ_NO_FRAME)
  712. #if ENABLED(XYZ_HOLLOW_FRAME)
  713. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  714. #else
  715. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  716. #endif
  717. #endif
  718. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) {
  719. #if NONE(XYZ_NO_FRAME, XYZ_HOLLOW_FRAME)
  720. u8g.setColorIndex(0); // white on black
  721. #endif
  722. #if HAS_DUAL_MIXING
  723. // Two-component mix / gradient instead of XY
  724. char mixer_messages[15];
  725. PGM_P mix_label;
  726. #if ENABLED(GRADIENT_MIX)
  727. if (mixer.gradient.enabled) {
  728. mixer.update_mix_from_gradient();
  729. mix_label = PSTR("Gr");
  730. }
  731. else
  732. #endif
  733. {
  734. mixer.update_mix_from_vtool();
  735. mix_label = PSTR("Mx");
  736. }
  737. #pragma GCC diagnostic push
  738. #if GCC_VERSION <= 50000
  739. #pragma GCC diagnostic ignored "-Wformat-overflow"
  740. #endif
  741. sprintf_P(mixer_messages, PSTR(S_FMT " %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
  742. lcd_put_u8str(X_LABEL_POS, XYZ_BASELINE, mixer_messages);
  743. #pragma GCC diagnostic pop
  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(F(" "));
  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_lchar(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_lchar('%');
  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_lchar('%');
  779. set_font(FONT_MENU);
  780. lcd_put_lchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str(F(LCD_STR_FILAM_DIA));
  781. lcd_put_lchar(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(F(LCD_STR_FILAM_DIA));
  793. lcd_put_lchar(':');
  794. lcd_put_u8str(wstring);
  795. lcd_put_u8str(F(" " LCD_STR_FILAM_MUL));
  796. lcd_put_lchar(':');
  797. lcd_put_u8str(mstring);
  798. lcd_put_lchar('%');
  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_lchar(' '); ++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_lchar(' '); // Always at 1+ spaces left, draw a space
  841. if (--chars) { // Draw a second space if there's room
  842. lcd_put_lchar(' ');
  843. if (--chars) { // Draw a third space if there's room
  844. lcd_put_lchar(' ');
  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_lchar(' ');
  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_lchar(' ');
  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