ultralcd_impl_DOGM.h 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732
  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. /**
  35. * Implementation of the LCD display routines for a DOGM128 graphic display.
  36. * These are common LCD 128x64 pixel graphic displays.
  37. */
  38. #ifndef ULTRALCD_IMPL_DOGM_H
  39. #define ULTRALCD_IMPL_DOGM_H
  40. #include "MarlinConfig.h"
  41. #include <U8glib.h>
  42. #include "ultralcd.h"
  43. #include "dogm_bitmaps.h"
  44. #include "utility.h"
  45. #include "duration_t.h"
  46. #if ENABLED(AUTO_BED_LEVELING_UBL)
  47. #include "ubl.h"
  48. #endif
  49. // Only Western languages support big / small fonts
  50. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  51. #undef USE_BIG_EDIT_FONT
  52. #undef USE_SMALL_INFOFONT
  53. #endif
  54. #if ENABLED(U8GLIB_ST7920)
  55. #include "ultralcd_st7920_u8glib_rrd.h"
  56. #endif
  57. #if ENABLED(U8GLIB_ST7565_64128N)
  58. #include "ultralcd_st7565_u8glib_VIKI.h"
  59. #endif
  60. #if ENABLED(USE_SMALL_INFOFONT)
  61. #include "dogm_font_data_6x9_marlin.h"
  62. #define FONT_STATUSMENU_NAME u8g_font_6x9
  63. #define INFO_FONT_HEIGHT 7
  64. #else
  65. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  66. #define INFO_FONT_HEIGHT 8
  67. #endif
  68. #include "dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  69. #define FONT_SPECIAL_NAME Marlin_symbols
  70. #if DISABLED(SIMULATE_ROMFONT)
  71. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  72. #include "dogm_font_data_ISO10646_1.h"
  73. #define FONT_MENU_NAME ISO10646_1_5x7
  74. #elif ENABLED(DISPLAY_CHARSET_ISO10646_PL)
  75. #include "dogm_font_data_ISO10646_1_PL.h"
  76. #define FONT_MENU_NAME ISO10646_1_PL_5x7
  77. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  78. #include "dogm_font_data_ISO10646_5_Cyrillic.h"
  79. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  80. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  81. #include "dogm_font_data_ISO10646_Kana.h"
  82. #define FONT_MENU_NAME ISO10646_Kana_5x7
  83. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KO_KR)
  84. #include "dogm_font_data_ISO10646_ko_KR.h"
  85. #define FONT_MENU_NAME ISO10646_ko_KR
  86. #define TALL_FONT_CORRECTION 1
  87. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  88. #include "dogm_font_data_ISO10646_Greek.h"
  89. #define FONT_MENU_NAME ISO10646_Greek_5x7
  90. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CN)
  91. #include "dogm_font_data_ISO10646_CN.h"
  92. #define FONT_MENU_NAME ISO10646_CN
  93. #define TALL_FONT_CORRECTION 1
  94. #elif ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  95. #include "dogm_font_data_ISO10646_1_tr.h"
  96. #define FONT_MENU_NAME ISO10646_TR
  97. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CZ)
  98. #include "dogm_font_data_ISO10646_CZ.h"
  99. #define FONT_MENU_NAME ISO10646_CZ
  100. #elif ENABLED(DISPLAY_CHARSET_ISO10646_SK)
  101. #include "dogm_font_data_ISO10646_SK.h"
  102. #define FONT_MENU_NAME ISO10646_SK
  103. #else // fall-back
  104. #include "dogm_font_data_ISO10646_1.h"
  105. #define FONT_MENU_NAME ISO10646_1_5x7
  106. #endif
  107. #else // SIMULATE_ROMFONT
  108. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  109. #include "dogm_font_data_HD44780_J.h"
  110. #define FONT_MENU_NAME HD44780_J_5x7
  111. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  112. #include "dogm_font_data_HD44780_W.h"
  113. #define FONT_MENU_NAME HD44780_W_5x7
  114. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  115. #include "dogm_font_data_HD44780_C.h"
  116. #define FONT_MENU_NAME HD44780_C_5x7
  117. #else // fall-back
  118. #include "dogm_font_data_ISO10646_1.h"
  119. #define FONT_MENU_NAME ISO10646_1_5x7
  120. #endif
  121. #endif // SIMULATE_ROMFONT
  122. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  123. #define FONT_STATUSMENU 1
  124. #define FONT_SPECIAL 2
  125. #define FONT_MENU_EDIT 3
  126. #define FONT_MENU 4
  127. // DOGM parameters (size in pixels)
  128. #define DOG_CHAR_WIDTH 6
  129. #define DOG_CHAR_HEIGHT 12
  130. #if ENABLED(USE_BIG_EDIT_FONT)
  131. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  132. #define DOG_CHAR_WIDTH_EDIT 9
  133. #define DOG_CHAR_HEIGHT_EDIT 18
  134. #else
  135. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  136. #define DOG_CHAR_WIDTH_EDIT DOG_CHAR_WIDTH
  137. #define DOG_CHAR_HEIGHT_EDIT DOG_CHAR_HEIGHT
  138. #endif
  139. #ifndef TALL_FONT_CORRECTION
  140. #define TALL_FONT_CORRECTION 0
  141. #endif
  142. #define START_COL 0
  143. // LCD selection
  144. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  145. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes
  146. // U8GLIB_ST7920_128X64 u8g(LCD_PINS_RS); // 8 stripes
  147. #elif ENABLED(U8GLIB_ST7920)
  148. //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes
  149. // No 4 stripe device available from u8glib.
  150. //U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 8 stripes
  151. U8GLIB_ST7920_128X64_RRD u8g(0); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
  152. #elif ENABLED(CARTESIO_UI)
  153. // The CartesioUI display
  154. #if defined(DOGLCD_MOSI) && DOGLCD_MOSI > -1 && defined(DOGLCD_SCK) && DOGLCD_SCK > -1
  155. // using SW-SPI
  156. //U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  157. U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  158. #else
  159. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  160. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  161. #endif
  162. #elif ENABLED(U8GLIB_LM6059_AF)
  163. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  164. //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  165. U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  166. #elif ENABLED(U8GLIB_ST7565_64128N)
  167. // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller as well
  168. // U8GLIB_ST7565_64128n_2x_VIKI u8g(0); // using SW-SPI DOGLCD_MOSI != -1 && DOGLCD_SCK
  169. U8GLIB_ST7565_64128n_2x_VIKI u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // using SW-SPI
  170. //U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes HWSPI
  171. #elif ENABLED(MKS_12864OLED_SSD1306)
  172. // MKS 128x64 (SSD1306) OLED I2C LCD
  173. U8GLIB_SSD1306_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  174. //U8GLIB_SSD1306_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  175. #elif ENABLED(U8GLIB_SSD1306)
  176. // Generic support for SSD1306 OLED I2C LCDs
  177. //U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 8 stripes
  178. U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  179. #elif ENABLED(MKS_12864OLED)
  180. // MKS 128x64 (SH1106) OLED I2C LCD
  181. U8GLIB_SH1106_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  182. //U8GLIB_SH1106_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  183. #elif ENABLED(U8GLIB_SH1106)
  184. // Generic support for SH1106 OLED I2C LCDs
  185. //U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 8 stripes
  186. U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  187. #elif ENABLED(U8GLIB_SSD1309)
  188. // Generic support for SSD1309 OLED I2C LCDs
  189. U8GLIB_SSD1309_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  190. #elif ENABLED(MINIPANEL)
  191. // The MINIPanel display
  192. #if defined(DOGLCD_MOSI) && DOGLCD_MOSI > -1 && defined(DOGLCD_SCK) && DOGLCD_SCK > -1
  193. // using SW-SPI
  194. //U8GLIB_MINI12864 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  195. U8GLIB_MINI12864_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  196. #else
  197. //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  198. U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  199. #endif
  200. #else
  201. // for regular DOGM128 display with HW-SPI
  202. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 8 stripes
  203. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 4 stripes
  204. #endif
  205. #ifndef LCD_PIXEL_WIDTH
  206. #define LCD_PIXEL_WIDTH 128
  207. #endif
  208. #ifndef LCD_PIXEL_HEIGHT
  209. #define LCD_PIXEL_HEIGHT 64
  210. #endif
  211. #include "utf_mapper.h"
  212. int16_t lcd_contrast; // Initialized by settings.load()
  213. static char currentfont = 0;
  214. // The current graphical page being rendered
  215. u8g_page_t &page = ((u8g_pb_t *)((u8g.getU8g())->dev->dev_mem))->p;
  216. // For selective rendering within a Y range
  217. #define PAGE_UNDER(yb) (u8g.getU8g()->current_page.y0 <= (yb))
  218. #define PAGE_CONTAINS(ya, yb) (PAGE_UNDER(yb) && u8g.getU8g()->current_page.y1 >= (ya))
  219. static void lcd_setFont(const char font_nr) {
  220. switch (font_nr) {
  221. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  222. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  223. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  224. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  225. break;
  226. }
  227. }
  228. void lcd_print(const char c) {
  229. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  230. u8g.setFont(FONT_SPECIAL_NAME);
  231. u8g.print(c);
  232. lcd_setFont(currentfont);
  233. }
  234. else charset_mapper(c);
  235. }
  236. char lcd_print_and_count(const char c) {
  237. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  238. u8g.setFont(FONT_SPECIAL_NAME);
  239. u8g.print(c);
  240. lcd_setFont(currentfont);
  241. return 1;
  242. }
  243. else return charset_mapper(c);
  244. }
  245. /**
  246. * Core LCD printing functions
  247. * On DOGM all strings go through a filter for utf
  248. * But only use lcd_print_utf and lcd_printPGM_utf for translated text
  249. */
  250. void lcd_print(const char *str) { while (*str) lcd_print(*str++); }
  251. void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd_print(c), ++str; }
  252. void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
  253. char c;
  254. while (n && (c = *str)) n -= charset_mapper(c), ++str;
  255. }
  256. void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
  257. char c;
  258. while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
  259. }
  260. #if ENABLED(SHOW_BOOTSCREEN)
  261. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  262. void lcd_custom_bootscreen() {
  263. constexpr u8g_uint_t left = (LCD_PIXEL_WIDTH - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2,
  264. top = (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2;
  265. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  266. constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
  267. bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
  268. #endif
  269. u8g.firstPage();
  270. do {
  271. u8g.drawBitmapP(
  272. left, top,
  273. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp
  274. );
  275. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  276. u8g.setColorIndex(1);
  277. if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top);
  278. if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  279. if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  280. if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom);
  281. #endif
  282. } while (u8g.nextPage());
  283. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  284. }
  285. #endif // SHOW_CUSTOM_BOOTSCREEN
  286. void lcd_bootscreen() {
  287. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  288. lcd_custom_bootscreen();
  289. #endif
  290. constexpr uint8_t offy =
  291. #if ENABLED(START_BMPHIGH)
  292. (LCD_PIXEL_HEIGHT - (START_BMPHEIGHT)) / 2
  293. #else
  294. DOG_CHAR_HEIGHT
  295. #endif
  296. ;
  297. const uint8_t width = u8g.getWidth(), height = u8g.getHeight(),
  298. offx = (width - (START_BMPWIDTH)) / 2;
  299. u8g.firstPage();
  300. do {
  301. u8g.drawBitmapP(offx, offy, (START_BMPWIDTH + 7) / 8, START_BMPHEIGHT, start_bmp);
  302. lcd_setFont(FONT_MENU);
  303. #ifndef STRING_SPLASH_LINE2
  304. const uint8_t txt1X = width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH);
  305. u8g.drawStr(txt1X, (height + DOG_CHAR_HEIGHT) / 2, STRING_SPLASH_LINE1);
  306. #else
  307. const uint8_t txt1X = (width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2,
  308. txt2X = (width - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  309. u8g.drawStr(txt1X, height - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  310. u8g.drawStr(txt2X, height - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  311. #endif
  312. } while (u8g.nextPage());
  313. safe_delay(BOOTSCREEN_TIMEOUT);
  314. }
  315. #endif // SHOW_BOOTSCREEN
  316. #if ENABLED(LIGHTWEIGHT_UI)
  317. #include "status_screen_lite_ST7920.h"
  318. #else
  319. #include "status_screen_DOGM.h"
  320. #endif
  321. // Initialize or re-initialize the LCD
  322. static void lcd_implementation_init() {
  323. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  324. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  325. #endif
  326. #if !defined(LCD_RESET_PIN) && (ENABLED(MKS_12864OLED) || ENABLED(MKS_12864OLED_SSD1306))
  327. #define LCD_RESET_PIN LCD_PINS_RS
  328. #endif
  329. #if PIN_EXISTS(LCD_RESET)
  330. OUT_WRITE(LCD_RESET_PIN, LOW); // perform a clean hardware reset
  331. _delay_ms(5);
  332. OUT_WRITE(LCD_RESET_PIN, HIGH);
  333. _delay_ms(5); // delay to allow the display to initalize
  334. #endif
  335. #if PIN_EXISTS(LCD_RESET)
  336. u8g.begin();
  337. #endif
  338. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  339. u8g.setContrast(lcd_contrast);
  340. #endif
  341. #if ENABLED(LCD_SCREEN_ROT_90)
  342. u8g.setRot90(); // Rotate screen by 90°
  343. #elif ENABLED(LCD_SCREEN_ROT_180)
  344. u8g.setRot180(); // Rotate screen by 180°
  345. #elif ENABLED(LCD_SCREEN_ROT_270)
  346. u8g.setRot270(); // Rotate screen by 270°
  347. #endif
  348. }
  349. // The kill screen is displayed for unrecoverable conditions
  350. void lcd_kill_screen() {
  351. #if ENABLED(LIGHTWEIGHT_UI)
  352. ST7920_Lite_Status_Screen::clear_text_buffer();
  353. #endif
  354. const uint8_t h4 = u8g.getHeight() / 4;
  355. u8g.firstPage();
  356. do {
  357. lcd_setFont(FONT_MENU);
  358. u8g.setPrintPos(0, h4 * 1);
  359. lcd_print_utf(lcd_status_message);
  360. u8g.setPrintPos(0, h4 * 2);
  361. lcd_printPGM_utf(PSTR(MSG_HALTED));
  362. u8g.setPrintPos(0, h4 * 3);
  363. lcd_printPGM_utf(PSTR(MSG_PLEASE_RESET));
  364. } while (u8g.nextPage());
  365. }
  366. void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  367. #if ENABLED(ULTIPANEL)
  368. uint8_t row_y1, row_y2;
  369. uint8_t constexpr row_height = DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION);
  370. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  371. static void lcd_implementation_hotend_status(const uint8_t row, const uint8_t extruder=active_extruder) {
  372. row_y1 = row * row_height + 1;
  373. row_y2 = row_y1 + row_height - 1;
  374. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  375. u8g.setPrintPos(LCD_PIXEL_WIDTH - 11 * (DOG_CHAR_WIDTH), row_y2);
  376. lcd_print('E');
  377. lcd_print((char)('1' + extruder));
  378. lcd_print(' ');
  379. lcd_print(itostr3(thermalManager.degHotend(extruder)));
  380. lcd_print('/');
  381. if (lcd_blink() || !thermalManager.is_heater_idle(extruder))
  382. lcd_print(itostr3(thermalManager.degTargetHotend(extruder)));
  383. }
  384. #endif // ADVANCED_PAUSE_FEATURE
  385. // Set the colors for a menu item based on whether it is selected
  386. static void lcd_implementation_mark_as_selected(const uint8_t row, const bool isSelected) {
  387. row_y1 = row * row_height + 1;
  388. row_y2 = row_y1 + row_height - 1;
  389. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  390. if (isSelected) {
  391. #if ENABLED(MENU_HOLLOW_FRAME)
  392. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  393. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  394. #else
  395. u8g.setColorIndex(1); // black on white
  396. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, row_height - 1);
  397. u8g.setColorIndex(0); // white on black
  398. #endif
  399. }
  400. #if DISABLED(MENU_HOLLOW_FRAME)
  401. else {
  402. u8g.setColorIndex(1); // unmarked text is black on white
  403. }
  404. #endif
  405. u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  406. }
  407. // Draw a static line of text in the same idiom as a menu item
  408. 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) {
  409. lcd_implementation_mark_as_selected(row, invert);
  410. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  411. char c;
  412. int8_t n = LCD_WIDTH - (START_COL);
  413. if (center && !valstr) {
  414. int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
  415. while (--pad >= 0) { u8g.print(' '); n--; }
  416. }
  417. while (n > 0 && (c = pgm_read_byte(pstr))) {
  418. n -= lcd_print_and_count(c);
  419. pstr++;
  420. }
  421. if (valstr) while (n > 0 && (c = *valstr)) {
  422. n -= lcd_print_and_count(c);
  423. valstr++;
  424. }
  425. while (n-- > 0) u8g.print(' ');
  426. }
  427. // Draw a generic menu item
  428. static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  429. UNUSED(pre_char);
  430. lcd_implementation_mark_as_selected(row, isSelected);
  431. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  432. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  433. while (char c = pgm_read_byte(pstr)) {
  434. n -= lcd_print_and_count(c);
  435. pstr++;
  436. }
  437. while (n--) u8g.print(' ');
  438. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  439. lcd_print(post_char);
  440. u8g.print(' ');
  441. }
  442. // Macros for specific types of menu items
  443. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  444. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  445. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  446. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  447. // Draw a menu item with an editable value
  448. static void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, const char* pstr, const char* const data, const bool pgm) {
  449. lcd_implementation_mark_as_selected(row, isSelected);
  450. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  451. const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data));
  452. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  453. while (char c = pgm_read_byte(pstr)) {
  454. n -= lcd_print_and_count(c);
  455. pstr++;
  456. }
  457. u8g.print(':');
  458. while (n--) u8g.print(' ');
  459. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  460. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  461. }
  462. // Macros for edit items
  463. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  464. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  465. #define DRAWMENU_SETTING_EDIT_GENERIC(_src) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _src)
  466. #define DRAW_BOOL_SETTING(sel, row, pstr, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  467. void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
  468. const uint8_t labellen = utf8_strlen_P(pstr),
  469. vallen = utf8_strlen(value);
  470. uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  471. #if ENABLED(USE_BIG_EDIT_FONT)
  472. constexpr uint8_t lcd_width_edit = (LCD_PIXEL_WIDTH) / (DOG_CHAR_WIDTH_EDIT);
  473. uint8_t lcd_width, char_width;
  474. if (labellen <= lcd_width_edit - 1) {
  475. if (labellen + vallen + 2 >= lcd_width_edit) rows = 2;
  476. lcd_width = lcd_width_edit + 1;
  477. char_width = DOG_CHAR_WIDTH_EDIT;
  478. lcd_setFont(FONT_MENU_EDIT);
  479. }
  480. else {
  481. lcd_width = LCD_WIDTH - (START_COL);
  482. char_width = DOG_CHAR_WIDTH;
  483. lcd_setFont(FONT_MENU);
  484. }
  485. #else
  486. constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
  487. char_width = DOG_CHAR_WIDTH;
  488. #endif
  489. // Center either one or two rows
  490. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  491. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  492. bool onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  493. if (onpage) {
  494. u8g.setPrintPos(0, baseline);
  495. lcd_printPGM_utf(pstr);
  496. }
  497. if (value != NULL) {
  498. u8g.print(':');
  499. if (rows == 2) {
  500. baseline += segmentHeight;
  501. onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  502. }
  503. if (onpage) {
  504. u8g.setPrintPos(((lcd_width - 1) - (vallen + 1)) * char_width, baseline); // Right-justified, leaving padded by spaces
  505. u8g.print(' '); // overwrite char if value gets shorter
  506. lcd_print(value);
  507. }
  508. }
  509. }
  510. #if ENABLED(SDSUPPORT)
  511. static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, CardReader& theCard, const bool isDir) {
  512. UNUSED(pstr);
  513. lcd_implementation_mark_as_selected(row, isSelected);
  514. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  515. constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
  516. const char *outstr = theCard.longest_filename();
  517. if (theCard.longFilename[0]) {
  518. #if ENABLED(SCROLL_LONG_FILENAMES)
  519. if (isSelected) {
  520. uint8_t name_hash = row;
  521. for (uint8_t l = FILENAME_LENGTH; l--;)
  522. name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l]; // rotate, xor
  523. if (filename_scroll_hash != name_hash) { // If the hash changed...
  524. filename_scroll_hash = name_hash; // Save the new hash
  525. filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
  526. filename_scroll_pos = 0; // Reset scroll to the start
  527. lcd_status_update_delay = 8; // Don't scroll right away
  528. }
  529. outstr += filename_scroll_pos;
  530. }
  531. #else
  532. theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
  533. #endif
  534. }
  535. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  536. char c;
  537. uint8_t n = maxlen;
  538. while (n && (c = *outstr)) {
  539. n -= lcd_print_and_count(c);
  540. ++outstr;
  541. }
  542. while (n) { --n; u8g.print(' '); }
  543. }
  544. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, false)
  545. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, theCard) _drawmenu_sd(sel, row, pstr, theCard, true)
  546. #endif // SDSUPPORT
  547. #if ENABLED(AUTO_BED_LEVELING_UBL)
  548. /**
  549. * UBL LCD "radar" map data
  550. */
  551. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  552. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  553. #define MAP_MAX_PIXELS_X 53
  554. #define MAP_MAX_PIXELS_Y 49
  555. void lcd_implementation_ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  556. // Scale the box pixels appropriately
  557. uint8_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  558. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  559. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  560. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  561. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  562. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  563. // Clear the Mesh Map
  564. if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) {
  565. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  566. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  567. if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) {
  568. u8g.setColorIndex(0); // Now actually clear the mesh map box
  569. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  570. }
  571. }
  572. // Display Mesh Point Locations
  573. u8g.setColorIndex(1);
  574. const uint8_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  575. uint8_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  576. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  577. if (PAGE_CONTAINS(y, y))
  578. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  579. u8g.drawBox(x, y, 1, 1);
  580. // Fill in the Specified Mesh Point
  581. uint8_t inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  582. // invert the Y to get it to plot in the right location.
  583. const uint8_t by = y_offset + inverted_y * pixels_per_y_mesh_pnt;
  584. if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
  585. u8g.drawBox(
  586. x_offset + x_plot * pixels_per_x_mesh_pnt, by,
  587. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
  588. );
  589. // Put Relevant Text on Display
  590. // Show X and Y positions at top of screen
  591. u8g.setColorIndex(1);
  592. if (PAGE_UNDER(7)) {
  593. u8g.setPrintPos(5, 7);
  594. lcd_print("X:");
  595. lcd_print(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  596. u8g.setPrintPos(74, 7);
  597. lcd_print("Y:");
  598. lcd_print(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  599. }
  600. // Print plot position
  601. if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) {
  602. u8g.setPrintPos(5, LCD_PIXEL_HEIGHT);
  603. lcd_print('(');
  604. u8g.print(x_plot);
  605. lcd_print(',');
  606. u8g.print(y_plot);
  607. lcd_print(')');
  608. // Show the location value
  609. u8g.setPrintPos(74, LCD_PIXEL_HEIGHT);
  610. lcd_print("Z:");
  611. if (!isnan(ubl.z_values[x_plot][y_plot]))
  612. lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  613. else
  614. lcd_printPGM(PSTR(" -----"));
  615. }
  616. }
  617. #endif // AUTO_BED_LEVELING_UBL
  618. #endif // ULTIPANEL
  619. #endif // __ULTRALCD_IMPL_DOGM_H