My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ultralcd_impl_DOGM.h 36KB

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