My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

ultralcd_impl_DOGM.h 24KB

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