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

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