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

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065
  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 "../inc/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. #if ENABLED(U8GLIB_ST7565_64128N)
  43. #include "dogm/ultralcd_st7565_u8glib_VIKI.h"
  44. #elif ENABLED(U8GLIB_ST7920)
  45. #include "dogm/ultralcd_st7920_u8glib_rrd.h"
  46. #endif
  47. #include "dogm/dogm_bitmaps.h"
  48. #if ENABLED(SDSUPPORT)
  49. #include "../libs/duration_t.h"
  50. #endif
  51. #include <U8glib.h>
  52. #if ENABLED(AUTO_BED_LEVELING_UBL)
  53. #include "../feature/bedlevel/ubl/ubl.h"
  54. #endif
  55. #if ENABLED(SHOW_BOOTSCREEN) && ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  56. #include "../config/_Bootscreen.h"
  57. #endif
  58. // Only Western languages support big / small fonts
  59. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  60. #undef USE_BIG_EDIT_FONT
  61. #undef USE_SMALL_INFOFONT
  62. #endif
  63. #if ENABLED(USE_SMALL_INFOFONT)
  64. #include "dogm/dogm_font_data_6x9_marlin.h"
  65. #define FONT_STATUSMENU_NAME u8g_font_6x9
  66. #else
  67. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  68. #endif
  69. #include "dogm/dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  70. #define FONT_SPECIAL_NAME Marlin_symbols
  71. #if DISABLED(SIMULATE_ROMFONT)
  72. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  73. #include "dogm/dogm_font_data_ISO10646_1.h"
  74. #define FONT_MENU_NAME ISO10646_1_5x7
  75. #elif ENABLED(DISPLAY_CHARSET_ISO10646_PL)
  76. #include "dogm/dogm_font_data_ISO10646_1_PL.h"
  77. #define FONT_MENU_NAME ISO10646_1_PL_5x7
  78. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  79. #include "dogm/dogm_font_data_ISO10646_5_Cyrillic.h"
  80. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  81. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  82. #include "dogm/dogm_font_data_ISO10646_Kana.h"
  83. #define FONT_MENU_NAME ISO10646_Kana_5x7
  84. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  85. #include "dogm/dogm_font_data_ISO10646_Greek.h"
  86. #define FONT_MENU_NAME ISO10646_Greek_5x7
  87. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CN)
  88. #include "dogm/dogm_font_data_ISO10646_CN.h"
  89. #define FONT_MENU_NAME ISO10646_CN
  90. #define TALL_FONT_CORRECTION 1
  91. #elif ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  92. #include "dogm/dogm_font_data_ISO10646_1_tr.h"
  93. #define FONT_MENU_NAME ISO10646_TR
  94. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CZ)
  95. #include "dogm/dogm_font_data_ISO10646_CZ.h"
  96. #define FONT_MENU_NAME ISO10646_CZ
  97. #elif ENABLED(DISPLAY_CHARSET_ISO10646_SK)
  98. #include "dogm/dogm_font_data_ISO10646_SK.h"
  99. #define FONT_MENU_NAME ISO10646_SK
  100. #else // fall-back
  101. #include "dogm/dogm_font_data_ISO10646_1.h"
  102. #define FONT_MENU_NAME ISO10646_1_5x7
  103. #endif
  104. #else // SIMULATE_ROMFONT
  105. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  106. #include "dogm/dogm_font_data_HD44780_J.h"
  107. #define FONT_MENU_NAME HD44780_J_5x7
  108. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  109. #include "dogm/dogm_font_data_HD44780_W.h"
  110. #define FONT_MENU_NAME HD44780_W_5x7
  111. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  112. #include "dogm/dogm_font_data_HD44780_C.h"
  113. #define FONT_MENU_NAME HD44780_C_5x7
  114. #else // fall-back
  115. #include "dogm/dogm_font_data_ISO10646_1.h"
  116. #define FONT_MENU_NAME ISO10646_1_5x7
  117. #endif
  118. #endif // SIMULATE_ROMFONT
  119. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  120. #define FONT_STATUSMENU 1
  121. #define FONT_SPECIAL 2
  122. #define FONT_MENU_EDIT 3
  123. #define FONT_MENU 4
  124. // DOGM parameters (size in pixels)
  125. #define DOG_CHAR_WIDTH 6
  126. #define DOG_CHAR_HEIGHT 12
  127. #if ENABLED(USE_BIG_EDIT_FONT)
  128. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  129. #define DOG_CHAR_WIDTH_EDIT 9
  130. #define DOG_CHAR_HEIGHT_EDIT 13
  131. #define LCD_WIDTH_EDIT 14
  132. #else
  133. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  134. #define DOG_CHAR_WIDTH_EDIT 6
  135. #define DOG_CHAR_HEIGHT_EDIT 12
  136. #define LCD_WIDTH_EDIT 22
  137. #endif
  138. #ifndef TALL_FONT_CORRECTION
  139. #define TALL_FONT_CORRECTION 0
  140. #endif
  141. #define START_COL 0
  142. // LCD selection
  143. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  144. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes
  145. // U8GLIB_ST7920_128X64 u8g(LCD_PINS_RS); // 8 stripes
  146. #elif ENABLED(U8GLIB_ST7920)
  147. //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes
  148. // No 4 stripe device available from u8glib.
  149. //U8GLIB_ST7920_128X64_1X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 8 stripes
  150. U8GLIB_ST7920_128X64_RRD u8g(0); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
  151. #elif ENABLED(CARTESIO_UI)
  152. // The CartesioUI display
  153. #if DOGLCD_MOSI != -1 && DOGLCD_SCK != -1
  154. // using SW-SPI
  155. //U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  156. U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  157. #else
  158. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  159. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  160. #endif
  161. #elif ENABLED(U8GLIB_LM6059_AF)
  162. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  163. //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  164. U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  165. #elif ENABLED(U8GLIB_ST7565_64128N)
  166. // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller
  167. //U8GLIB_ST7565_64128n_2x_VIKI u8g(0); // using SW-SPI DOGLCD_MOSI != -1 && DOGLCD_SCK
  168. U8GLIB_ST7565_64128n_2x_VIKI u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // using SW-SPI
  169. //U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  170. //U8GLIB_NHD_C12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes HWSPI
  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(MINIPANEL)
  184. // The MINIPanel display
  185. //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  186. U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  187. #else
  188. // for regular DOGM128 display with HW-SPI
  189. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 8 stripes
  190. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 4 stripes
  191. #endif
  192. #ifndef LCD_PIXEL_WIDTH
  193. #define LCD_PIXEL_WIDTH 128
  194. #endif
  195. #ifndef LCD_PIXEL_HEIGHT
  196. #define LCD_PIXEL_HEIGHT 64
  197. #endif
  198. #include "utf_mapper.h"
  199. uint16_t lcd_contrast; // Initialized by settings.load()
  200. static char currentfont = 0;
  201. // The current graphical page being rendered
  202. u8g_page_t &page = ((u8g_pb_t *)((u8g.getU8g())->dev->dev_mem))->p;
  203. // For selective rendering within a Y range
  204. #define PAGE_UNDER(yb) (u8g.getU8g()->current_page.y0 <= (yb))
  205. #define PAGE_CONTAINS(ya, yb) (PAGE_UNDER(yb) && u8g.getU8g()->current_page.y1 >= (ya))
  206. static void lcd_setFont(const char font_nr) {
  207. switch (font_nr) {
  208. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  209. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  210. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  211. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  212. break;
  213. }
  214. }
  215. void lcd_print(const char c) {
  216. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  217. u8g.setFont(FONT_SPECIAL_NAME);
  218. u8g.print(c);
  219. lcd_setFont(currentfont);
  220. }
  221. else charset_mapper(c);
  222. }
  223. char lcd_print_and_count(const char c) {
  224. if (WITHIN(c, 1, LCD_STR_SPECIAL_MAX)) {
  225. u8g.setFont(FONT_SPECIAL_NAME);
  226. u8g.print(c);
  227. lcd_setFont(currentfont);
  228. return 1;
  229. }
  230. else return charset_mapper(c);
  231. }
  232. /**
  233. * Core LCD printing functions
  234. * On DOGM all strings go through a filter for utf
  235. * But only use lcd_print_utf and lcd_printPGM_utf for translated text
  236. */
  237. void lcd_print(const char *str) { while (*str) lcd_print(*str++); }
  238. void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd_print(c), ++str; }
  239. void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
  240. char c;
  241. while (n && (c = *str)) n -= charset_mapper(c), ++str;
  242. }
  243. void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
  244. char c;
  245. while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
  246. }
  247. #if ENABLED(SHOW_BOOTSCREEN)
  248. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  249. #ifndef CUSTOM_BOOTSCREEN_TIMEOUT
  250. #define CUSTOM_BOOTSCREEN_TIMEOUT 2500
  251. #endif
  252. void lcd_custom_bootscreen() {
  253. u8g.firstPage();
  254. do {
  255. u8g.drawBitmapP(
  256. (128 - (CUSTOM_BOOTSCREEN_BMPWIDTH)) /2,
  257. ( 64 - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) /2,
  258. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp);
  259. } while (u8g.nextPage());
  260. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  261. }
  262. #endif // SHOW_CUSTOM_BOOTSCREEN
  263. void lcd_bootscreen() {
  264. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  265. lcd_custom_bootscreen();
  266. #endif
  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 offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2,
  273. txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
  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. safe_delay(BOOTSCREEN_TIMEOUT);
  287. }
  288. #endif // SHOW_BOOTSCREEN
  289. // Initialize or re-initialize the LCD
  290. static void lcd_implementation_init() {
  291. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  292. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  293. #endif
  294. #if PIN_EXISTS(LCD_RESET)
  295. OUT_WRITE(LCD_RESET_PIN, LOW); // perform a clean hardware reset
  296. _delay_ms(5);
  297. OUT_WRITE(LCD_RESET_PIN, HIGH);
  298. _delay_ms(5); // delay to allow the display to initalize
  299. u8g.begin(); // re-initialize the display
  300. #endif
  301. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  302. u8g.setContrast(lcd_contrast);
  303. #endif
  304. #if ENABLED(LCD_SCREEN_ROT_90)
  305. u8g.setRot90(); // Rotate screen by 90°
  306. #elif ENABLED(LCD_SCREEN_ROT_180)
  307. u8g.setRot180(); // Rotate screen by 180°
  308. #elif ENABLED(LCD_SCREEN_ROT_270)
  309. u8g.setRot270(); // Rotate screen by 270°
  310. #endif
  311. }
  312. // The kill screen is displayed for unrecoverable conditions
  313. void lcd_kill_screen() {
  314. u8g.firstPage();
  315. do {
  316. lcd_setFont(FONT_MENU);
  317. u8g.setPrintPos(0, u8g.getHeight()/4*1);
  318. lcd_print_utf(lcd_status_message);
  319. u8g.setPrintPos(0, u8g.getHeight()/4*2);
  320. lcd_printPGM(PSTR(MSG_HALTED));
  321. u8g.setPrintPos(0, u8g.getHeight()/4*3);
  322. lcd_printPGM(PSTR(MSG_PLEASE_RESET));
  323. } while (u8g.nextPage());
  324. }
  325. void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  326. //
  327. // Status Screen
  328. //
  329. FORCE_INLINE void _draw_centered_temp(const int16_t temp, const uint8_t x, const uint8_t y) {
  330. const uint8_t degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width
  331. u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
  332. lcd_print(itostr3(temp));
  333. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  334. }
  335. FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater, const bool blink) {
  336. #if !HEATER_IDLE_HANDLER
  337. UNUSED(blink);
  338. #endif
  339. #if HAS_TEMP_BED
  340. const bool isBed = heater < 0;
  341. #else
  342. constexpr bool isBed = false;
  343. #endif
  344. if (PAGE_UNDER(7)) {
  345. #if HEATER_IDLE_HANDLER
  346. const bool is_idle = (!isBed ? thermalManager.is_heater_idle(heater) :
  347. #if HAS_TEMP_BED
  348. thermalManager.is_bed_idle()
  349. #else
  350. false
  351. #endif
  352. );
  353. if (blink || !is_idle)
  354. #endif
  355. _draw_centered_temp((isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater)) + 0.5, x, 7); }
  356. if (PAGE_CONTAINS(21, 28))
  357. _draw_centered_temp((isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)) + 0.5, x, 28);
  358. if (PAGE_CONTAINS(17, 20)) {
  359. const uint8_t h = isBed ? 7 : 8,
  360. y = isBed ? 18 : 17;
  361. if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
  362. u8g.setColorIndex(0); // white on black
  363. u8g.drawBox(x + h, y, 2, 2);
  364. u8g.setColorIndex(1); // black on white
  365. }
  366. else {
  367. u8g.drawBox(x + h, y, 2, 2);
  368. }
  369. }
  370. }
  371. FORCE_INLINE void _draw_axis_label(const AxisEnum axis, const char* const pstr, const bool blink) {
  372. if (blink)
  373. lcd_printPGM(pstr);
  374. else {
  375. if (!axis_homed[axis])
  376. u8g.print('?');
  377. else {
  378. #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  379. if (!axis_known_position[axis])
  380. u8g.print(' ');
  381. else
  382. #endif
  383. lcd_printPGM(pstr);
  384. }
  385. }
  386. }
  387. inline void lcd_implementation_status_message(const bool blink) {
  388. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  389. static bool last_blink = false;
  390. const uint8_t slen = lcd_strlen(lcd_status_message);
  391. const char *stat = lcd_status_message + status_scroll_pos;
  392. if (slen <= LCD_WIDTH)
  393. lcd_print_utf(stat); // The string isn't scrolling
  394. else {
  395. if (status_scroll_pos <= slen - LCD_WIDTH)
  396. lcd_print_utf(stat); // The string fills the screen
  397. else {
  398. uint8_t chars = LCD_WIDTH;
  399. if (status_scroll_pos < slen) { // First string still visible
  400. lcd_print_utf(stat); // The string leaves space
  401. chars -= slen - status_scroll_pos; // Amount of space left
  402. }
  403. u8g.print('.'); // Always at 1+ spaces left, draw a dot
  404. if (--chars) {
  405. if (status_scroll_pos < slen + 1) // Draw a second dot if there's space
  406. --chars, u8g.print('.');
  407. if (chars) lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
  408. }
  409. }
  410. if (last_blink != blink) {
  411. last_blink = blink;
  412. // Skip any non-printing bytes
  413. if (status_scroll_pos < slen) while (!PRINTABLE(lcd_status_message[status_scroll_pos])) status_scroll_pos++;
  414. if (++status_scroll_pos >= slen + 2) status_scroll_pos = 0;
  415. }
  416. }
  417. #else
  418. UNUSED(blink);
  419. lcd_print_utf(lcd_status_message);
  420. #endif
  421. }
  422. //#define DOGM_SD_PERCENT
  423. static void lcd_implementation_status_screen() {
  424. const bool blink = lcd_blink();
  425. // Status Menu Font
  426. lcd_setFont(FONT_STATUSMENU);
  427. //
  428. // Fan Animation
  429. //
  430. if (PAGE_UNDER(STATUS_SCREENHEIGHT + 1)) {
  431. u8g.drawBitmapP(9, 1, STATUS_SCREENBYTEWIDTH, STATUS_SCREENHEIGHT,
  432. #if HAS_FAN0
  433. blink && fanSpeeds[0] ? status_screen0_bmp : status_screen1_bmp
  434. #else
  435. status_screen0_bmp
  436. #endif
  437. );
  438. }
  439. //
  440. // Temperature Graphics and Info
  441. //
  442. if (PAGE_UNDER(28)) {
  443. // Extruders
  444. HOTEND_LOOP() _draw_heater_status(5 + e * 25, e, blink);
  445. // Heated bed
  446. #if HOTENDS < 4 && HAS_TEMP_BED
  447. _draw_heater_status(81, -1, blink);
  448. #endif
  449. #if HAS_FAN0
  450. if (PAGE_CONTAINS(20, 27)) {
  451. // Fan
  452. const int16_t per = ((fanSpeeds[0] + 1) * 100) / 256;
  453. if (per) {
  454. u8g.setPrintPos(104, 27);
  455. lcd_print(itostr3(per));
  456. u8g.print('%');
  457. }
  458. }
  459. #endif
  460. }
  461. #if ENABLED(SDSUPPORT)
  462. //
  463. // SD Card Symbol
  464. //
  465. if (card.isFileOpen() && PAGE_CONTAINS(42 - (TALL_FONT_CORRECTION), 51 - (TALL_FONT_CORRECTION))) {
  466. // Upper box
  467. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7); // 42-48 (or 41-47)
  468. // Right edge
  469. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5); // 44-48 (or 43-47)
  470. // Bottom hollow box
  471. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4); // 49-52 (or 48-51)
  472. // Corner pixel
  473. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION)); // 43 (or 42)
  474. }
  475. //
  476. // Progress bar frame
  477. //
  478. #define PROGRESS_BAR_X 54
  479. #define PROGRESS_BAR_WIDTH (LCD_PIXEL_WIDTH - PROGRESS_BAR_X)
  480. if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION))) // 49-52 (or 49-51)
  481. u8g.drawFrame(
  482. PROGRESS_BAR_X, 49,
  483. PROGRESS_BAR_WIDTH, 4 - (TALL_FONT_CORRECTION)
  484. );
  485. #if DISABLED(LCD_SET_PROGRESS_MANUALLY)
  486. const uint8_t progress_bar_percent = card.percentDone();
  487. #endif
  488. if (progress_bar_percent > 1) {
  489. //
  490. // Progress bar solid part
  491. //
  492. if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION))) // 50-51 (or just 50)
  493. u8g.drawBox(
  494. PROGRESS_BAR_X + 1, 50,
  495. (uint16_t)((PROGRESS_BAR_WIDTH - 2) * progress_bar_percent * 0.01), 2 - (TALL_FONT_CORRECTION)
  496. );
  497. //
  498. // SD Percent Complete
  499. //
  500. #if ENABLED(DOGM_SD_PERCENT)
  501. if (PAGE_CONTAINS(41, 48)) {
  502. // Percent complete
  503. u8g.setPrintPos(55, 48);
  504. u8g.print(itostr3(progress_bar_percent));
  505. u8g.print('%');
  506. }
  507. #endif
  508. }
  509. //
  510. // Elapsed Time
  511. //
  512. #if DISABLED(DOGM_SD_PERCENT)
  513. #define SD_DURATION_X (PROGRESS_BAR_X + (PROGRESS_BAR_WIDTH / 2) - len * (DOG_CHAR_WIDTH / 2))
  514. #else
  515. #define SD_DURATION_X (LCD_PIXEL_WIDTH - len * DOG_CHAR_WIDTH)
  516. #endif
  517. if (PAGE_CONTAINS(41, 48)) {
  518. char buffer[10];
  519. duration_t elapsed = print_job_timer.duration();
  520. bool has_days = (elapsed.value > 60*60*24L);
  521. uint8_t len = elapsed.toDigital(buffer, has_days);
  522. u8g.setPrintPos(SD_DURATION_X, 48);
  523. lcd_print(buffer);
  524. }
  525. #endif
  526. //
  527. // XYZ Coordinates
  528. //
  529. #if ENABLED(USE_SMALL_INFOFONT)
  530. #define INFO_FONT_HEIGHT 7
  531. #else
  532. #define INFO_FONT_HEIGHT 8
  533. #endif
  534. #define XYZ_BASELINE (30 + INFO_FONT_HEIGHT)
  535. #define X_LABEL_POS 3
  536. #define X_VALUE_POS 11
  537. #define XYZ_SPACING 40
  538. #if ENABLED(XYZ_HOLLOW_FRAME)
  539. #define XYZ_FRAME_TOP 29
  540. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 3
  541. #else
  542. #define XYZ_FRAME_TOP 30
  543. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 1
  544. #endif
  545. // Before homing the axis letters are blinking 'X' <-> '?'.
  546. // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
  547. // When everything is ok you see a constant 'X'.
  548. static char xstring[5], ystring[5], zstring[7];
  549. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  550. static char wstring[5], mstring[4];
  551. #endif
  552. // At the first page, regenerate the XYZ strings
  553. if (page.page == 0) {
  554. strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
  555. strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
  556. strcpy(zstring, ftostr52sp(FIXFLOAT(current_position[Z_AXIS])));
  557. #if ENABLED(FILAMENT_LCD_DISPLAY) && DISABLED(SDSUPPORT)
  558. strcpy(wstring, ftostr12ns(filament_width_meas));
  559. strcpy(mstring, itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  560. #endif
  561. }
  562. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  563. #if ENABLED(XYZ_HOLLOW_FRAME)
  564. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  565. #else
  566. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  567. #endif
  568. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_HEIGHT - 1), XYZ_BASELINE)) {
  569. #if DISABLED(XYZ_HOLLOW_FRAME)
  570. u8g.setColorIndex(0); // white on black
  571. #endif
  572. u8g.setPrintPos(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  573. _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
  574. u8g.setPrintPos(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  575. lcd_print(xstring);
  576. u8g.setPrintPos(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  577. _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
  578. u8g.setPrintPos(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  579. lcd_print(ystring);
  580. u8g.setPrintPos(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  581. _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
  582. u8g.setPrintPos(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  583. lcd_print(zstring);
  584. #if DISABLED(XYZ_HOLLOW_FRAME)
  585. u8g.setColorIndex(1); // black on white
  586. #endif
  587. }
  588. }
  589. //
  590. // Feedrate
  591. //
  592. if (PAGE_CONTAINS(51 - INFO_FONT_HEIGHT, 49)) {
  593. lcd_setFont(FONT_MENU);
  594. u8g.setPrintPos(3, 50);
  595. lcd_print(LCD_STR_FEEDRATE[0]);
  596. lcd_setFont(FONT_STATUSMENU);
  597. u8g.setPrintPos(12, 50);
  598. lcd_print(itostr3(feedrate_percentage));
  599. u8g.print('%');
  600. //
  601. // Filament sensor display if SD is disabled
  602. //
  603. #if DISABLED(SDSUPPORT) && ENABLED(FILAMENT_LCD_DISPLAY)
  604. u8g.setPrintPos(56, 50);
  605. lcd_print(wstring);
  606. u8g.setPrintPos(102, 50);
  607. lcd_print(mstring);
  608. u8g.print('%');
  609. lcd_setFont(FONT_MENU);
  610. u8g.setPrintPos(47, 50);
  611. lcd_print(LCD_STR_FILAM_DIA);
  612. u8g.setPrintPos(93, 50);
  613. lcd_print(LCD_STR_FILAM_MUL);
  614. #endif
  615. }
  616. //
  617. // Status line
  618. //
  619. #define STATUS_BASELINE (55 + INFO_FONT_HEIGHT)
  620. if (PAGE_CONTAINS(STATUS_BASELINE - (INFO_FONT_HEIGHT - 1), STATUS_BASELINE)) {
  621. u8g.setPrintPos(0, STATUS_BASELINE);
  622. #if ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  623. if (PENDING(millis(), previous_lcd_status_ms + 5000UL)) { //Display both Status message line and Filament display on the last line
  624. lcd_implementation_status_message(blink);
  625. }
  626. else {
  627. lcd_printPGM(PSTR(LCD_STR_FILAM_DIA));
  628. u8g.print(':');
  629. lcd_print(ftostr12ns(filament_width_meas));
  630. lcd_printPGM(PSTR(" " LCD_STR_FILAM_MUL));
  631. u8g.print(':');
  632. lcd_print(itostr3(100.0 * planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  633. u8g.print('%');
  634. }
  635. #else
  636. lcd_implementation_status_message(blink);
  637. #endif
  638. }
  639. }
  640. #if ENABLED(ULTIPANEL)
  641. uint8_t row_y1, row_y2;
  642. uint8_t constexpr row_height = DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION);
  643. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  644. static void lcd_implementation_hotend_status(const uint8_t row) {
  645. row_y1 = row * row_height + 1;
  646. row_y2 = row_y1 + row_height - 1;
  647. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  648. u8g.setPrintPos(LCD_PIXEL_WIDTH - 11 * (DOG_CHAR_WIDTH), row_y2);
  649. lcd_print('E');
  650. lcd_print((char)('1' + active_extruder));
  651. lcd_print(' ');
  652. lcd_print(itostr3(thermalManager.degHotend(active_extruder)));
  653. lcd_print('/');
  654. if (lcd_blink() || !thermalManager.is_heater_idle(active_extruder))
  655. lcd_print(itostr3(thermalManager.degTargetHotend(active_extruder)));
  656. }
  657. #endif // ADVANCED_PAUSE_FEATURE
  658. // Set the colors for a menu item based on whether it is selected
  659. static void lcd_implementation_mark_as_selected(const uint8_t row, const bool isSelected) {
  660. row_y1 = row * row_height + 1;
  661. row_y2 = row_y1 + row_height - 1;
  662. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  663. if (isSelected) {
  664. #if ENABLED(MENU_HOLLOW_FRAME)
  665. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  666. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  667. #else
  668. u8g.setColorIndex(1); // black on white
  669. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, row_height - 1);
  670. u8g.setColorIndex(0); // white on black
  671. #endif
  672. }
  673. #if DISABLED(MENU_HOLLOW_FRAME)
  674. else {
  675. u8g.setColorIndex(1); // unmarked text is black on white
  676. }
  677. #endif
  678. u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  679. }
  680. // Draw a static line of text in the same idiom as a menu item
  681. 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) {
  682. lcd_implementation_mark_as_selected(row, invert);
  683. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  684. char c;
  685. int8_t n = LCD_WIDTH - (START_COL);
  686. if (center && !valstr) {
  687. int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
  688. while (--pad >= 0) { u8g.print(' '); n--; }
  689. }
  690. while (n > 0 && (c = pgm_read_byte(pstr))) {
  691. n -= lcd_print_and_count(c);
  692. pstr++;
  693. }
  694. if (valstr) while (n > 0 && (c = *valstr)) {
  695. n -= lcd_print_and_count(c);
  696. valstr++;
  697. }
  698. while (n-- > 0) u8g.print(' ');
  699. }
  700. // Draw a generic menu item
  701. static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  702. UNUSED(pre_char);
  703. lcd_implementation_mark_as_selected(row, isSelected);
  704. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  705. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  706. while (char c = pgm_read_byte(pstr)) {
  707. n -= lcd_print_and_count(c);
  708. pstr++;
  709. }
  710. while (n--) u8g.print(' ');
  711. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  712. lcd_print(post_char);
  713. u8g.print(' ');
  714. }
  715. // Macros for specific types of menu items
  716. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  717. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  718. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  719. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  720. // Draw a menu item with an editable value
  721. static void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, const char* pstr, const char* const data, const bool pgm) {
  722. lcd_implementation_mark_as_selected(row, isSelected);
  723. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  724. const uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
  725. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  726. while (char c = pgm_read_byte(pstr)) {
  727. n -= lcd_print_and_count(c);
  728. pstr++;
  729. }
  730. u8g.print(':');
  731. while (n--) u8g.print(' ');
  732. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  733. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  734. }
  735. // Macros for edit items
  736. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  737. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  738. #define DRAWMENU_SETTING_EDIT_GENERIC(_src) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _src)
  739. #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))
  740. void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
  741. const uint8_t labellen = lcd_strlen_P(pstr),
  742. vallen = lcd_strlen(value);
  743. uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  744. #if ENABLED(USE_BIG_EDIT_FONT)
  745. uint8_t lcd_width, char_width;
  746. if (labellen <= LCD_WIDTH_EDIT - 1) {
  747. if (labellen + vallen + 2 >= LCD_WIDTH_EDIT) rows = 2;
  748. lcd_width = LCD_WIDTH_EDIT + 1;
  749. char_width = DOG_CHAR_WIDTH_EDIT;
  750. lcd_setFont(FONT_MENU_EDIT);
  751. }
  752. else {
  753. lcd_width = LCD_WIDTH - (START_COL);
  754. char_width = DOG_CHAR_WIDTH;
  755. lcd_setFont(FONT_MENU);
  756. }
  757. #else
  758. constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
  759. char_width = DOG_CHAR_WIDTH;
  760. #endif
  761. // Center either one or two rows
  762. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  763. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  764. bool onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  765. if (onpage) {
  766. u8g.setPrintPos(0, baseline);
  767. lcd_printPGM(pstr);
  768. }
  769. if (value != NULL) {
  770. u8g.print(':');
  771. if (rows == 2) {
  772. baseline += segmentHeight;
  773. onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  774. }
  775. if (onpage) {
  776. u8g.setPrintPos(((lcd_width - 1) - (vallen + 1)) * char_width, baseline); // Right-justified, leaving padded by spaces
  777. u8g.print(' '); // overwrite char if value gets shorter
  778. lcd_print(value);
  779. }
  780. }
  781. }
  782. #if ENABLED(SDSUPPORT)
  783. static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
  784. UNUSED(pstr);
  785. lcd_implementation_mark_as_selected(row, isSelected);
  786. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  787. constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
  788. const char *outstr = longFilename[0] ? longFilename : filename;
  789. if (longFilename[0]) {
  790. #if ENABLED(SCROLL_LONG_FILENAMES)
  791. if (isSelected) {
  792. uint8_t name_hash = row;
  793. for (uint8_t l = FILENAME_LENGTH; l--;)
  794. name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
  795. if (filename_scroll_hash != name_hash) { // If the hash changed...
  796. filename_scroll_hash = name_hash; // Save the new hash
  797. filename_scroll_max = max(0, lcd_strlen(longFilename) - maxlen); // Update the scroll limit
  798. filename_scroll_pos = 0; // Reset scroll to the start
  799. lcd_status_update_delay = 8; // Don't scroll right away
  800. }
  801. outstr += filename_scroll_pos;
  802. }
  803. #else
  804. longFilename[maxlen] = '\0'; // cutoff at screen edge
  805. #endif
  806. }
  807. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  808. char c;
  809. uint8_t n = maxlen;
  810. while (n && (c = *outstr)) {
  811. n -= lcd_print_and_count(c);
  812. ++outstr;
  813. }
  814. while (n) { --n; u8g.print(' '); }
  815. }
  816. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  817. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  818. #endif // SDSUPPORT
  819. #if ENABLED(AUTO_BED_LEVELING_UBL)
  820. /**
  821. * UBL LCD "radar" map data
  822. */
  823. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  824. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  825. #define MAP_MAX_PIXELS_X 53
  826. #define MAP_MAX_PIXELS_Y 49
  827. void lcd_implementation_ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  828. // Scale the box pixels appropriately
  829. uint8_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  830. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  831. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  832. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  833. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  834. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  835. // Clear the Mesh Map
  836. if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) {
  837. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  838. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  839. if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) {
  840. u8g.setColorIndex(0); // Now actually clear the mesh map box
  841. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  842. }
  843. }
  844. // Display Mesh Point Locations
  845. u8g.setColorIndex(1);
  846. const uint8_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  847. uint8_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  848. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  849. if (PAGE_CONTAINS(y, y))
  850. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  851. u8g.drawBox(x, y, 1, 1);
  852. // Fill in the Specified Mesh Point
  853. uint8_t inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  854. // invert the Y to get it to plot in the right location.
  855. const uint8_t by = y_offset + inverted_y * pixels_per_y_mesh_pnt;
  856. if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
  857. u8g.drawBox(
  858. x_offset + x_plot * pixels_per_x_mesh_pnt, by,
  859. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
  860. );
  861. // Put Relevant Text on Display
  862. // Show X and Y positions at top of screen
  863. u8g.setColorIndex(1);
  864. if (PAGE_UNDER(7)) {
  865. u8g.setPrintPos(5, 7);
  866. lcd_print("X:");
  867. lcd_print(ftostr32(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  868. u8g.setPrintPos(74, 7);
  869. lcd_print("Y:");
  870. lcd_print(ftostr32(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  871. }
  872. // Print plot position
  873. if (PAGE_CONTAINS(64 - (INFO_FONT_HEIGHT - 1), 64)) {
  874. u8g.setPrintPos(5, 64);
  875. lcd_print('(');
  876. u8g.print(x_plot);
  877. lcd_print(',');
  878. u8g.print(y_plot);
  879. lcd_print(')');
  880. // Show the location value
  881. u8g.setPrintPos(74, 64);
  882. lcd_print("Z:");
  883. if (!isnan(ubl.z_values[x_plot][y_plot]))
  884. lcd_print(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  885. else
  886. lcd_printPGM(PSTR(" -----"));
  887. }
  888. }
  889. #endif // AUTO_BED_LEVELING_UBL
  890. #endif // ULTIPANEL
  891. #endif // __ULTRALCD_IMPL_DOGM_H