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

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