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

ultralcd_impl_DOGM.h 24KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * ultralcd_impl_DOGM.h
  24. *
  25. * Graphics LCD implementation for 128x64 pixel LCDs by STB for ErikZalm/Marlin
  26. * Demonstrator: http://www.reprap.org/wiki/STB_Electronics
  27. * License: http://opensource.org/licenses/BSD-3-Clause
  28. *
  29. * With the use of:
  30. * u8glib by Oliver Kraus
  31. * https://github.com/olikraus/U8glib_Arduino
  32. * License: http://opensource.org/licenses/BSD-3-Clause
  33. */
  34. #ifndef ULTRALCD_IMPL_DOGM_H
  35. #define ULTRALCD_IMPL_DOGM_H
  36. #include "../inc/MarlinConfig.h"
  37. /**
  38. * Implementation of the LCD display routines for a DOGM128 graphic display.
  39. * These are common LCD 128x64 pixel graphic displays.
  40. */
  41. #include "ultralcd.h"
  42. /*
  43. #if ENABLED(U8GLIB_ST7565_64128N)
  44. #include "dogm/ultralcd_st7565_u8glib_VIKI.h"
  45. #elif ENABLED(U8GLIB_ST7920)
  46. #include "dogm/ultralcd_st7920_u8glib_rrd.h"
  47. #endif
  48. */
  49. #include "dogm/dogm_bitmaps.h"
  50. #if ENABLED(SDSUPPORT)
  51. #include "../libs/duration_t.h"
  52. #endif
  53. #include <U8glib.h>
  54. #include "fontutils.h"
  55. #include "u8g_fontutf8.h"
  56. #include "dogm/HAL_LCD_class_defines.h"
  57. #if ENABLED(AUTO_BED_LEVELING_UBL)
  58. #include "../feature/bedlevel/ubl/ubl.h"
  59. #endif
  60. // Only Western languages support big / small fonts
  61. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  62. #undef USE_BIG_EDIT_FONT
  63. #undef USE_SMALL_INFOFONT
  64. #endif
  65. #if ENABLED(USE_SMALL_INFOFONT)
  66. #include "dogm/dogm_font_data_6x9_marlin.h"
  67. #define FONT_STATUSMENU_NAME u8g_font_6x9
  68. #define INFO_FONT_HEIGHT 7
  69. #else
  70. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  71. #define INFO_FONT_HEIGHT 8
  72. #endif
  73. // The Marlin special symbols is now in the dogm_font_data_ISO10646_1.h
  74. #define FONT_SPECIAL_NAME ISO10646_1_5x7
  75. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE)
  76. #include "dogm/dogm_font_data_ISO10646_1.h"
  77. #define FONT_MENU_NAME ISO10646_1_5x7
  78. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  79. #define FONT_STATUSMENU 1
  80. #define FONT_SPECIAL 2
  81. #define FONT_MENU_EDIT 3
  82. #define FONT_MENU 4
  83. // DOGM parameters (size in pixels)
  84. #define DOG_CHAR_WIDTH 6
  85. #define DOG_CHAR_HEIGHT 12
  86. #if ENABLED(USE_BIG_EDIT_FONT)
  87. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  88. #define DOG_CHAR_WIDTH_EDIT 9
  89. #define DOG_CHAR_HEIGHT_EDIT 18
  90. #else
  91. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  92. #define DOG_CHAR_WIDTH_EDIT DOG_CHAR_WIDTH
  93. #define DOG_CHAR_HEIGHT_EDIT DOG_CHAR_HEIGHT
  94. #endif
  95. #ifndef TALL_FONT_CORRECTION
  96. #define TALL_FONT_CORRECTION 0
  97. #endif
  98. #define START_COL 0
  99. // LCD selection
  100. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  101. #ifdef DISABLED(SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN) && (LCD_PINS_ENABLE == MOSI_PIN)
  102. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS); // 2 stripes, HW SPI (shared with SD card)
  103. #else
  104. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes, SW SPI
  105. #endif
  106. #elif ENABLED(U8GLIB_ST7920)
  107. // RepRap Discount Full Graphics Smart Controller
  108. #if DISABLED(SDSUPPORT) && (LCD_PINS_D4 == SCK_PIN) && (LCD_PINS_ENABLE == MOSI_PIN)
  109. U8GLIB_ST7920_128X64_4X_HAL u8g(LCD_PINS_RS); // 2 stripes, HW SPI (shared with SD card, on AVR does not use standard LCD adapter)
  110. #else
  111. //U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Original u8glib device. 2 stripes, SW SPI
  112. U8GLIB_ST7920_128X64_RRD u8g(LCD_PINS_D4, LCD_PINS_ENABLE, LCD_PINS_RS); // Number of stripes can be adjusted in ultralcd_st7920_u8glib_rrd.h with PAGE_HEIGHT
  113. // AVR version ignores these pin settings
  114. // HAL version uses these pin settings
  115. #endif
  116. #elif ENABLED(CARTESIO_UI)
  117. // The CartesioUI display
  118. //U8GLIB_DOGM128_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  119. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  120. #elif ENABLED(U8GLIB_LM6059_AF)
  121. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  122. //U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  123. U8GLIB_LM6059_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  124. #elif ENABLED(U8GLIB_ST7565_64128N)
  125. // The MaKrPanel, Mini Viki, Viki 2.0 & AZSMZ 12864 ST7565 controller
  126. #define SMART_RAMPS (MB(RAMPS_SMART_EFB) || MB(RAMPS_SMART_EEB) || MB(RAMPS_SMART_EFF) || MB(RAMPS_SMART_EEF) || MB(RAMPS_SMART_SF))
  127. #if DOGLCD_SCK == SCK_PIN && DOGLCD_MOSI == MOSI_PIN && !SMART_RAMPS
  128. U8GLIB_64128N_2X_HAL u8g(DOGLCD_CS, DOGLCD_A0); // using HW-SPI
  129. #else
  130. U8GLIB_64128N_2X_HAL u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // using SW-SPI
  131. #endif
  132. #elif ENABLED(MKS_12864OLED_SSD1306)
  133. // MKS 128x64 (SSD1306) OLED I2C LCD
  134. U8GLIB_SSD1306_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  135. //U8GLIB_SSD1306_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  136. #elif ENABLED(U8GLIB_SSD1306)
  137. // Generic support for SSD1306 OLED I2C LCDs
  138. //U8GLIB_SSD1306_128X64_2X_I2C_2_WIRE u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  139. U8GLIB_SSD1306_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  140. #elif ENABLED(MKS_12864OLED)
  141. // MKS 128x64 (SH1106) OLED I2C LCD
  142. U8GLIB_SH1106_128X64 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 8 stripes
  143. //U8GLIB_SH1106_128X64_2X u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0); // 4 stripes
  144. #elif ENABLED(U8GLIB_SH1106)
  145. // Generic support for SH1106 OLED I2C LCDs
  146. //U8GLIB_SH1106_128X64_2X_I2C_2_WIRE u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  147. U8GLIB_SH1106_128X64_2X u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST); // 4 stripes
  148. #elif ENABLED(U8GLIB_SSD1309)
  149. // Generic support for SSD1309 OLED I2C LCDs
  150. U8GLIB_SSD1309_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  151. #elif ENABLED(MINIPANEL)
  152. // The MINIPanel display
  153. //U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0); // 8 stripes
  154. U8GLIB_MINI12864_2X u8g(DOGLCD_CS, DOGLCD_A0); // 4 stripes
  155. #else
  156. // for regular DOGM128 display with HW-SPI
  157. //U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 8 stripes
  158. U8GLIB_DOGM128_2X u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0 // 4 stripes
  159. #endif
  160. U8GLIB *pu8g = &u8g;
  161. #ifndef LCD_PIXEL_WIDTH
  162. #define LCD_PIXEL_WIDTH 128
  163. #endif
  164. #ifndef LCD_PIXEL_HEIGHT
  165. #define LCD_PIXEL_HEIGHT 64
  166. #endif
  167. #include "lcdprint.h"
  168. int16_t lcd_contrast; // Initialized by settings.load()
  169. static char currentfont = 0;
  170. // The current graphical page being rendered
  171. u8g_page_t &page = ((u8g_pb_t *)((u8g.getU8g())->dev->dev_mem))->p;
  172. // For selective rendering within a Y range
  173. #define PAGE_UNDER(yb) (u8g.getU8g()->current_page.y0 <= (yb))
  174. #define PAGE_CONTAINS(ya, yb) (PAGE_UNDER(yb) && u8g.getU8g()->current_page.y1 >= (ya))
  175. static void lcd_setFont(const char font_nr) {
  176. switch (font_nr) {
  177. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  178. default:
  179. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  180. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  181. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  182. }
  183. }
  184. #if ENABLED(SHOW_BOOTSCREEN)
  185. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  186. void lcd_custom_bootscreen() {
  187. constexpr u8g_uint_t left = (LCD_PIXEL_WIDTH - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2,
  188. top = (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2;
  189. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  190. constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
  191. bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
  192. #endif
  193. u8g.firstPage();
  194. do {
  195. u8g.drawBitmapP(
  196. left, top,
  197. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp
  198. );
  199. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  200. u8g.setColorIndex(1);
  201. if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top);
  202. if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  203. if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  204. if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom);
  205. #endif
  206. } while (u8g.nextPage());
  207. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  208. }
  209. #endif // SHOW_CUSTOM_BOOTSCREEN
  210. void lcd_bootscreen() {
  211. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  212. lcd_custom_bootscreen();
  213. #endif
  214. constexpr uint8_t offy =
  215. #if ENABLED(START_BMPHIGH)
  216. (LCD_PIXEL_HEIGHT - (START_BMPHEIGHT)) / 2
  217. #else
  218. DOG_CHAR_HEIGHT
  219. #endif
  220. ;
  221. const uint8_t width = u8g.getWidth(), height = u8g.getHeight(),
  222. offx = (width - (START_BMPWIDTH)) / 2;
  223. u8g.firstPage();
  224. do {
  225. u8g.drawBitmapP(offx, offy, (START_BMPWIDTH + 7) / 8, START_BMPHEIGHT, start_bmp);
  226. lcd_setFont(FONT_MENU);
  227. #ifndef STRING_SPLASH_LINE2
  228. const uint8_t txt1X = width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH);
  229. u8g.drawStr(txt1X, (height + DOG_CHAR_HEIGHT) / 2, STRING_SPLASH_LINE1);
  230. #else
  231. const uint8_t txt1X = (width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2,
  232. txt2X = (width - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  233. u8g.drawStr(txt1X, height - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  234. u8g.drawStr(txt2X, height - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  235. #endif
  236. } while (u8g.nextPage());
  237. safe_delay(BOOTSCREEN_TIMEOUT);
  238. }
  239. #endif // SHOW_BOOTSCREEN
  240. #if ENABLED(LIGHTWEIGHT_UI)
  241. #include "dogm/status_screen_lite_ST7920.h"
  242. #else
  243. #include "dogm/status_screen_DOGM.h"
  244. #endif
  245. // Initialize or re-initialize the LCD
  246. static void lcd_implementation_init() {
  247. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  248. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  249. #endif
  250. #if ENABLED(MKS_12864OLED) || ENABLED(MKS_12864OLED_SSD1306)
  251. SET_OUTPUT(LCD_PINS_DC);
  252. OUT_WRITE(LCD_PINS_RS, LOW);
  253. _delay_ms(500);
  254. WRITE(LCD_PINS_RS, HIGH);
  255. #endif
  256. #if PIN_EXISTS(LCD_RESET)
  257. OUT_WRITE(LCD_RESET_PIN, LOW); // perform a clean hardware reset
  258. _delay_ms(5);
  259. OUT_WRITE(LCD_RESET_PIN, HIGH);
  260. _delay_ms(5); // delay to allow the display to initalize
  261. #endif
  262. #if PIN_EXISTS(LCD_RESET) || ENABLED(MKS_12864OLED) || ENABLED(MKS_12864OLED_SSD1306)
  263. u8g.begin();
  264. #endif
  265. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  266. u8g.setContrast(lcd_contrast);
  267. #endif
  268. #if ENABLED(LCD_SCREEN_ROT_90)
  269. u8g.setRot90(); // Rotate screen by 90°
  270. #elif ENABLED(LCD_SCREEN_ROT_180)
  271. u8g.setRot180(); // Rotate screen by 180°
  272. #elif ENABLED(LCD_SCREEN_ROT_270)
  273. u8g.setRot270(); // Rotate screen by 270°
  274. #endif
  275. uxg_SetUtf8Fonts (g_fontinfo, NUM_ARRAY(g_fontinfo));
  276. }
  277. // The kill screen is displayed for unrecoverable conditions
  278. void lcd_kill_screen() {
  279. #if ENABLED(LIGHTWEIGHT_UI)
  280. ST7920_Lite_Status_Screen::clear_text_buffer();
  281. #endif
  282. const uint8_t h4 = u8g.getHeight() / 4;
  283. u8g.firstPage();
  284. do {
  285. lcd_setFont(FONT_MENU);
  286. lcd_moveto(0, h4 * 1);
  287. lcd_put_u8str(lcd_status_message);
  288. lcd_moveto(0, h4 * 2);
  289. lcd_put_u8str_P(PSTR(MSG_HALTED));
  290. lcd_moveto(0, h4 * 3);
  291. lcd_put_u8str_P(PSTR(MSG_PLEASE_RESET));
  292. } while (u8g.nextPage());
  293. }
  294. void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  295. #if ENABLED(ULTIPANEL)
  296. uint8_t row_y1, row_y2;
  297. uint8_t constexpr row_height = DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION);
  298. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  299. static void lcd_implementation_hotend_status(const uint8_t row, const uint8_t extruder=active_extruder) {
  300. row_y1 = row * row_height + 1;
  301. row_y2 = row_y1 + row_height - 1;
  302. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  303. lcd_moveto(LCD_PIXEL_WIDTH - 11 * (DOG_CHAR_WIDTH), row_y2);
  304. lcd_put_wchar('E');
  305. lcd_put_wchar((char)('1' + extruder));
  306. lcd_put_wchar(' ');
  307. lcd_put_u8str(itostr3(thermalManager.degHotend(extruder)));
  308. lcd_put_wchar('/');
  309. if (lcd_blink() || !thermalManager.is_heater_idle(extruder))
  310. lcd_put_u8str(itostr3(thermalManager.degTargetHotend(extruder)));
  311. }
  312. #endif // ADVANCED_PAUSE_FEATURE
  313. // Set the colors for a menu item based on whether it is selected
  314. static bool lcd_implementation_mark_as_selected(const uint8_t row, const bool isSelected) {
  315. row_y1 = row * row_height + 1;
  316. row_y2 = row_y1 + row_height - 1;
  317. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return false;
  318. if (isSelected) {
  319. #if ENABLED(MENU_HOLLOW_FRAME)
  320. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  321. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  322. #else
  323. u8g.setColorIndex(1); // black on white
  324. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, row_height - 1);
  325. u8g.setColorIndex(0); // white on black
  326. #endif
  327. }
  328. #if DISABLED(MENU_HOLLOW_FRAME)
  329. else {
  330. u8g.setColorIndex(1); // unmarked text is black on white
  331. }
  332. #endif
  333. if (!PAGE_CONTAINS(row_y1, row_y2)) return false;
  334. lcd_moveto((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  335. return true;
  336. }
  337. // Draw a static line of text in the same idiom as a menu item
  338. 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) {
  339. if (lcd_implementation_mark_as_selected(row, invert)) {
  340. uint8_t n = LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * (START_COL); // pixel width of string allowed
  341. if (center && !valstr) {
  342. int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
  343. while (--pad >= 0) { lcd_put_wchar(' '); n--; }
  344. }
  345. n -= lcd_put_u8str_max_P(pstr, n);
  346. if (NULL != valstr) {
  347. n -= lcd_put_u8str_max(valstr, n);
  348. }
  349. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  350. }
  351. }
  352. // Draw a generic menu item
  353. static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  354. UNUSED(pre_char);
  355. if (lcd_implementation_mark_as_selected(row, isSelected)) {
  356. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  357. n *= DOG_CHAR_WIDTH;
  358. n -= lcd_put_u8str_max_P(pstr, n);
  359. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  360. lcd_moveto(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  361. lcd_put_wchar(post_char);
  362. lcd_put_wchar(' ');
  363. }
  364. }
  365. // Macros for specific types of menu items
  366. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  367. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  368. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  369. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  370. // Draw a menu item with an editable value
  371. static void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, const char* pstr, const char* const data, const bool pgm) {
  372. if (lcd_implementation_mark_as_selected(row, isSelected)) {
  373. const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data));
  374. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  375. n *= DOG_CHAR_WIDTH;
  376. n -= lcd_put_u8str_max_P(pstr, n);
  377. lcd_put_wchar(':');
  378. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  379. lcd_moveto(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  380. if (pgm) lcd_put_u8str_P(data); else lcd_put_u8str((char*)data);
  381. }
  382. }
  383. // Macros for edit items
  384. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  385. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  386. #define DRAWMENU_SETTING_EDIT_GENERIC(_src) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, _src)
  387. #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))
  388. void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
  389. const uint8_t labellen = utf8_strlen_P(pstr),
  390. vallen = utf8_strlen(value);
  391. uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  392. #if ENABLED(USE_BIG_EDIT_FONT)
  393. constexpr uint8_t lcd_width_edit = (LCD_PIXEL_WIDTH) / (DOG_CHAR_WIDTH_EDIT);
  394. uint8_t lcd_width, char_width;
  395. if (labellen <= lcd_width_edit - 1) {
  396. if (labellen + vallen + 2 >= lcd_width_edit) rows = 2;
  397. lcd_width = lcd_width_edit + 1;
  398. char_width = DOG_CHAR_WIDTH_EDIT;
  399. lcd_setFont(FONT_MENU_EDIT);
  400. }
  401. else {
  402. lcd_width = LCD_WIDTH - (START_COL);
  403. char_width = DOG_CHAR_WIDTH;
  404. lcd_setFont(FONT_MENU);
  405. }
  406. #else
  407. constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
  408. char_width = DOG_CHAR_WIDTH;
  409. #endif
  410. // Center either one or two rows
  411. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  412. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  413. bool onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  414. if (onpage) {
  415. lcd_moveto(0, baseline);
  416. lcd_put_u8str_P(pstr);
  417. }
  418. if (value != NULL) {
  419. lcd_put_wchar(':');
  420. if (rows == 2) {
  421. baseline += segmentHeight;
  422. onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  423. }
  424. if (onpage) {
  425. lcd_moveto(((lcd_width - 1) - (vallen + 1)) * char_width, baseline); // Right-justified, leaving padded by spaces
  426. lcd_put_wchar(' '); // overwrite char if value gets shorter
  427. lcd_put_u8str(value);
  428. }
  429. }
  430. }
  431. #if ENABLED(SDSUPPORT)
  432. static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
  433. UNUSED(pstr);
  434. lcd_implementation_mark_as_selected(row, isSelected);
  435. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  436. constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
  437. const char *outstr = longFilename[0] ? longFilename : filename;
  438. if (longFilename[0]) {
  439. #if ENABLED(SCROLL_LONG_FILENAMES)
  440. if (isSelected) {
  441. uint8_t name_hash = row;
  442. for (uint8_t l = FILENAME_LENGTH; l--;)
  443. name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
  444. if (filename_scroll_hash != name_hash) { // If the hash changed...
  445. filename_scroll_hash = name_hash; // Save the new hash
  446. filename_scroll_max = MAX(0, utf8_strlen(longFilename) - maxlen); // Update the scroll limit
  447. filename_scroll_pos = 0; // Reset scroll to the start
  448. lcd_status_update_delay = 8; // Don't scroll right away
  449. }
  450. outstr += filename_scroll_pos;
  451. }
  452. #else
  453. longFilename[maxlen] = '\0'; // cutoff at screen edge
  454. #endif
  455. }
  456. if (isDir) lcd_put_wchar(LCD_STR_FOLDER[0]);
  457. int n;
  458. n = lcd_put_u8str_max(outstr, maxlen * (DOG_CHAR_WIDTH));
  459. n = maxlen * (DOG_CHAR_WIDTH) - n;
  460. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  461. }
  462. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  463. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  464. #endif // SDSUPPORT
  465. #if ENABLED(AUTO_BED_LEVELING_UBL)
  466. /**
  467. * UBL LCD "radar" map data
  468. */
  469. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  470. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  471. #define MAP_MAX_PIXELS_X 53
  472. #define MAP_MAX_PIXELS_Y 49
  473. void lcd_implementation_ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  474. // Scale the box pixels appropriately
  475. uint8_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  476. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  477. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  478. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  479. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  480. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  481. // Clear the Mesh Map
  482. if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) {
  483. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  484. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  485. if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) {
  486. u8g.setColorIndex(0); // Now actually clear the mesh map box
  487. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  488. }
  489. }
  490. // Display Mesh Point Locations
  491. u8g.setColorIndex(1);
  492. const uint8_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  493. uint8_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  494. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  495. if (PAGE_CONTAINS(y, y))
  496. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  497. u8g.drawBox(x, y, 1, 1);
  498. // Fill in the Specified Mesh Point
  499. uint8_t inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  500. // invert the Y to get it to plot in the right location.
  501. const uint8_t by = y_offset + inverted_y * pixels_per_y_mesh_pnt;
  502. if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
  503. u8g.drawBox(
  504. x_offset + x_plot * pixels_per_x_mesh_pnt, by,
  505. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
  506. );
  507. // Put Relevant Text on Display
  508. // Show X and Y positions at top of screen
  509. u8g.setColorIndex(1);
  510. if (PAGE_UNDER(7)) {
  511. lcd_moveto(5, 7);
  512. lcd_put_u8str("X:");
  513. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  514. lcd_moveto(74, 7);
  515. lcd_put_u8str("Y:");
  516. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  517. }
  518. // Print plot position
  519. if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) {
  520. lcd_moveto(5, LCD_PIXEL_HEIGHT);
  521. lcd_put_wchar('(');
  522. u8g.print(x_plot);
  523. lcd_put_wchar(',');
  524. u8g.print(y_plot);
  525. lcd_put_wchar(')');
  526. // Show the location value
  527. lcd_moveto(74, LCD_PIXEL_HEIGHT);
  528. lcd_put_u8str("Z:");
  529. if (!isnan(ubl.z_values[x_plot][y_plot]))
  530. lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  531. else
  532. lcd_put_u8str_P(PSTR(" -----"));
  533. }
  534. }
  535. #endif // AUTO_BED_LEVELING_UBL
  536. #endif // ULTIPANEL
  537. #endif // __ULTRALCD_IMPL_DOGM_H