My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Vous ne pouvez pas sélectionner plus de 25 sujets Les noms de sujets doivent commencer par une lettre ou un nombre, peuvent contenir des tirets ('-') et peuvent comporter jusqu'à 35 caractères.

ultralcd_impl_DOGM.h 23KB

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