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.

dogm_lcd_implementation.h 21KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607
  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. * dogm_lcd_implementation.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 DOGM_LCD_IMPLEMENTATION_H
  35. #define DOGM_LCD_IMPLEMENTATION_H
  36. /**
  37. * Implementation of the LCD display routines for a DOGM128 graphic display. These are common LCD 128x64 pixel graphic displays.
  38. */
  39. #if ENABLED(ULTIPANEL)
  40. #define BLEN_A 0
  41. #define BLEN_B 1
  42. #define BLEN_C 2
  43. #define EN_A (_BV(BLEN_A))
  44. #define EN_B (_BV(BLEN_B))
  45. #define EN_C (_BV(BLEN_C))
  46. #define LCD_CLICKED (buttons&EN_C)
  47. #endif
  48. #include <U8glib.h>
  49. #include "dogm_bitmaps.h"
  50. #include "ultralcd.h"
  51. #include "ultralcd_st7920_u8glib_rrd.h"
  52. #include "Configuration.h"
  53. #if DISABLED(MAPPER_C2C3) && DISABLED(MAPPER_NON) && ENABLED(USE_BIG_EDIT_FONT)
  54. #undef USE_BIG_EDIT_FONT
  55. #endif
  56. #if ENABLED(USE_SMALL_INFOFONT)
  57. #include "dogm_font_data_6x9_marlin.h"
  58. #define FONT_STATUSMENU_NAME u8g_font_6x9
  59. #else
  60. #define FONT_STATUSMENU_NAME FONT_MENU_NAME
  61. #endif
  62. #include "dogm_font_data_Marlin_symbols.h" // The Marlin special symbols
  63. #define FONT_SPECIAL_NAME Marlin_symbols
  64. #if DISABLED(SIMULATE_ROMFONT)
  65. #if ENABLED(DISPLAY_CHARSET_ISO10646_1)
  66. #include "dogm_font_data_ISO10646_1.h"
  67. #define FONT_MENU_NAME ISO10646_1_5x7
  68. #elif ENABLED(DISPLAY_CHARSET_ISO10646_5)
  69. #include "dogm_font_data_ISO10646_5_Cyrillic.h"
  70. #define FONT_MENU_NAME ISO10646_5_Cyrillic_5x7
  71. #elif ENABLED(DISPLAY_CHARSET_ISO10646_KANA)
  72. #include "dogm_font_data_ISO10646_Kana.h"
  73. #define FONT_MENU_NAME ISO10646_Kana_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 ENABLED(DISPLAY_CHARSET_HD44780_JAPAN)
  84. #include "dogm_font_data_HD44780_J.h"
  85. #define FONT_MENU_NAME HD44780_J_5x7
  86. #elif ENABLED(DISPLAY_CHARSET_HD44780_WESTERN)
  87. #include "dogm_font_data_HD44780_W.h"
  88. #define FONT_MENU_NAME HD44780_W_5x7
  89. #elif ENABLED(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_ROW 0
  120. // LCD selection
  121. #if ENABLED(U8GLIB_ST7920)
  122. //U8GLIB_ST7920_128X64_RRD u8g(0,0,0);
  123. U8GLIB_ST7920_128X64_RRD u8g(0);
  124. #elif ENABLED(MAKRPANEL)
  125. // The MaKrPanel display, ST7565 controller as well
  126. U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);
  127. #elif ENABLED(VIKI2) || ENABLED(miniVIKI)
  128. // Mini Viki and Viki 2.0 LCD, ST7565 controller as well
  129. U8GLIB_NHD_C12864 u8g(DOGLCD_CS, DOGLCD_A0);
  130. #elif ENABLED(U8GLIB_LM6059_AF)
  131. // Based on the Adafruit ST7565 (http://www.adafruit.com/products/250)
  132. U8GLIB_LM6059 u8g(DOGLCD_CS, DOGLCD_A0);
  133. #elif ENABLED(U8GLIB_SSD1306)
  134. // Generic support for SSD1306 OLED I2C LCDs
  135. U8GLIB_SSD1306_128X64 u8g(U8G_I2C_OPT_NONE);
  136. #elif ENABLED(MINIPANEL)
  137. // The MINIPanel display
  138. U8GLIB_MINI12864 u8g(DOGLCD_CS, DOGLCD_A0);
  139. #else
  140. // for regular DOGM128 display with HW-SPI
  141. U8GLIB_DOGM128 u8g(DOGLCD_CS, DOGLCD_A0); // HW-SPI Com: CS, A0
  142. #endif
  143. #ifndef LCD_PIXEL_WIDTH
  144. #define LCD_PIXEL_WIDTH 128
  145. #endif
  146. #ifndef LCD_PIXEL_HEIGHT
  147. #define LCD_PIXEL_HEIGHT 64
  148. #endif
  149. #include "utf_mapper.h"
  150. int lcd_contrast;
  151. static char currentfont = 0;
  152. static void lcd_setFont(char font_nr) {
  153. switch(font_nr) {
  154. case FONT_STATUSMENU : {u8g.setFont(FONT_STATUSMENU_NAME); currentfont = FONT_STATUSMENU;}; break;
  155. case FONT_MENU : {u8g.setFont(FONT_MENU_NAME); currentfont = FONT_MENU;}; break;
  156. case FONT_SPECIAL : {u8g.setFont(FONT_SPECIAL_NAME); currentfont = FONT_SPECIAL;}; break;
  157. case FONT_MENU_EDIT : {u8g.setFont(FONT_MENU_EDIT_NAME); currentfont = FONT_MENU_EDIT;}; break;
  158. break;
  159. }
  160. }
  161. char lcd_print(char c) {
  162. if ((c > 0) && (c <= LCD_STR_SPECIAL_MAX)) {
  163. u8g.setFont(FONT_SPECIAL_NAME);
  164. u8g.print(c);
  165. lcd_setFont(currentfont);
  166. return 1;
  167. } else {
  168. return charset_mapper(c);
  169. }
  170. }
  171. char lcd_print(const char* str) {
  172. char c;
  173. int i = 0;
  174. char n = 0;
  175. while ((c = str[i++])) {
  176. n += lcd_print(c);
  177. }
  178. return n;
  179. }
  180. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  181. char lcd_printPGM(const char* str) {
  182. char c;
  183. char n = 0;
  184. while ((c = pgm_read_byte(str++))) {
  185. n += lcd_print(c);
  186. }
  187. return n;
  188. }
  189. #if ENABLED(SHOW_BOOTSCREEN)
  190. static bool show_bootscreen = true;
  191. #endif
  192. /* Warning: This function is called from interrupt context */
  193. static void lcd_implementation_init() {
  194. #if defined(LCD_PIN_BL) && LCD_PIN_BL > -1 // Enable LCD backlight
  195. pinMode(LCD_PIN_BL, OUTPUT);
  196. digitalWrite(LCD_PIN_BL, HIGH);
  197. #endif
  198. #if defined(LCD_PIN_RESET) && LCD_PIN_RESET > -1
  199. pinMode(LCD_PIN_RESET, OUTPUT);
  200. digitalWrite(LCD_PIN_RESET, HIGH);
  201. #endif
  202. #if DISABLED(MINIPANEL) // setContrast not working for Mini Panel
  203. u8g.setContrast(lcd_contrast);
  204. #endif
  205. // FIXME: remove this workaround
  206. // Uncomment this if you have the first generation (V1.10) of STBs board
  207. // pinMode(17, OUTPUT); // Enable LCD backlight
  208. // digitalWrite(17, HIGH);
  209. #if ENABLED(LCD_SCREEN_ROT_90)
  210. u8g.setRot90(); // Rotate screen by 90°
  211. #elif ENABLED(LCD_SCREEN_ROT_180)
  212. u8g.setRot180(); // Rotate screen by 180°
  213. #elif ENABLED(LCD_SCREEN_ROT_270)
  214. u8g.setRot270(); // Rotate screen by 270°
  215. #endif
  216. #if ENABLED(SHOW_BOOTSCREEN)
  217. int offx = (u8g.getWidth() - (START_BMPWIDTH)) / 2;
  218. #if ENABLED(START_BMPHIGH)
  219. int offy = 0;
  220. #else
  221. int offy = DOG_CHAR_HEIGHT;
  222. #endif
  223. int txt1X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE1) - 1) * (DOG_CHAR_WIDTH)) / 2;
  224. u8g.firstPage();
  225. do {
  226. if (show_bootscreen) {
  227. u8g.drawBitmapP(offx, offy, START_BMPBYTEWIDTH, START_BMPHEIGHT, start_bmp);
  228. lcd_setFont(FONT_MENU);
  229. #ifndef STRING_SPLASH_LINE2
  230. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT), STRING_SPLASH_LINE1);
  231. #else
  232. int txt2X = (u8g.getWidth() - (sizeof(STRING_SPLASH_LINE2) - 1) * (DOG_CHAR_WIDTH)) / 2;
  233. u8g.drawStr(txt1X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 3 / 2, STRING_SPLASH_LINE1);
  234. u8g.drawStr(txt2X, u8g.getHeight() - (DOG_CHAR_HEIGHT) * 1 / 2, STRING_SPLASH_LINE2);
  235. #endif
  236. }
  237. } while (u8g.nextPage());
  238. if (show_bootscreen) {
  239. delay(1000);
  240. show_bootscreen = false;
  241. }
  242. #endif
  243. }
  244. static void lcd_implementation_clear() { } // Automatically cleared by Picture Loop
  245. static void _draw_heater_status(int x, int heater) {
  246. bool isBed = heater < 0;
  247. int y = 17 + (isBed ? 1 : 0);
  248. lcd_setFont(FONT_STATUSMENU);
  249. u8g.setPrintPos(x, 7);
  250. lcd_print(itostr3(int((heater >= 0 ? degTargetHotend(heater) : degTargetBed()) + 0.5)));
  251. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  252. u8g.setPrintPos(x, 28);
  253. lcd_print(itostr3(int(heater >= 0 ? degHotend(heater) : degBed()) + 0.5));
  254. lcd_printPGM(PSTR(LCD_STR_DEGREE " "));
  255. if (heater >= 0 ? !isHeatingHotend(heater) : !isHeatingBed()) {
  256. u8g.drawBox(x+7,y,2,2);
  257. }
  258. else {
  259. u8g.setColorIndex(0); // white on black
  260. u8g.drawBox(x + 7, y, 2, 2);
  261. u8g.setColorIndex(1); // black on white
  262. }
  263. }
  264. static void lcd_implementation_status_screen() {
  265. u8g.setColorIndex(1); // black on white
  266. bool blink = lcd_blink();
  267. // Symbols menu graphics, animated fan
  268. u8g.drawBitmapP(9, 1, STATUS_SCREENBYTEWIDTH, STATUS_SCREENHEIGHT,
  269. #if HAS_FAN0
  270. blink && fanSpeeds[0] ? status_screen0_bmp : status_screen1_bmp
  271. #else
  272. status_screen0_bmp
  273. #endif
  274. );
  275. #if ENABLED(SDSUPPORT)
  276. // SD Card Symbol
  277. u8g.drawBox(42, 42 - (TALL_FONT_CORRECTION), 8, 7);
  278. u8g.drawBox(50, 44 - (TALL_FONT_CORRECTION), 2, 5);
  279. u8g.drawFrame(42, 49 - (TALL_FONT_CORRECTION), 10, 4);
  280. u8g.drawPixel(50, 43 - (TALL_FONT_CORRECTION));
  281. // Progress bar frame
  282. u8g.drawFrame(54, 49, 73, 4 - (TALL_FONT_CORRECTION));
  283. // SD Card Progress bar and clock
  284. lcd_setFont(FONT_STATUSMENU);
  285. if (IS_SD_PRINTING) {
  286. // Progress bar solid part
  287. u8g.drawBox(55, 50, (unsigned int)(71.f * card.percentDone() / 100.f), 2 - (TALL_FONT_CORRECTION));
  288. }
  289. u8g.setPrintPos(80,48);
  290. if (print_job_start_ms != 0) {
  291. uint16_t time = (((print_job_stop_ms > print_job_start_ms)
  292. ? print_job_stop_ms : millis()) - print_job_start_ms) / 60000;
  293. lcd_print(itostr2(time/60));
  294. lcd_print(':');
  295. lcd_print(itostr2(time%60));
  296. }
  297. else {
  298. lcd_printPGM(PSTR("--:--"));
  299. }
  300. #endif
  301. // Extruders
  302. for (int i = 0; i < EXTRUDERS; i++) _draw_heater_status(6 + i * 25, i);
  303. // Heatbed
  304. if (EXTRUDERS < 4) _draw_heater_status(81, -1);
  305. // Fan
  306. lcd_setFont(FONT_STATUSMENU);
  307. u8g.setPrintPos(104, 27);
  308. #if HAS_FAN0
  309. int per = ((fanSpeeds[0] + 1) * 100) / 256;
  310. if (per) {
  311. lcd_print(itostr3(per));
  312. lcd_print('%');
  313. }
  314. else
  315. #endif
  316. {
  317. lcd_printPGM(PSTR("---"));
  318. }
  319. // X, Y, Z-Coordinates
  320. // Before homing the axis letters are blinking 'X' <-> '?'.
  321. // When axis is homed but axis_known_position is false the axis letters are blinking 'X' <-> ' '.
  322. // When everything is ok you see a constant 'X'.
  323. #define XYZ_BASELINE 38
  324. lcd_setFont(FONT_STATUSMENU);
  325. #if ENABLED(USE_SMALL_INFOFONT)
  326. u8g.drawBox(0, 30, LCD_PIXEL_WIDTH, 10);
  327. #else
  328. u8g.drawBox(0, 30, LCD_PIXEL_WIDTH, 9);
  329. #endif
  330. u8g.setColorIndex(0); // white on black
  331. u8g.setPrintPos(2, XYZ_BASELINE);
  332. if (blink)
  333. lcd_printPGM(PSTR(MSG_X));
  334. else {
  335. if (!axis_homed[X_AXIS])
  336. lcd_printPGM(PSTR("?"));
  337. else {
  338. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  339. if (!axis_known_position[X_AXIS])
  340. lcd_printPGM(PSTR(" "));
  341. else
  342. #endif
  343. lcd_printPGM(PSTR(MSG_X));
  344. }
  345. }
  346. u8g.drawPixel(8, XYZ_BASELINE - 5);
  347. u8g.drawPixel(8, XYZ_BASELINE - 3);
  348. u8g.setPrintPos(10, XYZ_BASELINE);
  349. lcd_print(ftostr31ns(current_position[X_AXIS]));
  350. u8g.setPrintPos(43, XYZ_BASELINE);
  351. if (blink)
  352. lcd_printPGM(PSTR(MSG_Y));
  353. else {
  354. if (!axis_homed[Y_AXIS])
  355. lcd_printPGM(PSTR("?"));
  356. else {
  357. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  358. if (!axis_known_position[Y_AXIS])
  359. lcd_printPGM(PSTR(" "));
  360. else
  361. #endif
  362. lcd_printPGM(PSTR(MSG_Y));
  363. }
  364. }
  365. u8g.drawPixel(49, XYZ_BASELINE - 5);
  366. u8g.drawPixel(49, XYZ_BASELINE - 3);
  367. u8g.setPrintPos(51, XYZ_BASELINE);
  368. lcd_print(ftostr31ns(current_position[Y_AXIS]));
  369. u8g.setPrintPos(83, XYZ_BASELINE);
  370. if (blink)
  371. lcd_printPGM(PSTR(MSG_Z));
  372. else {
  373. if (!axis_homed[Z_AXIS])
  374. lcd_printPGM(PSTR("?"));
  375. else {
  376. #if DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  377. if (!axis_known_position[Z_AXIS])
  378. lcd_printPGM(PSTR(" "));
  379. else
  380. #endif
  381. lcd_printPGM(PSTR(MSG_Z));
  382. }
  383. }
  384. u8g.drawPixel(89, XYZ_BASELINE - 5);
  385. u8g.drawPixel(89, XYZ_BASELINE - 3);
  386. u8g.setPrintPos(91, XYZ_BASELINE);
  387. lcd_print(ftostr32sp(current_position[Z_AXIS]));
  388. u8g.setColorIndex(1); // black on white
  389. // Feedrate
  390. lcd_setFont(FONT_MENU);
  391. u8g.setPrintPos(3, 49);
  392. lcd_print(LCD_STR_FEEDRATE[0]);
  393. lcd_setFont(FONT_STATUSMENU);
  394. u8g.setPrintPos(12, 49);
  395. lcd_print(itostr3(feedrate_multiplier));
  396. lcd_print('%');
  397. // Status line
  398. lcd_setFont(FONT_STATUSMENU);
  399. #if ENABLED(USE_SMALL_INFOFONT)
  400. u8g.setPrintPos(0, 62);
  401. #else
  402. u8g.setPrintPos(0, 63);
  403. #endif
  404. #if DISABLED(FILAMENT_LCD_DISPLAY)
  405. lcd_print(lcd_status_message);
  406. #else
  407. if (millis() < previous_lcd_status_ms + 5000) { //Display both Status message line and Filament display on the last line
  408. lcd_print(lcd_status_message);
  409. }
  410. else {
  411. lcd_printPGM(PSTR("dia:"));
  412. lcd_print(ftostr12ns(filament_width_meas));
  413. lcd_printPGM(PSTR(" factor:"));
  414. lcd_print(itostr3(100.0 * volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  415. lcd_print('%');
  416. }
  417. #endif
  418. }
  419. static void lcd_implementation_mark_as_selected(uint8_t row, bool isSelected) {
  420. if (isSelected) {
  421. u8g.setColorIndex(1); // black on white
  422. u8g.drawBox(0, row * (DOG_CHAR_HEIGHT) + 3 - (TALL_FONT_CORRECTION), LCD_PIXEL_WIDTH, DOG_CHAR_HEIGHT);
  423. u8g.setColorIndex(0); // following text must be white on black
  424. }
  425. else {
  426. u8g.setColorIndex(1); // unmarked text is black on white
  427. }
  428. u8g.setPrintPos((START_ROW) * (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
  429. }
  430. static void lcd_implementation_drawmenu_generic(bool isSelected, uint8_t row, const char* pstr, char pre_char, char post_char) {
  431. char c;
  432. uint8_t n = LCD_WIDTH - 2;
  433. lcd_implementation_mark_as_selected(row, isSelected);
  434. while (c = pgm_read_byte(pstr)) {
  435. n -= lcd_print(c);
  436. pstr++;
  437. }
  438. while (n--) lcd_print(' ');
  439. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH), (row + 1) * (DOG_CHAR_HEIGHT));
  440. lcd_print(post_char);
  441. lcd_print(' ');
  442. }
  443. static void _drawmenu_setting_edit_generic(bool isSelected, uint8_t row, const char* pstr, const char* data, bool pgm) {
  444. char c;
  445. uint8_t vallen = (pgm ? lcd_strlen_P(data) : (lcd_strlen((char*)data)));
  446. uint8_t n = LCD_WIDTH - 2 - vallen;
  447. lcd_implementation_mark_as_selected(row, isSelected);
  448. while (c = pgm_read_byte(pstr)) {
  449. n -= lcd_print(c);
  450. pstr++;
  451. }
  452. lcd_print(':');
  453. while (n--) lcd_print(' ');
  454. u8g.setPrintPos(LCD_PIXEL_WIDTH - (DOG_CHAR_WIDTH) * vallen, (row + 1) * (DOG_CHAR_HEIGHT));
  455. if (pgm) lcd_printPGM(data); else lcd_print((char*)data);
  456. }
  457. #define lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, false)
  458. #define lcd_implementation_drawmenu_setting_edit_generic_P(sel, row, pstr, data) _drawmenu_setting_edit_generic(sel, row, pstr, data, true)
  459. #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)))
  460. #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)))
  461. #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)))
  462. #define lcd_implementation_drawmenu_setting_edit_float43(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr43(*(data)))
  463. #define lcd_implementation_drawmenu_setting_edit_float5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
  464. #define lcd_implementation_drawmenu_setting_edit_float52(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr52(*(data)))
  465. #define lcd_implementation_drawmenu_setting_edit_float51(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr51(*(data)))
  466. #define lcd_implementation_drawmenu_setting_edit_long5(sel, row, pstr, pstr2, data, minValue, maxValue) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, ftostr5(*(data)))
  467. #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))
  468. //Add version for callback functions
  469. #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)))
  470. #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)))
  471. #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)))
  472. #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, ftostr43(*(data)))
  473. #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, ftostr5(*(data)))
  474. #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, ftostr52(*(data)))
  475. #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, ftostr51(*(data)))
  476. #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, ftostr5(*(data)))
  477. #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))
  478. void lcd_implementation_drawedit(const char* pstr, const char* value) {
  479. uint8_t rows = 1;
  480. uint8_t lcd_width = LCD_WIDTH, char_width = DOG_CHAR_WIDTH;
  481. uint8_t vallen = lcd_strlen(value);
  482. #if ENABLED(USE_BIG_EDIT_FONT)
  483. if (lcd_strlen_P(pstr) <= LCD_WIDTH_EDIT - 1) {
  484. lcd_setFont(FONT_MENU_EDIT);
  485. lcd_width = LCD_WIDTH_EDIT + 1;
  486. char_width = DOG_CHAR_WIDTH_EDIT;
  487. if (lcd_strlen_P(pstr) >= LCD_WIDTH_EDIT - vallen) rows = 2;
  488. }
  489. else {
  490. lcd_setFont(FONT_MENU);
  491. }
  492. #endif
  493. if (lcd_strlen_P(pstr) > LCD_WIDTH - 2 - vallen) rows = 2;
  494. const float kHalfChar = (DOG_CHAR_HEIGHT_EDIT) / 2;
  495. float rowHeight = u8g.getHeight() / (rows + 1); // 1/(rows+1) = 1/2 or 1/3
  496. u8g.setPrintPos(0, rowHeight + kHalfChar);
  497. lcd_printPGM(pstr);
  498. if (value != NULL) {
  499. lcd_print(':');
  500. u8g.setPrintPos((lcd_width - 1 - vallen) * char_width, rows * rowHeight + kHalfChar);
  501. lcd_print(value);
  502. }
  503. }
  504. #if ENABLED(SDSUPPORT)
  505. static void _drawmenu_sd(bool isSelected, uint8_t row, const char* pstr, const char* filename, char* const longFilename, bool isDir) {
  506. char c;
  507. uint8_t n = LCD_WIDTH - 1;
  508. if (longFilename[0]) {
  509. filename = longFilename;
  510. longFilename[n] = '\0';
  511. }
  512. lcd_implementation_mark_as_selected(row, isSelected);
  513. if (isDir) lcd_print(LCD_STR_FOLDER[0]);
  514. while ((c = *filename)) {
  515. n -= lcd_print(c);
  516. filename++;
  517. }
  518. while (n--) lcd_print(' ');
  519. }
  520. #define lcd_implementation_drawmenu_sdfile(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, false)
  521. #define lcd_implementation_drawmenu_sddirectory(sel, row, pstr, filename, longFilename) _drawmenu_sd(sel, row, pstr, filename, longFilename, true)
  522. #endif //SDSUPPORT
  523. #define lcd_implementation_drawmenu_back(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  524. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  525. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  526. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  527. #endif //__DOGM_LCD_IMPLEMENTATION_H