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.h 28KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (C) 2016 MarlinFirmware [https://github.com/MarlinFirmware/Marlin]
  4. *
  5. * Based on Sprinter and grbl.
  6. * Copyright (C) 2011 Camiel Gubbels / Erik van der Zalm
  7. *
  8. * This program is free software: you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation, either version 3 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License
  19. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  20. *
  21. */
  22. /**
  23. * ultralcd_impl_DOGM.h
  24. *
  25. * Graphics LCD implementation for 128x64 pixel LCDs by STB for ErikZalm/Marlin
  26. * Demonstrator: http://www.reprap.org/wiki/STB_Electronics
  27. * License: http://opensource.org/licenses/BSD-3-Clause
  28. *
  29. * With the use of:
  30. * u8glib by Oliver Kraus
  31. * https://github.com/olikraus/U8glib_Arduino
  32. * License: http://opensource.org/licenses/BSD-3-Clause
  33. */
  34. #ifndef ULTRALCD_IMPL_DOGM_H
  35. #define ULTRALCD_IMPL_DOGM_H
  36. #include "MarlinConfig.h"
  37. /**
  38. * Implementation of the LCD display routines for a DOGM128 graphic display.
  39. * These are common LCD 128x64 pixel graphic displays.
  40. */
  41. #include "ultralcd.h"
  42. #include "ultralcd_st7920_u8glib_rrd.h"
  43. #include "dogm_bitmaps.h"
  44. #include "utility.h"
  45. #include "duration_t.h"
  46. #include <U8glib.h>
  47. #if ENABLED(SHOW_BOOTSCREEN) && ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  48. #include "_Bootscreen.h"
  49. #endif
  50. // Only Western languages support big / small fonts
  51. #if DISABLED(DISPLAY_CHARSET_ISO10646_1)
  52. #undef USE_BIG_EDIT_FONT
  53. #undef USE_SMALL_INFOFONT
  54. #endif
  55. #if ENABLED(USE_SMALL_INFOFONT)
  56. #include "dogm_font_data_6x9_marlin.h"
  57. #define FONT_STATUSMENU_NAME u8g_font_6x9
  58. #else
  59. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  60. #endif
  61. #include "dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  62. #define FONT_SPECIAL_NAME Marlin_symbols
  63. #if DISABLED(SIMULATE_ROMFONT)
  64. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  65. #include "dogm_font_data_ISO10646_1.h"
  66. #define FONT_MENU_NAME ISO10646_1_5x7
  67. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  68. #include "dogm_font_data_ISO10646_5_Cyrillic.h"
  69. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  70. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  71. #include "dogm_font_data_ISO10646_Kana.h"
  72. #define FONT_MENU_NAME ISO10646_Kana_5x7
  73. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  74. #include "dogm_font_data_ISO10646_Greek.h"
  75. #define FONT_MENU_NAME ISO10646_Greek_5x7
  76. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CN)
  77. #include "dogm_font_data_ISO10646_CN.h"
  78. #define FONT_MENU_NAME ISO10646_CN
  79. #define TALL_FONT_CORRECTION 1
  80. #elif ENABLED(DISPLAY_CHARSET_ISO10646_TR)
  81. #include "dogm_font_data_ISO10646_1_tr.h"
  82. #define FONT_MENU_NAME ISO10646_TR
  83. #else // fall-back
  84. #include "dogm_font_data_ISO10646_1.h"
  85. #define FONT_MENU_NAME ISO10646_1_5x7
  86. #endif
  87. #else // SIMULATE_ROMFONT
  88. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  89. #include "dogm_font_data_HD44780_J.h"
  90. #define FONT_MENU_NAME HD44780_J_5x7
  91. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  92. #include "dogm_font_data_HD44780_W.h"
  93. #define FONT_MENU_NAME HD44780_W_5x7
  94. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  95. #include "dogm_font_data_HD44780_C.h"
  96. #define FONT_MENU_NAME HD44780_C_5x7
  97. #else // fall-back
  98. #include "dogm_font_data_ISO10646_1.h"
  99. #define FONT_MENU_NAME ISO10646_1_5x7
  100. #endif
  101. #endif // SIMULATE_ROMFONT
  102. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  103. #define FONT_STATUSMENU 1
  104. #define FONT_SPECIAL 2
  105. #define FONT_MENU_EDIT 3
  106. #define FONT_MENU 4
  107. // DOGM parameters (size in pixels)
  108. #define DOG_CHAR_WIDTH 6
  109. #define DOG_CHAR_HEIGHT 12
  110. #if ENABLED(USE_BIG_EDIT_FONT)
  111. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  112. #define DOG_CHAR_WIDTH_EDIT 9
  113. #define DOG_CHAR_HEIGHT_EDIT 13
  114. #define LCD_WIDTH_EDIT 14
  115. #else
  116. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  117. #define DOG_CHAR_WIDTH_EDIT 6
  118. #define DOG_CHAR_HEIGHT_EDIT 12
  119. #define LCD_WIDTH_EDIT 22
  120. #endif
  121. #ifndef TALL_FONT_CORRECTION
  122. #define TALL_FONT_CORRECTION 0
  123. #endif
  124. #define START_COL 0
  125. // LCD selection
  126. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  127. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS);
  128. #elif ENABLED(U8GLIB_ST7920)
  129. //U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
  130. U8GLIB_ST7920_128X64_RRD u8g(0);
  131. #elif ENABLED(CARTESIO_UI)
  132. // The CartesioUI display
  133. #if DOGLCD_MOSI != -1 && DOGLCD_SCK != -1
  134. // using SW-SPI
  135. U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);
  136. #else
  137. U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);
  138. #endif
  139. #elif ENABLED(U8GLIB_LM6059_AF)
  140. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  141. U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);
  142. #elif ENABLED(MAKRPANEL) || ENABLED(VIKI2) || ENABLED(miniVIKI)
  143. // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller as well
  144. U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);
  145. #elif ENABLED(U8GLIB_SSD1306)
  146. // Generic support for SSD1306 OLED I2C LCDs
  147. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  148. #elif ENABLED(U8GLIB_SH1106)
  149. // Generic support for SH1106 OLED I2C LCDs
  150. U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  151. #elif ENABLED(MINIPANEL)
  152. // The MINIPanel display
  153. U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);
  154. #else
  155. // for regular DOGM128 display with HW-SPI
  156. U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0
  157. #endif
  158. #ifndef LCD_PIXEL_WIDTH
  159. #define LCD_PIXEL_WIDTH 128
  160. #endif
  161. #ifndef LCD_PIXEL_HEIGHT
  162. #define LCD_PIXEL_HEIGHT 64
  163. #endif
  164. #include "utf_mapper.h"
  165. int lcd_contrast;
  166. static char currentfont = 0;
  167. // The current graphical page being rendered
  168. u8g_page_t &page = ((u8g_pb_t *)((u8g.getU8g())->dev->dev_mem))->p;
  169. // For selective rendering within a Y range
  170. #define PAGE_UNDER(yb) (u8g.getU8g()->current_page.y0 <= (yb))
  171. #define PAGE_CONTAINS(ya, yb) (PAGE_UNDER(yb) && u8g.getU8g()->current_page.y1 >= (ya))
  172. static void lcd_setFont(const char font_nr) {
  173. switch (font_nr) {
  174. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  175. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  176. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  177. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  178. break;
  179. }
  180. }
  181. void lcd_print(const char c) {
  182. if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
  183. u8g.setFont(FONT_SPECIAL_NAME);
  184. u8g.print(c);
  185. lcd_setFont(currentfont);
  186. }
  187. else charset_mapper(c);
  188. }
  189. char lcd_print_and_count(const char c) {
  190. if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
  191. u8g.setFont(FONT_SPECIAL_NAME);
  192. u8g.print(c);
  193. lcd_setFont(currentfont);
  194. return 1;
  195. }
  196. else return charset_mapper(c);
  197. }
  198. void lcd_print(const char* const str) {
  199. for (uint8_t i = 0; char c = str[i]; ++i) lcd_print(c);
  200. }
  201. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  202. void lcd_printPGM(const char* str) {
  203. for (; char c = pgm_read_byte(str); ++str) lcd_print(c);
  204. }
  205. // Initialize or re-initializw the LCD
  206. static void lcd_implementation_init() {
  207. #if PIN_EXISTS(LCD_BACKLIGHT) // Enable LCD backlight
  208. OUT_WRITE(LCD_BACKLIGHT_PIN, HIGH);
  209. #endif
  210. #if PIN_EXISTS(LCD_RESET)
  211. OUT_WRITE(LCD_RESET_PIN, HIGH);
  212. #endif
  213. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  214. u8g.setContrast(lcd_contrast);
  215. #endif
  216. #if ENABLED(LCD_SCREEN_ROT_90)
  217. u8g.setRot90(); // Rotate screen by 90°
  218. #elif ENABLED(LCD_SCREEN_ROT_180)
  219. u8g.setRot180(); // Rotate screen by 180°
  220. #elif ENABLED(LCD_SCREEN_ROT_270)
  221. u8g.setRot270(); // Rotate screen by 270°
  222. #endif
  223. #if ENABLED(SHOW_BOOTSCREEN)
  224. static bool show_bootscreen = true;
  225. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  226. if (show_bootscreen) {
  227. u8g.firstPage();
  228. do {
  229. u8g.drawBitmapP(
  230. (128 - (CUSTOM_BOOTSCREEN_BMPWIDTH)) /2,
  231. ( 64 - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) /2,
  232. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp);
  233. } while (u8g.nextPage());
  234. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  235. }
  236. #endif // SHOW_CUSTOM_BOOTSCREEN
  237. const uint8_t offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2;
  238. #if ENABLED(START_BMPHIGH)
  239. constexpr uint8_t offy = 0;
  240. #else
  241. constexpr uint8_t offy = DOG_CHAR_HEIGHT;
  242. #endif
  243. const uint8_t txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
  244. if (show_bootscreen) {
  245. u8g.firstPage();
  246. do {
  247. u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
  248. lcd_setFont(FONT_MENU);
  249. #ifndef STRING_SPLASH_LINE2
  250. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT), STRING_SPLASH_LINE1);
  251. #else
  252. const uint8_t txt2X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  253. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  254. u8g.drawStr(txt2X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  255. #endif
  256. } while (u8g.nextPage());
  257. }
  258. show_bootscreen = false;
  259. #endif // SHOW_BOOTSCREEN
  260. }
  261. // The kill screen is displayed for unrecoverable conditions
  262. void lcd_kill_screen() {
  263. lcd_setFont(FONT_MENU);
  264. u8g.setPrintPos(0, u8g.getHeight()/4*1);
  265. lcd_print(lcd_status_message);
  266. u8g.setPrintPos(0, u8g.getHeight()/4*2);
  267. lcd_printPGM(PSTR(MSG_HALTED));
  268. u8g.setPrintPos(0, u8g.getHeight()/4*3);
  269. lcd_printPGM(PSTR(MSG_PLEASE_RESET));
  270. }
  271. static void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  272. //
  273. // Status Screen
  274. //
  275. FORCE_INLINE void _draw_centered_temp(const int temp, const uint8_t x, const uint8_t y) {
  276. const uint8_t degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width
  277. u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
  278. lcd_print(itostr3(temp));
  279. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  280. }
  281. FORCE_INLINE void _draw_heater_status(const uint8_t x, const int8_t heater) {
  282. #if HAS_TEMP_BED
  283. bool isBed = heater < 0;
  284. #else
  285. const bool isBed = false;
  286. #endif
  287. if (PAGE_UNDER(7))
  288. _draw_centered_temp((isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater)) + 0.5, x, 7);
  289. if (PAGE_CONTAINS(21, 28))
  290. _draw_centered_temp((isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)) + 0.5, x, 28);
  291. if (PAGE_CONTAINS(17, 20)) {
  292. const uint8_t h = isBed ? 7 : 8,
  293. y = isBed ? 18 : 17;
  294. if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
  295. u8g.setColorIndex(0); // white on black
  296. u8g.drawBox(x + h, y, 2, 2);
  297. u8g.setColorIndex(1); // black on white
  298. }
  299. else {
  300. u8g.drawBox(x + h, y, 2, 2);
  301. }
  302. }
  303. }
  304. FORCE_INLINE void _draw_axis_label(const AxisEnum axis, const char* const pstr, const bool blink) {
  305. if (blink)
  306. lcd_printPGM(pstr);
  307. else {
  308. if (!axis_homed[axis])
  309. u8g.print('?');
  310. else {
  311. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  312. if (!axis_known_position[axis])
  313. u8g.print(' ');
  314. else
  315. #endif
  316. lcd_printPGM(pstr);
  317. }
  318. }
  319. }
  320. //#define DOGM_SD_PERCENT
  321. static void lcd_implementation_status_screen() {
  322. bool blink = lcd_blink();
  323. // Black color, white background
  324. u8g.setColorIndex(1);
  325. // Status Menu Font
  326. lcd_setFont(FONT_STATUSMENU);
  327. //
  328. // Fan Animation
  329. //
  330. if (PAGE_UNDER(STATUS_SCREENHEIGHT + 1)) {
  331. u8g.drawBitmapP(9, 1, STATUS_SCREENBYTEWIDTH, STATUS_SCREENHEIGHT,
  332. #if HAS_FAN0
  333. blink && fanSpeeds[0] ? status_screen0_bmp : status_screen1_bmp
  334. #else
  335. status_screen0_bmp
  336. #endif
  337. );
  338. }
  339. //
  340. // Temperature Graphics and Info
  341. //
  342. if (PAGE_UNDER(28)) {
  343. // Extruders
  344. HOTEND_LOOP() _draw_heater_status(5 + e * 25, e);
  345. // Heated bed
  346. #if HOTENDS < 4 && HAS_TEMP_BED
  347. _draw_heater_status(81, -1);
  348. #endif
  349. if (PAGE_CONTAINS(20, 27)) {
  350. // Fan
  351. u8g.setPrintPos(104, 27);
  352. #if HAS_FAN0
  353. int per = ((fanSpeeds[0] + 1) * 100) / 256;
  354. if (per) {
  355. lcd_print(itostr3(per));
  356. u8g.print('%');
  357. }
  358. #endif
  359. }
  360. }
  361. #if ENABLED(SDSUPPORT)
  362. //
  363. // SD Card Symbol
  364. //
  365. if (PAGE_CONTAINS(42 - (TALL_FONT_CORRECTION), 51 - (TALL_FONT_CORRECTION))) {
  366. // Upper box
  367. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7); // 42-48 (or 41-47)
  368. // Right edge
  369. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5); // 44-48 (or 43-47)
  370. // Bottom hollow box
  371. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4); // 49-52 (or 48-51)
  372. // Corner pixel
  373. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION)); // 43 (or 42)
  374. }
  375. //
  376. // Progress bar frame
  377. //
  378. if (PAGE_CONTAINS(49, 52 - (TALL_FONT_CORRECTION)))
  379. u8g.drawFrame(54, 49, 73, 4 - (TALL_FONT_CORRECTION)); // 49-52 (or 49-51)
  380. if (IS_SD_PRINTING) {
  381. //
  382. // Progress bar solid part
  383. //
  384. if (PAGE_CONTAINS(50, 51 - (TALL_FONT_CORRECTION)))
  385. u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION));
  386. //
  387. // SD Percent Complete
  388. //
  389. #if ENABLED(DOGM_SD_PERCENT)
  390. if (PAGE_CONTAINS(41, 48)) {
  391. // Percent complete
  392. u8g.setPrintPos(55, 48);
  393. u8g.print(itostr3(card.percentDone()));
  394. u8g.print('%');
  395. }
  396. #endif
  397. }
  398. //
  399. // Elapsed Time
  400. //
  401. #if DISABLED(DOGM_SD_PERCENT)
  402. #define SD_DURATION_X 71
  403. #else
  404. #define SD_DURATION_X 89
  405. #endif
  406. if (PAGE_CONTAINS(41, 48)) {
  407. char buffer[10];
  408. duration_t elapsed = print_job_timer.duration();
  409. bool has_days = (elapsed.value > 60*60*24L);
  410. elapsed.toDigital(buffer, has_days);
  411. u8g.setPrintPos(SD_DURATION_X + (has_days ? 0 : 9), 48);
  412. lcd_print(buffer);
  413. }
  414. #endif
  415. //
  416. // XYZ Coordinates
  417. //
  418. #if ENABLED(USE_SMALL_INFOFONT)
  419. #define INFO_FONT_HEIGHT 7
  420. #else
  421. #define INFO_FONT_HEIGHT 8
  422. #endif
  423. #define XYZ_BASELINE (30 + INFO_FONT_HEIGHT)
  424. #define X_LABEL_POS 3
  425. #define X_VALUE_POS 11
  426. #define XYZ_SPACING 40
  427. // Enable to save many cycles by drawing a hollow frame
  428. #define XYZ_HOLLOW_FRAME
  429. #define MENU_HOLLOW_FRAME
  430. #if ENABLED(XYZ_HOLLOW_FRAME)
  431. #define XYZ_FRAME_TOP 29
  432. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 3
  433. #else
  434. #define XYZ_FRAME_TOP 30
  435. #define XYZ_FRAME_HEIGHT INFO_FONT_HEIGHT + 1
  436. #endif
  437. // Before homing the axis letters are blinking 'X' <-> '?'.
  438. // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
  439. // When everything is ok you see a constant 'X'.
  440. static char xstring[5], ystring[5], zstring[7];
  441. // At the first page, regenerate the XYZ strings
  442. if (page.page == 0) {
  443. strcpy(xstring, ftostr4sign(current_position[X_AXIS]));
  444. strcpy(ystring, ftostr4sign(current_position[Y_AXIS]));
  445. strcpy(zstring, ftostr52sp(current_position[Z_AXIS] + 0.00001));
  446. }
  447. if (PAGE_CONTAINS(XYZ_FRAME_TOP, XYZ_FRAME_TOP + XYZ_FRAME_HEIGHT - 1)) {
  448. #if ENABLED(XYZ_HOLLOW_FRAME)
  449. u8g.drawFrame(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 29-40 7: 29-39
  450. #else
  451. u8g.drawBox(0, XYZ_FRAME_TOP, LCD_PIXEL_WIDTH, XYZ_FRAME_HEIGHT); // 8: 30-39 7: 30-37
  452. #endif
  453. if (PAGE_CONTAINS(XYZ_BASELINE - (INFO_FONT_HEIGHT - 1), XYZ_BASELINE)) {
  454. #if DISABLED(XYZ_HOLLOW_FRAME)
  455. u8g.setColorIndex(0); // white on black
  456. #endif
  457. u8g.setPrintPos(0 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  458. _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
  459. u8g.setPrintPos(0 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  460. lcd_print(xstring);
  461. u8g.setPrintPos(1 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  462. _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
  463. u8g.setPrintPos(1 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  464. lcd_print(ystring);
  465. u8g.setPrintPos(2 * XYZ_SPACING + X_LABEL_POS, XYZ_BASELINE);
  466. _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
  467. u8g.setPrintPos(2 * XYZ_SPACING + X_VALUE_POS, XYZ_BASELINE);
  468. lcd_print(zstring);
  469. #if DISABLED(XYZ_HOLLOW_FRAME)
  470. u8g.setColorIndex(1); // black on white
  471. #endif
  472. }
  473. }
  474. //
  475. // Feedrate
  476. //
  477. if (PAGE_CONTAINS(51 - INFO_FONT_HEIGHT, 49)) {
  478. lcd_setFont(FONT_MENU);
  479. u8g.setPrintPos(3, 50);
  480. lcd_print(LCD_STR_FEEDRATE[0]);
  481. lcd_setFont(FONT_STATUSMENU);
  482. u8g.setPrintPos(12, 50);
  483. lcd_print(itostr3(feedrate_percentage));
  484. u8g.print('%');
  485. }
  486. //
  487. // Status line
  488. //
  489. #define STATUS_BASELINE (55 + INFO_FONT_HEIGHT)
  490. if (PAGE_CONTAINS(STATUS_BASELINE + 1 - INFO_FONT_HEIGHT, STATUS_BASELINE)) {
  491. u8g.setPrintPos(0, STATUS_BASELINE);
  492. #if DISABLED(FILAMENT_LCD_DISPLAY)
  493. lcd_print(lcd_status_message);
  494. #else
  495. if (PENDING(millis(), previous_lcd_status_ms + 5000UL)) { //Display both Status message line and Filament display on the last line
  496. lcd_print(lcd_status_message);
  497. }
  498. else {
  499. lcd_printPGM(PSTR("dia:"));
  500. lcd_print(ftostr12ns(filament_width_meas));
  501. lcd_printPGM(PSTR(" factor:"));
  502. lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  503. u8g.print('%');
  504. }
  505. #endif
  506. }
  507. }
  508. #if ENABLED(ULTIPANEL)
  509. uint8_t row_y1, row_y2;
  510. // Set the colors for a menu item based on whether it is selected
  511. static void lcd_implementation_mark_as_selected(const uint8_t row, const bool isSelected) {
  512. row_y1 = row * (DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION)) + 1;
  513. row_y2 = row_y1 + (DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION)) - 1;
  514. if (!PAGE_CONTAINS(row_y1 + 1, row_y1 + 1 + DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION))) return;
  515. if (isSelected) {
  516. #if ENABLED(MENU_HOLLOW_FRAME)
  517. u8g.drawHLine(0, row_y1 + 1, LCD_PIXEL_WIDTH);
  518. u8g.drawHLine(0, row_y1 + 1 + DOG_CHAR_HEIGHT + 2 * (TALL_FONT_CORRECTION), LCD_PIXEL_WIDTH);
  519. #else
  520. u8g.setColorIndex(1); // black on white
  521. u8g.drawBox(0, row_y1 + 2, LCD_PIXEL_WIDTH, DOG_CHAR_HEIGHT - 1 + 2 * (TALL_FONT_CORRECTION));
  522. u8g.setColorIndex(0); // white on black
  523. #endif
  524. }
  525. #if DISABLED(MENU_HOLLOW_FRAME)
  526. else {
  527. u8g.setColorIndex(1); // unmarked text is black on white
  528. }
  529. #endif
  530. u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), row_y2);
  531. }
  532. #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE)
  533. // Draw a static line of text in the same idiom as a menu item
  534. static void lcd_implementation_drawmenu_static(const uint8_t row, const char* pstr, const bool center=true, const bool invert=false, const char* valstr=NULL) {
  535. lcd_implementation_mark_as_selected(row, invert);
  536. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  537. char c;
  538. int8_t n = LCD_WIDTH - (START_COL);
  539. if (center && !valstr) {
  540. int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
  541. while (--pad >= 0) { u8g.print(' '); n--; }
  542. }
  543. while (n > 0 && (c = pgm_read_byte(pstr))) {
  544. n -= lcd_print_and_count(c);
  545. pstr++;
  546. }
  547. if (valstr) while (n > 0 && (c = *valstr)) {
  548. n -= lcd_print_and_count(c);
  549. valstr++;
  550. }
  551. while (n-- > 0) u8g.print(' ');
  552. }
  553. #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
  554. // Draw a generic menu item
  555. static void lcd_implementation_drawmenu_generic(const bool isSelected, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  556. UNUSED(pre_char);
  557. lcd_implementation_mark_as_selected(row, isSelected);
  558. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  559. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  560. while (char c = pgm_read_byte(pstr)) {
  561. n -= lcd_print_and_count(c);
  562. pstr++;
  563. }
  564. while (n--) u8g.print(' ');
  565. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), row_y2);
  566. lcd_print(post_char);
  567. u8g.print(' ');
  568. }
  569. // Macros for specific types of menu items
  570. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  571. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  572. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  573. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  574. // Draw a menu item with an editable value
  575. static void _drawmenu_setting_edit_generic(const bool isSelected, const uint8_t row, const char* pstr, const char* const data, const bool pgm) {
  576. lcd_implementation_mark_as_selected(row, isSelected);
  577. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  578. const uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
  579. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  580. while (char c = pgm_read_byte(pstr)) {
  581. n -= lcd_print_and_count(c);
  582. pstr++;
  583. }
  584. u8g.print(':');
  585. while (n--) u8g.print(' ');
  586. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, row_y2);
  587. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  588. }
  589. // Macros for edit items
  590. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  591. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  592. #define lcd_implementation_drawmenu_setting_edit_int3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
  593. #define lcd_implementation_drawmenu_setting_edit_float3(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
  594. #define lcd_implementation_drawmenu_setting_edit_float32(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
  595. #define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43sign(*(data)))
  596. #define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
  597. #define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52sign(*(data)))
  598. #define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51sign(*(data)))
  599. #define lcd_implementation_drawmenu_setting_edit_float62(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr62sign(*(data)))
  600. #define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
  601. #define lcd_implementation_drawmenu_setting_edit_bool(sel, row, pstr, pstr2, data) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  602. #define lcd_implementation_drawmenu_setting_edit_callback_int3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, itostr3(*(data)))
  603. #define lcd_implementation_drawmenu_setting_edit_callback_float3(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr3(*(data)))
  604. #define lcd_implementation_drawmenu_setting_edit_callback_float32(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr32(*(data)))
  605. #define lcd_implementation_drawmenu_setting_edit_callback_float43(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43sign(*(data)))
  606. #define lcd_implementation_drawmenu_setting_edit_callback_float5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
  607. #define lcd_implementation_drawmenu_setting_edit_callback_float52(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52sign(*(data)))
  608. #define lcd_implementation_drawmenu_setting_edit_callback_float51(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51sign(*(data)))
  609. #define lcd_implementation_drawmenu_setting_edit_callback_float62(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr62sign(*(data)))
  610. #define lcd_implementation_drawmenu_setting_edit_callback_long5(sel, row, pstr, pstr2, data, minValue, maxValue, callback) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5rj(*(data)))
  611. #define lcd_implementation_drawmenu_setting_edit_callback_bool(sel, row, pstr, pstr2, data, callback) lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, (*(data))?PSTR(MSG_ON):PSTR(MSG_OFF))
  612. void lcd_implementation_drawedit(const char* const pstr, const char* const value=NULL) {
  613. const uint8_t labellen = lcd_strlen_P(pstr), vallen = lcd_strlen(value);
  614. uint8_t lcd_width, char_width,
  615. rows = (labellen > LCD_WIDTH - 2 - vallen) ? 2 : 1;
  616. #if ENABLED(USE_BIG_EDIT_FONT)
  617. if (labellen <= LCD_WIDTH_EDIT - 1) {
  618. if (labellen >= LCD_WIDTH_EDIT - vallen) rows = 2;
  619. lcd_width = LCD_WIDTH_EDIT + 1;
  620. char_width = DOG_CHAR_WIDTH_EDIT;
  621. lcd_setFont(FONT_MENU_EDIT);
  622. }
  623. else {
  624. lcd_width = LCD_WIDTH - (START_COL);
  625. char_width = DOG_CHAR_WIDTH;
  626. lcd_setFont(FONT_MENU);
  627. }
  628. #else
  629. lcd_width = LCD_WIDTH - (START_COL);
  630. char_width = DOG_CHAR_WIDTH;
  631. #endif
  632. // Center either one or two rows
  633. const uint8_t segmentHeight = u8g.getHeight() / (rows + 1); // 1 / (rows+1) = 1/2 or 1/3
  634. uint8_t baseline = segmentHeight + (DOG_CHAR_HEIGHT_EDIT + 1) / 2;
  635. if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) {
  636. u8g.setPrintPos(0, baseline);
  637. lcd_printPGM(pstr);
  638. }
  639. if (value != NULL) {
  640. baseline += (rows - 1) * segmentHeight;
  641. if (PAGE_CONTAINS(baseline + 1 - (DOG_CHAR_HEIGHT_EDIT), baseline)) {
  642. u8g.print(':');
  643. u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, baseline);
  644. lcd_print(value);
  645. }
  646. }
  647. }
  648. #if ENABLED(SDSUPPORT)
  649. static void _drawmenu_sd(const bool isSelected, const uint8_t row, const char* const pstr, const char* filename, char* const longFilename, const bool isDir) {
  650. UNUSED(pstr);
  651. lcd_implementation_mark_as_selected(row, isSelected);
  652. if (!PAGE_CONTAINS(row_y1, row_y2)) return;
  653. uint8_t n = LCD_WIDTH - (START_COL) - 1;
  654. if (longFilename[0]) {
  655. filename = longFilename;
  656. longFilename[n] = '\0';
  657. }
  658. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  659. while (char c = *filename) {
  660. n -= lcd_print_and_count(c);
  661. filename++;
  662. }
  663. while (n--) u8g.print(' ');
  664. }
  665. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  666. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  667. #endif // SDSUPPORT
  668. #endif // ULTIPANEL
  669. #endif //__ULTRALCD_IMPL_DOGM_H