My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kannst nicht mehr als 25 Themen auswählen Themen müssen mit entweder einem Buchstaben oder einer Ziffer beginnen. Sie können Bindestriche („-“) enthalten und bis zu 35 Zeichen lang sein.

ultralcd_impl_DOGM.h 35KB

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