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

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