status_screen_DOGM.h 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 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.h
  24. *
  25. * Standard Status Screen for Graphical Display
  26. */
  27. #ifndef _STATUS_SCREEN_DOGM_H_
  28. #define _STATUS_SCREEN_DOGM_H_
  29. FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t x, const uint8_t y) {
  30. const char * const str = itostr3(temp);
  31. u8g.setPrintPos(x - (str[0] != ' ' ? 0 : str[1] != ' ' ? 1 : 2) * DOG_CHAR_WIDTH / 2, y);
  32. lcd_print(str);
  33. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  34. }
  35. #ifndef HEAT_INDICATOR_X
  36. #define HEAT_INDICATOR_X 8
  37. #endif
  38. FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, const bool blink) {
  39. #if !HEATER_IDLE_HANDLER
  40. UNUSED(blink);
  41. #endif
  42. #if HAS_HEATED_BED
  43. const bool isBed = heater < 0;
  44. #else
  45. constexpr bool isBed = false;
  46. #endif
  47. if (PAGE_UNDER(7)) {
  48. #if HEATER_IDLE_HANDLER
  49. const bool is_idle = (
  50. #if HAS_HEATED_BED
  51. isBed ? thermalManager.is_bed_idle() :
  52. #endif
  53. thermalManager.is_heater_idle(heater)
  54. );
  55. if (blink || !is_idle)
  56. #endif
  57. _draw_centered_temp(0.5f + (
  58. #if HAS_HEATED_BED
  59. isBed ? thermalManager.degTargetBed() :
  60. #endif
  61. thermalManager.degTargetHotend(heater)
  62. ), x, 7
  63. );
  64. }
  65. if (PAGE_CONTAINS(21, 28)) {
  66. _draw_centered_temp(0.5f + (
  67. #if HAS_HEATED_BED
  68. isBed ? thermalManager.degBed() :
  69. #endif
  70. thermalManager.degHotend(heater)
  71. ), x, 28
  72. );
  73. if (PAGE_CONTAINS(17, 20)) {
  74. const uint8_t h = isBed ? 7 : HEAT_INDICATOR_X,
  75. y = isBed ? 18 : 17;
  76. if (
  77. #if HAS_HEATED_BED
  78. isBed ? thermalManager.isHeatingBed() :
  79. #endif
  80. thermalManager.isHeatingHotend(heater)
  81. ) {
  82. u8g.setColorIndex(0); // white on black
  83. u8g.drawBox(x + h, y, 2, 2);
  84. u8g.setColorIndex(1); // black on white
  85. }
  86. else
  87. u8g.drawBox(x + h, y, 2, 2);
  88. }
  89. }
  90. }
  91. //
  92. // Before homing, blink '123' <-> '???'.
  93. // Homed but unknown... '123' <-> ' '.
  94. // Homed and known, display constantly.
  95. //
  96. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  97. if (blink)
  98. lcd_print(value);
  99. else {
  100. if (!TEST(axis_homed, axis))
  101. while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
  102. else {
  103. #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  104. if (!TEST(axis_known_position, axis))
  105. lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
  106. else
  107. #endif
  108. lcd_print(value);
  109. }
  110. }
  111. }
  112. inline void lcd_implementation_status_message(const bool blink) {
  113. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  114. static bool last_blink = false;
  115. // Get the UTF8 character count of the string
  116. uint8_t slen = utf8_strlen(lcd_status_message);
  117. // If the string fits into the LCD, just print it and do not scroll it
  118. if (slen <= LCD_WIDTH) {
  119. // The string isn't scrolling and may not fill the screen
  120. lcd_print_utf(lcd_status_message);
  121. // Fill the rest with spaces
  122. while (slen < LCD_WIDTH) {
  123. u8g.print(' ');
  124. ++slen;
  125. }
  126. }
  127. else {
  128. // String is larger than the available space in screen.
  129. // Get a pointer to the next valid UTF8 character
  130. const char *stat = lcd_status_message + status_scroll_offset;
  131. // Get the string remaining length
  132. const uint8_t rlen = utf8_strlen(stat);
  133. // If we have enough characters to display
  134. if (rlen >= LCD_WIDTH) {
  135. // The remaining string fills the screen - Print it
  136. lcd_print_utf(stat, LCD_WIDTH);
  137. }
  138. else {
  139. // The remaining string does not completely fill the screen
  140. lcd_print_utf(stat, LCD_WIDTH); // The string leaves space
  141. uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
  142. u8g.print('.'); // Always at 1+ spaces left, draw a dot
  143. if (--chars) { // Draw a second dot if there's space
  144. u8g.print('.');
  145. if (--chars) // Print a second copy of the message
  146. lcd_print_utf(lcd_status_message, LCD_WIDTH - (rlen + 2));
  147. }
  148. }
  149. if (last_blink != blink) {
  150. last_blink = blink;
  151. // Adjust by complete UTF8 characters
  152. if (status_scroll_offset < slen) {
  153. status_scroll_offset++;
  154. while (!START_OF_UTF8_CHAR(lcd_status_message[status_scroll_offset]))
  155. status_scroll_offset++;
  156. }
  157. else
  158. status_scroll_offset = 0;
  159. }
  160. }
  161. #else
  162. UNUSED(blink);
  163. // Get the UTF8 character count of the string
  164. uint8_t slen = utf8_strlen(lcd_status_message);
  165. // Just print the string to the LCD
  166. lcd_print_utf(lcd_status_message, LCD_WIDTH);
  167. // Fill the rest with spaces if there are missing spaces
  168. while (slen < LCD_WIDTH) {
  169. u8g.print(' ');
  170. ++slen;
  171. }
  172. #endif
  173. }
  174. static void lcd_implementation_status_screen() {
  175. const bool blink = lcd_blink();
  176. #if FAN_ANIM_FRAMES > 2
  177. static bool old_blink;
  178. static uint8_t fan_frame;
  179. if (old_blink != blink) {
  180. old_blink = blink;
  181. if (!fanSpeeds[0] || ++fan_frame >= FAN_ANIM_FRAMES) fan_frame = 0;
  182. }
  183. #endif
  184. // Status Menu Font
  185. lcd_setFont(FONT_STATUSMENU);
  186. //
  187. // Fan Animation
  188. //
  189. // Draws the whole heading image as a B/W bitmap rather than
  190. // drawing the elements separately.
  191. // This was done as an optimization, as it was slower to draw
  192. // multiple parts compared to a single bitmap.
  193. //
  194. // The bitmap:
  195. // - May be offset in X
  196. // - Includes all nozzle(s), bed(s), and the fan.
  197. //
  198. // TODO:
  199. //
  200. // - Only draw the whole header on the first
  201. // entry to the status screen. Nozzle, bed, and
  202. // fan outline bits don't change.
  203. //
  204. if (PAGE_UNDER(STATUS_SCREENHEIGHT + 1)) {
  205. u8g.drawBitmapP(
  206. STATUS_SCREEN_X, STATUS_SCREEN_Y,
  207. (STATUS_SCREENWIDTH + 7) / 8, STATUS_SCREENHEIGHT,
  208. #if HAS_FAN0
  209. #if FAN_ANIM_FRAMES > 2
  210. fan_frame == 1 ? status_screen1_bmp :
  211. fan_frame == 2 ? status_screen2_bmp :
  212. #if FAN_ANIM_FRAMES > 3
  213. fan_frame == 3 ? status_screen3_bmp :
  214. #endif
  215. #else
  216. blink && fanSpeeds[0] ? status_screen1_bmp :
  217. #endif
  218. #endif
  219. status_screen0_bmp
  220. );
  221. }
  222. //
  223. // Temperature Graphics and Info
  224. //
  225. if (PAGE_UNDER(28)) {
  226. // Extruders
  227. HOTEND_LOOP() _draw_heater_status(STATUS_SCREEN_HOTEND_TEXT_X(e), e, blink);
  228. // Heated bed
  229. #if HOTENDS < 4 && HAS_HEATED_BED
  230. _draw_heater_status(STATUS_SCREEN_BED_TEXT_X, -1, blink);
  231. #endif
  232. #if HAS_FAN0
  233. if (PAGE_CONTAINS(STATUS_SCREEN_FAN_TEXT_Y - 7, STATUS_SCREEN_FAN_TEXT_Y)) {
  234. // Fan
  235. const int16_t per = ((fanSpeeds[0] + 1) * 100) / 256;
  236. if (per) {
  237. u8g.setPrintPos(STATUS_SCREEN_FAN_TEXT_X, STATUS_SCREEN_FAN_TEXT_Y);
  238. lcd_print(itostr3(per));
  239. u8g.print('%');
  240. }
  241. }
  242. #endif
  243. }
  244. #if ENABLED(SDSUPPORT)
  245. //
  246. // SD Card Symbol
  247. //
  248. if (card.isFileOpen() && PAGE_CONTAINS(42 - (TALL_FONT_CORRECTION), 51 - (TALL_FONT_CORRECTION))) {
  249. // Upper box
  250. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7); // 42-48 (or 41-47)
  251. // Right edge
  252. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5); // 44-48 (or 43-47)
  253. // Bottom hollow box
  254. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4); // 49-52 (or 48-51)
  255. // Corner pixel
  256. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION)); // 43 (or 42)
  257. }
  258. #endif // SDSUPPORT
  259. #if ENABLED(SDSUPPORT) || ENABLED(LCD_SET_PROGRESS_MANUALLY)
  260. //
  261. // Progress bar frame
  262. //
  263. #define PROGRESS_BAR_X 54
  264. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  265. if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION))) // 49-52 (or 49-51)
  266. u8g.drawFrame(
  267. PROGRESS_BAR_X, 49,
  268. PROGRESS_BAR_WIDTH, 4 - (TALL_FONT_CORRECTION)
  269. );
  270. #if DISABLED(LCD_SET_PROGRESS_MANUALLY)
  271. const uint8_t progress_bar_percent = card.percentDone();
  272. #endif
  273. if (progress_bar_percent > 1) {
  274. //
  275. // Progress bar solid part
  276. //
  277. if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION))) // 50-51 (or just 50)
  278. u8g.drawBox(
  279. PROGRESS_BAR_X + 1, 50,
  280. (uint16_t)((PROGRESS_BAR_WIDTH - 2) * progress_bar_percent * 0.01), 2 - (TALL_FONT_CORRECTION)
  281. );
  282. //
  283. // SD Percent Complete
  284. //
  285. #if ENABLED(DOGM_SD_PERCENT)
  286. if (PAGE_CONTAINS(41, 48)) {
  287. // Percent complete
  288. u8g.setPrintPos(55, 48);
  289. u8g.print(itostr3(progress_bar_percent));
  290. u8g.print('%');
  291. }
  292. #endif
  293. }
  294. //
  295. // Elapsed Time
  296. //
  297. #if DISABLED(DOGM_SD_PERCENT)
  298. #define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (DOG_CHAR_WIDTH / 2))
  299. #else
  300. #define SD_DURATION_X (LCD_PIXEL_WIDTH - len * DOG_CHAR_WIDTH)
  301. #endif
  302. if (PAGE_CONTAINS(41, 48)) {
  303. char buffer[10];
  304. duration_t elapsed = print_job_timer.duration();
  305. bool has_days = (elapsed.value >= 60*60*24L);
  306. uint8_t len = elapsed.toDigital(buffer, has_days);
  307. u8g.setPrintPos(SD_DURATION_X, 48);
  308. lcd_print(buffer);
  309. }
  310. #endif // SDSUPPORT || LCD_SET_PROGRESS_MANUALLY
  311. //
  312. // XYZ Coordinates
  313. //
  314. #define XYZ_BASELINE (30 + INFO_FONT_HEIGHT)
  315. #define X_LABEL_POS 3
  316. #define X_VALUE_POS 11
  317. #define XYZ_SPACING 40
  318. #if ENABLED(XYZ_HOLLOW_FRAME)
  319. #define XYZ_FRAME_TOP 29
  320. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 3
  321. #else
  322. #define XYZ_FRAME_TOP 30
  323. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 1
  324. #endif
  325. static char xstring[5], ystring[5], zstring[7];
  326. #if ENABLED(FILAMENT_LCD_DISPLAY)
  327. static char wstring[5], mstring[4];
  328. #endif
  329. // At the first page, regenerate the XYZ strings
  330. if (page.page == 0) {
  331. strcpy(xstring, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])));
  332. strcpy(ystring, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])));
  333. strcpy(zstring, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])));
  334. #if ENABLED(FILAMENT_LCD_DISPLAY)
  335. strcpy(wstring, ftostr12ns(filament_width_meas));
  336. strcpy(mstring, itostr3(100.0 * (
  337. parser.volumetric_enabled
  338. ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  339. : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  340. )
  341. ));
  342. #endif
  343. }
  344. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  345. #if ENABLED(XYZ_HOLLOW_FRAME)
  346. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  347. #else
  348. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  349. #endif
  350. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_HEIGHT - 1), XYZ_BASELINE)) {
  351. #if DISABLED(XYZ_HOLLOW_FRAME)
  352. u8g.setColorIndex(0); // white on black
  353. #endif
  354. u8g.setPrintPos(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  355. lcd_printPGM(PSTR(MSG_X));
  356. u8g.setPrintPos(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  357. _draw_axis_value(X_AXIS, xstring, blink);
  358. u8g.setPrintPos(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  359. lcd_printPGM(PSTR(MSG_Y));
  360. u8g.setPrintPos(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  361. _draw_axis_value(Y_AXIS, ystring, blink);
  362. u8g.setPrintPos(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  363. lcd_printPGM(PSTR(MSG_Z));
  364. u8g.setPrintPos(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  365. _draw_axis_value(Z_AXIS, zstring, blink);
  366. #if DISABLED(XYZ_HOLLOW_FRAME)
  367. u8g.setColorIndex(1); // black on white
  368. #endif
  369. }
  370. }
  371. //
  372. // Feedrate
  373. //
  374. if (PAGE_CONTAINS(51 - INFO_FONT_HEIGHT, 49)) {
  375. lcd_setFont(FONT_MENU);
  376. u8g.setPrintPos(3, 50);
  377. lcd_print(LCD_STR_FEEDRATE[0]);
  378. lcd_setFont(FONT_STATUSMENU);
  379. u8g.setPrintPos(12, 50);
  380. lcd_print(itostr3(feedrate_percentage));
  381. u8g.print('%');
  382. //
  383. // Filament sensor display if SD is disabled
  384. //
  385. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  386. u8g.setPrintPos(56, 50);
  387. lcd_print(wstring);
  388. u8g.setPrintPos(102, 50);
  389. lcd_print(mstring);
  390. u8g.print('%');
  391. lcd_setFont(FONT_MENU);
  392. u8g.setPrintPos(47, 50);
  393. lcd_print(LCD_STR_FILAM_DIA);
  394. u8g.setPrintPos(93, 50);
  395. lcd_print(LCD_STR_FILAM_MUL);
  396. #endif
  397. }
  398. //
  399. // Status line
  400. //
  401. #define STATUS_BASELINE (55 + INFO_FONT_HEIGHT)
  402. if (PAGE_CONTAINS(STATUS_BASELINE - (INFO_FONT_HEIGHT - 1), STATUS_BASELINE)) {
  403. u8g.setPrintPos(0, STATUS_BASELINE);
  404. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  405. if (PENDING(millis(), previous_lcd_status_ms + 5000UL)) { //Display both Status message line and Filament display on the last line
  406. lcd_implementation_status_message(blink);
  407. }
  408. else {
  409. lcd_printPGM(PSTR(LCD_STR_FILAM_DIA));
  410. u8g.print(':');
  411. lcd_print(wstring);
  412. lcd_printPGM(PSTR(" " LCD_STR_FILAM_MUL));
  413. u8g.print(':');
  414. lcd_print(mstring);
  415. u8g.print('%');
  416. }
  417. #else
  418. lcd_implementation_status_message(blink);
  419. #endif
  420. }
  421. }
  422. #endif // _STATUS_SCREEN_DOGM_H_