My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd_impl_DOGM.cpp 22KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660
  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.cpp
  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.h"
  39. #include <U8glib.h>
  40. #include "HAL_LCD_class_defines.h"
  41. #include "u8g_fontutf8.h"
  42. #include "../lcdprint.h"
  43. #include "../fontutils.h"
  44. #include "dogm_Bootscreen.h"
  45. #include "../../sd/cardreader.h"
  46. #include "../../module/temperature.h"
  47. #include "../../module/printcounter.h"
  48. #if ENABLED(SDSUPPORT)
  49. #include "../../libs/duration_t.h"
  50. #endif
  51. #if ENABLED(AUTO_BED_LEVELING_UBL)
  52. #include "../../feature/bedlevel/ubl/ubl.h"
  53. #endif
  54. #define FONT_SPECIAL_NAME ISO10646_1_5x7
  55. #define FONT_MENU_NAME ISO10646_1_5x7
  56. #include "fontdata/fontdata_ISO10646_1.h"
  57. #if ENABLED(USE_SMALL_INFOFONT)
  58. #include "fontdata/fontdata_6x9_marlin.h"
  59. #define FONT_STATUSMENU_NAME u8g_font_6x9
  60. #else
  61. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  62. #endif
  63. #define START_COL 0
  64. U8G_CLASS u8g(U8G_PARAM);
  65. U8GLIB *pu8g = &u8g;
  66. #include LANGUAGE_DATA_INCL(LCD_LANGUAGE)
  67. #if HAS_LCD_CONTRAST
  68. int16_t lcd_contrast; // Initialized by settings.load()
  69. void set_lcd_contrast(const int16_t value) {
  70. lcd_contrast = constrain(value, LCD_CONTRAST_MIN, LCD_CONTRAST_MAX);
  71. u8g.setContrast(lcd_contrast);
  72. }
  73. #endif
  74. void lcd_setFont(const MarlinFont font_nr) {
  75. static char currentfont = 0;
  76. if (font_nr != currentfont) {
  77. switch ((currentfont = font_nr)) {
  78. case FONT_STATUSMENU : u8g.setFont(FONT_STATUSMENU_NAME); break;
  79. default:
  80. case FONT_MENU : u8g.setFont(FONT_MENU_NAME); break;
  81. case FONT_SPECIAL : u8g.setFont(FONT_SPECIAL_NAME); break;
  82. case FONT_MENU_EDIT : u8g.setFont(FONT_MENU_EDIT_NAME); break;
  83. }
  84. }
  85. }
  86. #if ENABLED(SHOW_BOOTSCREEN)
  87. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  88. FORCE_INLINE void draw_custom_bootscreen(const u8g_pgm_uint8_t * const bmp, const bool erase=true) {
  89. constexpr u8g_uint_t left = (LCD_PIXEL_WIDTH - (CUSTOM_BOOTSCREEN_BMPWIDTH)) / 2,
  90. top = (LCD_PIXEL_HEIGHT - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) / 2;
  91. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  92. constexpr u8g_uint_t right = left + CUSTOM_BOOTSCREEN_BMPWIDTH,
  93. bottom = top + CUSTOM_BOOTSCREEN_BMPHEIGHT;
  94. #endif
  95. u8g.firstPage();
  96. do {
  97. u8g.drawBitmapP(
  98. left, top,
  99. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, bmp
  100. );
  101. #if ENABLED(CUSTOM_BOOTSCREEN_INVERTED)
  102. if (erase) {
  103. u8g.setColorIndex(1);
  104. if (top) u8g.drawBox(0, 0, LCD_PIXEL_WIDTH, top);
  105. if (left) u8g.drawBox(0, top, left, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  106. if (right < LCD_PIXEL_WIDTH) u8g.drawBox(right, top, LCD_PIXEL_WIDTH - right, CUSTOM_BOOTSCREEN_BMPHEIGHT);
  107. if (bottom < LCD_PIXEL_HEIGHT) u8g.drawBox(0, bottom, LCD_PIXEL_WIDTH, LCD_PIXEL_HEIGHT - bottom);
  108. }
  109. #else
  110. UNUSED(erase);
  111. #endif
  112. } while (u8g.nextPage());
  113. }
  114. void lcd_custom_bootscreen() {
  115. #if ENABLED(ANIMATED_BOOTSCREEN)
  116. LOOP_L_N(f, COUNT(custom_bootscreen_animation)) {
  117. if (f) safe_delay(CUSTOM_BOOTSCREEN_FRAME_TIME);
  118. draw_custom_bootscreen((u8g_pgm_uint8_t*)pgm_read_ptr(&custom_bootscreen_animation[f]), f == 0);
  119. }
  120. #else
  121. draw_custom_bootscreen(custom_start_bmp);
  122. #endif
  123. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  124. }
  125. #endif // SHOW_CUSTOM_BOOTSCREEN
  126. void lcd_bootscreen() {
  127. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  128. lcd_custom_bootscreen();
  129. #endif
  130. constexpr uint8_t offy =
  131. #if ENABLED(START_BMPHIGH)
  132. (LCD_PIXEL_HEIGHT - (START_BMPHEIGHT)) / 2
  133. #else
  134. DOG_CHAR_HEIGHT
  135. #endif
  136. ;
  137. const uint8_t width = u8g.getWidth(), height = u8g.getHeight(),
  138. offx = (width - (START_BMPWIDTH)) / 2;
  139. u8g.firstPage();
  140. do {
  141. u8g.drawBitmapP(offx, offy, (START_BMPWIDTH + 7) / 8, START_BMPHEIGHT, start_bmp);
  142. lcd_setFont(FONT_MENU);
  143. #ifndef STRING_SPLASH_LINE2
  144. const uint8_t txt1X = width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH);
  145. u8g.drawStr(txt1X, (height + DOG_CHAR_HEIGHT) / 2, STRING_SPLASH_LINE1);
  146. #else
  147. const uint8_t txt1X = (width - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2,
  148. txt2X = (width - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  149. u8g.drawStr(txt1X, height - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  150. u8g.drawStr(txt2X, height - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  151. #endif
  152. } while (u8g.nextPage());
  153. safe_delay(BOOTSCREEN_TIMEOUT);
  154. }
  155. #endif // SHOW_BOOTSCREEN
  156. #if ENABLED(LIGHTWEIGHT_UI)
  157. #include "status_screen_lite_ST7920_class.h"
  158. #endif
  159. // Initialize or re-initialize the LCD
  160. void lcd_implementation_init() {
  161. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  162. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  163. #endif
  164. #if ENABLED(MKS_12864OLED) || ENABLED(MKS_12864OLED_SSD1306)
  165. SET_OUTPUT(LCD_PINS_DC);
  166. #if !defined(LCD_RESET_PIN)
  167. #define LCD_RESET_PIN LCD_PINS_RS
  168. #endif
  169. #endif
  170. #if PIN_EXISTS(LCD_RESET)
  171. OUT_WRITE(LCD_RESET_PIN, LOW); // perform a clean hardware reset
  172. _delay_ms(5);
  173. OUT_WRITE(LCD_RESET_PIN, HIGH);
  174. _delay_ms(5); // delay to allow the display to initalize
  175. #endif
  176. #if PIN_EXISTS(LCD_RESET)
  177. u8g.begin();
  178. #endif
  179. #if HAS_LCD_CONTRAST
  180. set_lcd_contrast(lcd_contrast);
  181. #endif
  182. #if ENABLED(LCD_SCREEN_ROT_90)
  183. u8g.setRot90(); // Rotate screen by 90°
  184. #elif ENABLED(LCD_SCREEN_ROT_180)
  185. u8g.setRot180(); // Rotate screen by 180°
  186. #elif ENABLED(LCD_SCREEN_ROT_270)
  187. u8g.setRot270(); // Rotate screen by 270°
  188. #endif
  189. uxg_SetUtf8Fonts(g_fontinfo, NUM_ARRAY(g_fontinfo));
  190. }
  191. // The kill screen is displayed for unrecoverable conditions
  192. void lcd_kill_screen() {
  193. #if ENABLED(LIGHTWEIGHT_UI)
  194. ST7920_Lite_Status_Screen::clear_text_buffer();
  195. #endif
  196. const uint8_t h4 = u8g.getHeight() / 4;
  197. u8g.firstPage();
  198. do {
  199. lcd_setFont(FONT_MENU);
  200. lcd_moveto(0, h4 * 1);
  201. lcd_put_u8str(lcd_status_message);
  202. lcd_moveto(0, h4 * 2);
  203. lcd_put_u8str_P(PSTR(MSG_HALTED));
  204. lcd_moveto(0, h4 * 3);
  205. lcd_put_u8str_P(PSTR(MSG_PLEASE_RESET));
  206. } while (u8g.nextPage());
  207. }
  208. void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  209. #if ENABLED(ULTIPANEL)
  210. uint8_t row_y1, row_y2;
  211. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  212. void lcd_implementation_hotend_status(const uint8_t row, const uint8_t extruder) {
  213. row_y1 = row * (DOG_CHAR_HEIGHT) + 1;
  214. row_y2 = row_y1 + DOG_CHAR_HEIGHT - 1;
  215. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return;
  216. lcd_moveto(LCD_PIXEL_WIDTH - 11 * (DOG_CHAR_WIDTH), row_y2);
  217. lcd_put_wchar('E');
  218. lcd_put_wchar((char)('1' + extruder));
  219. lcd_put_wchar(' ');
  220. lcd_put_u8str(itostr3(thermalManager.degHotend(extruder)));
  221. lcd_put_wchar('/');
  222. if (lcd_blink() || !thermalManager.is_heater_idle(extruder))
  223. lcd_put_u8str(itostr3(thermalManager.degTargetHotend(extruder)));
  224. }
  225. #endif // ADVANCED_PAUSE_FEATURE
  226. // Set the colors for a menu item based on whether it is selected
  227. static bool mark_as_selected(const uint8_t row, const bool isSelected) {
  228. row_y1 = row * (DOG_CHAR_HEIGHT) + 1;
  229. row_y2 = row_y1 + DOG_CHAR_HEIGHT - 1;
  230. if (!PAGE_CONTAINS(row_y1 + 1, row_y2 + 2)) return false;
  231. if (isSelected) {
  232. #if ENABLED(MENU_HOLLOW_FRAME)
  233. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  234. u8g.drawHLine(0, row_y2 + 2, LCD_PIXEL_WIDTH);
  235. #else
  236. u8g.setColorIndex(1); // black on white
  237. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, DOG_CHAR_HEIGHT - 1);
  238. u8g.setColorIndex(0); // white on black
  239. #endif
  240. }
  241. #if DISABLED(MENU_HOLLOW_FRAME)
  242. else {
  243. u8g.setColorIndex(1); // unmarked text is black on white
  244. }
  245. #endif
  246. if (!PAGE_CONTAINS(row_y1, row_y2)) return false;
  247. lcd_moveto((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  248. return true;
  249. }
  250. // Draw a static line of text in the same idiom as a menu item
  251. void lcd_implementation_drawmenu_static(const uint8_t row, PGM_P pstr, const bool center/*=true*/, const bool invert/*=false*/, const char* valstr/*=NULL*/) {
  252. if (mark_as_selected(row, invert)) {
  253. uint8_t n = LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * (START_COL); // pixel width of string allowed
  254. if (center && !valstr) {
  255. int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
  256. while (--pad >= 0) { lcd_put_wchar(' '); n--; }
  257. }
  258. n -= lcd_put_u8str_max_P(pstr, n);
  259. if (NULL != valstr) {
  260. n -= lcd_put_u8str_max(valstr, n);
  261. }
  262. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  263. }
  264. }
  265. // Draw a generic menu item
  266. void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, PGM_P pstr, const char pre_char, const char post_char) {
  267. UNUSED(pre_char);
  268. if (mark_as_selected(row, isSelected)) {
  269. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  270. n *= DOG_CHAR_WIDTH;
  271. n -= lcd_put_u8str_max_P(pstr, n);
  272. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  273. lcd_moveto(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  274. lcd_put_wchar(post_char);
  275. lcd_put_wchar(' ');
  276. }
  277. }
  278. // Draw a menu item with an editable value
  279. void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, PGM_P pstr, const char* const data, const bool pgm) {
  280. if (mark_as_selected(row, isSelected)) {
  281. const uint8_t vallen = (pgm ? utf8_strlen_P(data) : utf8_strlen((char*)data));
  282. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  283. n *= DOG_CHAR_WIDTH;
  284. n -= lcd_put_u8str_max_P(pstr, n);
  285. lcd_put_wchar(':');
  286. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  287. lcd_moveto(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  288. if (pgm) lcd_put_u8str_P(data); else lcd_put_u8str((char*)data);
  289. }
  290. }
  291. void lcd_implementation_drawedit(PGM_P const pstr, const char* const value/*=NULL*/) {
  292. const uint8_t labellen = utf8_strlen_P(pstr),
  293. vallen = utf8_strlen(value);
  294. uint8_t rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  295. #if ENABLED(USE_BIG_EDIT_FONT)
  296. constexpr uint8_t lcd_width_edit = (LCD_PIXEL_WIDTH) / (DOG_CHAR_WIDTH_EDIT);
  297. uint8_t lcd_width, char_width;
  298. if (labellen <= lcd_width_edit - 1) {
  299. if (labellen + vallen + 2 >= lcd_width_edit) rows = 2;
  300. lcd_width = lcd_width_edit + 1;
  301. char_width = DOG_CHAR_WIDTH_EDIT;
  302. lcd_setFont(FONT_MENU_EDIT);
  303. }
  304. else {
  305. lcd_width = LCD_WIDTH - (START_COL);
  306. char_width = DOG_CHAR_WIDTH;
  307. lcd_setFont(FONT_MENU);
  308. }
  309. #else
  310. constexpr uint8_t lcd_width = LCD_WIDTH - (START_COL),
  311. char_width = DOG_CHAR_WIDTH;
  312. #endif
  313. // Center either one or two rows
  314. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  315. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  316. bool onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  317. if (onpage) {
  318. lcd_moveto(0, baseline);
  319. lcd_put_u8str_P(pstr);
  320. }
  321. if (value != NULL) {
  322. lcd_put_wchar(':');
  323. if (rows == 2) {
  324. baseline += segmentHeight;
  325. onpage = PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline);
  326. }
  327. if (onpage) {
  328. lcd_moveto(((lcd_width - 1) - (vallen + 1)) * char_width, baseline); // Right-justified, leaving padded by spaces
  329. lcd_put_wchar(' '); // overwrite char if value gets shorter
  330. lcd_put_u8str(value);
  331. }
  332. }
  333. }
  334. #if ENABLED(SDSUPPORT)
  335. void _drawmenu_sd(const bool isSelected, const uint8_t row, PGM_P const pstr, CardReader &theCard, const bool isDir) {
  336. UNUSED(pstr);
  337. mark_as_selected(row, isSelected);
  338. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  339. constexpr uint8_t maxlen = LCD_WIDTH - (START_COL) - 1;
  340. const char *outstr = theCard.longest_filename();
  341. if (theCard.longFilename[0]) {
  342. #if ENABLED(SCROLL_LONG_FILENAMES)
  343. static uint8_t filename_scroll_hash;
  344. if (isSelected) {
  345. uint8_t name_hash = row;
  346. for (uint8_t l = FILENAME_LENGTH; l--;)
  347. name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l]; // rotate, xor
  348. if (filename_scroll_hash != name_hash) { // If the hash changed...
  349. filename_scroll_hash = name_hash; // Save the new hash
  350. filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - maxlen); // Update the scroll limit
  351. filename_scroll_pos = 0; // Reset scroll to the start
  352. lcd_status_update_delay = 8; // Don't scroll right away
  353. }
  354. outstr += filename_scroll_pos;
  355. }
  356. #else
  357. theCard.longFilename[maxlen] = '\0'; // cutoff at screen edge
  358. #endif
  359. }
  360. if (isDir) lcd_put_wchar(LCD_STR_FOLDER[0]);
  361. int n;
  362. n = lcd_put_u8str_max(outstr, maxlen * (DOG_CHAR_WIDTH));
  363. n = maxlen * (DOG_CHAR_WIDTH) - n;
  364. while (n - DOG_CHAR_WIDTH > 0) { n -= lcd_put_wchar(' '); }
  365. }
  366. #endif // SDSUPPORT
  367. #if ENABLED(AUTO_BED_LEVELING_UBL)
  368. /**
  369. * UBL LCD "radar" map data
  370. */
  371. #define MAP_UPPER_LEFT_CORNER_X 35 // These probably should be moved to the .h file But for now,
  372. #define MAP_UPPER_LEFT_CORNER_Y 8 // it is easier to play with things having them here
  373. #define MAP_MAX_PIXELS_X 53
  374. #define MAP_MAX_PIXELS_Y 49
  375. void lcd_implementation_ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  376. // Scale the box pixels appropriately
  377. uint8_t x_map_pixels = ((MAP_MAX_PIXELS_X - 4) / (GRID_MAX_POINTS_X)) * (GRID_MAX_POINTS_X),
  378. y_map_pixels = ((MAP_MAX_PIXELS_Y - 4) / (GRID_MAX_POINTS_Y)) * (GRID_MAX_POINTS_Y),
  379. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X),
  380. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y),
  381. x_offset = MAP_UPPER_LEFT_CORNER_X + 1 + (MAP_MAX_PIXELS_X - x_map_pixels - 2) / 2,
  382. y_offset = MAP_UPPER_LEFT_CORNER_Y + 1 + (MAP_MAX_PIXELS_Y - y_map_pixels - 2) / 2;
  383. // Clear the Mesh Map
  384. if (PAGE_CONTAINS(y_offset - 2, y_offset + y_map_pixels + 4)) {
  385. u8g.setColorIndex(1); // First draw the bigger box in White so we have a border around the mesh map box
  386. u8g.drawBox(x_offset - 2, y_offset - 2, x_map_pixels + 4, y_map_pixels + 4);
  387. if (PAGE_CONTAINS(y_offset, y_offset + y_map_pixels)) {
  388. u8g.setColorIndex(0); // Now actually clear the mesh map box
  389. u8g.drawBox(x_offset, y_offset, x_map_pixels, y_map_pixels);
  390. }
  391. }
  392. // Display Mesh Point Locations
  393. u8g.setColorIndex(1);
  394. const uint8_t sx = x_offset + pixels_per_x_mesh_pnt / 2;
  395. uint8_t y = y_offset + pixels_per_y_mesh_pnt / 2;
  396. for (uint8_t j = 0; j < GRID_MAX_POINTS_Y; j++, y += pixels_per_y_mesh_pnt)
  397. if (PAGE_CONTAINS(y, y))
  398. for (uint8_t i = 0, x = sx; i < GRID_MAX_POINTS_X; i++, x += pixels_per_x_mesh_pnt)
  399. u8g.drawBox(x, y, 1, 1);
  400. // Fill in the Specified Mesh Point
  401. uint8_t inverted_y = GRID_MAX_POINTS_Y - y_plot - 1; // The origin is typically in the lower right corner. We need to
  402. // invert the Y to get it to plot in the right location.
  403. const uint8_t by = y_offset + inverted_y * pixels_per_y_mesh_pnt;
  404. if (PAGE_CONTAINS(by, by + pixels_per_y_mesh_pnt))
  405. u8g.drawBox(
  406. x_offset + x_plot * pixels_per_x_mesh_pnt, by,
  407. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt
  408. );
  409. // Put Relevant Text on Display
  410. // Show X and Y positions at top of screen
  411. u8g.setColorIndex(1);
  412. if (PAGE_UNDER(7)) {
  413. lcd_moveto(5, 7);
  414. lcd_put_u8str("X:");
  415. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x_plot]))));
  416. lcd_moveto(74, 7);
  417. lcd_put_u8str("Y:");
  418. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[y_plot]))));
  419. }
  420. // Print plot position
  421. if (PAGE_CONTAINS(LCD_PIXEL_HEIGHT - (INFO_FONT_HEIGHT - 1), LCD_PIXEL_HEIGHT)) {
  422. lcd_moveto(5, LCD_PIXEL_HEIGHT);
  423. lcd_put_wchar('(');
  424. u8g.print(x_plot);
  425. lcd_put_wchar(',');
  426. u8g.print(y_plot);
  427. lcd_put_wchar(')');
  428. // Show the location value
  429. lcd_moveto(74, LCD_PIXEL_HEIGHT);
  430. lcd_put_u8str("Z:");
  431. if (!isnan(ubl.z_values[x_plot][y_plot]))
  432. lcd_put_u8str(ftostr43sign(ubl.z_values[x_plot][y_plot]));
  433. else
  434. lcd_put_u8str_P(PSTR(" -----"));
  435. }
  436. }
  437. #endif // AUTO_BED_LEVELING_UBL
  438. #if ENABLED(BABYSTEP_ZPROBE_GFX_OVERLAY) || ENABLED(MESH_EDIT_GFX_OVERLAY)
  439. const unsigned char cw_bmp[] PROGMEM = {
  440. B00000011,B11111000,B00000000,
  441. B00001111,B11111110,B00000000,
  442. B00011110,B00001111,B00000000,
  443. B00111000,B00000111,B00000000,
  444. B00111000,B00000011,B10000000,
  445. B01110000,B00000011,B10000000,
  446. B01110000,B00001111,B11100000,
  447. B01110000,B00000111,B11000000,
  448. B01110000,B00000011,B10000000,
  449. B01110000,B00000001,B00000000,
  450. B01110000,B00000000,B00000000,
  451. B00111000,B00000000,B00000000,
  452. B00111000,B00000111,B00000000,
  453. B00011110,B00001111,B00000000,
  454. B00001111,B11111110,B00000000,
  455. B00000011,B11111000,B00000000
  456. };
  457. const unsigned char ccw_bmp[] PROGMEM = {
  458. B00000000,B11111110,B00000000,
  459. B00000011,B11111111,B10000000,
  460. B00000111,B10000011,B11000000,
  461. B00001110,B00000001,B11000000,
  462. B00001110,B00000000,B11100000,
  463. B00011100,B00000000,B11100000,
  464. B01111111,B00000000,B11100000,
  465. B00111110,B00000000,B11100000,
  466. B00011100,B00000000,B11100000,
  467. B00001000,B00000000,B11100000,
  468. B00000000,B00000000,B11100000,
  469. B00000000,B00000001,B11000000,
  470. B00001110,B00000001,B11000000,
  471. B00001111,B00000111,B10000000,
  472. B00000111,B11111111,B00000000,
  473. B00000001,B11111100,B00000000
  474. };
  475. const unsigned char up_arrow_bmp[] PROGMEM = {
  476. B00000100,B00000000,
  477. B00001110,B00000000,
  478. B00011111,B00000000,
  479. B00111111,B10000000,
  480. B01111111,B11000000,
  481. B00001110,B00000000,
  482. B00001110,B00000000,
  483. B00001110,B00000000,
  484. B00001110,B00000000,
  485. B00001110,B00000000,
  486. B00001110,B00000000,
  487. B00001110,B00000000,
  488. B00001110,B00000000
  489. };
  490. const unsigned char down_arrow_bmp[] PROGMEM = {
  491. B00001110,B00000000,
  492. B00001110,B00000000,
  493. B00001110,B00000000,
  494. B00001110,B00000000,
  495. B00001110,B00000000,
  496. B00001110,B00000000,
  497. B00001110,B00000000,
  498. B00001110,B00000000,
  499. B01111111,B11000000,
  500. B00111111,B10000000,
  501. B00011111,B00000000,
  502. B00001110,B00000000,
  503. B00000100,B00000000
  504. };
  505. const unsigned char offset_bedline_bmp[] PROGMEM = {
  506. B11111111,B11111111,B11111111
  507. };
  508. const unsigned char nozzle_bmp[] PROGMEM = {
  509. B01111111,B10000000,
  510. B11111111,B11000000,
  511. B11111111,B11000000,
  512. B11111111,B11000000,
  513. B01111111,B10000000,
  514. B01111111,B10000000,
  515. B11111111,B11000000,
  516. B11111111,B11000000,
  517. B11111111,B11000000,
  518. B00111111,B00000000,
  519. B00011110,B00000000,
  520. B00001100,B00000000
  521. };
  522. void _lcd_zoffset_overlay_gfx(const float zvalue) {
  523. // Determine whether the user is raising or lowering the nozzle.
  524. static int8_t dir;
  525. static float old_zvalue;
  526. if (zvalue != old_zvalue) {
  527. dir = zvalue ? zvalue < old_zvalue ? -1 : 1 : 0;
  528. old_zvalue = zvalue;
  529. }
  530. #if ENABLED(OVERLAY_GFX_REVERSE)
  531. const unsigned char *rot_up = ccw_bmp, *rot_down = cw_bmp;
  532. #else
  533. const unsigned char *rot_up = cw_bmp, *rot_down = ccw_bmp;
  534. #endif
  535. #if ENABLED(USE_BIG_EDIT_FONT)
  536. const int left = 0, right = 45, nozzle = 95;
  537. #else
  538. const int left = 5, right = 90, nozzle = 60;
  539. #endif
  540. // Draw a representation of the nozzle
  541. if (PAGE_CONTAINS(3, 16)) u8g.drawBitmapP(nozzle + 6, 4 - dir, 2, 12, nozzle_bmp);
  542. if (PAGE_CONTAINS(20, 20)) u8g.drawBitmapP(nozzle + 0, 20, 3, 1, offset_bedline_bmp);
  543. // Draw cw/ccw indicator and up/down arrows.
  544. if (PAGE_CONTAINS(47, 62)) {
  545. u8g.drawBitmapP(left + 0, 47, 3, 16, rot_down);
  546. u8g.drawBitmapP(right + 0, 47, 3, 16, rot_up);
  547. u8g.drawBitmapP(right + 20, 48 - dir, 2, 13, up_arrow_bmp);
  548. u8g.drawBitmapP(left + 20, 49 - dir, 2, 13, down_arrow_bmp);
  549. }
  550. }
  551. #endif // BABYSTEP_ZPROBE_GFX_OVERLAY || MESH_EDIT_GFX_OVERLAY
  552. #endif // ULTIPANEL
  553. #endif // HAS_GRAPHICAL_LCD