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

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