ultralcd_impl_DOGM.h 35 KB

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