My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

status_screen_DOGM.cpp 30KB

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