My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd_implementation_hitachi_HD44780.h 27KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869
  1. #ifndef ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H
  2. #define ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H
  3. /**
  4. * Implementation of the LCD display routines for a Hitachi HD44780 display. These are common LCD character displays.
  5. * When selecting the Russian language, a slightly different LCD implementation is used to handle UTF8 characters.
  6. **/
  7. //#if DISABLED(REPRAPWORLD_KEYPAD)
  8. // extern volatile uint8_t buttons; //the last checked buttons in a bit array.
  9. //#else
  10. extern volatile uint8_t buttons; //an extended version of the last checked buttons in a bit array.
  11. //#endif
  12. ////////////////////////////////////
  13. // Setup button and encode mappings for each panel (into 'buttons' variable
  14. //
  15. // This is just to map common functions (across different panels) onto the same
  16. // macro name. The mapping is independent of whether the button is directly connected or
  17. // via a shift/i2c register.
  18. #if ENABLED(ULTIPANEL)
  19. // All UltiPanels might have an encoder - so this is always be mapped onto first two bits
  20. #define BLEN_B 1
  21. #define BLEN_A 0
  22. #define EN_B BIT(BLEN_B) // The two encoder pins are connected through BTN_EN1 and BTN_EN2
  23. #define EN_A BIT(BLEN_A)
  24. #if defined(BTN_ENC) && BTN_ENC > -1
  25. // encoder click is directly connected
  26. #define BLEN_C 2
  27. #define EN_C BIT(BLEN_C)
  28. #endif
  29. //
  30. // Setup other button mappings of each panel
  31. //
  32. #if ENABLED(LCD_I2C_VIKI)
  33. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  34. // button and encoder bit positions within 'buttons'
  35. #define B_LE (BUTTON_LEFT<<B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
  36. #define B_UP (BUTTON_UP<<B_I2C_BTN_OFFSET)
  37. #define B_MI (BUTTON_SELECT<<B_I2C_BTN_OFFSET)
  38. #define B_DW (BUTTON_DOWN<<B_I2C_BTN_OFFSET)
  39. #define B_RI (BUTTON_RIGHT<<B_I2C_BTN_OFFSET)
  40. #if defined(BTN_ENC) && BTN_ENC > -1
  41. // the pause/stop/restart button is connected to BTN_ENC when used
  42. #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
  43. #define LCD_CLICKED (buttons&(B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
  44. #else
  45. #define LCD_CLICKED (buttons&(B_MI|B_RI))
  46. #endif
  47. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  48. #define LCD_HAS_SLOW_BUTTONS
  49. #elif ENABLED(LCD_I2C_PANELOLU2)
  50. // encoder click can be read through I2C if not directly connected
  51. #if BTN_ENC <= 0
  52. #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
  53. #define B_MI (PANELOLU2_ENCODER_C<<B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
  54. #define LCD_CLICKED (buttons&B_MI)
  55. // I2C buttons take too long to read inside an interrupt context and so we read them during lcd_update
  56. #define LCD_HAS_SLOW_BUTTONS
  57. #else
  58. #define LCD_CLICKED (buttons&EN_C)
  59. #endif
  60. #elif ENABLED(REPRAPWORLD_KEYPAD)
  61. // define register bit values, don't change it
  62. #define BLEN_REPRAPWORLD_KEYPAD_F3 0
  63. #define BLEN_REPRAPWORLD_KEYPAD_F2 1
  64. #define BLEN_REPRAPWORLD_KEYPAD_F1 2
  65. #define BLEN_REPRAPWORLD_KEYPAD_UP 6
  66. #define BLEN_REPRAPWORLD_KEYPAD_RIGHT 4
  67. #define BLEN_REPRAPWORLD_KEYPAD_MIDDLE 5
  68. #define BLEN_REPRAPWORLD_KEYPAD_DOWN 3
  69. #define BLEN_REPRAPWORLD_KEYPAD_LEFT 7
  70. #define REPRAPWORLD_BTN_OFFSET 0 // bit offset into buttons for shift register values
  71. #define EN_REPRAPWORLD_KEYPAD_F3 BIT((BLEN_REPRAPWORLD_KEYPAD_F3+REPRAPWORLD_BTN_OFFSET))
  72. #define EN_REPRAPWORLD_KEYPAD_F2 BIT((BLEN_REPRAPWORLD_KEYPAD_F2+REPRAPWORLD_BTN_OFFSET))
  73. #define EN_REPRAPWORLD_KEYPAD_F1 BIT((BLEN_REPRAPWORLD_KEYPAD_F1+REPRAPWORLD_BTN_OFFSET))
  74. #define EN_REPRAPWORLD_KEYPAD_UP BIT((BLEN_REPRAPWORLD_KEYPAD_UP+REPRAPWORLD_BTN_OFFSET))
  75. #define EN_REPRAPWORLD_KEYPAD_RIGHT BIT((BLEN_REPRAPWORLD_KEYPAD_RIGHT+REPRAPWORLD_BTN_OFFSET))
  76. #define EN_REPRAPWORLD_KEYPAD_MIDDLE BIT((BLEN_REPRAPWORLD_KEYPAD_MIDDLE+REPRAPWORLD_BTN_OFFSET))
  77. #define EN_REPRAPWORLD_KEYPAD_DOWN BIT((BLEN_REPRAPWORLD_KEYPAD_DOWN+REPRAPWORLD_BTN_OFFSET))
  78. #define EN_REPRAPWORLD_KEYPAD_LEFT BIT((BLEN_REPRAPWORLD_KEYPAD_LEFT+REPRAPWORLD_BTN_OFFSET))
  79. //#define LCD_CLICKED ((buttons&EN_C) || (buttons&EN_REPRAPWORLD_KEYPAD_F1))
  80. //#define REPRAPWORLD_KEYPAD_MOVE_Y_DOWN (buttons&EN_REPRAPWORLD_KEYPAD_DOWN)
  81. //#define REPRAPWORLD_KEYPAD_MOVE_Y_UP (buttons&EN_REPRAPWORLD_KEYPAD_UP)
  82. //#define REPRAPWORLD_KEYPAD_MOVE_HOME (buttons&EN_REPRAPWORLD_KEYPAD_MIDDLE)
  83. #elif ENABLED(NEWPANEL)
  84. #define LCD_CLICKED (buttons&EN_C)
  85. #else // old style ULTIPANEL
  86. //bits in the shift register that carry the buttons for:
  87. // left up center down right red(stop)
  88. #define BL_LE 7
  89. #define BL_UP 6
  90. #define BL_MI 5
  91. #define BL_DW 4
  92. #define BL_RI 3
  93. #define BL_ST 2
  94. //automatic, do not change
  95. #define B_LE BIT(BL_LE)
  96. #define B_UP BIT(BL_UP)
  97. #define B_MI BIT(BL_MI)
  98. #define B_DW BIT(BL_DW)
  99. #define B_RI BIT(BL_RI)
  100. #define B_ST BIT(BL_ST)
  101. #define LCD_CLICKED (buttons&(B_MI|B_ST))
  102. #endif
  103. #endif //ULTIPANEL
  104. ////////////////////////////////////
  105. // Create LCD class instance and chipset-specific information
  106. #if ENABLED(LCD_I2C_TYPE_PCF8575)
  107. // note: these are register mapped pins on the PCF8575 controller not Arduino pins
  108. #define LCD_I2C_PIN_BL 3
  109. #define LCD_I2C_PIN_EN 2
  110. #define LCD_I2C_PIN_RW 1
  111. #define LCD_I2C_PIN_RS 0
  112. #define LCD_I2C_PIN_D4 4
  113. #define LCD_I2C_PIN_D5 5
  114. #define LCD_I2C_PIN_D6 6
  115. #define LCD_I2C_PIN_D7 7
  116. #include <Wire.h>
  117. #include <LCD.h>
  118. #include <LiquidCrystal_I2C.h>
  119. #define LCD_CLASS LiquidCrystal_I2C
  120. LCD_CLASS lcd(LCD_I2C_ADDRESS,LCD_I2C_PIN_EN,LCD_I2C_PIN_RW,LCD_I2C_PIN_RS,LCD_I2C_PIN_D4,LCD_I2C_PIN_D5,LCD_I2C_PIN_D6,LCD_I2C_PIN_D7);
  121. #elif ENABLED(LCD_I2C_TYPE_MCP23017)
  122. //for the LED indicators (which maybe mapped to different things in lcd_implementation_update_indicators())
  123. #define LED_A 0x04 //100
  124. #define LED_B 0x02 //010
  125. #define LED_C 0x01 //001
  126. #define LCD_HAS_STATUS_INDICATORS
  127. #include <Wire.h>
  128. #include <LiquidTWI2.h>
  129. #define LCD_CLASS LiquidTWI2
  130. #if ENABLED(DETECT_DEVICE)
  131. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  132. #else
  133. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  134. #endif
  135. #elif ENABLED(LCD_I2C_TYPE_MCP23008)
  136. #include <Wire.h>
  137. #include <LiquidTWI2.h>
  138. #define LCD_CLASS LiquidTWI2
  139. #if ENABLED(DETECT_DEVICE)
  140. LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
  141. #else
  142. LCD_CLASS lcd(LCD_I2C_ADDRESS);
  143. #endif
  144. #elif ENABLED(LCD_I2C_TYPE_PCA8574)
  145. #include <LiquidCrystal_I2C.h>
  146. #define LCD_CLASS LiquidCrystal_I2C
  147. LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
  148. // 2 wire Non-latching LCD SR from:
  149. // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
  150. #elif ENABLED(SR_LCD_2W_NL)
  151. extern "C" void __cxa_pure_virtual() { while (1); }
  152. #include <LCD.h>
  153. #include <LiquidCrystal_SR.h>
  154. #define LCD_CLASS LiquidCrystal_SR
  155. LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN);
  156. #else
  157. // Standard directly connected LCD implementations
  158. #include <LiquidCrystal.h>
  159. #define LCD_CLASS LiquidCrystal
  160. LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5,LCD_PINS_D6,LCD_PINS_D7); //RS,Enable,D4,D5,D6,D7
  161. #endif
  162. #include "utf_mapper.h"
  163. #if ENABLED(SHOW_BOOTSCREEN)
  164. static void bootscreen();
  165. static bool show_bootscreen = true;
  166. #endif
  167. #if ENABLED(LCD_PROGRESS_BAR)
  168. static millis_t progress_bar_ms = 0;
  169. #if PROGRESS_MSG_EXPIRE > 0
  170. static millis_t expire_status_ms = 0;
  171. #endif
  172. #define LCD_STR_PROGRESS "\x03\x04\x05"
  173. #endif
  174. static void lcd_set_custom_characters(
  175. #if ENABLED(LCD_PROGRESS_BAR)
  176. bool progress_bar_set=true
  177. #endif
  178. ) {
  179. byte bedTemp[8] = {
  180. B00000,
  181. B11111,
  182. B10101,
  183. B10001,
  184. B10101,
  185. B11111,
  186. B00000,
  187. B00000
  188. }; //thanks Sonny Mounicou
  189. byte degree[8] = {
  190. B01100,
  191. B10010,
  192. B10010,
  193. B01100,
  194. B00000,
  195. B00000,
  196. B00000,
  197. B00000
  198. };
  199. byte thermometer[8] = {
  200. B00100,
  201. B01010,
  202. B01010,
  203. B01010,
  204. B01010,
  205. B10001,
  206. B10001,
  207. B01110
  208. };
  209. byte uplevel[8] = {
  210. B00100,
  211. B01110,
  212. B11111,
  213. B00100,
  214. B11100,
  215. B00000,
  216. B00000,
  217. B00000
  218. }; //thanks joris
  219. byte refresh[8] = {
  220. B00000,
  221. B00110,
  222. B11001,
  223. B11000,
  224. B00011,
  225. B10011,
  226. B01100,
  227. B00000,
  228. }; //thanks joris
  229. byte folder[8] = {
  230. B00000,
  231. B11100,
  232. B11111,
  233. B10001,
  234. B10001,
  235. B11111,
  236. B00000,
  237. B00000
  238. }; //thanks joris
  239. byte feedrate[8] = {
  240. B11100,
  241. B10000,
  242. B11000,
  243. B10111,
  244. B00101,
  245. B00110,
  246. B00101,
  247. B00000
  248. }; //thanks Sonny Mounicou
  249. byte clock[8] = {
  250. B00000,
  251. B01110,
  252. B10011,
  253. B10101,
  254. B10001,
  255. B01110,
  256. B00000,
  257. B00000
  258. }; //thanks Sonny Mounicou
  259. #if ENABLED(LCD_PROGRESS_BAR)
  260. static bool char_mode = false;
  261. byte progress[3][8] = { {
  262. B00000,
  263. B10000,
  264. B10000,
  265. B10000,
  266. B10000,
  267. B10000,
  268. B10000,
  269. B00000
  270. }, {
  271. B00000,
  272. B10100,
  273. B10100,
  274. B10100,
  275. B10100,
  276. B10100,
  277. B10100,
  278. B00000
  279. }, {
  280. B00000,
  281. B10101,
  282. B10101,
  283. B10101,
  284. B10101,
  285. B10101,
  286. B10101,
  287. B00000
  288. } };
  289. if (progress_bar_set != char_mode) {
  290. char_mode = progress_bar_set;
  291. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  292. lcd.createChar(LCD_STR_DEGREE[0], degree);
  293. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  294. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  295. lcd.createChar(LCD_STR_CLOCK[0], clock);
  296. if (progress_bar_set) {
  297. // Progress bar characters for info screen
  298. for (int i=3; i--;) lcd.createChar(LCD_STR_PROGRESS[i], progress[i]);
  299. }
  300. else {
  301. // Custom characters for submenus
  302. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  303. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  304. lcd.createChar(LCD_STR_FOLDER[0], folder);
  305. }
  306. }
  307. #else
  308. lcd.createChar(LCD_STR_BEDTEMP[0], bedTemp);
  309. lcd.createChar(LCD_STR_DEGREE[0], degree);
  310. lcd.createChar(LCD_STR_THERMOMETER[0], thermometer);
  311. lcd.createChar(LCD_STR_UPLEVEL[0], uplevel);
  312. lcd.createChar(LCD_STR_REFRESH[0], refresh);
  313. lcd.createChar(LCD_STR_FOLDER[0], folder);
  314. lcd.createChar(LCD_STR_FEEDRATE[0], feedrate);
  315. lcd.createChar(LCD_STR_CLOCK[0], clock);
  316. #endif
  317. }
  318. static void lcd_implementation_init(
  319. #if ENABLED(LCD_PROGRESS_BAR)
  320. bool progress_bar_set=true
  321. #endif
  322. ) {
  323. #if ENABLED(LCD_I2C_TYPE_PCF8575)
  324. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  325. #ifdef LCD_I2C_PIN_BL
  326. lcd.setBacklightPin(LCD_I2C_PIN_BL, POSITIVE);
  327. lcd.setBacklight(HIGH);
  328. #endif
  329. #elif ENABLED(LCD_I2C_TYPE_MCP23017)
  330. lcd.setMCPType(LTI_TYPE_MCP23017);
  331. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  332. lcd.setBacklight(0); //set all the LEDs off to begin with
  333. #elif ENABLED(LCD_I2C_TYPE_MCP23008)
  334. lcd.setMCPType(LTI_TYPE_MCP23008);
  335. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  336. #elif ENABLED(LCD_I2C_TYPE_PCA8574)
  337. lcd.init();
  338. lcd.backlight();
  339. #else
  340. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  341. #endif
  342. #if ENABLED(SHOW_BOOTSCREEN)
  343. if (show_bootscreen) bootscreen();
  344. #endif
  345. lcd_set_custom_characters(
  346. #if ENABLED(LCD_PROGRESS_BAR)
  347. progress_bar_set
  348. #endif
  349. );
  350. lcd.clear();
  351. }
  352. static void lcd_implementation_clear() { lcd.clear(); }
  353. /* Arduino < 1.0.0 is missing a function to print PROGMEM strings, so we need to implement our own */
  354. char lcd_printPGM(const char* str) {
  355. char c, n = 0;
  356. while ((c = pgm_read_byte(str++))) n += charset_mapper(c);
  357. return n;
  358. }
  359. char lcd_print(char* str) {
  360. char c, n = 0;
  361. unsigned char i = 0;
  362. while ((c = str[i++])) n += charset_mapper(c);
  363. return n;
  364. }
  365. unsigned lcd_print(char c) { return charset_mapper(c); }
  366. #if ENABLED(SHOW_BOOTSCREEN)
  367. void lcd_erase_line(int line) {
  368. lcd.setCursor(0, 3);
  369. for (int i=0; i < LCD_WIDTH; i++)
  370. lcd_print(' ');
  371. }
  372. // scrol the PSTR'text' in a 'len' wide field for 'time' milliseconds at position col,line
  373. void lcd_scroll(int col, int line, const char * text, int len, int time) {
  374. char tmp[LCD_WIDTH+1] = {0};
  375. int n = max(lcd_strlen_P(text) - len, 0);
  376. for (int i = 0; i <= n; i++) {
  377. strncpy_P(tmp, text+i, min(len, LCD_WIDTH));
  378. lcd.setCursor(col, line);
  379. lcd_print(tmp);
  380. delay(time / max(n, 1));
  381. }
  382. }
  383. static void bootscreen() {
  384. show_bootscreen = false;
  385. byte top_left[8] = {
  386. B00000,
  387. B00000,
  388. B00000,
  389. B00000,
  390. B00001,
  391. B00010,
  392. B00100,
  393. B00100
  394. };
  395. byte top_right[8] = {
  396. B00000,
  397. B00000,
  398. B00000,
  399. B11100,
  400. B11100,
  401. B01100,
  402. B00100,
  403. B00100
  404. };
  405. byte botom_left[8] = {
  406. B00100,
  407. B00010,
  408. B00001,
  409. B00000,
  410. B00000,
  411. B00000,
  412. B00000,
  413. B00000
  414. };
  415. byte botom_right[8] = {
  416. B00100,
  417. B01000,
  418. B10000,
  419. B00000,
  420. B00000,
  421. B00000,
  422. B00000,
  423. B00000
  424. };
  425. lcd.createChar(0, top_left);
  426. lcd.createChar(1, top_right);
  427. lcd.createChar(2, botom_left);
  428. lcd.createChar(3, botom_right);
  429. lcd.clear();
  430. #define TEXT_SCREEN_LOGO_SHIFT ((LCD_WIDTH/2) - 4)
  431. lcd.setCursor(TEXT_SCREEN_LOGO_SHIFT, 0); lcd.print('\x00'); lcd_printPGM(PSTR( "------" )); lcd.print('\x01');
  432. lcd.setCursor(TEXT_SCREEN_LOGO_SHIFT, 1); lcd_printPGM(PSTR("|Marlin|"));
  433. lcd.setCursor(TEXT_SCREEN_LOGO_SHIFT, 2); lcd.print('\x02'); lcd_printPGM(PSTR( "------" )); lcd.print('\x03');
  434. lcd_scroll(0, 3, PSTR("www.marlinfirmware.org"), LCD_WIDTH, 3000);
  435. #ifdef STRING_SPLASH_LINE1
  436. lcd_erase_line(3);
  437. lcd_scroll(0, 3, PSTR(STRING_SPLASH_LINE1), LCD_WIDTH, 1000);
  438. #endif
  439. #ifdef STRING_SPLASH_LINE2
  440. lcd_erase_line(3);
  441. lcd_scroll(0, 3, PSTR(STRING_SPLASH_LINE2), LCD_WIDTH, 1000);
  442. #endif
  443. }
  444. #endif // SHOW_BOOTSCREEN
  445. /*
  446. Possible status screens:
  447. 16x2 |000/000 B000/000|
  448. |0123456789012345|
  449. 16x4 |000/000 B000/000|
  450. |SD100% Z000.00 |
  451. |F100% T--:--|
  452. |0123456789012345|
  453. 20x2 |T000/000D B000/000D |
  454. |01234567890123456789|
  455. 20x4 |T000/000D B000/000D |
  456. |X000 Y000 Z000.00 |
  457. |F100% SD100% T--:--|
  458. |01234567890123456789|
  459. 20x4 |T000/000D B000/000D |
  460. |T000/000D Z000.00 |
  461. |F100% SD100% T--:--|
  462. |01234567890123456789|
  463. */
  464. static void lcd_implementation_status_screen() {
  465. #define LCD_TEMP_ONLY(T1,T2) \
  466. lcd.print(itostr3(T1 + 0.5)); \
  467. lcd.print('/'); \
  468. lcd.print(itostr3left(T2 + 0.5))
  469. #define LCD_TEMP(T1,T2,PREFIX) \
  470. lcd.print(PREFIX); \
  471. LCD_TEMP_ONLY(T1,T2); \
  472. lcd_printPGM(PSTR(LCD_STR_DEGREE " ")); \
  473. if (T2 < 10) lcd.print(' ')
  474. //
  475. // Line 1
  476. //
  477. lcd.setCursor(0, 0);
  478. #if LCD_WIDTH < 20
  479. //
  480. // Hotend 0 Temperature
  481. //
  482. LCD_TEMP_ONLY(degHotend(0), degTargetHotend(0));
  483. //
  484. // Hotend 1 or Bed Temperature
  485. //
  486. #if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  487. lcd.setCursor(8, 0);
  488. #if EXTRUDERS > 1
  489. lcd.print(LCD_STR_THERMOMETER[0]);
  490. LCD_TEMP_ONLY(degHotend(1), degTargetHotend(1));
  491. #else
  492. lcd.print(LCD_STR_BEDTEMP[0]);
  493. LCD_TEMP_ONLY(degBed(), degTargetBed());
  494. #endif
  495. #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  496. #else // LCD_WIDTH >= 20
  497. //
  498. // Hotend 0 Temperature
  499. //
  500. LCD_TEMP(degHotend(0), degTargetHotend(0), LCD_STR_THERMOMETER[0]);
  501. //
  502. // Hotend 1 or Bed Temperature
  503. //
  504. #if EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  505. lcd.setCursor(10, 0);
  506. #if EXTRUDERS > 1
  507. LCD_TEMP(degHotend(1), degTargetHotend(1), LCD_STR_THERMOMETER[0]);
  508. #else
  509. LCD_TEMP(degBed(), degTargetBed(), LCD_STR_BEDTEMP[0]);
  510. #endif
  511. #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  512. #endif // LCD_WIDTH >= 20
  513. //
  514. // Line 2
  515. //
  516. #if LCD_HEIGHT > 2
  517. #if LCD_WIDTH < 20
  518. #if ENABLED(SDSUPPORT)
  519. lcd.setCursor(0, 2);
  520. lcd_printPGM(PSTR("SD"));
  521. if (IS_SD_PRINTING)
  522. lcd.print(itostr3(card.percentDone()));
  523. else
  524. lcd_printPGM(PSTR("---"));
  525. lcd.print('%');
  526. #endif // SDSUPPORT
  527. #else // LCD_WIDTH >= 20
  528. lcd.setCursor(0, 1);
  529. #if EXTRUDERS > 1 && TEMP_SENSOR_BED != 0
  530. // If we both have a 2nd extruder and a heated bed,
  531. // show the heated bed temp on the left,
  532. // since the first line is filled with extruder temps
  533. LCD_TEMP(degBed(), degTargetBed(), LCD_STR_BEDTEMP[0]);
  534. #else
  535. lcd.print('X');
  536. if (axis_known_position[X_AXIS])
  537. lcd.print(ftostr3(current_position[X_AXIS]));
  538. else
  539. lcd_printPGM(PSTR("---"));
  540. lcd_printPGM(PSTR(" Y"));
  541. if (axis_known_position[Y_AXIS])
  542. lcd.print(ftostr3(current_position[Y_AXIS]));
  543. else
  544. lcd_printPGM(PSTR("---"));
  545. #endif // EXTRUDERS > 1 || TEMP_SENSOR_BED != 0
  546. #endif // LCD_WIDTH >= 20
  547. lcd.setCursor(LCD_WIDTH - 8, 1);
  548. lcd.print('Z');
  549. if (axis_known_position[Z_AXIS])
  550. lcd.print(ftostr32sp(current_position[Z_AXIS] + 0.00001));
  551. else
  552. lcd_printPGM(PSTR("---.--"));
  553. #endif // LCD_HEIGHT > 2
  554. //
  555. // Line 3
  556. //
  557. #if LCD_HEIGHT > 3
  558. lcd.setCursor(0, 2);
  559. lcd.print(LCD_STR_FEEDRATE[0]);
  560. lcd.print(itostr3(feedrate_multiplier));
  561. lcd.print('%');
  562. #if LCD_WIDTH > 19 && ENABLED(SDSUPPORT)
  563. lcd.setCursor(7, 2);
  564. lcd_printPGM(PSTR("SD"));
  565. if (IS_SD_PRINTING)
  566. lcd.print(itostr3(card.percentDone()));
  567. else
  568. lcd_printPGM(PSTR("---"));
  569. lcd.print('%');
  570. #endif // LCD_WIDTH > 19 && SDSUPPORT
  571. lcd.setCursor(LCD_WIDTH - 6, 2);
  572. lcd.print(LCD_STR_CLOCK[0]);
  573. if (print_job_start_ms != 0) {
  574. uint16_t time = millis()/60000 - print_job_start_ms/60000;
  575. lcd.print(itostr2(time/60));
  576. lcd.print(':');
  577. lcd.print(itostr2(time%60));
  578. }
  579. else {
  580. lcd_printPGM(PSTR("--:--"));
  581. }
  582. #endif // LCD_HEIGHT > 3
  583. //
  584. // Last Line
  585. // Status Message (which may be a Progress Bar or Filament display)
  586. //
  587. lcd.setCursor(0, LCD_HEIGHT - 1);
  588. #if ENABLED(LCD_PROGRESS_BAR)
  589. if (card.isFileOpen()) {
  590. // Draw the progress bar if the message has shown long enough
  591. // or if there is no message set.
  592. if (millis() >= progress_bar_ms + PROGRESS_BAR_MSG_TIME || !lcd_status_message[0]) {
  593. int tix = (int)(card.percentDone() * LCD_WIDTH * 3) / 100,
  594. cel = tix / 3, rem = tix % 3, i = LCD_WIDTH;
  595. char msg[LCD_WIDTH+1], b = ' ';
  596. msg[i] = '\0';
  597. while (i--) {
  598. if (i == cel - 1)
  599. b = LCD_STR_PROGRESS[2];
  600. else if (i == cel && rem != 0)
  601. b = LCD_STR_PROGRESS[rem-1];
  602. msg[i] = b;
  603. }
  604. lcd.print(msg);
  605. return;
  606. }
  607. } //card.isFileOpen
  608. #elif ENABLED(FILAMENT_LCD_DISPLAY)
  609. // Show Filament Diameter and Volumetric Multiplier %
  610. // After allowing lcd_status_message to show for 5 seconds
  611. if (millis() >= previous_lcd_status_ms + 5000) {
  612. lcd_printPGM(PSTR("Dia "));
  613. lcd.print(ftostr12ns(filament_width_meas));
  614. lcd_printPGM(PSTR(" V"));
  615. lcd.print(itostr3(100.0*volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]));
  616. lcd.print('%');
  617. return;
  618. }
  619. #endif // FILAMENT_LCD_DISPLAY
  620. lcd_print(lcd_status_message);
  621. }
  622. static void lcd_implementation_drawmenu_generic(bool sel, uint8_t row, const char* pstr, char pre_char, char post_char) {
  623. char c;
  624. uint8_t n = LCD_WIDTH - 2;
  625. lcd.setCursor(0, row);
  626. lcd.print(sel ? pre_char : ' ');
  627. while ((c = pgm_read_byte(pstr)) && n > 0) {
  628. n -= lcd_print(c);
  629. pstr++;
  630. }
  631. while(n--) lcd.print(' ');
  632. lcd.print(post_char);
  633. }
  634. static void lcd_implementation_drawmenu_setting_edit_generic(bool sel, uint8_t row, const char* pstr, char pre_char, char* data) {
  635. char c;
  636. uint8_t n = LCD_WIDTH - 2 - lcd_strlen(data);
  637. lcd.setCursor(0, row);
  638. lcd.print(sel ? pre_char : ' ');
  639. while ((c = pgm_read_byte(pstr)) && n > 0) {
  640. n -= lcd_print(c);
  641. pstr++;
  642. }
  643. lcd.print(':');
  644. while (n--) lcd.print(' ');
  645. lcd_print(data);
  646. }
  647. static void lcd_implementation_drawmenu_setting_edit_generic_P(bool sel, uint8_t row, const char* pstr, char pre_char, const char* data) {
  648. char c;
  649. uint8_t n = LCD_WIDTH - 2 - lcd_strlen_P(data);
  650. lcd.setCursor(0, row);
  651. lcd.print(sel ? pre_char : ' ');
  652. while ((c = pgm_read_byte(pstr)) && n > 0) {
  653. n -= lcd_print(c);
  654. pstr++;
  655. }
  656. lcd.print(':');
  657. while (n--) lcd.print(' ');
  658. lcd_printPGM(data);
  659. }
  660. #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)))
  661. #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)))
  662. #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)))
  663. #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)))
  664. #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)))
  665. #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)))
  666. #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)))
  667. #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)))
  668. #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))
  669. //Add version for callback functions
  670. #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)))
  671. #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)))
  672. #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)))
  673. #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)))
  674. #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)))
  675. #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)))
  676. #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)))
  677. #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)))
  678. #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))
  679. void lcd_implementation_drawedit(const char* pstr, char* value) {
  680. lcd.setCursor(1, 1);
  681. lcd_printPGM(pstr);
  682. lcd.print(':');
  683. lcd.setCursor(LCD_WIDTH - lcd_strlen(value), 1);
  684. lcd_print(value);
  685. }
  686. static void lcd_implementation_drawmenu_sd(bool sel, uint8_t row, const char* pstr, const char* filename, char* longFilename, uint8_t concat, char post_char) {
  687. char c;
  688. uint8_t n = LCD_WIDTH - concat;
  689. lcd.setCursor(0, row);
  690. lcd.print(sel ? '>' : ' ');
  691. if (longFilename[0]) {
  692. filename = longFilename;
  693. longFilename[n] = '\0';
  694. }
  695. while ((c = *filename) && n > 0) {
  696. n -= lcd_print(c);
  697. filename++;
  698. }
  699. while (n--) lcd.print(' ');
  700. lcd.print(post_char);
  701. }
  702. static void lcd_implementation_drawmenu_sdfile(bool sel, uint8_t row, const char* pstr, const char* filename, char* longFilename) {
  703. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
  704. }
  705. static void lcd_implementation_drawmenu_sddirectory(bool sel, uint8_t row, const char* pstr, const char* filename, char* longFilename) {
  706. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
  707. }
  708. #define lcd_implementation_drawmenu_back(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_STR_UPLEVEL[0], LCD_STR_UPLEVEL[0])
  709. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  710. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  711. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  712. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  713. static void lcd_implementation_update_indicators() {
  714. #if ENABLED(LCD_I2C_PANELOLU2) || ENABLED(LCD_I2C_VIKI)
  715. // Set the LEDS - referred to as backlights by the LiquidTWI2 library
  716. static uint8_t ledsprev = 0;
  717. uint8_t leds = 0;
  718. if (target_temperature_bed > 0) leds |= LED_A;
  719. if (target_temperature[0] > 0) leds |= LED_B;
  720. if (fanSpeed) leds |= LED_C;
  721. #if EXTRUDERS > 1
  722. if (target_temperature[1] > 0) leds |= LED_C;
  723. #endif
  724. if (leds != ledsprev) {
  725. lcd.setBacklight(leds);
  726. ledsprev = leds;
  727. }
  728. #endif
  729. }
  730. #endif // LCD_HAS_STATUS_INDICATORS
  731. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  732. extern millis_t next_button_update_ms;
  733. static uint8_t lcd_implementation_read_slow_buttons() {
  734. #if ENABLED(LCD_I2C_TYPE_MCP23017)
  735. uint8_t slow_buttons;
  736. // Reading these buttons this is likely to be too slow to call inside interrupt context
  737. // so they are called during normal lcd_update
  738. slow_buttons = lcd.readButtons() << B_I2C_BTN_OFFSET;
  739. #if ENABLED(LCD_I2C_VIKI)
  740. if ((slow_buttons & (B_MI|B_RI)) && millis() < next_button_update_ms) // LCD clicked
  741. slow_buttons &= ~(B_MI|B_RI); // Disable LCD clicked buttons if screen is updated
  742. #endif
  743. return slow_buttons;
  744. #endif
  745. }
  746. #endif // LCD_HAS_SLOW_BUTTONS
  747. #endif // ULTRALCD_IMPLEMENTATION_HITACHI_HD44780_H