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.

marlinui_DOGM.cpp 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * lcd/dogm/marlinui_DOGM.h
  24. *
  25. * Implementation of the LCD display routines for a DOGM128 graphic display.
  26. * by STB for ErikZalm/Marlin. Common LCD 128x64 pixel graphic displays.
  27. *
  28. * Demonstrator: https://www.reprap.org/wiki/STB_Electronics
  29. * License: https://opensource.org/licenses/BSD-3-Clause
  30. *
  31. * With the use of:
  32. * u8glib by Oliver Kraus
  33. * https://github.com/olikraus/U8glib_Arduino
  34. * License: https://opensource.org/licenses/BSD-3-Clause
  35. */
  36. #include "../../inc/MarlinConfigPre.h"
  37. #if HAS_MARLINUI_U8GLIB
  38. #include "marlinui_DOGM.h"
  39. #include "u8g_fontutf8.h"
  40. #if ENABLED(SHOW_BOOTSCREEN)
  41. #include "dogm_Bootscreen.h"
  42. #endif
  43. #include "../lcdprint.h"
  44. #include "../fontutils.h"
  45. #include "../../libs/numtostr.h"
  46. #include "../marlinui.h"
  47. #include "../../sd/cardreader.h"
  48. #include "../../module/temperature.h"
  49. #include "../../module/printcounter.h"
  50. #include "../../MarlinCore.h"
  51. #if ENABLED(SDSUPPORT)
  52. #include "../../libs/duration_t.h"
  53. #endif
  54. #if ENABLED(AUTO_BED_LEVELING_UBL)
  55. #include "../../feature/bedlevel/bedlevel.h"
  56. #endif
  57. /**
  58. * Include all needed font files
  59. * (See https://marlinfw.org/docs/development/fonts.html)
  60. */
  61. #include "fontdata/fontdata_ISO10646_1.h"
  62. #if ENABLED(USE_SMALL_INFOFONT)
  63. #include "fontdata/fontdata_6x9_marlin.h"
  64. #define FONT_STATUSMENU_NAME u8g_font_6x9
  65. #else
  66. #define FONT_STATUSMENU_NAME MENU_FONT_NAME
  67. #endif
  68. U8G_CLASS u8g;
  69. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE)
  70. #ifdef LCD_LANGUAGE_2
  71. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE_2)
  72. #endif
  73. #ifdef LCD_LANGUAGE_3
  74. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE_3)
  75. #endif
  76. #ifdef LCD_LANGUAGE_4
  77. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE_4)
  78. #endif
  79. #ifdef LCD_LANGUAGE_5
  80. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE_5)
  81. #endif
  82. #if HAS_LCD_CONTRAST
  83. void MarlinUI::_set_contrast() { u8g.setContrast(contrast); }
  84. #endif
  85. void MarlinUI::set_font(const MarlinFont font_nr) {
  86. static char currentfont = 0;
  87. if (font_nr != currentfont) {
  88. switch ((currentfont = font_nr)) {
  89. case FONT_STATUSMENU : u8g.setFont(FONT_STATUSMENU_NAME); break;
  90. case FONT_EDIT : u8g.setFont(EDIT_FONT_NAME); break;
  91. default:
  92. case FONT_MENU : u8g.setFont(MENU_FONT_NAME); break;
  93. }
  94. }
  95. }
  96. bool MarlinUI::detected() { return true; }
  97. #if ENABLED(SHOW_BOOTSCREEN)
  98. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  99. // Draws a slice of a particular frame of the custom bootscreen, without the u8g loop
  100. void MarlinUI::draw_custom_bootscreen(const uint8_t frame/*=0*/) {
  101. constexpr u8g_uint_t left = u8g_uint_t((LCD_PIXEL_WIDTH - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2),
  102. top = u8g_uint_t(CUSTOM_BOOTSCREEN_Y);
  103. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  104. constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
  105. bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
  106. #endif
  107. #if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED)
  108. #if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
  109. const u8g_pgm_uint8_t * const bmp = (u8g_pgm_uint8_t*)pgm_read_ptr(&custom_bootscreen_animation[frame].bitmap);
  110. #else
  111. const u8g_pgm_uint8_t * const bmp = (u8g_pgm_uint8_t*)pgm_read_ptr(&custom_bootscreen_animation[frame]);
  112. #endif
  113. #else
  114. const u8g_pgm_uint8_t * const bmp = custom_start_bmp;
  115. #endif
  116. UNUSED(frame);
  117. u8g.drawBitmapP(left, top, CUSTOM_BOOTSCREEN_BMP_BYTEWIDTH, CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp);
  118. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  119. if (frame == 0) {
  120. u8g.setColorIndex(1);
  121. if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top);
  122. if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  123. if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  124. if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom);
  125. }
  126. #endif
  127. }
  128. // Shows the custom bootscreen, with the u8g loop, animations and delays
  129. void MarlinUI::show_custom_bootscreen() {
  130. #if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED)
  131. constexpr millis_t frame_time = 0;
  132. constexpr uint8_t f = 0;
  133. #else
  134. #if DISABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
  135. constexpr millis_t frame_time = CUSTOM_BOOTSCREEN_FRAME_TIME;
  136. #endif
  137. LOOP_L_N(f, COUNT(custom_bootscreen_animation))
  138. #endif
  139. {
  140. #if ENABLED(CUSTOM_BOOTSCREEN_ANIMATED_FRAME_TIME)
  141. const uint8_t fr = _MIN(f, COUNT(custom_bootscreen_animation) - 1);
  142. const millis_t frame_time = pgm_read_word(&custom_bootscreen_animation[fr].duration);
  143. #endif
  144. u8g.firstPage();
  145. do { draw_custom_bootscreen(f); } while (u8g.nextPage());
  146. if (frame_time) safe_delay(frame_time);
  147. }
  148. #ifndef CUSTOM_BOOTSCREEN_TIMEOUT
  149. #define CUSTOM_BOOTSCREEN_TIMEOUT 2500
  150. #endif
  151. #if CUSTOM_BOOTSCREEN_TIMEOUT
  152. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  153. #endif
  154. }
  155. #endif // SHOW_CUSTOM_BOOTSCREEN
  156. // Two-part needed to display all info
  157. constexpr bool two_part = ((LCD_PIXEL_HEIGHT) - (START_BMPHEIGHT)) < ((MENU_FONT_ASCENT) * 2);
  158. constexpr uint8_t bootscreen_pages = 1 + two_part;
  159. // Draw the static Marlin bootscreen from a u8g loop
  160. // or the animated boot screen within its own u8g loop
  161. void MarlinUI::draw_marlin_bootscreen(const bool line2/*=false*/) {
  162. // Determine text space needed
  163. constexpr u8g_uint_t text_width_1 = u8g_uint_t((sizeof(SHORT_BUILD_VERSION) - 1) * (MENU_FONT_WIDTH)),
  164. text_width_2 = u8g_uint_t((sizeof(MARLIN_WEBSITE_URL) - 1) * (MENU_FONT_WIDTH)),
  165. text_max_width = _MAX(text_width_1, text_width_2),
  166. text_total_height = (MENU_FONT_HEIGHT) * 2,
  167. width = LCD_PIXEL_WIDTH, height = LCD_PIXEL_HEIGHT,
  168. rspace = width - (START_BMPWIDTH);
  169. u8g_int_t offx, offy, txt_base, txt_offx_1, txt_offx_2;
  170. // Can the text fit to the right of the bitmap?
  171. if (text_max_width < rspace) {
  172. constexpr int8_t inter = (width - text_max_width - (START_BMPWIDTH)) / 3; // Evenly distribute horizontal space
  173. offx = inter; // First the boot logo...
  174. offy = (height - (START_BMPHEIGHT)) / 2; // ...V-aligned in the full height
  175. txt_offx_1 = txt_offx_2 = inter + (START_BMPWIDTH) + inter; // Text right of the bitmap
  176. txt_base = (height + MENU_FONT_ASCENT + text_total_height - (MENU_FONT_HEIGHT)) / 2; // Text vertical center
  177. }
  178. else {
  179. constexpr int8_t inter = (height - text_total_height - (START_BMPHEIGHT)) / 3; // Evenly distribute vertical space
  180. offx = rspace / 2; // Center the boot logo in the whole space
  181. offy = inter; // V-align boot logo proportionally
  182. txt_offx_1 = (width - text_width_1) / 2; // Text 1 centered
  183. txt_offx_2 = (width - text_width_2) / 2; // Text 2 centered
  184. txt_base = offy + START_BMPHEIGHT + offy + text_total_height - (MENU_FONT_DESCENT); // Even spacing looks best
  185. }
  186. NOLESS(offx, 0);
  187. NOLESS(offy, 0);
  188. auto _draw_bootscreen_bmp = [&](const uint8_t *bitmap) {
  189. u8g.drawBitmapP(offx, offy, START_BMP_BYTEWIDTH, START_BMPHEIGHT, bitmap);
  190. set_font(FONT_MENU);
  191. if (!two_part || !line2) lcd_put_u8str(txt_offx_1, txt_base - (MENU_FONT_HEIGHT), F(SHORT_BUILD_VERSION));
  192. if (!two_part || line2) lcd_put_u8str(txt_offx_2, txt_base, F(MARLIN_WEBSITE_URL));
  193. };
  194. auto draw_bootscreen_bmp = [&](const uint8_t *bitmap) {
  195. u8g.firstPage(); do { _draw_bootscreen_bmp(bitmap); } while (u8g.nextPage());
  196. };
  197. #if DISABLED(BOOT_MARLIN_LOGO_ANIMATED)
  198. draw_bootscreen_bmp(start_bmp);
  199. #else
  200. constexpr millis_t frame_time = MARLIN_BOOTSCREEN_FRAME_TIME;
  201. LOOP_L_N(f, COUNT(marlin_bootscreen_animation)) {
  202. draw_bootscreen_bmp((uint8_t*)pgm_read_ptr(&marlin_bootscreen_animation[f]));
  203. if (frame_time) safe_delay(frame_time);
  204. }
  205. #endif
  206. }
  207. // Show the Marlin bootscreen, with the u8g loop and delays
  208. void MarlinUI::show_marlin_bootscreen() {
  209. for (uint8_t q = bootscreen_pages; q--;) {
  210. draw_marlin_bootscreen(q == 0);
  211. if (q) safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages);
  212. }
  213. }
  214. void MarlinUI::show_bootscreen() {
  215. TERN_(SHOW_CUSTOM_BOOTSCREEN, show_custom_bootscreen());
  216. show_marlin_bootscreen();
  217. }
  218. void MarlinUI::bootscreen_completion(const millis_t sofar) {
  219. if ((BOOTSCREEN_TIMEOUT) / bootscreen_pages > sofar) safe_delay((BOOTSCREEN_TIMEOUT) / bootscreen_pages - sofar);
  220. }
  221. #endif // SHOW_BOOTSCREEN
  222. #if ENABLED(LIGHTWEIGHT_UI)
  223. #include "status_screen_lite_ST7920.h"
  224. #endif
  225. // Initialize or re-initialize the LCD
  226. void MarlinUI::init_lcd() {
  227. static bool did_init_u8g = false;
  228. if (!did_init_u8g) {
  229. u8g.init(U8G_PARAM);
  230. did_init_u8g = true;
  231. }
  232. #if PIN_EXISTS(LCD_BACKLIGHT)
  233. OUT_WRITE(LCD_BACKLIGHT_PIN, DISABLED(DELAYED_BACKLIGHT_INIT)); // Illuminate after reset or right away
  234. #endif
  235. #if ANY(MKS_12864OLED, MKS_12864OLED_SSD1306, FYSETC_242_OLED_12864, ZONESTAR_12864OLED, K3D_242_OLED_CONTROLLER)
  236. SET_OUTPUT(LCD_PINS_DC);
  237. #ifndef LCD_RESET_PIN
  238. #define LCD_RESET_PIN LCD_PINS_RS
  239. #endif
  240. #endif
  241. #if PIN_EXISTS(LCD_RESET)
  242. // Perform a clean hardware reset with needed delays
  243. OUT_WRITE(LCD_RESET_PIN, LOW);
  244. hal.delay_ms(5);
  245. WRITE(LCD_RESET_PIN, HIGH);
  246. hal.delay_ms(5);
  247. u8g.begin();
  248. #endif
  249. #if PIN_EXISTS(LCD_BACKLIGHT) && ENABLED(DELAYED_BACKLIGHT_INIT)
  250. WRITE(LCD_BACKLIGHT_PIN, HIGH);
  251. #endif
  252. TERN_(HAS_LCD_CONTRAST, refresh_contrast());
  253. #if LCD_SCREEN_ROTATE == 90
  254. u8g.setRot90();
  255. #elif LCD_SCREEN_ROTATE == 180
  256. u8g.setRot180();
  257. #elif LCD_SCREEN_ROTATE == 270
  258. u8g.setRot270();
  259. #endif
  260. update_language_font();
  261. }
  262. void MarlinUI::update_language_font() {
  263. #if HAS_MULTI_LANGUAGE
  264. switch (language) {
  265. default: uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE), COUNT(LANG_FONT_INFO(LCD_LANGUAGE))); break;
  266. #ifdef LCD_LANGUAGE_2
  267. case 1: uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE_2), COUNT(LANG_FONT_INFO(LCD_LANGUAGE_2))); break;
  268. #endif
  269. #ifdef LCD_LANGUAGE_3
  270. case 2: uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE_3), COUNT(LANG_FONT_INFO(LCD_LANGUAGE_3))); break;
  271. #endif
  272. #ifdef LCD_LANGUAGE_4
  273. case 3: uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE_4), COUNT(LANG_FONT_INFO(LCD_LANGUAGE_4))); break;
  274. #endif
  275. #ifdef LCD_LANGUAGE_5
  276. case 4: uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE_5), COUNT(LANG_FONT_INFO(LCD_LANGUAGE_5))); break;
  277. #endif
  278. }
  279. #else
  280. uxg_SetUtf8Fonts(LANG_FONT_INFO(LCD_LANGUAGE), COUNT(LANG_FONT_INFO(LCD_LANGUAGE)));
  281. #endif
  282. }
  283. // The kill screen is displayed for unrecoverable conditions
  284. void MarlinUI::draw_kill_screen() {
  285. TERN_(LIGHTWEIGHT_UI, ST7920_Lite_Status_Screen::clear_text_buffer());
  286. const u8g_uint_t x = 0, h4 = u8g.getHeight() / 4;
  287. u8g.firstPage();
  288. do {
  289. set_font(FONT_MENU);
  290. lcd_put_u8str(x, h4 * 1, status_message);
  291. lcd_put_u8str(x, h4 * 2, GET_TEXT_F(MSG_HALTED));
  292. lcd_put_u8str(x, h4 * 3, GET_TEXT_F(MSG_PLEASE_RESET));
  293. } while (u8g.nextPage());
  294. }
  295. void MarlinUI::clear_lcd() { } // Automatically cleared by Picture Loop
  296. #if HAS_DISPLAY_SLEEP
  297. void MarlinUI::sleep_on() { u8g.sleepOn(); }
  298. void MarlinUI::sleep_off() { u8g.sleepOff(); }
  299. #endif
  300. #if HAS_LCD_BRIGHTNESS
  301. void MarlinUI::_set_brightness() {
  302. #if PIN_EXISTS(TFT_BACKLIGHT)
  303. if (PWM_PIN(TFT_BACKLIGHT_PIN))
  304. analogWrite(pin_t(TFT_BACKLIGHT_PIN), backlight ? brightness : 0);
  305. #endif
  306. }
  307. #endif
  308. #if HAS_MARLINUI_MENU
  309. #include "../menu/menu.h"
  310. u8g_uint_t row_y1, row_y2;
  311. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  312. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  313. u8g_uint_t y1 = row * (MENU_FONT_HEIGHT) + 1, y2 = y1 + MENU_FONT_HEIGHT - 1;
  314. if (!PAGE_CONTAINS(y1 + 1, y2 + 2)) return;
  315. lcd_put_wchar(LCD_PIXEL_WIDTH - 11 * (MENU_FONT_WIDTH), y2, 'E');
  316. lcd_put_wchar((char)('1' + extruder));
  317. lcd_put_wchar(' ');
  318. lcd_put_u8str(i16tostr3rj(thermalManager.wholeDegHotend(extruder)));
  319. lcd_put_wchar('/');
  320. if (get_blink() || !thermalManager.heater_idle[extruder].timed_out)
  321. lcd_put_u8str(i16tostr3rj(thermalManager.degTargetHotend(extruder)));
  322. }
  323. #endif // ADVANCED_PAUSE_FEATURE
  324. // Mark a menu item and set font color if selected.
  325. // Return 'false' if the item is not on screen.
  326. static bool mark_as_selected(const uint8_t row, const bool sel) {
  327. row_y1 = row * (MENU_FONT_HEIGHT) + 1;
  328. row_y2 = row_y1 + MENU_FONT_HEIGHT - 1;
  329. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return false;
  330. if (sel) {
  331. #if ENABLED(MENU_HOLLOW_FRAME)
  332. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  333. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  334. #else
  335. u8g.setColorIndex(1); // solid outline
  336. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, MENU_FONT_HEIGHT - 1);
  337. u8g.setColorIndex(0); // inverted text
  338. #endif
  339. }
  340. #if DISABLED(MENU_HOLLOW_FRAME)
  341. else u8g.setColorIndex(1); // solid text
  342. #endif
  343. if (!PAGE_CONTAINS(row_y1, row_y2)) return false;
  344. lcd_moveto(0, row_y2);
  345. return true;
  346. }
  347. // Draw a static line of text in the same idiom as a menu item
  348. void MenuItem_static::draw(const uint8_t row, FSTR_P const ftpl, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  349. if (mark_as_selected(row, style & SS_INVERT)) {
  350. pixel_len_t n = LCD_PIXEL_WIDTH; // pixel width of string allowed
  351. const int plen = ftpl ? calculateWidth(ftpl) : 0,
  352. vlen = vstr ? utf8_strlen(vstr) : 0;
  353. if (style & SS_CENTER) {
  354. int pad = (LCD_PIXEL_WIDTH - plen - vlen * MENU_FONT_WIDTH) / MENU_FONT_WIDTH / 2;
  355. while (--pad >= 0) n -= lcd_put_wchar(' ');
  356. }
  357. if (plen) n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, n / (MENU_FONT_WIDTH)) * (MENU_FONT_WIDTH);
  358. if (vlen) n -= lcd_put_u8str_max(vstr, n);
  359. while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
  360. }
  361. }
  362. // Draw a generic menu item
  363. void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char, const char post_char) {
  364. if (mark_as_selected(row, sel)) {
  365. pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1) * (MENU_FONT_WIDTH);
  366. while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
  367. lcd_put_wchar(LCD_PIXEL_WIDTH - (MENU_FONT_WIDTH), row_y2, post_char);
  368. lcd_put_wchar(' ');
  369. }
  370. }
  371. // Draw a menu item with an editable value
  372. void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
  373. if (mark_as_selected(row, sel)) {
  374. const uint8_t vallen = (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)),
  375. pixelwidth = (pgm ? uxg_GetUtf8StrPixelWidthP(u8g.getU8g(), inStr) : uxg_GetUtf8StrPixelWidth(u8g.getU8g(), inStr));
  376. const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
  377. pixel_len_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vallen * prop) * (MENU_FONT_WIDTH);
  378. if (vallen) {
  379. lcd_put_wchar(':');
  380. while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
  381. lcd_moveto(LCD_PIXEL_WIDTH - _MAX((MENU_FONT_WIDTH) * vallen, pixelwidth + 2), row_y2);
  382. if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr);
  383. }
  384. }
  385. }
  386. void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
  387. ui.encoder_direction_normal();
  388. const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
  389. const u8g_uint_t labellen = utf8_strlen(ftpl), vallen = utf8_strlen(value);
  390. bool extra_row = labellen * prop > LCD_WIDTH - 2 - vallen * prop;
  391. #if ENABLED(USE_BIG_EDIT_FONT)
  392. // Use the menu font if the label won't fit on a single line
  393. constexpr u8g_uint_t lcd_edit_width = (LCD_PIXEL_WIDTH) / (EDIT_FONT_WIDTH);
  394. u8g_uint_t lcd_chr_fit, one_chr_width;
  395. if (labellen * prop <= lcd_edit_width - 1) {
  396. if (labellen * prop + vallen * prop + 1 > lcd_edit_width) extra_row = true;
  397. lcd_chr_fit = lcd_edit_width + 1;
  398. one_chr_width = EDIT_FONT_WIDTH;
  399. ui.set_font(FONT_EDIT);
  400. }
  401. else {
  402. lcd_chr_fit = LCD_WIDTH;
  403. one_chr_width = MENU_FONT_WIDTH;
  404. ui.set_font(FONT_MENU);
  405. }
  406. #else
  407. constexpr u8g_uint_t lcd_chr_fit = LCD_WIDTH,
  408. one_chr_width = MENU_FONT_WIDTH;
  409. #endif
  410. // Center the label and value lines on the middle line
  411. u8g_uint_t baseline = extra_row ? (LCD_PIXEL_HEIGHT) / 2 - 1
  412. : (LCD_PIXEL_HEIGHT + EDIT_FONT_ASCENT) / 2;
  413. // Assume the label is alpha-numeric (with a descender)
  414. bool onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline + EDIT_FONT_DESCENT);
  415. if (onpage) lcd_put_u8str(0, baseline, ftpl, itemIndex, itemStringC, itemStringF);
  416. // If a value is included, print a colon, then print the value right-justified
  417. if (value) {
  418. lcd_put_wchar(':');
  419. if (extra_row) {
  420. // Assume that value is numeric (with no descender)
  421. baseline += EDIT_FONT_ASCENT + 2;
  422. onpage = PAGE_CONTAINS(baseline - (EDIT_FONT_ASCENT - 1), baseline);
  423. }
  424. if (onpage) {
  425. lcd_put_wchar(((lcd_chr_fit - 1) - (vallen * prop + 1)) * one_chr_width, baseline, ' '); // Right-justified, padded, add a leading space
  426. lcd_put_u8str(value);
  427. }
  428. }
  429. TERN_(USE_BIG_EDIT_FONT, ui.set_font(FONT_MENU));
  430. }
  431. inline void draw_boxed_string(const u8g_uint_t x, const u8g_uint_t y, FSTR_P const fstr, const bool inv) {
  432. const u8g_uint_t len = utf8_strlen(fstr),
  433. by = (y + 1) * (MENU_FONT_HEIGHT);
  434. const u8g_uint_t prop = USE_WIDE_GLYPH ? 2 : 1;
  435. const pixel_len_t bw = len * prop * (MENU_FONT_WIDTH), bx = x * prop * (MENU_FONT_WIDTH);
  436. if (inv) {
  437. u8g.setColorIndex(1);
  438. u8g.drawBox(bx / prop - 1, by - (MENU_FONT_ASCENT), bw + 2, MENU_FONT_HEIGHT);
  439. u8g.setColorIndex(0);
  440. }
  441. lcd_put_u8str(bx / prop, by, fstr);
  442. if (inv) u8g.setColorIndex(1);
  443. }
  444. void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const fpre, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
  445. ui.draw_select_screen_prompt(fpre, string, suff);
  446. if (no) draw_boxed_string(1, LCD_HEIGHT - 1, no, !yesno);
  447. if (yes) draw_boxed_string(LCD_WIDTH - (utf8_strlen(yes) * (USE_WIDE_GLYPH ? 2 : 1) + 1), LCD_HEIGHT - 1, yes, yesno);
  448. }
  449. #if ENABLED(SDSUPPORT)
  450. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
  451. if (mark_as_selected(row, sel)) {
  452. const uint8_t maxlen = LCD_WIDTH - isDir;
  453. if (isDir) lcd_put_wchar(LCD_STR_FOLDER[0]);
  454. const pixel_len_t pixw = maxlen * (MENU_FONT_WIDTH);
  455. pixel_len_t n = pixw - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), pixw);
  456. while (n > MENU_FONT_WIDTH) n -= lcd_put_wchar(' ');
  457. }
  458. }
  459. #endif // SDSUPPORT
  460. #if ENABLED(AUTO_BED_LEVELING_UBL)
  461. /**
  462. * UBL LCD "radar" map data
  463. */
  464. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  465. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  466. #define MAP_MAX_PIXELS_X 53
  467. #define MAP_MAX_PIXELS_Y 49
  468. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  469. // Scale the box pixels appropriately
  470. u8g_uint_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  471. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  472. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  473. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  474. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  475. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  476. // Clear the Mesh Map
  477. if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) {
  478. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  479. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  480. if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) {
  481. u8g.setColorIndex(0); // Now actually clear the mesh map box
  482. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  483. }
  484. }
  485. // Display Mesh Point Locations
  486. u8g.setColorIndex(1);
  487. const u8g_uint_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  488. u8g_uint_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  489. for (uint8_t j = 0; j < (GRID_MAX_POINTS_Y); j++, y += pixels_per_y_mesh_pnt)
  490. if (PAGE_CONTAINS(y, y))
  491. for (uint8_t i = 0, x = sx; i < (GRID_MAX_POINTS_X); i++, x += pixels_per_x_mesh_pnt)
  492. u8g.drawBox(x, y, 1, 1);
  493. // Fill in the Specified Mesh Point
  494. const uint8_t y_plot_inv = (GRID_MAX_POINTS_Y) - 1 - y_plot; // The origin is typically in the lower right corner. We need to
  495. // invert the Y to get it to plot in the right location.
  496. const u8g_uint_t by = y_offset + y_plot_inv * pixels_per_y_mesh_pnt;
  497. if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
  498. u8g.drawBox(
  499. x_offset + x_plot * pixels_per_x_mesh_pnt, by,
  500. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
  501. );
  502. // Put Relevant Text on Display
  503. // Show X and Y positions at top of screen
  504. u8g.setColorIndex(1);
  505. if (PAGE_UNDER(7)) {
  506. const xy_pos_t pos = { bedlevel.get_mesh_x(x_plot), bedlevel.get_mesh_y(y_plot) },
  507. lpos = pos.asLogical();
  508. lcd_put_u8str_P(5, 7, X_LBL);
  509. lcd_put_u8str(ftostr52(lpos.x));
  510. lcd_put_u8str_P(74, 7, Y_LBL);
  511. lcd_put_u8str(ftostr52(lpos.y));
  512. }
  513. // Print plot position
  514. if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) {
  515. lcd_put_wchar(5, LCD_PIXEL_HEIGHT, '(');
  516. u8g.print(x_plot);
  517. lcd_put_wchar(',');
  518. u8g.print(y_plot);
  519. lcd_put_wchar(')');
  520. // Show the location value
  521. lcd_put_u8str_P(74, LCD_PIXEL_HEIGHT, Z_LBL);
  522. if (!isnan(bedlevel.z_values[x_plot][y_plot]))
  523. lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
  524. else
  525. lcd_put_u8str(F(" -----"));
  526. }
  527. }
  528. #endif // AUTO_BED_LEVELING_UBL
  529. #if EITHER(BABYSTEP_ZPROBE_GFX_OVERLAY, MESH_EDIT_GFX_OVERLAY)
  530. //
  531. // Draw knob rotation => Z motion key for:
  532. // - menu.cpp:lcd_babystep_zoffset
  533. // - menu_ubl.cpp:_lcd_mesh_fine_tune
  534. //
  535. const unsigned char cw_bmp[] PROGMEM = {
  536. B00000000,B11111110,B00000000,
  537. B00000011,B11111111,B10000000,
  538. B00000111,B11000111,B11000000,
  539. B00000111,B00000001,B11100000,
  540. B00000000,B00000000,B11100000,
  541. B00000000,B00000000,B11110000,
  542. B00000000,B00000000,B01110000,
  543. B00000100,B00000000,B01110000,
  544. B00001110,B00000000,B01110000,
  545. B00011111,B00000000,B01110000,
  546. B00111111,B10000000,B11110000,
  547. B00001110,B00000000,B11100000,
  548. B00001111,B00000001,B11100000,
  549. B00000111,B11000111,B11000000,
  550. B00000011,B11111111,B10000000,
  551. B00000000,B11111110,B00000000
  552. };
  553. const unsigned char ccw_bmp[] PROGMEM = {
  554. B00000000,B11111110,B00000000,
  555. B00000011,B11111111,B10000000,
  556. B00000111,B11000111,B11000000,
  557. B00001111,B00000001,B11100000,
  558. B00001110,B00000000,B11100000,
  559. B00111111,B10000000,B11110000,
  560. B00011111,B00000000,B01110000,
  561. B00001110,B00000000,B01110000,
  562. B00000100,B00000000,B01110000,
  563. B00000000,B00000000,B01110000,
  564. B00000000,B00000000,B11110000,
  565. B00000000,B00000000,B11100000,
  566. B00000111,B00000001,B11100000,
  567. B00000111,B11000111,B11000000,
  568. B00000011,B11111111,B10000000,
  569. B00000000,B11111110,B00000000
  570. };
  571. const unsigned char up_arrow_bmp[] PROGMEM = {
  572. B00000100,B00000000,
  573. B00001110,B00000000,
  574. B00011111,B00000000,
  575. B00111111,B10000000,
  576. B01111111,B11000000,
  577. B00001110,B00000000,
  578. B00001110,B00000000,
  579. B00001110,B00000000,
  580. B00001110,B00000000,
  581. B00001110,B00000000,
  582. B00001110,B00000000,
  583. B00001110,B00000000,
  584. B00001110,B00000000
  585. };
  586. const unsigned char down_arrow_bmp[] PROGMEM = {
  587. B00001110,B00000000,
  588. B00001110,B00000000,
  589. B00001110,B00000000,
  590. B00001110,B00000000,
  591. B00001110,B00000000,
  592. B00001110,B00000000,
  593. B00001110,B00000000,
  594. B00001110,B00000000,
  595. B01111111,B11000000,
  596. B00111111,B10000000,
  597. B00011111,B00000000,
  598. B00001110,B00000000,
  599. B00000100,B00000000
  600. };
  601. const unsigned char offset_bedline_bmp[] PROGMEM = {
  602. B11111111,B11111111,B11111111
  603. };
  604. const unsigned char nozzle_bmp[] PROGMEM = {
  605. B01111111,B10000000,
  606. B11111111,B11000000,
  607. B11111111,B11000000,
  608. B11111111,B11000000,
  609. B01111111,B10000000,
  610. B01111111,B10000000,
  611. B11111111,B11000000,
  612. B11111111,B11000000,
  613. B11111111,B11000000,
  614. B00111111,B00000000,
  615. B00011110,B00000000,
  616. B00001100,B00000000
  617. };
  618. void MarlinUI::zoffset_overlay(const int8_t dir) {
  619. const unsigned char *rot_up = TERN(OVERLAY_GFX_REVERSE, ccw_bmp, cw_bmp),
  620. *rot_down = TERN(OVERLAY_GFX_REVERSE, cw_bmp, ccw_bmp);
  621. const int left = TERN(USE_BIG_EDIT_FONT, 0, 5),
  622. right = TERN(USE_BIG_EDIT_FONT, 45, 90),
  623. nozzle = TERN(USE_BIG_EDIT_FONT, 95, 60);
  624. // Draw nozzle lowered or raised according to direction moved
  625. if (PAGE_CONTAINS( 3, 16)) u8g.drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp);
  626. if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20 , 3, 1, offset_bedline_bmp);
  627. // Draw cw/ccw indicator and up/down arrows.
  628. if (PAGE_CONTAINS(47, 62)) {
  629. u8g.drawBitmapP(right + 0, 48 - dir, 2, 13, up_arrow_bmp);
  630. u8g.drawBitmapP(left + 0, 49 - dir, 2, 13, down_arrow_bmp);
  631. u8g.drawBitmapP(left + 13, 47 , 3, 16, rot_down);
  632. u8g.drawBitmapP(right + 13, 47 , 3, 16, rot_up);
  633. }
  634. }
  635. #endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
  636. #endif // HAS_MARLINUI_MENU
  637. #endif // HAS_MARLINUI_U8GLIB