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

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