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_impl_HD44780.h 30KB

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