My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

status_screen_DOGM.cpp 29KB

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