My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd_impl_DOGM.h 36KB

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