My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Ви не можете вибрати більше 25 тем Теми мають розпочинатися з літери або цифри, можуть містити дефіси (-) і не повинні перевищувати 35 символів.

ultralcd_impl_DOGM.h 36KB

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