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

ultralcd_DOGM.cpp 24KB

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