ultralcd_impl_DOGM.h 26 KB

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