My Marlin configs for Fabrikator Mini and CTC i3 Pro B
Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

ultralcd_impl_HD44780.h 31KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087
  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_STR_REFRESH[0], refresh);
  304. createChar_P(LCD_STR_FOLDER[0], folder);
  305. }
  306. }
  307. #else
  308. createChar_P(LCD_UPLEVEL_CHAR, uplevel);
  309. createChar_P(LCD_STR_REFRESH[0], 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 HEATER_IDLE_HANDLER
  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. const uint8_t slen = lcd_strlen(lcd_status_message);
  715. const char *stat = lcd_status_message + status_scroll_pos;
  716. if (slen <= LCD_WIDTH)
  717. lcd_print_utf(stat); // The string isn't scrolling
  718. else {
  719. if (status_scroll_pos <= slen - LCD_WIDTH)
  720. lcd_print_utf(stat); // The string fills the screen
  721. else {
  722. uint8_t chars = LCD_WIDTH;
  723. if (status_scroll_pos < slen) { // First string still visible
  724. lcd_print_utf(stat); // The string leaves space
  725. chars -= slen - status_scroll_pos; // Amount of space left
  726. }
  727. lcd.print('.'); // Always at 1+ spaces left, draw a dot
  728. if (--chars) {
  729. if (status_scroll_pos < slen + 1) // Draw a second dot if there's space
  730. --chars, lcd.print('.');
  731. if (chars) lcd_print_utf(lcd_status_message, chars); // Print a second copy of the message
  732. }
  733. }
  734. if (last_blink != blink) {
  735. last_blink = blink;
  736. // Skip any non-printing bytes
  737. if (status_scroll_pos < slen) while (!PRINTABLE(lcd_status_message[status_scroll_pos])) status_scroll_pos++;
  738. if (++status_scroll_pos >= slen + 2) status_scroll_pos = 0;
  739. }
  740. }
  741. #else
  742. lcd_print_utf(lcd_status_message);
  743. #endif
  744. }
  745. #if ENABLED(ULTIPANEL)
  746. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  747. static void lcd_implementation_hotend_status(const uint8_t row) {
  748. if (row < LCD_HEIGHT) {
  749. lcd.setCursor(LCD_WIDTH - 9, row);
  750. _draw_heater_status(active_extruder, LCD_STR_THERMOMETER[0], lcd_blink());
  751. }
  752. }
  753. #endif // ADVANCED_PAUSE_FEATURE
  754. 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) {
  755. UNUSED(invert);
  756. char c;
  757. int8_t n = LCD_WIDTH;
  758. lcd.setCursor(0, row);
  759. if (center && !valstr) {
  760. int8_t pad = (LCD_WIDTH - lcd_strlen_P(pstr)) / 2;
  761. while (--pad >= 0) { lcd.print(' '); n--; }
  762. }
  763. while (n > 0 && (c = pgm_read_byte(pstr))) {
  764. n -= charset_mapper(c);
  765. pstr++;
  766. }
  767. if (valstr) while (n > 0 && (c = *valstr)) {
  768. n -= charset_mapper(c);
  769. valstr++;
  770. }
  771. while (n-- > 0) lcd.print(' ');
  772. }
  773. static void lcd_implementation_drawmenu_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  774. char c;
  775. uint8_t n = LCD_WIDTH - 2;
  776. lcd.setCursor(0, row);
  777. lcd.print(sel ? pre_char : ' ');
  778. while ((c = pgm_read_byte(pstr)) && n > 0) {
  779. n -= charset_mapper(c);
  780. pstr++;
  781. }
  782. while (n--) lcd.print(' ');
  783. lcd.print(post_char);
  784. }
  785. 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) {
  786. char c;
  787. uint8_t n = LCD_WIDTH - 2 - lcd_strlen(data);
  788. lcd.setCursor(0, row);
  789. lcd.print(sel ? pre_char : ' ');
  790. while ((c = pgm_read_byte(pstr)) && n > 0) {
  791. n -= charset_mapper(c);
  792. pstr++;
  793. }
  794. lcd.print(':');
  795. while (n--) lcd.print(' ');
  796. lcd_print(data);
  797. }
  798. 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) {
  799. char c;
  800. uint8_t n = LCD_WIDTH - 2 - lcd_strlen_P(data);
  801. lcd.setCursor(0, row);
  802. lcd.print(sel ? pre_char : ' ');
  803. while ((c = pgm_read_byte(pstr)) && n > 0) {
  804. n -= charset_mapper(c);
  805. pstr++;
  806. }
  807. lcd.print(':');
  808. while (n--) lcd.print(' ');
  809. lcd_printPGM(data);
  810. }
  811. #define DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(_type, _name, _strFunc) \
  812. inline void lcd_implementation_drawmenu_setting_edit_ ## _name (const bool sel, const uint8_t row, const char* pstr, const char* pstr2, _type * const data, ...) { \
  813. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', _strFunc(*(data))); \
  814. } \
  815. 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, ...) { \
  816. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', _strFunc(*(data))); \
  817. } \
  818. 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), ...) { \
  819. lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', _strFunc(pget())); \
  820. } \
  821. typedef void _name##_void
  822. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(int, int3, itostr3);
  823. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float3, ftostr3);
  824. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float32, ftostr32);
  825. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float43, ftostr43sign);
  826. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float5, ftostr5rj);
  827. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float51, ftostr51sign);
  828. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float52, ftostr52sign);
  829. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(float, float62, ftostr62rj);
  830. DEFINE_LCD_IMPLEMENTATION_DRAWMENU_SETTING_EDIT_TYPE(unsigned long, long5, ftostr5rj);
  831. #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))
  832. #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))
  833. #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))
  834. void lcd_implementation_drawedit(const char* pstr, const char* const value=NULL) {
  835. lcd.setCursor(1, 1);
  836. lcd_printPGM(pstr);
  837. if (value != NULL) {
  838. lcd.print(':');
  839. lcd.setCursor(LCD_WIDTH - lcd_strlen(value), 1);
  840. lcd_print(value);
  841. }
  842. }
  843. #if ENABLED(SDSUPPORT)
  844. 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) {
  845. UNUSED(pstr);
  846. char c;
  847. uint8_t n = LCD_WIDTH - concat;
  848. lcd.setCursor(0, row);
  849. lcd.print(sel ? '>' : ' ');
  850. if (longFilename[0]) {
  851. filename = longFilename;
  852. longFilename[n] = '\0';
  853. }
  854. while ((c = *filename) && n > 0) {
  855. n -= charset_mapper(c);
  856. filename++;
  857. }
  858. while (n--) lcd.print(' ');
  859. lcd.print(post_char);
  860. }
  861. static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
  862. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
  863. }
  864. static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
  865. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
  866. }
  867. #endif // SDSUPPORT
  868. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_UPLEVEL_CHAR, LCD_UPLEVEL_CHAR)
  869. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  870. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  871. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  872. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  873. extern millis_t next_button_update_ms;
  874. static uint8_t lcd_implementation_read_slow_buttons() {
  875. #if ENABLED(LCD_I2C_TYPE_MCP23017)
  876. // Reading these buttons this is likely to be too slow to call inside interrupt context
  877. // so they are called during normal lcd_update
  878. uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
  879. #if ENABLED(LCD_I2C_VIKI)
  880. if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
  881. slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
  882. #endif // LCD_I2C_VIKI
  883. return slow_bits;
  884. #endif // LCD_I2C_TYPE_MCP23017
  885. }
  886. #endif // LCD_HAS_SLOW_BUTTONS
  887. #endif // ULTIPANEL
  888. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  889. static void lcd_implementation_update_indicators() {
  890. // Set the LEDS - referred to as backlights by the LiquidTWI2 library
  891. static uint8_t ledsprev = 0;
  892. uint8_t leds = 0;
  893. if (thermalManager.degTargetBed() > 0) leds |= LED_A;
  894. if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
  895. #if FAN_COUNT > 0
  896. if (0
  897. #if HAS_FAN0
  898. || fanSpeeds[0]
  899. #endif
  900. #if HAS_FAN1
  901. || fanSpeeds[1]
  902. #endif
  903. #if HAS_FAN2
  904. || fanSpeeds[2]
  905. #endif
  906. ) leds |= LED_C;
  907. #endif // FAN_COUNT > 0
  908. #if HOTENDS > 1
  909. if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
  910. #endif
  911. if (leds != ledsprev) {
  912. lcd.setBacklight(leds);
  913. ledsprev = leds;
  914. }
  915. }
  916. #endif // LCD_HAS_STATUS_INDICATORS
  917. #ifdef AUTO_BED_LEVELING_UBL
  918. void lcd_return_to_status(); // These are just place holders for the 20x4 LCD work that
  919. void _lcd_ubl_output_char_lcd() { // is coming up very soon. Soon this will morph into the
  920. lcd_return_to_status(); // real code.
  921. }
  922. #endif // AUTO_BED_LEVELING_UBL
  923. #endif // ULTRALCD_IMPL_HD44780_H