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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2019 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 ENABLED(SDSUPPORT)
  41. #include "../../sd/cardreader.h"
  42. #endif
  43. #if HAS_PRINT_PROGRESS
  44. #include "../../module/printcounter.h"
  45. #endif
  46. #if DUAL_MIXING_EXTRUDER
  47. #include "../../feature/mixing.h"
  48. #endif
  49. #define X_LABEL_POS 3
  50. #define X_VALUE_POS 11
  51. #define XYZ_SPACING 37
  52. #define XYZ_BASELINE (30 + INFO_FONT_ASCENT)
  53. #define EXTRAS_BASELINE (40 + INFO_FONT_ASCENT)
  54. #define STATUS_BASELINE (LCD_PIXEL_HEIGHT - INFO_FONT_DESCENT)
  55. #define DO_DRAW_LOGO (STATUS_LOGO_WIDTH && ENABLED(CUSTOM_STATUS_SCREEN_IMAGE))
  56. #define DO_DRAW_BED (HAS_HEATED_BED && STATUS_BED_WIDTH && HOTENDS <= 4)
  57. #define DO_DRAW_CHAMBER (HAS_HEATED_CHAMBER && STATUS_CHAMBER_WIDTH && HOTENDS <= 4)
  58. #define DO_DRAW_FAN (HAS_FAN0 && STATUS_FAN_WIDTH && HOTENDS <= 4 && defined(STATUS_FAN_FRAMES))
  59. #define ANIM_HOTEND (HOTENDS && ENABLED(STATUS_HOTEND_ANIM))
  60. #define ANIM_BED (DO_DRAW_BED && ENABLED(STATUS_BED_ANIM))
  61. #define ANIM_CHAMBER (DO_DRAW_CHAMBER && ENABLED(STATUS_CHAMBER_ANIM))
  62. #define ANIM_HBC (ANIM_HOTEND || ANIM_BED || ANIM_CHAMBER)
  63. #if ANIM_HBC
  64. uint8_t heat_bits;
  65. #endif
  66. #if ANIM_HOTEND
  67. #define HOTEND_ALT(N) TEST(heat_bits, N)
  68. #else
  69. #define HOTEND_ALT(N) false
  70. #endif
  71. #if ANIM_BED
  72. #define BED_ALT() TEST(heat_bits, 7)
  73. #else
  74. #define BED_ALT() false
  75. #endif
  76. #if ANIM_CHAMBER
  77. #define CHAMBER_ALT() TEST(heat_bits, 6)
  78. #else
  79. #define CHAMBER_ALT() false
  80. #endif
  81. #define MAX_HOTEND_DRAW _MIN(HOTENDS, ((LCD_PIXEL_WIDTH - (STATUS_LOGO_BYTEWIDTH + STATUS_FAN_BYTEWIDTH) * 8) / (STATUS_HEATERS_XSPACE)))
  82. #define STATUS_HEATERS_BOT (STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1)
  83. #if ENABLED(MARLIN_DEV_MODE)
  84. #define SHOW_ON_STATE READ(X_MIN_PIN)
  85. #else
  86. #define SHOW_ON_STATE false
  87. #endif
  88. FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t tx, const uint8_t ty) {
  89. const char *str = i16tostr3(temp);
  90. const uint8_t len = str[0] != ' ' ? 3 : str[1] != ' ' ? 2 : 1;
  91. lcd_put_u8str(tx - len * (INFO_FONT_WIDTH) / 2 + 1, ty, &str[3-len]);
  92. lcd_put_wchar(LCD_STR_DEGREE[0]);
  93. }
  94. FORCE_INLINE void _draw_heater_status(const heater_ind_t heater, const bool blink) {
  95. #if !HEATER_IDLE_HANDLER
  96. UNUSED(blink);
  97. #endif
  98. #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS) || (HAS_HEATED_BED && ENABLED(STATUS_COMBINE_HEATERS) && HOTENDS <= 4)
  99. const bool isBed = heater < 0;
  100. #define IFBED(A,B) (isBed ? (A) : (B))
  101. #else
  102. #define IFBED(A,B) (B)
  103. #endif
  104. #if ENABLED(MARLIN_DEV_MODE)
  105. constexpr bool isHeat = true;
  106. #else
  107. const bool isHeat = IFBED(BED_ALT(), HOTEND_ALT(heater));
  108. #endif
  109. const uint8_t tx = IFBED(STATUS_BED_TEXT_X, STATUS_HOTEND_TEXT_X(heater));
  110. #if ENABLED(MARLIN_DEV_MODE)
  111. const float temp = 20 + (millis() >> 8) % IFBED(100, 200),
  112. target = IFBED(100, 200);
  113. #else
  114. const float temp = IFBED(thermalManager.degBed(), thermalManager.degHotend(heater)),
  115. target = IFBED(thermalManager.degTargetBed(), thermalManager.degTargetHotend(heater));
  116. #endif
  117. #if DISABLED(STATUS_HOTEND_ANIM)
  118. #define STATIC_HOTEND true
  119. #define HOTEND_DOT isHeat
  120. #else
  121. #define STATIC_HOTEND false
  122. #define HOTEND_DOT false
  123. #endif
  124. #if DO_DRAW_BED && DISABLED(STATUS_BED_ANIM)
  125. #define STATIC_BED true
  126. #define BED_DOT isHeat
  127. #else
  128. #define STATIC_BED false
  129. #define BED_DOT false
  130. #endif
  131. #if ANIM_HOTEND && BOTH(STATUS_HOTEND_INVERTED, STATUS_HOTEND_NUMBERLESS)
  132. #define OFF_BMP(N) status_hotend_b_bmp
  133. #define ON_BMP(N) status_hotend_a_bmp
  134. #elif ANIM_HOTEND && DISABLED(STATUS_HOTEND_INVERTED) && ENABLED(STATUS_HOTEND_NUMBERLESS)
  135. #define OFF_BMP(N) status_hotend_a_bmp
  136. #define ON_BMP(N) status_hotend_b_bmp
  137. #elif ANIM_HOTEND && ENABLED(STATUS_HOTEND_INVERTED)
  138. #define OFF_BMP(N) status_hotend##N##_b_bmp
  139. #define ON_BMP(N) status_hotend##N##_a_bmp
  140. #else
  141. #define OFF_BMP(N) status_hotend##N##_a_bmp
  142. #define ON_BMP(N) status_hotend##N##_b_bmp
  143. #endif
  144. #if STATUS_HOTEND_BITMAPS > 1
  145. 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));
  146. #if ANIM_HOTEND
  147. 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));
  148. #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)])
  149. #else
  150. #define HOTEND_BITMAP(N,S) (unsigned char*)pgm_read_ptr(&status_hotend_gfx[(N) % (STATUS_HOTEND_BITMAPS)])
  151. #endif
  152. #elif ANIM_HOTEND
  153. #define HOTEND_BITMAP(N,S) ((S) ? ON_BMP() : OFF_BMP())
  154. #else
  155. #define HOTEND_BITMAP(N,S) status_hotend_a_bmp
  156. #endif
  157. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_BOT)) {
  158. #define BAR_TALL (STATUS_HEATERS_HEIGHT - 2)
  159. const float prop = target - 20,
  160. perc = prop > 0 && temp >= 20 ? (temp - 20) / prop : 0;
  161. uint8_t tall = uint8_t(perc * BAR_TALL + 0.5f);
  162. NOMORE(tall, BAR_TALL);
  163. #if ANIM_HOTEND
  164. // Draw hotend bitmap, either whole or split by the heating percent
  165. if (IFBED(0, 1)) {
  166. const uint8_t hx = STATUS_HOTEND_X(heater),
  167. bw = STATUS_HOTEND_BYTEWIDTH(heater);
  168. #if ENABLED(STATUS_HEAT_PERCENT)
  169. if (isHeat && tall <= BAR_TALL) {
  170. const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall;
  171. u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, ph, HOTEND_BITMAP(heater, false));
  172. u8g.drawBitmapP(hx, STATUS_HEATERS_Y + ph, bw, tall + 1, HOTEND_BITMAP(heater, true) + ph * bw);
  173. }
  174. else
  175. #endif
  176. u8g.drawBitmapP(hx, STATUS_HEATERS_Y, bw, STATUS_HEATERS_HEIGHT, HOTEND_BITMAP(heater, isHeat));
  177. }
  178. #endif
  179. // Draw a heating progress bar, if specified
  180. #if DO_DRAW_BED && ENABLED(STATUS_HEAT_PERCENT)
  181. if (IFBED(true, STATIC_HOTEND) && isHeat) {
  182. const uint8_t bx = IFBED(STATUS_BED_X + STATUS_BED_WIDTH - 1, STATUS_HOTEND_X(heater) + STATUS_HOTEND_WIDTH(heater)) + 1;
  183. u8g.drawFrame(bx, STATUS_HEATERS_Y, 3, STATUS_HEATERS_HEIGHT);
  184. if (tall) {
  185. const uint8_t ph = STATUS_HEATERS_HEIGHT - 1 - tall;
  186. if (PAGE_OVER(STATUS_HEATERS_Y + ph))
  187. u8g.drawVLine(bx + 1, STATUS_HEATERS_Y + ph, tall);
  188. }
  189. }
  190. #endif
  191. } // PAGE_CONTAINS
  192. if (PAGE_UNDER(7)) {
  193. #if HEATER_IDLE_HANDLER
  194. const bool is_idle = IFBED(thermalManager.bed_idle.timed_out, thermalManager.hotend_idle[heater].timed_out),
  195. dodraw = (blink || !is_idle);
  196. #else
  197. constexpr bool dodraw = true;
  198. #endif
  199. if (dodraw) _draw_centered_temp(target + 0.5, tx, 7);
  200. }
  201. if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1))
  202. _draw_centered_temp(temp + 0.5f, tx, 28);
  203. if (IFBED(STATIC_BED && BED_DOT, STATIC_HOTEND && HOTEND_DOT) && PAGE_CONTAINS(17, 19)) {
  204. u8g.setColorIndex(0); // set to white on black
  205. u8g.drawBox(tx, IFBED(20-2, 20-3), 2, 2);
  206. u8g.setColorIndex(1); // restore black on white
  207. }
  208. }
  209. #if DO_DRAW_CHAMBER
  210. FORCE_INLINE void _draw_chamber_status(const bool blink) {
  211. #if ENABLED(MARLIN_DEV_MODE)
  212. const float temp = 10 + (millis() >> 8) % CHAMBER_MAXTEMP,
  213. target = CHAMBER_MAXTEMP;
  214. #else
  215. const float temp = thermalManager.degChamber(),
  216. target = thermalManager.degTargetChamber();
  217. #endif
  218. #if !HEATER_IDLE_HANDLER
  219. UNUSED(blink);
  220. #endif
  221. if (PAGE_UNDER(7)) {
  222. #if HEATER_IDLE_HANDLER
  223. const bool is_idle = false, // thermalManager.chamber_idle.timed_out,
  224. dodraw = (blink || !is_idle);
  225. #else
  226. constexpr bool dodraw = true;
  227. #endif
  228. if (dodraw) _draw_centered_temp(target + 0.5, STATUS_CHAMBER_TEXT_X, 7);
  229. }
  230. if (PAGE_CONTAINS(28 - INFO_FONT_ASCENT, 28 - 1))
  231. _draw_centered_temp(temp + 0.5f, STATUS_CHAMBER_TEXT_X, 28);
  232. }
  233. #endif
  234. //
  235. // Before homing, blink '123' <-> '???'.
  236. // Homed but unknown... '123' <-> ' '.
  237. // Homed and known, display constantly.
  238. //
  239. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  240. const uint8_t offs = (XYZ_SPACING) * axis;
  241. lcd_put_wchar(X_LABEL_POS + offs, XYZ_BASELINE, 'X' + axis);
  242. lcd_moveto(X_VALUE_POS + offs, XYZ_BASELINE);
  243. if (blink)
  244. lcd_put_u8str(value);
  245. else {
  246. if (!TEST(axis_homed, axis))
  247. while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
  248. else {
  249. #if NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING)
  250. if (!TEST(axis_known_position, axis))
  251. lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
  252. else
  253. #endif
  254. lcd_put_u8str(value);
  255. }
  256. }
  257. }
  258. #if ENABLED(MARLIN_DEV_MODE)
  259. uint16_t count_renders = 0;
  260. uint32_t total_cycles = 0;
  261. #endif
  262. void MarlinUI::draw_status_screen() {
  263. #if ENABLED(MARLIN_DEV_MODE)
  264. if (first_page) count_renders++;
  265. #endif
  266. static char xstring[5], ystring[5], zstring[8];
  267. #if ENABLED(FILAMENT_LCD_DISPLAY)
  268. static char wstring[5], mstring[4];
  269. #endif
  270. // At the first page, generate new display values
  271. if (first_page) {
  272. #if ANIM_HBC
  273. uint8_t new_bits = 0;
  274. #if ANIM_HOTEND
  275. HOTEND_LOOP() if (thermalManager.isHeatingHotend(e) ^ SHOW_ON_STATE) SBI(new_bits, e);
  276. #endif
  277. #if ANIM_BED
  278. if (thermalManager.isHeatingBed() ^ SHOW_ON_STATE) SBI(new_bits, 7);
  279. #endif
  280. #if DO_DRAW_CHAMBER
  281. if (thermalManager.isHeatingChamber() ^ SHOW_ON_STATE) SBI(new_bits, 6);
  282. #endif
  283. heat_bits = new_bits;
  284. #endif
  285. strcpy(xstring, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])));
  286. strcpy(ystring, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])));
  287. strcpy(zstring, ftostr52sp( LOGICAL_Z_POSITION(current_position[Z_AXIS])));
  288. #if ENABLED(FILAMENT_LCD_DISPLAY)
  289. strcpy(wstring, ftostr12ns(filament_width_meas));
  290. strcpy(mstring, i16tostr3(100.0 * (
  291. parser.volumetric_enabled
  292. ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  293. : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  294. )
  295. ));
  296. #endif
  297. }
  298. const bool blink = get_blink();
  299. // Status Menu Font
  300. set_font(FONT_STATUSMENU);
  301. #if ENABLED(MARLIN_DEV_MODE)
  302. TCNT5 = 0;
  303. #endif
  304. #if DO_DRAW_LOGO
  305. if (PAGE_CONTAINS(STATUS_LOGO_Y, STATUS_LOGO_Y + STATUS_LOGO_HEIGHT - 1))
  306. u8g.drawBitmapP(STATUS_LOGO_X, STATUS_LOGO_Y, STATUS_LOGO_BYTEWIDTH, STATUS_LOGO_HEIGHT, status_logo_bmp);
  307. #endif
  308. #if STATUS_HEATERS_WIDTH
  309. // Draw all heaters (and maybe the bed) in one go
  310. if (PAGE_CONTAINS(STATUS_HEATERS_Y, STATUS_HEATERS_Y + STATUS_HEATERS_HEIGHT - 1))
  311. u8g.drawBitmapP(STATUS_HEATERS_X, STATUS_HEATERS_Y, STATUS_HEATERS_BYTEWIDTH, STATUS_HEATERS_HEIGHT, status_heaters_bmp);
  312. #endif
  313. #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS)
  314. #if ANIM_BED
  315. #define BED_BITMAP(S) ((S) ? status_bed_on_bmp : status_bed_bmp)
  316. #else
  317. #define BED_BITMAP(S) status_bed_bmp
  318. #endif
  319. const uint8_t bedy = STATUS_BED_Y(BED_ALT()),
  320. bedh = STATUS_BED_HEIGHT(BED_ALT());
  321. if (PAGE_CONTAINS(bedy, bedy + bedh - 1))
  322. u8g.drawBitmapP(STATUS_BED_X, bedy, STATUS_BED_BYTEWIDTH, bedh, BED_BITMAP(BED_ALT()));
  323. #endif
  324. #if DO_DRAW_CHAMBER
  325. #if ANIM_CHAMBER
  326. #define CHAMBER_BITMAP(S) ((S) ? status_chamber_on_bmp : status_chamber_bmp)
  327. #else
  328. #define CHAMBER_BITMAP(S) status_chamber_bmp
  329. #endif
  330. const uint8_t chambery = STATUS_CHAMBER_Y(CHAMBER_ALT()),
  331. chamberh = STATUS_CHAMBER_HEIGHT(CHAMBER_ALT());
  332. if (PAGE_CONTAINS(chambery, chambery + chamberh - 1))
  333. u8g.drawBitmapP(STATUS_CHAMBER_X, chambery, STATUS_CHAMBER_BYTEWIDTH, chamberh, CHAMBER_BITMAP(CHAMBER_ALT()));
  334. #endif
  335. #if DO_DRAW_FAN
  336. #if STATUS_FAN_FRAMES > 2
  337. static bool old_blink;
  338. static uint8_t fan_frame;
  339. if (old_blink != blink) {
  340. old_blink = blink;
  341. if (!thermalManager.fan_speed[0] || ++fan_frame >= STATUS_FAN_FRAMES) fan_frame = 0;
  342. }
  343. #endif
  344. if (PAGE_CONTAINS(STATUS_FAN_Y, STATUS_FAN_Y + STATUS_FAN_HEIGHT - 1))
  345. u8g.drawBitmapP(STATUS_FAN_X, STATUS_FAN_Y, STATUS_FAN_BYTEWIDTH, STATUS_FAN_HEIGHT,
  346. #if STATUS_FAN_FRAMES > 2
  347. fan_frame == 1 ? status_fan1_bmp :
  348. fan_frame == 2 ? status_fan2_bmp :
  349. #if STATUS_FAN_FRAMES > 3
  350. fan_frame == 3 ? status_fan3_bmp :
  351. #endif
  352. #elif STATUS_FAN_FRAMES > 1
  353. blink && thermalManager.fan_speed[0] ? status_fan1_bmp :
  354. #endif
  355. status_fan0_bmp
  356. );
  357. #endif
  358. //
  359. // Temperature Graphics and Info
  360. //
  361. if (PAGE_UNDER(6 + 1 + 12 + 1 + 6 + 1)) {
  362. // Extruders
  363. for (uint8_t e = 0; e < MAX_HOTEND_DRAW; ++e)
  364. _draw_heater_status((heater_ind_t)e, blink);
  365. // Heated bed
  366. #if DO_DRAW_BED && DISABLED(STATUS_COMBINE_HEATERS) || (HAS_HEATED_BED && ENABLED(STATUS_COMBINE_HEATERS) && HOTENDS <= 4)
  367. _draw_heater_status(H_BED, blink);
  368. #endif
  369. #if DO_DRAW_CHAMBER
  370. _draw_chamber_status(blink);
  371. #endif
  372. // Fan, if a bitmap was provided
  373. #if DO_DRAW_FAN
  374. if (PAGE_CONTAINS(STATUS_FAN_TEXT_Y - INFO_FONT_ASCENT, STATUS_FAN_TEXT_Y - 1)) {
  375. char c = '%';
  376. uint16_t spd = thermalManager.fan_speed[0];
  377. if (spd) {
  378. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  379. if (!blink && thermalManager.fan_speed_scaler[0] < 128) {
  380. spd = thermalManager.scaledFanSpeed(0, spd);
  381. c = '*';
  382. }
  383. #endif
  384. lcd_put_u8str(STATUS_FAN_TEXT_X, STATUS_FAN_TEXT_Y, i16tostr3(thermalManager.fanPercent(spd)));
  385. lcd_put_wchar(c);
  386. }
  387. }
  388. #endif
  389. }
  390. #if ENABLED(MARLIN_DEV_MODE)
  391. total_cycles += TCNT5;
  392. #endif
  393. #if ENABLED(SDSUPPORT)
  394. //
  395. // SD Card Symbol
  396. //
  397. if (card.isFileOpen() && PAGE_CONTAINS(42, 51)) {
  398. // Upper box
  399. u8g.drawBox(42, 42, 8, 7); // 42-48 (or 41-47)
  400. // Right edge
  401. u8g.drawBox(50, 44, 2, 5); // 44-48 (or 43-47)
  402. // Bottom hollow box
  403. u8g.drawFrame(42, 49, 10, 4); // 49-52 (or 48-51)
  404. // Corner pixel
  405. u8g.drawPixel(50, 43); // 43 (or 42)
  406. }
  407. #endif // SDSUPPORT
  408. #if HAS_PRINT_PROGRESS
  409. //
  410. // Progress bar frame
  411. //
  412. #define PROGRESS_BAR_X 54
  413. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  414. if (PAGE_CONTAINS(49, 52))
  415. u8g.drawFrame(PROGRESS_BAR_X, 49, PROGRESS_BAR_WIDTH, 4);
  416. const uint8_t progress = get_progress();
  417. if (progress > 1) {
  418. //
  419. // Progress bar solid part
  420. //
  421. if (PAGE_CONTAINS(50, 51)) // 50-51 (or just 50)
  422. u8g.drawBox(
  423. PROGRESS_BAR_X + 1, 50,
  424. (uint16_t)((PROGRESS_BAR_WIDTH - 2) * progress * 0.01), 2
  425. );
  426. //
  427. // SD Percent Complete
  428. //
  429. #if ENABLED(DOGM_SD_PERCENT)
  430. if (PAGE_CONTAINS(41, 48)) {
  431. // Percent complete
  432. lcd_put_u8str(55, 48, ui8tostr3(progress));
  433. lcd_put_wchar('%');
  434. }
  435. #endif
  436. }
  437. //
  438. // Elapsed Time
  439. //
  440. #if DISABLED(DOGM_SD_PERCENT)
  441. #define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (MENU_FONT_WIDTH / 2))
  442. #else
  443. #define SD_DURATION_X (LCD_PIXEL_WIDTH - len * MENU_FONT_WIDTH)
  444. #endif
  445. if (PAGE_CONTAINS(EXTRAS_BASELINE - INFO_FONT_ASCENT, EXTRAS_BASELINE - 1)) {
  446. char buffer[13];
  447. duration_t elapsed = print_job_timer.duration();
  448. bool has_days = (elapsed.value >= 60*60*24L);
  449. uint8_t len = elapsed.toDigital(buffer, has_days);
  450. lcd_put_u8str(SD_DURATION_X, EXTRAS_BASELINE, buffer);
  451. }
  452. #endif // HAS_PRINT_PROGRESS
  453. //
  454. // XYZ Coordinates
  455. //
  456. #if ENABLED(XYZ_HOLLOW_FRAME)
  457. #define XYZ_FRAME_TOP 29
  458. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 3
  459. #else
  460. #define XYZ_FRAME_TOP 30
  461. #define XYZ_FRAME_HEIGHT INFO_FONT_ASCENT + 1
  462. #endif
  463. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  464. #if ENABLED(XYZ_HOLLOW_FRAME)
  465. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  466. #else
  467. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  468. #endif
  469. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_ASCENT - 1), XYZ_BASELINE)) {
  470. #if DISABLED(XYZ_HOLLOW_FRAME)
  471. u8g.setColorIndex(0); // white on black
  472. #endif
  473. #if DUAL_MIXING_EXTRUDER
  474. // Two-component mix / gradient instead of XY
  475. char mixer_messages[12];
  476. const char *mix_label;
  477. #if ENABLED(GRADIENT_MIX)
  478. if (mixer.gradient.enabled) {
  479. mixer.update_mix_from_gradient();
  480. mix_label = "Gr";
  481. }
  482. else
  483. #endif
  484. {
  485. mixer.update_mix_from_vtool();
  486. mix_label = "Mx";
  487. }
  488. sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
  489. lcd_put_u8str(X_LABEL_POS, XYZ_BASELINE, mixer_messages);
  490. #else
  491. _draw_axis_value(X_AXIS, xstring, blink);
  492. _draw_axis_value(Y_AXIS, ystring, blink);
  493. #endif
  494. _draw_axis_value(Z_AXIS, zstring, blink);
  495. #if DISABLED(XYZ_HOLLOW_FRAME)
  496. u8g.setColorIndex(1); // black on white
  497. #endif
  498. }
  499. }
  500. //
  501. // Feedrate
  502. //
  503. #define EXTRAS_2_BASELINE (EXTRAS_BASELINE + 3)
  504. if (PAGE_CONTAINS(EXTRAS_2_BASELINE - INFO_FONT_ASCENT, EXTRAS_2_BASELINE - 1)) {
  505. set_font(FONT_MENU);
  506. lcd_put_wchar(3, EXTRAS_2_BASELINE, LCD_STR_FEEDRATE[0]);
  507. set_font(FONT_STATUSMENU);
  508. lcd_put_u8str(12, EXTRAS_2_BASELINE, i16tostr3(feedrate_percentage));
  509. lcd_put_wchar('%');
  510. //
  511. // Filament sensor display if SD is disabled
  512. //
  513. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  514. lcd_put_u8str(56, EXTRAS_2_BASELINE, wstring);
  515. lcd_put_u8str(102, EXTRAS_2_BASELINE, mstring);
  516. lcd_put_wchar('%');
  517. set_font(FONT_MENU);
  518. lcd_put_wchar(47, EXTRAS_2_BASELINE, LCD_STR_FILAM_DIA[0]); // lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
  519. lcd_put_wchar(93, EXTRAS_2_BASELINE, LCD_STR_FILAM_MUL[0]);
  520. #endif
  521. }
  522. //
  523. // Status line
  524. //
  525. if (PAGE_CONTAINS(STATUS_BASELINE - INFO_FONT_ASCENT, STATUS_BASELINE + INFO_FONT_DESCENT)) {
  526. lcd_moveto(0, STATUS_BASELINE);
  527. #if BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  528. // Alternate Status message and Filament display
  529. if (ELAPSED(millis(), next_filament_display)) {
  530. lcd_put_u8str_P(PSTR(LCD_STR_FILAM_DIA));
  531. lcd_put_wchar(':');
  532. lcd_put_u8str(wstring);
  533. lcd_put_u8str_P(PSTR(" " LCD_STR_FILAM_MUL));
  534. lcd_put_wchar(':');
  535. lcd_put_u8str(mstring);
  536. lcd_put_wchar('%');
  537. }
  538. else
  539. #endif
  540. draw_status_message(blink);
  541. }
  542. }
  543. void MarlinUI::draw_status_message(const bool blink) {
  544. #if ENABLED(MARLIN_DEV_MODE)
  545. if (PAGE_CONTAINS(64-8, 64-1)) {
  546. lcd_put_int(total_cycles);
  547. lcd_put_wchar('/');
  548. lcd_put_int(count_renders);
  549. lcd_put_wchar('=');
  550. lcd_put_int(int(total_cycles / count_renders));
  551. return;
  552. }
  553. #endif
  554. // Get the UTF8 character count of the string
  555. uint8_t slen = utf8_strlen(status_message);
  556. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  557. static bool last_blink = false;
  558. if (slen <= LCD_WIDTH) {
  559. // The string fits within the line. Print with no scrolling
  560. lcd_put_u8str(status_message);
  561. while (slen < LCD_WIDTH) { lcd_put_wchar(' '); ++slen; }
  562. }
  563. else {
  564. // String is longer than the available space
  565. // Get a pointer to the next valid UTF8 character
  566. // and the string remaining length
  567. uint8_t rlen;
  568. const char *stat = status_and_len(rlen);
  569. lcd_put_u8str_max(stat, LCD_PIXEL_WIDTH);
  570. // If the remaining string doesn't completely fill the screen
  571. if (rlen < LCD_WIDTH) {
  572. lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
  573. uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
  574. if (--chars) { // Draw a second dot if there's space
  575. lcd_put_wchar('.');
  576. if (--chars) { // Print a second copy of the message
  577. lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH - (rlen + 2) * (MENU_FONT_WIDTH));
  578. lcd_put_wchar(' ');
  579. }
  580. }
  581. }
  582. if (last_blink != blink) {
  583. last_blink = blink;
  584. advance_status_scroll();
  585. }
  586. }
  587. #else // !STATUS_MESSAGE_SCROLLING
  588. UNUSED(blink);
  589. // Just print the string to the LCD
  590. lcd_put_u8str_max(status_message, LCD_PIXEL_WIDTH);
  591. // Fill the rest with spaces
  592. for (; slen < LCD_WIDTH; ++slen) lcd_put_wchar(' ');
  593. #endif // !STATUS_MESSAGE_SCROLLING
  594. }
  595. #endif // HAS_GRAPHICAL_LCD && !LIGHTWEIGHT_UI