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 23KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649
  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. #if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
  51. #undef USE_BIG_EDIT_FONT
  52. #endif
  53. #if ENABLED(USE_SMALL_INFOFONT)
  54. #include "dogm_font_data_6x9_marlin.h"
  55. #define FONT_STATUSMENU_NAME u8g_font_6x9
  56. #else
  57. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  58. #endif
  59. #include "dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  60. #define FONT_SPECIAL_NAME Marlin_symbols
  61. #if DISABLED(SIMULATE_ROMFONT)
  62. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  63. #include "dogm_font_data_ISO10646_1.h"
  64. #define FONT_MENU_NAME ISO10646_1_5x7
  65. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  66. #include "dogm_font_data_ISO10646_5_Cyrillic.h"
  67. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  68. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  69. #include "dogm_font_data_ISO10646_Kana.h"
  70. #define FONT_MENU_NAME ISO10646_Kana_5x7
  71. #elif ENABLED(DISPLAY_CHARSET_ISO10646_GREEK)
  72. #include "dogm_font_data_ISO10646_Greek.h"
  73. #define FONT_MENU_NAME ISO10646_Greek_5x7
  74. #elif ENABLED(DISPLAY_CHARSET_ISO10646_CN)
  75. #include "dogm_font_data_ISO10646_CN.h"
  76. #define FONT_MENU_NAME ISO10646_CN
  77. #define TALL_FONT_CORRECTION 1
  78. #else // fall-back
  79. #include "dogm_font_data_ISO10646_1.h"
  80. #define FONT_MENU_NAME ISO10646_1_5x7
  81. #endif
  82. #else // SIMULATE_ROMFONT
  83. #if DISPLAY_CHARSET_HD44780 == JAPANESE
  84. #include "dogm_font_data_HD44780_J.h"
  85. #define FONT_MENU_NAME HD44780_J_5x7
  86. #elif DISPLAY_CHARSET_HD44780 == WESTERN
  87. #include "dogm_font_data_HD44780_W.h"
  88. #define FONT_MENU_NAME HD44780_W_5x7
  89. #elif DISPLAY_CHARSET_HD44780 == CYRILLIC
  90. #include "dogm_font_data_HD44780_C.h"
  91. #define FONT_MENU_NAME HD44780_C_5x7
  92. #else // fall-back
  93. #include "dogm_font_data_ISO10646_1.h"
  94. #define FONT_MENU_NAME ISO10646_1_5x7
  95. #endif
  96. #endif // SIMULATE_ROMFONT
  97. //#define FONT_STATUSMENU_NAME FONT_MENU_NAME
  98. #define FONT_STATUSMENU 1
  99. #define FONT_SPECIAL 2
  100. #define FONT_MENU_EDIT 3
  101. #define FONT_MENU 4
  102. // DOGM parameters (size in pixels)
  103. #define DOG_CHAR_WIDTH 6
  104. #define DOG_CHAR_HEIGHT 12
  105. #if ENABLED(USE_BIG_EDIT_FONT)
  106. #define FONT_MENU_EDIT_NAME u8g_font_9x18
  107. #define DOG_CHAR_WIDTH_EDIT 9
  108. #define DOG_CHAR_HEIGHT_EDIT 18
  109. #define LCD_WIDTH_EDIT 14
  110. #else
  111. #define FONT_MENU_EDIT_NAME FONT_MENU_NAME
  112. #define DOG_CHAR_WIDTH_EDIT 6
  113. #define DOG_CHAR_HEIGHT_EDIT 12
  114. #define LCD_WIDTH_EDIT 22
  115. #endif
  116. #ifndef TALL_FONT_CORRECTION
  117. #define TALL_FONT_CORRECTION 0
  118. #endif
  119. #define START_COL 0
  120. // LCD selection
  121. #if ENABLED(REPRAPWORLD_GRAPHICAL_LCD)
  122. U8GLIB_ST7920_128X64_4X u8g(LCD_PINS_RS);
  123. #elif ENABLED(U8GLIB_ST7920)
  124. //U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
  125. U8GLIB_ST7920_128X64_RRD u8g(0);
  126. #elif ENABLED(CARTESIO_UI)
  127. // The CartesioUI display
  128. #if DOGLCD_MOSI != -1 && DOGLCD_SCK != -1
  129. // using SW-SPI
  130. U8GLIB_DOGM128 u8g(DOGLCD_SCK, DOGLCD_MOSI, DOGLCD_CS, DOGLCD_A0);
  131. #else
  132. U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0);
  133. #endif
  134. #elif ENABLED(U8GLIB_LM6059_AF)
  135. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  136. U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);
  137. #elif ENABLED(MAKRPANEL) || ENABLED(VIKI2) || ENABLED(miniVIKI)
  138. // The MaKrPanel, Mini Viki, and Viki 2.0, ST7565 controller as well
  139. U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);
  140. #elif ENABLED(U8GLIB_SSD1306)
  141. // Generic support for SSD1306 OLED I2C LCDs
  142. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  143. #elif ENABLED(U8GLIB_SH1106)
  144. // Generic support for SH1106 OLED I2C LCDs
  145. U8GLIB_SH1106_128X64 u8g(U8G_I2C_OPT_NONE | U8G_I2C_OPT_FAST);
  146. #elif ENABLED(MINIPANEL)
  147. // The MINIPanel display
  148. U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);
  149. #else
  150. // for regular DOGM128 display with HW-SPI
  151. U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0
  152. #endif
  153. #ifndef LCD_PIXEL_WIDTH
  154. #define LCD_PIXEL_WIDTH 128
  155. #endif
  156. #ifndef LCD_PIXEL_HEIGHT
  157. #define LCD_PIXEL_HEIGHT 64
  158. #endif
  159. #include "utf_mapper.h"
  160. int lcd_contrast;
  161. static char currentfont = 0;
  162. static void lcd_setFont(char font_nr) {
  163. switch(font_nr) {
  164. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  165. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  166. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  167. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  168. break;
  169. }
  170. }
  171. char lcd_print(char c) {
  172. if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
  173. u8g.setFont(FONT_SPECIAL_NAME);
  174. u8g.print(c);
  175. lcd_setFont(currentfont);
  176. return 1;
  177. } else {
  178. return charset_mapper(c);
  179. }
  180. }
  181. char lcd_print(const char* str) {
  182. char c;
  183. int i = 0;
  184. char n = 0;
  185. while ((c = str[i++])) {
  186. n += lcd_print(c);
  187. }
  188. return n;
  189. }
  190. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  191. char lcd_printPGM(const char* str) {
  192. char c;
  193. char n = 0;
  194. while ((c = pgm_read_byte(str++))) {
  195. n += lcd_print(c);
  196. }
  197. return n;
  198. }
  199. /* Warning: This function is called from interrupt context */
  200. static void lcd_implementation_init() {
  201. #if defined(LCD_PIN_BL) && LCD_PIN_BL > -1 // Enable LCD backlight
  202. pinMode(LCD_PIN_BL, OUTPUT);
  203. digitalWrite(LCD_PIN_BL, HIGH);
  204. #endif
  205. #if defined(LCD_PIN_RESET) && LCD_PIN_RESET > -1
  206. pinMode(LCD_PIN_RESET, OUTPUT);
  207. digitalWrite(LCD_PIN_RESET, HIGH);
  208. #endif
  209. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  210. u8g.setContrast(lcd_contrast);
  211. #endif
  212. #if ENABLED(LCD_SCREEN_ROT_90)
  213. u8g.setRot90(); // Rotate screen by 90°
  214. #elif ENABLED(LCD_SCREEN_ROT_180)
  215. u8g.setRot180(); // Rotate screen by 180°
  216. #elif ENABLED(LCD_SCREEN_ROT_270)
  217. u8g.setRot270(); // Rotate screen by 270°
  218. #endif
  219. #if ENABLED(SHOW_BOOTSCREEN)
  220. static bool show_bootscreen = true;
  221. #if ENABLED(SHOW_CUSTOM_BOOTSCREEN)
  222. if (show_bootscreen) {
  223. u8g.firstPage();
  224. do {
  225. u8g.drawBitmapP(
  226. (128 - (CUSTOM_BOOTSCREEN_BMPWIDTH)) /2,
  227. ( 64 - (CUSTOM_BOOTSCREEN_BMPHEIGHT)) /2,
  228. CEILING(CUSTOM_BOOTSCREEN_BMPWIDTH, 8), CUSTOM_BOOTSCREEN_BMPHEIGHT, custom_start_bmp);
  229. } while (u8g.nextPage());
  230. safe_delay(CUSTOM_BOOTSCREEN_TIMEOUT);
  231. }
  232. #endif // SHOW_CUSTOM_BOOTSCREEN
  233. int offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2;
  234. #if ENABLED(START_BMPHIGH)
  235. int offy = 0;
  236. #else
  237. int offy = DOG_CHAR_HEIGHT;
  238. #endif
  239. int txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
  240. if (show_bootscreen) {
  241. u8g.firstPage();
  242. do {
  243. u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
  244. lcd_setFont(FONT_MENU);
  245. #ifndef STRING_SPLASH_LINE2
  246. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT), STRING_SPLASH_LINE1);
  247. #else
  248. int txt2X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  249. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  250. u8g.drawStr(txt2X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  251. #endif
  252. } while (u8g.nextPage());
  253. }
  254. show_bootscreen = false;
  255. #endif // SHOW_BOOTSCREEN
  256. }
  257. void lcd_kill_screen() {
  258. lcd_setFont(FONT_MENU);
  259. u8g.setPrintPos(0, u8g.getHeight()/4*1);
  260. lcd_print(lcd_status_message);
  261. u8g.setPrintPos(0, u8g.getHeight()/4*2);
  262. lcd_printPGM(PSTR(MSG_HALTED));
  263. u8g.setPrintPos(0, u8g.getHeight()/4*3);
  264. lcd_printPGM(PSTR(MSG_PLEASE_RESET));
  265. }
  266. static void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  267. //
  268. // Status Screen
  269. //
  270. FORCE_INLINE void _draw_centered_temp(int temp, int x, int y) {
  271. int degsize = 6 * (temp >= 100 ? 3 : temp >= 10 ? 2 : 1); // number's pixel width
  272. u8g.setPrintPos(x - (18 - degsize) / 2, y); // move left if shorter
  273. lcd_print(itostr3(temp));
  274. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  275. }
  276. FORCE_INLINE void _draw_heater_status(int x, int heater) {
  277. #if HAS_TEMP_BED
  278. bool isBed = heater < 0;
  279. #else
  280. const bool isBed = false;
  281. #endif
  282. _draw_centered_temp((isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater)) + 0.5, x, 7);
  283. _draw_centered_temp((isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)) + 0.5, x, 28);
  284. int h = isBed ? 7 : 8,
  285. y = isBed ? 18 : 17;
  286. if (isBed ? thermalManager.isHeatingBed() : thermalManager.isHeatingHotend(heater)) {
  287. u8g.setColorIndex(0); // white on black
  288. u8g.drawBox(x + h, y, 2, 2);
  289. u8g.setColorIndex(1); // black on white
  290. }
  291. else {
  292. u8g.drawBox(x + h, y, 2, 2);
  293. }
  294. }
  295. FORCE_INLINE void _draw_axis_label(AxisEnum axis, const char *pstr, bool blink) {
  296. if (blink)
  297. lcd_printPGM(pstr);
  298. else {
  299. if (!axis_homed[axis])
  300. lcd_printPGM(PSTR("?"));
  301. else {
  302. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  303. if (!axis_known_position[axis])
  304. lcd_printPGM(PSTR(" "));
  305. else
  306. #endif
  307. lcd_printPGM(pstr);
  308. }
  309. }
  310. }
  311. static void lcd_implementation_status_screen() {
  312. u8g.setColorIndex(1); // black on white
  313. bool blink = lcd_blink();
  314. // Symbols menu graphics, animated fan
  315. u8g.drawBitmapP(9, 1, STATUS_SCREENBYTEWIDTH, STATUS_SCREENHEIGHT,
  316. #if HAS_FAN0
  317. blink && fanSpeeds[0] ? status_screen0_bmp : status_screen1_bmp
  318. #else
  319. status_screen0_bmp
  320. #endif
  321. );
  322. // Status Menu Font for SD info, Heater status, Fan, XYZ
  323. lcd_setFont(FONT_STATUSMENU);
  324. #if ENABLED(SDSUPPORT)
  325. // SD Card Symbol
  326. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7);
  327. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5);
  328. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4);
  329. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION));
  330. // Progress bar frame
  331. u8g.drawFrame(54, 49, 73, 4 - (TALL_FONT_CORRECTION));
  332. // SD Card Progress bar and clock
  333. if (IS_SD_PRINTING) {
  334. // Progress bar solid part
  335. u8g.drawBox(55, 50, (unsigned int)(71 * card.percentDone() * 0.01), 2 - (TALL_FONT_CORRECTION));
  336. }
  337. char buffer[10];
  338. duration_t elapsed = print_job_timer.duration();
  339. bool has_days = (elapsed.value > 60*60*24L);
  340. elapsed.toDigital(buffer, has_days);
  341. u8g.setPrintPos(has_days ? 71 : 80, 48);
  342. lcd_print(buffer);
  343. #endif
  344. // Extruders
  345. HOTEND_LOOP() _draw_heater_status(5 + e * 25, e);
  346. // Heated bed
  347. #if HOTENDS < 4 && HAS_TEMP_BED
  348. _draw_heater_status(81, -1);
  349. #endif
  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. lcd_print('%');
  357. }
  358. #endif
  359. // X, Y, Z-Coordinates
  360. // Before homing the axis letters are blinking 'X' <-> '?'.
  361. // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
  362. // When everything is ok you see a constant 'X'.
  363. #define XYZ_BASELINE 38
  364. #if ENABLED(USE_SMALL_INFOFONT)
  365. u8g.drawBox(0, 30, LCD_PIXEL_WIDTH, 10);
  366. #else
  367. u8g.drawBox(0, 30, LCD_PIXEL_WIDTH, 9);
  368. #endif
  369. u8g.setColorIndex(0); // white on black
  370. u8g.setPrintPos(2, XYZ_BASELINE);
  371. _draw_axis_label(X_AXIS, PSTR(MSG_X), blink);
  372. u8g.setPrintPos(10, XYZ_BASELINE);
  373. lcd_print(ftostr4sign(current_position[X_AXIS]));
  374. u8g.setPrintPos(43, XYZ_BASELINE);
  375. _draw_axis_label(Y_AXIS, PSTR(MSG_Y), blink);
  376. u8g.setPrintPos(51, XYZ_BASELINE);
  377. lcd_print(ftostr4sign(current_position[Y_AXIS]));
  378. u8g.setPrintPos(83, XYZ_BASELINE);
  379. _draw_axis_label(Z_AXIS, PSTR(MSG_Z), blink);
  380. u8g.setPrintPos(91, XYZ_BASELINE);
  381. lcd_print(ftostr52sp(current_position[Z_AXIS] + 0.00001));
  382. u8g.setColorIndex(1); // black on white
  383. // Feedrate
  384. lcd_setFont(FONT_MENU);
  385. u8g.setPrintPos(3, 49);
  386. lcd_print(LCD_STR_FEEDRATE[0]);
  387. lcd_setFont(FONT_STATUSMENU);
  388. u8g.setPrintPos(12, 49);
  389. lcd_print(itostr3(feedrate_percentage));
  390. lcd_print('%');
  391. // Status line
  392. #if ENABLED(USE_SMALL_INFOFONT)
  393. u8g.setPrintPos(0, 62);
  394. #else
  395. u8g.setPrintPos(0, 63);
  396. #endif
  397. #if DISABLED(FILAMENT_LCD_DISPLAY)
  398. lcd_print(lcd_status_message);
  399. #else
  400. if (PENDING(millis(), previous_lcd_status_ms + 5000UL)) { //Display both Status message line and Filament display on the last line
  401. lcd_print(lcd_status_message);
  402. }
  403. else {
  404. lcd_printPGM(PSTR("dia:"));
  405. lcd_print(ftostr12ns(filament_width_meas));
  406. lcd_printPGM(PSTR(" factor:"));
  407. lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  408. lcd_print('%');
  409. }
  410. #endif
  411. }
  412. #if ENABLED(ULTIPANEL)
  413. // Set the colors for a menu item based on whether it is selected
  414. static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) {
  415. if (isSelected) {
  416. u8g.setColorIndex(1); // black on white
  417. u8g.drawBox(0, row * (DOG_CHAR_HEIGHT) + 3 - (TALL_FONT_CORRECTION), LCD_PIXEL_WIDTH, DOG_CHAR_HEIGHT);
  418. u8g.setColorIndex(0); // following text must be white on black
  419. }
  420. else {
  421. u8g.setColorIndex(1); // unmarked text is black on white
  422. }
  423. u8g.setPrintPos((START_COL) * (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
  424. }
  425. #if ENABLED(LCD_INFO_MENU) || ENABLED(FILAMENT_CHANGE_FEATURE)
  426. // Draw a static line of text in the same idiom as a menu item
  427. static void lcd_implementation_drawmenu_static(uint8_t row, const char* pstr, bool center=true, bool invert=false, const char* valstr=NULL) {
  428. lcd_implementation_mark_as_selected(row, invert);
  429. char c;
  430. int8_t n = LCD_WIDTH - (START_COL);
  431. if (center && !valstr) {
  432. int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
  433. while (--pad >= 0) { lcd_print(' '); n--; }
  434. }
  435. while (n > 0 && (c = pgm_read_byte(pstr))) {
  436. n -= lcd_print(c);
  437. pstr++;
  438. }
  439. if (valstr) while (n > 0 && (c = *valstr)) {
  440. n -= lcd_print(c);
  441. valstr++;
  442. }
  443. while (n-- > 0) lcd_print(' ');
  444. }
  445. #endif // LCD_INFO_MENU || FILAMENT_CHANGE_FEATURE
  446. // Draw a generic menu item
  447. static void lcd_implementation_drawmenu_generic(bool isSelected, uint8_t row, const char* pstr, char pre_char, char post_char) {
  448. UNUSED(pre_char);
  449. char c;
  450. uint8_t n = LCD_WIDTH - (START_COL) - 2;
  451. lcd_implementation_mark_as_selected(row, isSelected);
  452. while (c = pgm_read_byte(pstr)) {
  453. n -= lcd_print(c);
  454. pstr++;
  455. }
  456. while (n--) lcd_print(' ');
  457. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
  458. lcd_print(post_char);
  459. lcd_print(' ');
  460. }
  461. // Macros for specific types of menu items
  462. #define lcd_implementation_drawmenu_back(sel, row, pstr) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  463. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  464. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  465. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  466. // Draw a menu item with an editable value
  467. static void _drawmenu_setting_edit_generic(bool isSelected, uint8_t row, const char* pstr, const char* data, bool pgm) {
  468. char c;
  469. uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
  470. uint8_t n = LCD_WIDTH - (START_COL) - 2 - vallen;
  471. lcd_implementation_mark_as_selected(row, isSelected);
  472. while (c = pgm_read_byte(pstr)) {
  473. n -= lcd_print(c);
  474. pstr++;
  475. }
  476. lcd_print(':');
  477. while (n--) lcd_print(' ');
  478. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, (row + 1) * (DOG_CHAR_HEIGHT));
  479. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  480. }
  481. // Macros for edit items
  482. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  483. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  484. #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)))
  485. #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)))
  486. #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)))
  487. #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)))
  488. #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)))
  489. #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)))
  490. #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)))
  491. #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)))
  492. #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))
  493. #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)))
  494. #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)))
  495. #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)))
  496. #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)))
  497. #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)))
  498. #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)))
  499. #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)))
  500. #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)))
  501. #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))
  502. void lcd_implementation_drawedit(const char* pstr, const char* value=NULL) {
  503. uint8_t rows = 1;
  504. uint8_t lcd_width = LCD_WIDTH - (START_COL), char_width = DOG_CHAR_WIDTH;
  505. uint8_t vallen = lcd_strlen(value);
  506. #if ENABLED(USE_BIG_EDIT_FONT)
  507. if (lcd_strlen_P(pstr) <= LCD_WIDTH_EDIT - 1) {
  508. lcd_setFont(FONT_MENU_EDIT);
  509. lcd_width = LCD_WIDTH_EDIT + 1;
  510. char_width = DOG_CHAR_WIDTH_EDIT;
  511. if (lcd_strlen_P(pstr) >= LCD_WIDTH_EDIT - vallen) rows = 2;
  512. }
  513. else {
  514. lcd_setFont(FONT_MENU);
  515. }
  516. #endif
  517. if (lcd_strlen_P(pstr) > LCD_WIDTH - 2 - vallen) rows = 2;
  518. const float kHalfChar = (DOG_CHAR_HEIGHT_EDIT) / 2;
  519. float rowHeight = u8g.getHeight() / (rows + 1); // 1/(rows+1) = 1/2 or 1/3
  520. u8g.setPrintPos(0, rowHeight + kHalfChar);
  521. lcd_printPGM(pstr);
  522. if (value != NULL) {
  523. lcd_print(':');
  524. u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, rows * rowHeight + kHalfChar);
  525. lcd_print(value);
  526. }
  527. }
  528. #if ENABLED(SDSUPPORT)
  529. static void _drawmenu_sd(bool isSelected, uint8_t row, const char* pstr, const char* filename, char* const longFilename, bool isDir) {
  530. UNUSED(pstr);
  531. char c;
  532. uint8_t n = LCD_WIDTH - (START_COL) - 1;
  533. if (longFilename[0]) {
  534. filename = longFilename;
  535. longFilename[n] = '\0';
  536. }
  537. lcd_implementation_mark_as_selected(row, isSelected);
  538. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  539. while ((c = *filename)) {
  540. n -= lcd_print(c);
  541. filename++;
  542. }
  543. while (n--) lcd_print(' ');
  544. }
  545. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  546. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  547. #endif // SDSUPPORT
  548. #endif // ULTIPANEL
  549. #endif //__ULTRALCD_IMPL_DOGM_H