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.

ultralcd_impl_DOGM.h 31KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938
  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. * ultralcd_impl_DOGM.h
  24. *
  25. * Graphics LCD implementation for 128x64 pixel LCDs by STB for ErikZalm/Marlin
  26. * Demonstrator: http://www.reprap.org/wiki/STB_Electronics
  27. * License: http://opensource.org/licenses/BSD-3-Clause
  28. *
  29. * With the use of:
  30. * u8glib by Oliver Kraus
  31. * https://github.com/olikraus/U8glib_Arduino
  32. * License: http://opensource.org/licenses/BSD-3-Clause
  33. */
  34. #ifndef ULTRALCD_IMPL_DOGM_H
  35. #define ULTRALCD_IMPL_DOGM_H
  36. #include "MarlinConfig.h"
  37. /**
  38. * Implementation of the LCD display routines for a DOGM128 graphic display.
  39. * These are common LCD 128x64 pixel graphic displays.
  40. */
  41. #include "ultralcd.h"
  42. #include "ultralcd_st7920_u8glib_rrd.h"
  43. #include "dogm_bitmaps.h"
  44. #include "utility.h"
  45. #include "duration_t.h"
  46. #include <U8glib.h>
  47. #if ENABLED(AUTO_BED_LEVELING_UBL)
  48. #include "ubl.h"
  49. #endif
  50. #if ENABLED(SHOW_BOOTSCREEN) && ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  51. #include "_Bootscreen.h"
  52. #endif
  53. // Only Western languages support big / small fonts
  54. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  55. #undef USE_BIG_EDIT_FONT
  56. #undef USE_SMALL_INFOFONT
  57. #endif
  58. #if ENABLED(USE_SMALL_INFOFONT)
  59. #include "dogm_font_data_6x9_marlin.h"
  60. #define FONT_STATUSMENU_NAME u8g_font_6x9
  61. #else
  62. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  63. #endif
  64. #include "dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  65. #define FONT_SPECIAL_NAME Marlin_symbols
  66. #if DISABLED(SIMULATE_ROMFONT)
  67. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  68. #include "dogm_font_data_ISO10646_1.h"
  69. #define FONT_MENU_NAME ISO10646_1_5x7
  70. #elif ENABLED(DISPLAY_CHARSET_ISO10646_PL)
  71. #include "dogm_font_data_ISO10646_1_PL.h"
  72. #define FONT_MENU_NAME ISO10646_1_PL_5x7
  73. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  74. #include "dogm_font_data_ISO10646_5_Cyrillic.h"
  75. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  76. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  77. #include "dogm_font_data_ISO10646_Kana.h"
  78. #define FONT_MENU_NAME ISO10646_Kana_5x7
  79. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  80. #include "dogm_font_data_ISO10646_Greek.h"
  81. #define FONT_MENU_NAME ISO10646_Greek_5x7
  82. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CN)
  83. #include "dogm_font_data_ISO10646_CN.h"
  84. #define FONT_MENU_NAME ISO10646_CN
  85. #define TALL_FONT_CORRECTION 1
  86. #elif ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  87. #include "dogm_font_data_ISO10646_1_tr.h"
  88. #define FONT_MENU_NAME ISO10646_TR
  89. #else // fall-back
  90. #include "dogm_font_data_ISO10646_1.h"
  91. #define FONT_MENU_NAME ISO10646_1_5x7
  92. #endif
  93. #else // SIMULATE_ROMFONT
  94. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  95. #include "dogm_font_data_HD44780_J.h"
  96. #define FONT_MENU_NAME HD44780_J_5x7
  97. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  98. #include "dogm_font_data_HD44780_W.h"
  99. #define FONT_MENU_NAME HD44780_W_5x7
  100. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  101. #include "dogm_font_data_HD44780_C.h"
  102. #define FONT_MENU_NAME HD44780_C_5x7
  103. #else // fall-back
  104. #include "dogm_font_data_ISO10646_1.h"
  105. #define FONT_MENU_NAME ISO10646_1_5x7
  106. #endif
  107. #endif // SIMULATE_ROMFONT
  108. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  109. #define FONT_STATUSMENU 1
  110. #define FONT_SPECIAL 2
  111. #define FONT_MENU_EDIT 3
  112. #define FONT_MENU 4
  113. // DOGM parameters (size in pixels)
  114. #define DOG_CHAR_WIDTH 6
  115. #define DOG_CHAR_HEIGHT 12
  116. #if ENABLED(USE_BIG_EDIT_FONT)
  117. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  118. #define DOG_CHAR_WIDTH_EDIT 9
  119. #define DOG_CHAR_HEIGHT_EDIT 13
  120. #define LCD_WIDTH_EDIT 14
  121. #else
  122. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  123. #define DOG_CHAR_WIDTH_EDIT 6
  124. #define DOG_CHAR_HEIGHT_EDIT 12
  125. #define LCD_WIDTH_EDIT 22
  126. #endif
  127. #ifndef TALL_FONT_CORRECTION
  128. #define TALL_FONT_CORRECTION 0
  129. #endif
  130. #define START_COL 0
  131. // LCD selection
  132. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  133. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes
  134. // U8GLIB_ST7920_128X64 u8g(LCD_PINS_RS); // 8 stripes
  135. #elif ENABLED(U8GLIB_ST7920)
  136. //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes
  137. // No 4 stripe device available from u8glib.
  138. //U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 8 stripes
  139. U8GLIB_ST7920_128X64_RRD u8g(0); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
  140. #elif ENABLED(CARTESIO_UI)
  141. // The CartesioUI display
  142. #if DOGLCD_MOSI != -1 && DOGLCD_SCK != -1
  143. // using SW-SPI
  144. //U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  145. U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  146. #else
  147. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  148. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  149. #endif
  150. #elif ENABLED(U8GLIB_LM6059_AF)
  151. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  152. //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  153. U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  154. #elif ENABLED(MAKRPANEL) || ENABLED(VIKI2) || ENABLED(miniVIKI)
  155. // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller as well
  156. //U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  157. U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  158. #elif ENABLED(U8GLIB_SSD1306)
  159. // Generic support for SSD1306 OLED I2C LCDs
  160. //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 8 stripes
  161. U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  162. #elif ENABLED(U8GLIB_SH1106)
  163. // Generic support for SH1106 OLED I2C LCDs
  164. //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 8 stripes
  165. U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  166. #elif ENABLED(MINIPANEL)
  167. // The MINIPanel display
  168. //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  169. U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  170. #else
  171. // for regular DOGM128 display with HW-SPI
  172. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 8 stripes
  173. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 4 stripes
  174. #endif
  175. #ifndef LCD_PIXEL_WIDTH
  176. #define LCD_PIXEL_WIDTH 128
  177. #endif
  178. #ifndef LCD_PIXEL_HEIGHT
  179. #define LCD_PIXEL_HEIGHT 64
  180. #endif
  181. #include "utf_mapper.h"
  182. uint16_t lcd_contrast;
  183. static char currentfont = 0;
  184. // The current graphical page being rendered
  185. u8g_page_t &page = ((u8g_pb_t *)((u8g.getU8g())->dev->dev_mem))->p;
  186. // For selective rendering within a Y range
  187. #define PAGE_UNDER(yb) (u8g.getU8g()->current_page.y0 <= (yb))
  188. #define PAGE_CONTAINS(ya, yb) (PAGE_UNDER(yb) && u8g.getU8g()->current_page.y1 >= (ya))
  189. static void lcd_setFont(const char font_nr) {
  190. switch (font_nr) {
  191. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  192. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  193. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  194. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  195. break;
  196. }
  197. }
  198. void lcd_print(const char c) {
  199. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  200. u8g.setFont(FONT_SPECIAL_NAME);
  201. u8g.print(c);
  202. lcd_setFont(currentfont);
  203. }
  204. else charset_mapper(c);
  205. }
  206. char lcd_print_and_count(const char c) {
  207. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  208. u8g.setFont(FONT_SPECIAL_NAME);
  209. u8g.print(c);
  210. lcd_setFont(currentfont);
  211. return 1;
  212. }
  213. else return charset_mapper(c);
  214. }
  215. /**
  216. * Core LCD printing functions
  217. * On DOGM all strings go through a filter for utf
  218. * But only use lcd_print_utf and lcd_printPGM_utf for translated text
  219. */
  220. void lcd_print(const char *str) { while (*str) lcd_print(*str++); }
  221. void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd_print(c), ++str; }
  222. void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
  223. char c;
  224. while (n && (c = *str)) n -= charset_mapper(c), ++str;
  225. }
  226. void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
  227. char c;
  228. while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
  229. }
  230. // Initialize or re-initialize the LCD
  231. static void lcd_implementation_init() {
  232. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  233. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  234. #endif
  235. #if PIN_EXISTS(LCD_RESET)
  236. OUT_WRITE(LCD_RESET_PIN, LOW); // perform a clean hardware reset
  237. _delay_ms(5);
  238. OUT_WRITE(LCD_RESET_PIN, HIGH);
  239. _delay_ms(5); // delay to allow the display to initalize
  240. u8g.begin(); // re-initialize the display
  241. #endif
  242. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  243. u8g.setContrast(lcd_contrast);
  244. #endif
  245. #if ENABLED(LCD_SCREEN_ROT_90)
  246. u8g.setRot90(); // Rotate screen by 90°
  247. #elif ENABLED(LCD_SCREEN_ROT_180)
  248. u8g.setRot180(); // Rotate screen by 180°
  249. #elif ENABLED(LCD_SCREEN_ROT_270)
  250. u8g.setRot270(); // Rotate screen by 270°
  251. #endif
  252. #if ENABLED(SHOW_BOOTSCREEN)
  253. static bool show_bootscreen = true;
  254. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  255. if (show_bootscreen) {
  256. u8g.firstPage();
  257. do {
  258. u8g.drawBitmapP(
  259. (128 - (CUSTOM_BOOTSCREEN_BMPWIDTH)) /2,
  260. ( 64 - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) /2,
  261. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp);
  262. } while (u8g.nextPage());
  263. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  264. }
  265. #endif // SHOW_CUSTOM_BOOTSCREEN
  266. const uint8_t offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2;
  267. #if ENABLED(START_BMPHIGH)
  268. constexpr uint8_t offy = 0;
  269. #else
  270. constexpr uint8_t offy = DOG_CHAR_HEIGHT;
  271. #endif
  272. const uint8_t txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
  273. if (show_bootscreen) {
  274. u8g.firstPage();
  275. do {
  276. u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
  277. lcd_setFont(FONT_MENU);
  278. #ifndef STRING_SPLASH_LINE2
  279. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT), STRING_SPLASH_LINE1);
  280. #else
  281. const uint8_t txt2X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  282. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  283. u8g.drawStr(txt2X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  284. #endif
  285. } while (u8g.nextPage());
  286. }
  287. show_bootscreen = false;
  288. #endif // SHOW_BOOTSCREEN
  289. }
  290. // The kill screen is displayed for unrecoverable conditions
  291. void lcd_kill_screen() {
  292. lcd_setFont(FONT_MENU);
  293. u8g.setPrintPos(0, u8g.getHeight()/4*1);
  294. lcd_print_utf(lcd_status_message);
  295. u8g.setPrintPos(0, u8g.getHeight()/4*2);
  296. lcd_printPGM(PSTR(MSG_HALTED));
  297. u8g.setPrintPos(0, u8g.getHeight()/4*3);
  298. lcd_printPGM(PSTR(MSG_PLEASE_RESET));
  299. }
  300. void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  301. //
  302. // Status Screen
  303. //
  304. FORCE_INLINE void _draw_centered_temp(const int temp, const uint8_t x, const uint8_t y) {
  305. const uint8_t degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width
  306. u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
  307. lcd_print(itostr3(temp));
  308. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  309. }
  310. FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, const bool blink) {
  311. #if HAS_TEMP_BED
  312. bool isBed = heater < 0;
  313. #else
  314. const bool isBed = false;
  315. #endif
  316. if (PAGE_UNDER(7)) {
  317. #if HEATER_IDLE_HANDLER
  318. const bool is_idle = (!isBed ? thermalManager.is_heater_idle(heater) :
  319. #if HAS_TEMP_BED
  320. thermalManager.is_bed_idle()
  321. #else
  322. false
  323. #endif
  324. );
  325. if (blink || !is_idle)
  326. #endif
  327. _draw_centered_temp((isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater)) + 0.5, x, 7); }
  328. if (PAGE_CONTAINS(21, 28))
  329. _draw_centered_temp((isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)) + 0.5, x, 28);
  330. if (PAGE_CONTAINS(17, 20)) {
  331. const uint8_t h = isBed ? 7 : 8,
  332. y = isBed ? 18 : 17;
  333. if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
  334. u8g.setColorIndex(0); // white on black
  335. u8g.drawBox(x + h, y, 2, 2);
  336. u8g.setColorIndex(1); // black on white
  337. }
  338. else {
  339. u8g.drawBox(x + h, y, 2, 2);
  340. }
  341. }
  342. }
  343. FORCE_INLINE void _draw_axis_label(const AxisEnum axis, const char* const pstr, const bool blink) {
  344. if (blink)
  345. lcd_printPGM(pstr);
  346. else {
  347. if (!axis_homed[axis])
  348. u8g.print('?');
  349. else {
  350. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  351. if (!axis_known_position[axis])
  352. u8g.print(' ');
  353. else
  354. #endif
  355. lcd_printPGM(pstr);
  356. }
  357. }
  358. }
  359. inline void lcd_implementation_status_message(const bool blink) {
  360. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  361. static bool last_blink = false;
  362. const uint8_t slen = lcd_strlen(lcd_status_message);
  363. const char *stat = lcd_status_message + status_scroll_pos;
  364. if (slen <= LCD_WIDTH)
  365. lcd_print_utf(stat); // The string isn't scrolling
  366. else {
  367. if (status_scroll_pos <= slen - LCD_WIDTH)
  368. lcd_print_utf(stat); // The string fills the screen
  369. else {
  370. uint8_t chars = LCD_WIDTH;
  371. if (status_scroll_pos < slen) { // First string still visible
  372. lcd_print_utf(stat); // The string leaves space
  373. chars -= slen - status_scroll_pos; // Amount of space left
  374. }
  375. u8g.print('.'); // Always at 1+ spaces left, draw a dot
  376. if (--chars) {
  377. if (status_scroll_pos < slen + 1) // Draw a second dot if there's space
  378. --chars, u8g.print('.');
  379. if (chars) lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
  380. }
  381. }
  382. if (last_blink != blink) {
  383. last_blink = blink;
  384. // Skip any non-printing bytes
  385. if (status_scroll_pos < slen) while (!PRINTABLE(lcd_status_message[status_scroll_pos])) status_scroll_pos++;
  386. if (++status_scroll_pos >= slen + 2) status_scroll_pos = 0;
  387. }
  388. }
  389. #else
  390. lcd_print_utf(lcd_status_message);
  391. #endif
  392. }
  393. //#define DOGM_SD_PERCENT
  394. static void lcd_implementation_status_screen() {
  395. const bool blink = lcd_blink();
  396. // Status Menu Font
  397. lcd_setFont(FONT_STATUSMENU);
  398. //
  399. // Fan Animation
  400. //
  401. if (PAGE_UNDER(STATUS_SCREENHEIGHT + 1)) {
  402. u8g.drawBitmapP(9, 1, STATUS_SCREENBYTEWIDTH, STATUS_SCREENHEIGHT,
  403. #if HAS_FAN0
  404. blink && fanSpeeds[0] ? status_screen0_bmp : status_screen1_bmp
  405. #else
  406. status_screen0_bmp
  407. #endif
  408. );
  409. }
  410. //
  411. // Temperature Graphics and Info
  412. //
  413. if (PAGE_UNDER(28)) {
  414. // Extruders
  415. HOTEND_LOOP() _draw_heater_status(5 + e * 25, e, blink);
  416. // Heated bed
  417. #if HOTENDS < 4 && HAS_TEMP_BED
  418. _draw_heater_status(81, -1, blink);
  419. #endif
  420. #if HAS_FAN0
  421. if (PAGE_CONTAINS(20, 27)) {
  422. // Fan
  423. const int per = ((fanSpeeds[0] + 1) * 100) / 256;
  424. if (per) {
  425. u8g.setPrintPos(104, 27);
  426. lcd_print(itostr3(per));
  427. u8g.print('%');
  428. }
  429. }
  430. #endif
  431. }
  432. #if ENABLED(SDSUPPORT)
  433. //
  434. // SD Card Symbol
  435. //
  436. if (PAGE_CONTAINS(42 - (TALL_FONT_CORRECTION), 51 - (TALL_FONT_CORRECTION))) {
  437. // Upper box
  438. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7); // 42-48 (or 41-47)
  439. // Right edge
  440. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5); // 44-48 (or 43-47)
  441. // Bottom hollow box
  442. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4); // 49-52 (or 48-51)
  443. // Corner pixel
  444. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION)); // 43 (or 42)
  445. }
  446. //
  447. // Progress bar frame
  448. //
  449. #define PROGRESS_BAR_X 54
  450. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  451. if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION))) // 49-52 (or 49-51)
  452. u8g.drawFrame(
  453. PROGRESS_BAR_X, 49,
  454. PROGRESS_BAR_WIDTH, 4 - (TALL_FONT_CORRECTION)
  455. );
  456. if (IS_SD_PRINTING) {
  457. //
  458. // Progress bar solid part
  459. //
  460. if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION))) // 50-51 (or just 50)
  461. u8g.drawBox(
  462. PROGRESS_BAR_X + 1, 50,
  463. (unsigned int)((PROGRESS_BAR_WIDTH - 2) * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION)
  464. );
  465. //
  466. // SD Percent Complete
  467. //
  468. #if ENABLED(DOGM_SD_PERCENT)
  469. if (PAGE_CONTAINS(41, 48)) {
  470. // Percent complete
  471. u8g.setPrintPos(55, 48);
  472. u8g.print(itostr3(card.percentDone()));
  473. u8g.print('%');
  474. }
  475. #endif
  476. }
  477. //
  478. // Elapsed Time
  479. //
  480. #if DISABLED(DOGM_SD_PERCENT)
  481. #define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (DOG_CHAR_WIDTH / 2))
  482. #else
  483. #define SD_DURATION_X (LCD_PIXEL_WIDTH - len * DOG_CHAR_WIDTH)
  484. #endif
  485. if (PAGE_CONTAINS(41, 48)) {
  486. char buffer[10];
  487. duration_t elapsed = print_job_timer.duration();
  488. bool has_days = (elapsed.value > 60*60*24L);
  489. uint8_t len = elapsed.toDigital(buffer, has_days);
  490. u8g.setPrintPos(SD_DURATION_X, 48);
  491. lcd_print(buffer);
  492. }
  493. #endif
  494. //
  495. // XYZ Coordinates
  496. //
  497. #if ENABLED(USE_SMALL_INFOFONT)
  498. #define INFO_FONT_HEIGHT 7
  499. #else
  500. #define INFO_FONT_HEIGHT 8
  501. #endif
  502. #define XYZ_BASELINE (30 + INFO_FONT_HEIGHT)
  503. #define X_LABEL_POS 3
  504. #define X_VALUE_POS 11
  505. #define XYZ_SPACING 40
  506. #if ENABLED(XYZ_HOLLOW_FRAME)
  507. #define XYZ_FRAME_TOP 29
  508. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 3
  509. #else
  510. #define XYZ_FRAME_TOP 30
  511. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 1
  512. #endif
  513. // Before homing the axis letters are blinking 'X' <-> '?'.
  514. // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
  515. // When everything is ok you see a constant 'X'.
  516. static char xstring[5], ystring[5], zstring[7];
  517. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  518. static char wstring[5], mstring[4];
  519. #endif
  520. // At the first page, regenerate the XYZ strings
  521. if (page.page == 0) {
  522. strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
  523. strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
  524. strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
  525. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  526. strcpy(wstring, ftostr12ns(filament_width_meas));
  527. strcpy(mstring, itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  528. #endif
  529. }
  530. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  531. #if ENABLED(XYZ_HOLLOW_FRAME)
  532. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  533. #else
  534. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  535. #endif
  536. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_HEIGHT - 1), XYZ_BASELINE)) {
  537. #if DISABLED(XYZ_HOLLOW_FRAME)
  538. u8g.setColorIndex(0); // white on black
  539. #endif
  540. u8g.setPrintPos(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  541. _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
  542. u8g.setPrintPos(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  543. lcd_print(xstring);
  544. u8g.setPrintPos(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  545. _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
  546. u8g.setPrintPos(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  547. lcd_print(ystring);
  548. u8g.setPrintPos(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  549. _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
  550. u8g.setPrintPos(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  551. lcd_print(zstring);
  552. #if DISABLED(XYZ_HOLLOW_FRAME)
  553. u8g.setColorIndex(1); // black on white
  554. #endif
  555. }
  556. }
  557. //
  558. // Feedrate
  559. //
  560. if (PAGE_CONTAINS(51 - INFO_FONT_HEIGHT, 49)) {
  561. lcd_setFont(FONT_MENU);
  562. u8g.setPrintPos(3, 50);
  563. lcd_print(LCD_STR_FEEDRATE[0]);
  564. lcd_setFont(FONT_STATUSMENU);
  565. u8g.setPrintPos(12, 50);
  566. lcd_print(itostr3(feedrate_percentage));
  567. u8g.print('%');
  568. //
  569. // Filament sensor display if SD is disabled
  570. //
  571. #if DISABLED(SDSUPPORT) && ENABLED(FILAMENT_LCD_DISPLAY)
  572. u8g.setPrintPos(56, 50);
  573. lcd_print(wstring);
  574. u8g.setPrintPos(102, 50);
  575. lcd_print(mstring);
  576. u8g.print('%');
  577. lcd_setFont(FONT_MENU);
  578. u8g.setPrintPos(47, 50);
  579. lcd_print(LCD_STR_FILAM_DIA);
  580. u8g.setPrintPos(93, 50);
  581. lcd_print(LCD_STR_FILAM_MUL);
  582. #endif
  583. }
  584. //
  585. // Status line
  586. //
  587. #define STATUS_BASELINE (55 + INFO_FONT_HEIGHT)
  588. if (PAGE_CONTAINS(STATUS_BASELINE + 1 - INFO_FONT_HEIGHT, STATUS_BASELINE)) {
  589. u8g.setPrintPos(0, STATUS_BASELINE);
  590. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  591. if (PENDING(millis(), previous_lcd_status_ms + 5000UL)) { //Display both Status message line and Filament display on the last line
  592. lcd_implementation_status_message(blink);
  593. }
  594. else {
  595. lcd_printPGM(PSTR(LCD_STR_FILAM_DIA));
  596. u8g.print(':');
  597. lcd_print(ftostr12ns(filament_width_meas));
  598. lcd_printPGM(PSTR(" " LCD_STR_FILAM_MUL));
  599. u8g.print(':');
  600. lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  601. u8g.print('%');
  602. }
  603. #else
  604. lcd_implementation_status_message(blink);
  605. #endif
  606. }
  607. }
  608. #if ENABLED(ULTIPANEL)
  609. uint8_t row_y1, row_y2;
  610. uint8_t constexpr row_height = DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION);
  611. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  612. static void lcd_implementation_hotend_status(const uint8_t row) {
  613. row_y1 = row * row_height + 1;
  614. row_y2 = row_y1 + row_height - 1;
  615. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  616. u8g.setPrintPos(LCD_PIXEL_WIDTH - 11 * (DOG_CHAR_WIDTH), row_y2);
  617. lcd_print('E');
  618. lcd_print((char)('1' + active_extruder));
  619. lcd_print(' ');
  620. lcd_print(itostr3(thermalManager.degHotend(active_extruder)));
  621. lcd_print('/');
  622. if (lcd_blink() || !thermalManager.is_heater_idle(active_extruder))
  623. lcd_print(itostr3(thermalManager.degTargetHotend(active_extruder)));
  624. }
  625. #endif // ADVANCED_PAUSE_FEATURE
  626. // Set the colors for a menu item based on whether it is selected
  627. static void lcd_implementation_mark_as_selected(const uint8_t row, const bool isSelected) {
  628. row_y1 = row * row_height + 1;
  629. row_y2 = row_y1 + row_height - 1;
  630. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  631. if (isSelected) {
  632. #if ENABLED(MENU_HOLLOW_FRAME)
  633. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  634. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  635. #else
  636. u8g.setColorIndex(1); // black on white
  637. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, row_height - 1);
  638. u8g.setColorIndex(0); // white on black
  639. #endif
  640. }
  641. #if DISABLED(MENU_HOLLOW_FRAME)
  642. else {
  643. u8g.setColorIndex(1); // unmarked text is black on white
  644. }
  645. #endif
  646. u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  647. }
  648. // Draw a static line of text in the same idiom as a menu item
  649. static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char* valstr=NULL) {
  650. lcd_implementation_mark_as_selected(row, invert);
  651. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  652. char c;
  653. int8_t n = LCD_WIDTH - (START_COL);
  654. if (center && !valstr) {
  655. int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
  656. while (--pad >= 0) { u8g.print(' '); n--; }
  657. }
  658. while (n > 0 && (c = pgm_read_byte(pstr))) {
  659. n -= lcd_print_and_count(c);
  660. pstr++;
  661. }
  662. if (valstr) while (n > 0 && (c = *valstr)) {
  663. n -= lcd_print_and_count(c);
  664. valstr++;
  665. }
  666. while (n-- > 0) u8g.print(' ');
  667. }
  668. // Draw a generic menu item
  669. static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  670. UNUSED(pre_char);
  671. lcd_implementation_mark_as_selected(row, isSelected);
  672. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  673. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  674. while (char c = pgm_read_byte(pstr)) {
  675. n -= lcd_print_and_count(c);
  676. pstr++;
  677. }
  678. while (n--) u8g.print(' ');
  679. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  680. lcd_print(post_char);
  681. u8g.print(' ');
  682. }
  683. // Macros for specific types of menu items
  684. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  685. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  686. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  687. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  688. // Draw a menu item with an editable value
  689. static void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, const char* pstr, const char* const data, const bool pgm) {
  690. lcd_implementation_mark_as_selected(row, isSelected);
  691. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  692. const uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
  693. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  694. while (char c = pgm_read_byte(pstr)) {
  695. n -= lcd_print_and_count(c);
  696. pstr++;
  697. }
  698. u8g.print(':');
  699. while (n--) u8g.print(' ');
  700. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  701. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  702. }
  703. // Macros for edit items
  704. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  705. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  706. #define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \
  707. inline void lcd_implementation_drawmenu_setting_edit_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
  708. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _strFunc(*(data))); \
  709. } \
  710. inline void lcd_implementation_drawmenu_setting_edit_callback_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
  711. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _strFunc(*(data))); \
  712. } \
  713. inline void lcd_implementation_drawmenu_setting_edit_accessor_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type (*pget)(), void (*pset)(_type), ...) { \
  714. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _strFunc(pget())); \
  715. } \
  716. typedef void _name##_void
  717. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3);
  718. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
  719. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
  720. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
  721. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float5, ftostr5rj);
  722. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
  723. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
  724. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
  725. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(unsigned long, long5, ftostr5rj);
  726. #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  727. #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  728. #define lcd_implementation_drawmenu_setting_edit_accessor_bool(sel, row, pstr, pstr2, pget, pset) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  729. void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
  730. const uint8_t labellen = lcd_strlen_P(pstr),
  731. vallen = lcd_strlen(value);
  732. uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  733. #if ENABLED(USE_BIG_EDIT_FONT)
  734. uint8_t lcd_width, char_width;
  735. if (labellen <= LCD_WIDTH_EDIT - 1) {
  736. if (labellen >= LCD_WIDTH_EDIT - vallen) rows = 2;
  737. lcd_width = LCD_WIDTH_EDIT + 1;
  738. char_width = DOG_CHAR_WIDTH_EDIT;
  739. lcd_setFont(FONT_MENU_EDIT);
  740. }
  741. else {
  742. lcd_width = LCD_WIDTH - (START_COL);
  743. char_width = DOG_CHAR_WIDTH;
  744. lcd_setFont(FONT_MENU);
  745. }
  746. #else
  747. constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
  748. char_width = DOG_CHAR_WIDTH;
  749. #endif
  750. // Center either one or two rows
  751. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  752. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  753. if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) {
  754. u8g.setPrintPos(0, baseline);
  755. lcd_printPGM(pstr);
  756. }
  757. if (value != NULL) {
  758. baseline += (rows - 1) * segmentHeight;
  759. if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) {
  760. u8g.print(':');
  761. u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, baseline);
  762. lcd_print(value);
  763. }
  764. }
  765. }
  766. #if ENABLED(SDSUPPORT)
  767. static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
  768. UNUSED(pstr);
  769. lcd_implementation_mark_as_selected(row, isSelected);
  770. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  771. uint8_t n = LCD_WIDTH - (START_COL) - 1;
  772. if (longFilename[0]) {
  773. filename = longFilename;
  774. longFilename[n] = '\0';
  775. }
  776. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  777. while (char c = *filename) {
  778. n -= lcd_print_and_count(c);
  779. filename++;
  780. }
  781. while (n--) u8g.print(' ');
  782. }
  783. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  784. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  785. #endif // SDSUPPORT
  786. #endif // ULTIPANEL
  787. #endif // __ULTRALCD_IMPL_DOGM_H