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.

marlinui_HD44780.cpp 50KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602
  1. /**
  2. * Marlin 3D Printer Firmware
  3. * Copyright (c) 2020 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 <https://www.gnu.org/licenses/>.
  20. *
  21. */
  22. #include "../../inc/MarlinConfigPre.h"
  23. #if HAS_MARLINUI_HD44780
  24. /**
  25. * marlinui_HD44780.cpp
  26. *
  27. * LCD display implementations for Hitachi HD44780.
  28. * These are the most common LCD character displays.
  29. */
  30. #include "marlinui_HD44780.h"
  31. #include "../marlinui.h"
  32. #include "../../libs/numtostr.h"
  33. #include "../../sd/cardreader.h"
  34. #include "../../module/temperature.h"
  35. #include "../../module/printcounter.h"
  36. #include "../../module/planner.h"
  37. #include "../../module/motion.h"
  38. #if DISABLED(LCD_PROGRESS_BAR) && BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  39. #include "../../feature/filwidth.h"
  40. #include "../../gcode/parser.h"
  41. #endif
  42. #if EITHER(HAS_COOLER, LASER_COOLANT_FLOW_METER)
  43. #include "../../feature/cooler.h"
  44. #endif
  45. #if ENABLED(I2C_AMMETER)
  46. #include "../../feature/ammeter.h"
  47. #endif
  48. #if ENABLED(AUTO_BED_LEVELING_UBL)
  49. #include "../../feature/bedlevel/bedlevel.h"
  50. #endif
  51. //
  52. // Create LCD instance and chipset-specific information
  53. //
  54. #if ENABLED(LCD_I2C_TYPE_PCF8575)
  55. 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);
  56. #elif EITHER(LCD_I2C_TYPE_MCP23017, LCD_I2C_TYPE_MCP23008)
  57. LCD_CLASS lcd(LCD_I2C_ADDRESS OPTARG(DETECT_I2C_LCD_DEVICE, 1));
  58. #elif ENABLED(LCD_I2C_TYPE_PCA8574)
  59. LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
  60. #elif ENABLED(SR_LCD_2W_NL)
  61. // 2 wire Non-latching LCD SR from:
  62. // https://bitbucket.org/fmalpartida/new-liquidcrystal/wiki/schematics#!shiftregister-connection
  63. LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN
  64. #if PIN_EXISTS(SR_STROBE)
  65. , SR_STROBE_PIN
  66. #endif
  67. );
  68. #elif ENABLED(SR_LCD_3W_NL)
  69. // NewLiquidCrystal was not working
  70. // https://github.com/mikeshub/SailfishLCD
  71. // uses the code directly from Sailfish
  72. LCD_CLASS lcd(SR_STROBE_PIN, SR_DATA_PIN, SR_CLK_PIN);
  73. #elif ENABLED(LCM1602)
  74. LCD_CLASS lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
  75. #elif ENABLED(YHCB2004)
  76. LCD_CLASS lcd(YHCB2004_CLK, 20, 4, YHCB2004_MOSI, YHCB2004_MISO); // CLK, cols, rows, MOSI, MISO
  77. #else
  78. // Standard direct-connected LCD implementations
  79. LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5, LCD_PINS_D6, LCD_PINS_D7);
  80. #endif
  81. static void createChar_P(const char c, const byte * const ptr) {
  82. byte temp[8];
  83. LOOP_L_N(i, 8)
  84. temp[i] = pgm_read_byte(&ptr[i]);
  85. lcd.createChar(c, temp);
  86. }
  87. #if ENABLED(LCD_PROGRESS_BAR)
  88. #define LCD_STR_PROGRESS "\x03\x04\x05"
  89. #endif
  90. #if ENABLED(LCD_USE_I2C_BUZZER)
  91. void MarlinUI::buzz(const long duration, const uint16_t freq) {
  92. if (sound_on) lcd.buzz(duration, freq);
  93. }
  94. #endif
  95. void MarlinUI::set_custom_characters(const HD44780CharSet screen_charset/*=CHARSET_INFO*/) {
  96. #if NONE(LCD_PROGRESS_BAR, SHOW_BOOTSCREEN)
  97. UNUSED(screen_charset);
  98. #endif
  99. // CHARSET_BOOT
  100. #if ENABLED(SHOW_BOOTSCREEN)
  101. const static PROGMEM byte corner[4][8] = { {
  102. B00000,
  103. B00000,
  104. B00000,
  105. B00000,
  106. B00001,
  107. B00010,
  108. B00100,
  109. B00100
  110. }, {
  111. B00000,
  112. B00000,
  113. B00000,
  114. B11100,
  115. B11100,
  116. B01100,
  117. B00100,
  118. B00100
  119. }, {
  120. B00100,
  121. B00010,
  122. B00001,
  123. B00000,
  124. B00000,
  125. B00000,
  126. B00000,
  127. B00000
  128. }, {
  129. B00100,
  130. B01000,
  131. B10000,
  132. B00000,
  133. B00000,
  134. B00000,
  135. B00000,
  136. B00000
  137. } };
  138. #endif // SHOW_BOOTSCREEN
  139. // CHARSET_INFO
  140. const static PROGMEM byte bedTemp[8] = {
  141. B00000,
  142. B11111,
  143. B10101,
  144. B10001,
  145. B10101,
  146. B11111,
  147. B00000,
  148. B00000
  149. };
  150. const static PROGMEM byte degree[8] = {
  151. B01100,
  152. B10010,
  153. B10010,
  154. B01100,
  155. B00000,
  156. B00000,
  157. B00000,
  158. B00000
  159. };
  160. const static PROGMEM byte thermometer[8] = {
  161. B00100,
  162. B01010,
  163. B01010,
  164. B01010,
  165. B01010,
  166. B10001,
  167. B10001,
  168. B01110
  169. };
  170. const static PROGMEM byte uplevel[8] = {
  171. B00100,
  172. B01110,
  173. B11111,
  174. B00100,
  175. B11100,
  176. B00000,
  177. B00000,
  178. B00000
  179. };
  180. const static PROGMEM byte feedrate[8] = {
  181. #if LCD_INFO_SCREEN_STYLE == 1
  182. B00000,
  183. B00100,
  184. B10010,
  185. B01001,
  186. B10010,
  187. B00100,
  188. B00000,
  189. B00000
  190. #else
  191. B11100,
  192. B10000,
  193. B11000,
  194. B10111,
  195. B00101,
  196. B00110,
  197. B00101,
  198. B00000
  199. #endif
  200. };
  201. const static PROGMEM byte clock[8] = {
  202. B00000,
  203. B01110,
  204. B10011,
  205. B10101,
  206. B10001,
  207. B01110,
  208. B00000,
  209. B00000
  210. };
  211. #if ENABLED(LCD_PROGRESS_BAR)
  212. // CHARSET_INFO
  213. const static PROGMEM byte progress[3][8] = { {
  214. B00000,
  215. B10000,
  216. B10000,
  217. B10000,
  218. B10000,
  219. B10000,
  220. B10000,
  221. B00000
  222. }, {
  223. B00000,
  224. B10100,
  225. B10100,
  226. B10100,
  227. B10100,
  228. B10100,
  229. B10100,
  230. B00000
  231. }, {
  232. B00000,
  233. B10101,
  234. B10101,
  235. B10101,
  236. B10101,
  237. B10101,
  238. B10101,
  239. B00000
  240. } };
  241. #endif // LCD_PROGRESS_BAR
  242. #if BOTH(SDSUPPORT, HAS_MARLINUI_MENU)
  243. // CHARSET_MENU
  244. const static PROGMEM byte refresh[8] = {
  245. B00000,
  246. B00110,
  247. B11001,
  248. B11000,
  249. B00011,
  250. B10011,
  251. B01100,
  252. B00000,
  253. };
  254. const static PROGMEM byte folder[8] = {
  255. B00000,
  256. B11100,
  257. B11111,
  258. B10001,
  259. B10001,
  260. B11111,
  261. B00000,
  262. B00000
  263. };
  264. #endif // SDSUPPORT
  265. #if ENABLED(SHOW_BOOTSCREEN)
  266. // Set boot screen corner characters
  267. if (screen_charset == CHARSET_BOOT) {
  268. for (uint8_t i = 4; i--;)
  269. createChar_P(i, corner[i]);
  270. }
  271. else
  272. #endif
  273. { // Info Screen uses 5 special characters
  274. createChar_P(LCD_STR_BEDTEMP[0], bedTemp);
  275. createChar_P(LCD_STR_DEGREE[0], degree);
  276. createChar_P(LCD_STR_THERMOMETER[0], thermometer);
  277. createChar_P(LCD_STR_FEEDRATE[0], feedrate);
  278. createChar_P(LCD_STR_CLOCK[0], clock);
  279. #if ENABLED(LCD_PROGRESS_BAR)
  280. if (screen_charset == CHARSET_INFO) { // 3 Progress bar characters for info screen
  281. for (int16_t i = 3; i--;)
  282. createChar_P(LCD_STR_PROGRESS[i], progress[i]);
  283. }
  284. else
  285. #endif
  286. {
  287. createChar_P(LCD_STR_UPLEVEL[0], uplevel);
  288. #if BOTH(SDSUPPORT, HAS_MARLINUI_MENU)
  289. // SD Card sub-menu special characters
  290. createChar_P(LCD_STR_REFRESH[0], refresh);
  291. createChar_P(LCD_STR_FOLDER[0], folder);
  292. #endif
  293. }
  294. }
  295. }
  296. void MarlinUI::init_lcd() {
  297. #if ENABLED(LCD_I2C_TYPE_PCF8575)
  298. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  299. #ifdef LCD_I2C_PIN_BL
  300. lcd.setBacklightPin(LCD_I2C_PIN_BL, POSITIVE);
  301. lcd.setBacklight(HIGH);
  302. #endif
  303. #elif ENABLED(LCD_I2C_TYPE_MCP23017)
  304. lcd.setMCPType(LTI_TYPE_MCP23017);
  305. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  306. update_indicators();
  307. #elif ENABLED(LCD_I2C_TYPE_MCP23008)
  308. lcd.setMCPType(LTI_TYPE_MCP23008);
  309. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  310. #elif ENABLED(LCD_I2C_TYPE_PCA8574)
  311. lcd.init();
  312. lcd.backlight();
  313. #else
  314. lcd.begin(LCD_WIDTH, LCD_HEIGHT);
  315. #endif
  316. set_custom_characters(on_status_screen() ? CHARSET_INFO : CHARSET_MENU);
  317. lcd.clear();
  318. }
  319. bool MarlinUI::detected() {
  320. return TERN1(DETECT_I2C_LCD_DEVICE, lcd.LcdDetected() == 1);
  321. }
  322. #if HAS_SLOW_BUTTONS
  323. uint8_t MarlinUI::read_slow_buttons() {
  324. #if ENABLED(LCD_I2C_TYPE_MCP23017)
  325. // Reading these buttons is too slow for interrupt context
  326. // so they are read during LCD update in the main loop.
  327. uint8_t slow_bits = lcd.readButtons()
  328. #if !BUTTON_EXISTS(ENC)
  329. << B_I2C_BTN_OFFSET
  330. #endif
  331. ;
  332. #if ENABLED(LCD_I2C_VIKI)
  333. if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
  334. slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
  335. #endif
  336. return slow_bits;
  337. #endif // LCD_I2C_TYPE_MCP23017
  338. }
  339. #endif
  340. void MarlinUI::clear_lcd() { lcd.clear(); }
  341. #if ENABLED(SHOW_BOOTSCREEN)
  342. void lcd_erase_line(const lcd_uint_t line) {
  343. lcd_moveto(0, line);
  344. for (uint8_t i = LCD_WIDTH + 1; --i;)
  345. lcd_put_lchar(' ');
  346. }
  347. // Scroll the PSTR 'text' in a 'len' wide field for 'time' milliseconds at position col,line
  348. void lcd_scroll(const lcd_uint_t col, const lcd_uint_t line, FSTR_P const ftxt, const uint8_t len, const int16_t time) {
  349. uint8_t slen = utf8_strlen(ftxt);
  350. if (slen < len) {
  351. lcd_put_u8str_max(col, line, ftxt, len);
  352. for (; slen < len; ++slen) lcd_put_lchar(' ');
  353. safe_delay(time);
  354. }
  355. else {
  356. PGM_P p = FTOP(ftxt);
  357. int dly = time / _MAX(slen, 1);
  358. LOOP_LE_N(i, slen) {
  359. // Print the text at the correct place
  360. lcd_put_u8str_max_P(col, line, p, len);
  361. // Fill with spaces
  362. for (uint8_t ix = slen - i; ix < len; ++ix) lcd_put_lchar(' ');
  363. // Delay
  364. safe_delay(dly);
  365. // Advance to the next UTF8 valid position
  366. p++;
  367. while (!START_OF_UTF8_CHAR(pgm_read_byte(p))) p++;
  368. }
  369. }
  370. }
  371. static void logo_lines(FSTR_P const extra) {
  372. int16_t indent = (LCD_WIDTH - 8 - utf8_strlen(extra)) / 2;
  373. lcd_put_lchar(indent, 0, '\x00'); lcd_put_u8str(F( "------" )); lcd_put_lchar('\x01');
  374. lcd_put_u8str(indent, 1, F("|Marlin|")); lcd_put_u8str(extra);
  375. lcd_put_lchar(indent, 2, '\x02'); lcd_put_u8str(F( "------" )); lcd_put_lchar('\x03');
  376. }
  377. void MarlinUI::show_bootscreen() {
  378. set_custom_characters(CHARSET_BOOT);
  379. lcd.clear();
  380. #define LCD_EXTRA_SPACE (LCD_WIDTH-8)
  381. #define CENTER_OR_SCROLL(STRING,DELAY) { \
  382. lcd_erase_line(3); \
  383. const int len = utf8_strlen(STRING); \
  384. if (len <= LCD_WIDTH) { \
  385. lcd_put_u8str((LCD_WIDTH - len) / 2, 3, F(STRING)); \
  386. safe_delay(DELAY); \
  387. } \
  388. else \
  389. lcd_scroll(0, 3, F(STRING), LCD_WIDTH, DELAY); \
  390. }
  391. //
  392. // Show the Marlin logo with splash line 1
  393. //
  394. if (LCD_EXTRA_SPACE >= utf8_strlen(SHORT_BUILD_VERSION) + 1) {
  395. //
  396. // Show the Marlin logo, splash line1, and splash line 2
  397. //
  398. logo_lines(F(" " SHORT_BUILD_VERSION));
  399. CENTER_OR_SCROLL(MARLIN_WEBSITE_URL, 2000);
  400. }
  401. else {
  402. //
  403. // Show the Marlin logo and short build version
  404. // After a delay show the website URL
  405. //
  406. logo_lines(FPSTR(NUL_STR));
  407. CENTER_OR_SCROLL(SHORT_BUILD_VERSION, 1500);
  408. CENTER_OR_SCROLL(MARLIN_WEBSITE_URL, 1500);
  409. #ifdef STRING_SPLASH_LINE3
  410. CENTER_OR_SCROLL(STRING_SPLASH_LINE3, 1500);
  411. #endif
  412. }
  413. }
  414. void MarlinUI::bootscreen_completion(const millis_t) {
  415. lcd.clear();
  416. safe_delay(100);
  417. set_custom_characters(CHARSET_INFO);
  418. lcd.clear();
  419. }
  420. #endif // SHOW_BOOTSCREEN
  421. void MarlinUI::draw_kill_screen() {
  422. lcd_uint_t x = 0, y = 0;
  423. lcd_put_u8str(x, y, status_message);
  424. y = 2;
  425. #if LCD_HEIGHT >= 4
  426. lcd_put_u8str(x, y++, GET_TEXT_F(MSG_HALTED));
  427. #endif
  428. lcd_put_u8str(x, y, GET_TEXT_F(MSG_PLEASE_RESET));
  429. }
  430. //
  431. // Before homing, blink '123' <-> '???'.
  432. // Homed but unknown... '123' <-> ' '.
  433. // Homed and known, display constantly.
  434. //
  435. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  436. lcd_put_lchar('X' + uint8_t(axis));
  437. if (blink)
  438. lcd_put_u8str(value);
  439. else if (axis_should_home(axis))
  440. while (const char c = *value++) lcd_put_lchar(c <= '.' ? c : '?');
  441. else if (NONE(HOME_AFTER_DEACTIVATE, DISABLE_REDUCED_ACCURACY_WARNING) && !axis_is_trusted(axis))
  442. #ifdef Z_AXIS
  443. lcd_put_u8str(axis == Z_AXIS ? F(" ") : F(" "));
  444. #else
  445. lcd_put_u8str(F(" "));
  446. #endif
  447. else
  448. lcd_put_u8str(value);
  449. }
  450. FORCE_INLINE void _draw_heater_status(const heater_id_t heater_id, const char prefix, const bool blink) {
  451. #if HAS_HEATED_BED
  452. const bool isBed = TERN(HAS_HEATED_CHAMBER, heater_id == H_BED, heater_id < 0);
  453. const celsius_t t1 = (isBed ? thermalManager.wholeDegBed() : thermalManager.wholeDegHotend(heater_id)),
  454. t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater_id));
  455. #else
  456. const celsius_t t1 = thermalManager.wholeDegHotend(heater_id), t2 = thermalManager.degTargetHotend(heater_id);
  457. #endif
  458. if (prefix >= 0) lcd_put_lchar(prefix);
  459. lcd_put_u8str(t1 < 0 ? "err" : i16tostr3rj(t1));
  460. lcd_put_lchar('/');
  461. #if !HEATER_IDLE_HANDLER
  462. UNUSED(blink);
  463. #else
  464. if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
  465. lcd_put_lchar(' ');
  466. if (t2 >= 10) lcd_put_lchar(' ');
  467. if (t2 >= 100) lcd_put_lchar(' ');
  468. }
  469. else
  470. #endif
  471. lcd_put_u8str(i16tostr3left(t2));
  472. if (prefix >= 0) {
  473. lcd_put_lchar(LCD_STR_DEGREE[0]);
  474. lcd_put_lchar(' ');
  475. if (t2 < 10) lcd_put_lchar(' ');
  476. }
  477. }
  478. #if HAS_COOLER
  479. FORCE_INLINE void _draw_cooler_status(const char prefix, const bool blink) {
  480. const celsius_t t2 = thermalManager.degTargetCooler();
  481. if (prefix >= 0) lcd_put_lchar(prefix);
  482. lcd_put_u8str(i16tostr3rj(thermalManager.wholeDegCooler()));
  483. lcd_put_lchar('/');
  484. #if !HEATER_IDLE_HANDLER
  485. UNUSED(blink);
  486. #else
  487. if (!blink && thermalManager.heater_idle[thermalManager.idle_index_for_id(heater_id)].timed_out) {
  488. lcd_put_lchar(' ');
  489. if (t2 >= 10) lcd_put_lchar(' ');
  490. if (t2 >= 100) lcd_put_lchar(' ');
  491. }
  492. else
  493. #endif
  494. lcd_put_u8str(i16tostr3left(t2));
  495. if (prefix >= 0) {
  496. lcd_put_lchar(LCD_STR_DEGREE[0]);
  497. lcd_put_lchar(' ');
  498. if (t2 < 10) lcd_put_lchar(' ');
  499. }
  500. }
  501. #endif
  502. #if ENABLED(LASER_COOLANT_FLOW_METER)
  503. FORCE_INLINE void _draw_flowmeter_status() {
  504. lcd_put_u8str("~");
  505. lcd_put_u8str(ftostr11ns(cooler.flowrate));
  506. lcd_put_lchar('L');
  507. }
  508. #endif
  509. #if ENABLED(I2C_AMMETER)
  510. FORCE_INLINE void _draw_ammeter_status() {
  511. lcd_put_u8str(" ");
  512. ammeter.read();
  513. if (ammeter.current <= 0.999f) {
  514. lcd_put_u8str(ui16tostr3rj(uint16_t(ammeter.current * 1000 + 0.5f)));
  515. lcd_put_u8str("mA");
  516. }
  517. else {
  518. lcd_put_u8str(ftostr12ns(ammeter.current));
  519. lcd_put_lchar('A');
  520. }
  521. }
  522. #endif
  523. FORCE_INLINE void _draw_bed_status(const bool blink) {
  524. _draw_heater_status(H_BED, TERN0(HAS_LEVELING, blink && planner.leveling_active) ? '_' : LCD_STR_BEDTEMP[0], blink);
  525. }
  526. #if ENABLED(LCD_PROGRESS_BAR)
  527. void MarlinUI::draw_progress_bar(const uint8_t percent) {
  528. const int16_t tix = int16_t(percent * (LCD_WIDTH) * 3) / 100,
  529. cel = tix / 3,
  530. rem = tix % 3;
  531. uint8_t i = LCD_WIDTH;
  532. char msg[LCD_WIDTH + 1], b = ' ';
  533. msg[LCD_WIDTH] = '\0';
  534. while (i--) {
  535. if (i == cel - 1)
  536. b = LCD_STR_PROGRESS[2];
  537. else if (i == cel && rem != 0)
  538. b = LCD_STR_PROGRESS[rem - 1];
  539. msg[i] = b;
  540. }
  541. lcd_put_u8str(msg);
  542. }
  543. #endif // LCD_PROGRESS_BAR
  544. void MarlinUI::draw_status_message(const bool blink) {
  545. lcd_moveto(0, LCD_HEIGHT - 1);
  546. #if ENABLED(LCD_PROGRESS_BAR)
  547. // Draw the progress bar if the message has shown long enough
  548. // or if there is no message set.
  549. if (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !has_status()) {
  550. const uint8_t progress = get_progress_percent();
  551. if (progress > 2) return draw_progress_bar(progress);
  552. }
  553. #elif BOTH(FILAMENT_LCD_DISPLAY, SDSUPPORT)
  554. // Alternate Status message and Filament display
  555. if (ELAPSED(millis(), next_filament_display)) {
  556. lcd_put_u8str(F("Dia "));
  557. lcd_put_u8str(ftostr12ns(filwidth.measured_mm));
  558. lcd_put_u8str(F(" V"));
  559. lcd_put_u8str(i16tostr3rj(planner.volumetric_percent(parser.volumetric_enabled)));
  560. lcd_put_lchar('%');
  561. return;
  562. }
  563. #endif // FILAMENT_LCD_DISPLAY && SDSUPPORT
  564. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  565. static bool last_blink = false;
  566. // Get the UTF8 character count of the string
  567. uint8_t slen = utf8_strlen(status_message);
  568. // If the string fits into the LCD, just print it and do not scroll it
  569. if (slen <= LCD_WIDTH) {
  570. // The string isn't scrolling and may not fill the screen
  571. lcd_put_u8str(status_message);
  572. // Fill the rest with spaces
  573. while (slen < LCD_WIDTH) { lcd_put_lchar(' '); ++slen; }
  574. }
  575. else {
  576. // String is larger than the available space in screen.
  577. // Get a pointer to the next valid UTF8 character
  578. // and the string remaining length
  579. uint8_t rlen;
  580. const char *stat = status_and_len(rlen);
  581. lcd_put_u8str_max(stat, LCD_WIDTH); // The string leaves space
  582. // If the remaining string doesn't completely fill the screen
  583. if (rlen < LCD_WIDTH) {
  584. uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
  585. lcd_put_lchar(' '); // Always at 1+ spaces left, draw a space
  586. if (--chars) { // Draw a second space if there's room
  587. lcd_put_lchar(' ');
  588. if (--chars) { // Draw a third space if there's room
  589. lcd_put_lchar(' ');
  590. if (--chars)
  591. lcd_put_u8str_max(status_message, chars); // Print a second copy of the message
  592. }
  593. }
  594. }
  595. if (last_blink != blink) {
  596. last_blink = blink;
  597. advance_status_scroll();
  598. }
  599. }
  600. #else
  601. UNUSED(blink);
  602. // Get the UTF8 character count of the string
  603. uint8_t slen = utf8_strlen(status_message);
  604. // Just print the string to the LCD
  605. lcd_put_u8str_max(status_message, LCD_WIDTH);
  606. // Fill the rest with spaces if there are missing spaces
  607. while (slen < LCD_WIDTH) {
  608. lcd_put_lchar(' ');
  609. ++slen;
  610. }
  611. #endif
  612. }
  613. #if HAS_PRINT_PROGRESS
  614. #define TPOFFSET (LCD_WIDTH - 1)
  615. static uint8_t timepos = TPOFFSET - 6;
  616. static char buffer[14];
  617. static lcd_uint_t pc, pr;
  618. #if ENABLED(SHOW_PROGRESS_PERCENT)
  619. void MarlinUI::drawPercent() {
  620. const uint8_t progress = ui.get_progress_percent();
  621. if (progress) {
  622. lcd_moveto(pc, pr);
  623. lcd_put_u8str(F(TERN(IS_SD_PRINTING, "SD", "P:")));
  624. lcd_put_u8str(TERN(PRINT_PROGRESS_SHOW_DECIMALS, permyriadtostr4(ui.get_progress_permyriad()), ui8tostr3rj(progress)));
  625. lcd_put_lchar('%');
  626. }
  627. }
  628. #endif
  629. #if ENABLED(SHOW_REMAINING_TIME)
  630. void MarlinUI::drawRemain() {
  631. const duration_t remaint = ui.get_remaining_time();
  632. if (printJobOngoing()) {
  633. timepos = TPOFFSET - remaint.toDigital(buffer);
  634. lcd_put_lchar(TERN(LCD_INFO_SCREEN_STYLE, 11, timepos), 2, 'R');
  635. lcd_put_u8str(buffer);
  636. }
  637. }
  638. #endif
  639. #if ENABLED(SHOW_INTERACTION_TIME)
  640. void MarlinUI::drawInter() {
  641. const duration_t interactt = ui.interaction_time;
  642. if (printingIsActive() && interactt.value) {
  643. timepos = TPOFFSET - interactt.toDigital(buffer);
  644. lcd_put_lchar(TERN(LCD_INFO_SCREEN_STYLE, 11, timepos), 2, 'C');
  645. lcd_put_u8str(buffer);
  646. }
  647. }
  648. #endif
  649. #if ENABLED(SHOW_ELAPSED_TIME)
  650. void MarlinUI::drawElapsed() {
  651. const duration_t elapsedt = print_job_timer.duration();
  652. if (printJobOngoing()) {
  653. timepos = TPOFFSET - elapsedt.toDigital(buffer);
  654. lcd_put_lchar(TERN(LCD_INFO_SCREEN_STYLE, 11, timepos), 2, 'E');
  655. //lcd_put_lchar(timepos, 2, LCD_STR_CLOCK[0]);
  656. lcd_put_u8str(buffer);
  657. }
  658. }
  659. #endif
  660. #endif // HAS_PRINT_PROGRESS
  661. /**
  662. * LCD_INFO_SCREEN_STYLE 0 : Classic Status Screen
  663. *
  664. * 16x2 |000/000 B000/000|
  665. * |0123456789012345|
  666. *
  667. * 16x4 |000/000 B000/000|
  668. * |SD---% Z 000.00|
  669. * |F---% T--:--|
  670. * |0123456789012345|
  671. *
  672. * 20x2 |T000/000° B000/000° |
  673. * |01234567890123456789|
  674. *
  675. * 20x4 |T000/000° B000/000° |
  676. * |X 000 Y 000 Z000.000|
  677. * |F---% SD---% T--:--|
  678. * |01234567890123456789|
  679. *
  680. * LCD_INFO_SCREEN_STYLE 1 : Průša-style Status Screen
  681. *
  682. * |T000/000° Z 000.00 |
  683. * |B000/000° F---% |
  684. * |SD---% T--:-- |
  685. * |01234567890123456789|
  686. *
  687. * |T000/000° Z 000.00 |
  688. * |T000/000° F---% |
  689. * |B000/000° SD---% |
  690. * |01234567890123456789|
  691. */
  692. void MarlinUI::draw_status_screen() {
  693. const bool blink = get_blink();
  694. lcd_moveto(0, 0);
  695. #if LCD_INFO_SCREEN_STYLE == 0
  696. // ========== Line 1 ==========
  697. #if LCD_WIDTH < 20
  698. //
  699. // Hotend 0 Temperature
  700. //
  701. #if HAS_HOTEND
  702. _draw_heater_status(H_E0, -1, blink);
  703. //
  704. // Hotend 1 or Bed Temperature
  705. //
  706. #if HAS_MULTI_HOTEND
  707. lcd_moveto(8, 0);
  708. _draw_heater_status(H_E1, LCD_STR_THERMOMETER[0], blink);
  709. #elif HAS_HEATED_BED
  710. lcd_moveto(8, 0);
  711. _draw_bed_status(blink);
  712. #endif
  713. #endif
  714. #else // LCD_WIDTH >= 20
  715. //
  716. // Hotend 0 Temperature
  717. //
  718. #if HAS_HOTEND
  719. _draw_heater_status(H_E0, LCD_STR_THERMOMETER[0], blink);
  720. //
  721. // Hotend 1 or Bed Temperature
  722. //
  723. #if HAS_MULTI_HOTEND
  724. lcd_moveto(10, 0);
  725. _draw_heater_status(H_E1, LCD_STR_THERMOMETER[0], blink);
  726. #elif HAS_HEATED_BED
  727. lcd_moveto(10, 0);
  728. _draw_bed_status(blink);
  729. #endif
  730. #endif
  731. TERN_(HAS_COOLER, _draw_cooler_status('*', blink));
  732. TERN_(LASER_COOLANT_FLOW_METER, _draw_flowmeter_status());
  733. TERN_(I2C_AMMETER, _draw_ammeter_status());
  734. #endif // LCD_WIDTH >= 20
  735. // ========== Line 2 ==========
  736. #if LCD_HEIGHT > 2
  737. #if LCD_WIDTH < 20
  738. #if HAS_PRINT_PROGRESS
  739. pc = 0, pr = 2;
  740. rotate_progress();
  741. #endif
  742. #else // LCD_WIDTH >= 20
  743. lcd_moveto(0, 1);
  744. // If the first line has two extruder temps,
  745. // show more temperatures on the next line
  746. #if HOTENDS > 2 || (HAS_MULTI_HOTEND && HAS_HEATED_BED)
  747. #if HOTENDS > 2
  748. _draw_heater_status(H_E2, LCD_STR_THERMOMETER[0], blink);
  749. lcd_moveto(10, 1);
  750. #endif
  751. _draw_bed_status(blink);
  752. #else // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
  753. #if HAS_DUAL_MIXING
  754. // Two-component mix / gradient instead of XY
  755. char mixer_messages[12];
  756. const char *mix_label;
  757. #if ENABLED(GRADIENT_MIX)
  758. if (mixer.gradient.enabled) {
  759. mixer.update_mix_from_gradient();
  760. mix_label = "Gr";
  761. }
  762. else
  763. #endif
  764. {
  765. mixer.update_mix_from_vtool();
  766. mix_label = "Mx";
  767. }
  768. sprintf_P(mixer_messages, PSTR("%s %d;%d%% "), mix_label, int(mixer.mix[0]), int(mixer.mix[1]));
  769. lcd_put_u8str(mixer_messages);
  770. #else // !HAS_DUAL_MIXING
  771. const bool show_e_total = TERN0(LCD_SHOW_E_TOTAL, printingIsActive());
  772. if (show_e_total) {
  773. #if ENABLED(LCD_SHOW_E_TOTAL)
  774. char tmp[20];
  775. const uint8_t escale = e_move_accumulator >= 100000.0f ? 10 : 1; // After 100m switch to cm
  776. sprintf_P(tmp, PSTR("E %ld%cm "), uint32_t(_MAX(e_move_accumulator, 0.0f)) / escale, escale == 10 ? 'c' : 'm'); // 1234567mm
  777. lcd_put_u8str(tmp);
  778. #endif
  779. }
  780. else {
  781. const xy_pos_t lpos = current_position.asLogical();
  782. _draw_axis_value(X_AXIS, ftostr4sign(lpos.x), blink);
  783. lcd_put_lchar(' ');
  784. _draw_axis_value(Y_AXIS, ftostr4sign(lpos.y), blink);
  785. }
  786. #endif // !HAS_DUAL_MIXING
  787. #endif // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
  788. #endif // LCD_WIDTH >= 20
  789. #ifdef Z_AXIS
  790. lcd_moveto(LCD_WIDTH - 8, 1);
  791. _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink);
  792. #endif
  793. #if HAS_LEVELING && !HAS_HEATED_BED
  794. lcd_put_lchar(planner.leveling_active || blink ? '_' : ' ');
  795. #endif
  796. #endif // LCD_HEIGHT > 2
  797. // ========== Line 3 ==========
  798. #if LCD_HEIGHT > 3
  799. lcd_put_lchar(0, 2, LCD_STR_FEEDRATE[0]);
  800. lcd_put_u8str(i16tostr3rj(feedrate_percentage));
  801. lcd_put_lchar('%');
  802. #if LCD_WIDTH >= 20
  803. #if HAS_PRINT_PROGRESS
  804. pc = timepos - 7, pr = 2;
  805. rotate_progress();
  806. #else
  807. char c;
  808. uint16_t per;
  809. #if HAS_FAN0
  810. if (true
  811. #if EXTRUDERS && ENABLED(ADAPTIVE_FAN_SLOWING)
  812. && (blink || thermalManager.fan_speed_scaler[0] < 128)
  813. #endif
  814. ) {
  815. uint16_t spd = thermalManager.fan_speed[0];
  816. if (blink) c = 'F';
  817. #if ENABLED(ADAPTIVE_FAN_SLOWING)
  818. else { c = '*'; spd = thermalManager.scaledFanSpeed(0, spd); }
  819. #endif
  820. per = thermalManager.pwmToPercent(spd);
  821. }
  822. else
  823. #endif
  824. {
  825. #if HAS_EXTRUDERS
  826. c = 'E';
  827. per = planner.flow_percentage[0];
  828. #endif
  829. }
  830. lcd_put_lchar(c);
  831. lcd_put_u8str(i16tostr3rj(per));
  832. lcd_put_lchar('%');
  833. #endif
  834. #endif
  835. #endif // LCD_HEIGHT > 3
  836. #elif LCD_INFO_SCREEN_STYLE == 1
  837. // ========== Line 1 ==========
  838. //
  839. // Hotend 0 Temperature
  840. //
  841. _draw_heater_status(H_E0, LCD_STR_THERMOMETER[0], blink);
  842. //
  843. // Z Coordinate
  844. //
  845. #ifdef Z_AXIS
  846. lcd_moveto(LCD_WIDTH - 9, 0);
  847. _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position.z)), blink);
  848. #endif
  849. #if HAS_LEVELING && (HAS_MULTI_HOTEND || !HAS_HEATED_BED)
  850. lcd_put_lchar(LCD_WIDTH - 1, 0, planner.leveling_active || blink ? '_' : ' ');
  851. #endif
  852. // ========== Line 2 ==========
  853. //
  854. // Hotend 1 or Bed Temperature
  855. //
  856. lcd_moveto(0, 1);
  857. #if HAS_MULTI_HOTEND
  858. _draw_heater_status(H_E1, LCD_STR_THERMOMETER[0], blink);
  859. #elif HAS_HEATED_BED
  860. _draw_bed_status(blink);
  861. #endif
  862. lcd_put_lchar(LCD_WIDTH - 9, 1, LCD_STR_FEEDRATE[0]);
  863. lcd_put_u8str(i16tostr3rj(feedrate_percentage));
  864. lcd_put_lchar('%');
  865. // ========== Line 3 ==========
  866. //
  867. // Progress percent, Hotend 2, or Bed
  868. //
  869. lcd_moveto(0, 2);
  870. #if HOTENDS > 2
  871. _draw_heater_status(H_E2, LCD_STR_THERMOMETER[0], blink);
  872. #elif HAS_MULTI_HOTEND && HAS_HEATED_BED
  873. _draw_bed_status(blink);
  874. #elif HAS_PRINT_PROGRESS
  875. #define DREW_PRINT_PROGRESS 1
  876. pc = 0, pr = 2;
  877. rotate_progress();
  878. #endif
  879. //
  880. // All progress strings
  881. //
  882. #if HAS_PRINT_PROGRESS && !DREW_PRINT_PROGRESS
  883. pc = LCD_WIDTH - 9, pr = 2;
  884. rotate_progress();
  885. #endif
  886. #endif // LCD_INFO_SCREEN_STYLE 1
  887. // ========= Last Line ========
  888. //
  889. // Status Message (which may be a Progress Bar or Filament display)
  890. //
  891. draw_status_message(blink);
  892. }
  893. #if HAS_MARLINUI_MENU
  894. #include "../menu/menu.h"
  895. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  896. void MarlinUI::draw_hotend_status(const uint8_t row, const uint8_t extruder) {
  897. if (row < LCD_HEIGHT) {
  898. lcd_moveto(LCD_WIDTH - 9, row);
  899. _draw_heater_status((heater_id_t)extruder, LCD_STR_THERMOMETER[0], get_blink());
  900. }
  901. }
  902. #endif // ADVANCED_PAUSE_FEATURE
  903. // Draw a static item with no left-right margin required. Centered by default.
  904. void MenuItem_static::draw(const uint8_t row, FSTR_P const fstr, const uint8_t style/*=SS_DEFAULT*/, const char * const vstr/*=nullptr*/) {
  905. int8_t n = LCD_WIDTH;
  906. lcd_moveto(0, row);
  907. const int8_t plen = fstr ? utf8_strlen(fstr) : 0,
  908. vlen = vstr ? utf8_strlen(vstr) : 0;
  909. if (style & SS_CENTER) {
  910. int8_t pad = (LCD_WIDTH - plen - vlen) / 2;
  911. while (--pad >= 0) { lcd_put_lchar(' '); n--; }
  912. }
  913. if (plen) n = lcd_put_u8str(fstr, itemIndex, itemStringC, itemStringF, n);
  914. if (vlen) n -= lcd_put_u8str_max(vstr, n);
  915. for (; n > 0; --n) lcd_put_lchar(' ');
  916. }
  917. // Draw a generic menu item with pre_char (if selected) and post_char
  918. void MenuItemBase::_draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char pre_char, const char post_char) {
  919. lcd_put_lchar(0, row, sel ? pre_char : ' ');
  920. uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2);
  921. for (; n; --n) lcd_put_lchar(' ');
  922. lcd_put_lchar(post_char);
  923. }
  924. // Draw a menu item with a (potentially) editable value
  925. void MenuEditItemBase::draw(const bool sel, const uint8_t row, FSTR_P const ftpl, const char * const inStr, const bool pgm) {
  926. const uint8_t vlen = inStr ? (pgm ? utf8_strlen_P(inStr) : utf8_strlen(inStr)) : 0;
  927. lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
  928. uint8_t n = lcd_put_u8str(ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 2 - vlen);
  929. if (vlen) {
  930. lcd_put_lchar(':');
  931. for (; n; --n) lcd_put_lchar(' ');
  932. if (pgm) lcd_put_u8str_P(inStr); else lcd_put_u8str(inStr);
  933. }
  934. }
  935. // Low-level draw_edit_screen can be used to draw an edit screen from anyplace
  936. void MenuEditItemBase::draw_edit_screen(FSTR_P const ftpl, const char * const value/*=nullptr*/) {
  937. ui.encoder_direction_normal();
  938. uint8_t n = lcd_put_u8str(0, 1, ftpl, itemIndex, itemStringC, itemStringF, LCD_WIDTH - 1);
  939. if (value) {
  940. lcd_put_lchar(':'); n--;
  941. const uint8_t len = utf8_strlen(value) + 1; // Plus one for a leading space
  942. const lcd_uint_t valrow = n < len ? 2 : 1; // Value on the next row if it won't fit
  943. lcd_put_lchar(LCD_WIDTH - len, valrow, ' '); // Right-justified, padded, leading space
  944. lcd_put_u8str(value);
  945. }
  946. }
  947. // The Select Screen presents a prompt and two "buttons"
  948. void MenuItem_confirm::draw_select_screen(FSTR_P const yes, FSTR_P const no, const bool yesno, FSTR_P const pref, const char * const string/*=nullptr*/, FSTR_P const suff/*=nullptr*/) {
  949. ui.draw_select_screen_prompt(pref, string, suff);
  950. if (no) {
  951. SETCURSOR(0, LCD_HEIGHT - 1);
  952. lcd_put_lchar(yesno ? ' ' : '['); lcd_put_u8str(no); lcd_put_lchar(yesno ? ' ' : ']');
  953. }
  954. if (yes) {
  955. SETCURSOR_RJ(utf8_strlen(yes) + 2, LCD_HEIGHT - 1);
  956. lcd_put_lchar(yesno ? '[' : ' '); lcd_put_u8str(yes); lcd_put_lchar(yesno ? ']' : ' ');
  957. }
  958. }
  959. #if ENABLED(SDSUPPORT)
  960. void MenuItem_sdbase::draw(const bool sel, const uint8_t row, FSTR_P const, CardReader &theCard, const bool isDir) {
  961. lcd_put_lchar(0, row, sel ? LCD_STR_ARROW_RIGHT[0] : ' ');
  962. constexpr uint8_t maxlen = LCD_WIDTH - 2;
  963. uint8_t n = maxlen - lcd_put_u8str_max(ui.scrolled_filename(theCard, maxlen, row, sel), maxlen);
  964. for (; n; --n) lcd_put_lchar(' ');
  965. lcd_put_lchar(isDir ? LCD_STR_FOLDER[0] : ' ');
  966. }
  967. #endif
  968. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  969. void MarlinUI::update_indicators() {
  970. // Set the LEDS - referred to as backlights by the LiquidTWI2 library
  971. static uint8_t ledsprev = 0;
  972. uint8_t leds = 0;
  973. if (TERN0(HAS_HEATED_BED, thermalManager.degTargetBed() > 0)) leds |= LED_A;
  974. if (TERN0(HAS_HOTEND, thermalManager.degTargetHotend(0) > 0)) leds |= LED_B;
  975. #if HAS_FAN
  976. if ( TERN0(HAS_FAN0, thermalManager.fan_speed[0])
  977. || TERN0(HAS_FAN1, thermalManager.fan_speed[1])
  978. || TERN0(HAS_FAN2, thermalManager.fan_speed[2])
  979. || TERN0(HAS_FAN3, thermalManager.fan_speed[3])
  980. || TERN0(HAS_FAN4, thermalManager.fan_speed[4])
  981. || TERN0(HAS_FAN5, thermalManager.fan_speed[5])
  982. || TERN0(HAS_FAN6, thermalManager.fan_speed[6])
  983. || TERN0(HAS_FAN7, thermalManager.fan_speed[7])
  984. ) leds |= LED_C;
  985. #endif // HAS_FAN
  986. if (TERN0(HAS_MULTI_HOTEND, thermalManager.degTargetHotend(1) > 0)) leds |= LED_C;
  987. if (leds != ledsprev) {
  988. lcd.setBacklight(leds);
  989. ledsprev = leds;
  990. }
  991. }
  992. #endif // LCD_HAS_STATUS_INDICATORS
  993. #if ENABLED(AUTO_BED_LEVELING_UBL)
  994. #define HD44780_CHAR_WIDTH 5
  995. #define HD44780_CHAR_HEIGHT 8
  996. #define MESH_MAP_COLS 7
  997. #define MESH_MAP_ROWS 4
  998. #define CHAR_LINE_TOP 0
  999. #define CHAR_LINE_BOT 1
  1000. #define CHAR_EDGE_L 2
  1001. #define CHAR_EDGE_R 3
  1002. #define CHAR_UL_UL 4
  1003. #define CHAR_LR_UL 5
  1004. #define CHAR_UL_LR 6
  1005. #define CHAR_LR_LR 7
  1006. #define TOP_LEFT _BV(0)
  1007. #define TOP_RIGHT _BV(1)
  1008. #define LOWER_LEFT _BV(2)
  1009. #define LOWER_RIGHT _BV(3)
  1010. /**
  1011. * Possible map screens:
  1012. *
  1013. * 16x2 |X000.00 Y000.00|
  1014. * |(00,00) Z00.000|
  1015. *
  1016. * 20x2 | X:000.00 Y:000.00 |
  1017. * | (00,00) Z:00.000 |
  1018. *
  1019. * 16x4 |+-------+(00,00)|
  1020. * || |X000.00|
  1021. * || |Y000.00|
  1022. * |+-------+Z00.000|
  1023. *
  1024. * 20x4 | +-------+ (00,00) |
  1025. * | | | X:000.00|
  1026. * | | | Y:000.00|
  1027. * | +-------+ Z:00.000|
  1028. */
  1029. typedef struct {
  1030. uint8_t custom_char_bits[HD44780_CHAR_HEIGHT];
  1031. } custom_char;
  1032. typedef struct {
  1033. lcd_uint_t column, row,
  1034. x_pixel_offset, y_pixel_offset;
  1035. uint8_t x_pixel_mask;
  1036. } coordinate;
  1037. void add_edges_to_custom_char(custom_char &custom, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cell_location);
  1038. FORCE_INLINE static void clear_custom_char(custom_char * const cc) { ZERO(cc->custom_char_bits); }
  1039. coordinate pixel_location(int16_t x, int16_t y) {
  1040. coordinate ret_val;
  1041. int16_t xp, yp, r, c;
  1042. x++; y++; // +1 because lines on the left and top
  1043. c = x / (HD44780_CHAR_WIDTH);
  1044. r = y / (HD44780_CHAR_HEIGHT);
  1045. ret_val.column = c;
  1046. ret_val.row = r;
  1047. xp = x - c * (HD44780_CHAR_WIDTH); // Get the pixel offsets into the character cell
  1048. xp = HD44780_CHAR_WIDTH - 1 - xp; // Column within relevant character cell (0 on the right)
  1049. yp = y - r * (HD44780_CHAR_HEIGHT);
  1050. ret_val.x_pixel_mask = _BV(xp);
  1051. ret_val.x_pixel_offset = xp;
  1052. ret_val.y_pixel_offset = yp;
  1053. return ret_val;
  1054. }
  1055. inline coordinate pixel_location(const lcd_uint_t x, const lcd_uint_t y) { return pixel_location((int16_t)x, (int16_t)y); }
  1056. void prep_and_put_map_char(custom_char &chrdata, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cl, const char c, const lcd_uint_t x, const lcd_uint_t y) {
  1057. add_edges_to_custom_char(chrdata, ul, lr, brc, cl);
  1058. lcd.createChar(c, (uint8_t*)&chrdata);
  1059. lcd_put_lchar(x, y, c);
  1060. }
  1061. void MarlinUI::ubl_plot(const uint8_t x_plot, const uint8_t y_plot) {
  1062. #if LCD_WIDTH >= 20
  1063. #define _LCD_W_POS 12
  1064. #define _PLOT_X 1
  1065. #define _MAP_X 3
  1066. #define _LABEL(C,X,Y) lcd_put_u8str_P(X, Y, C)
  1067. #define _XLABEL(X,Y) _LABEL(X_LBL,X,Y)
  1068. #define _YLABEL(X,Y) _LABEL(Y_LBL,X,Y)
  1069. #define _ZLABEL(X,Y) _LABEL(Z_LBL,X,Y)
  1070. #else
  1071. #define _LCD_W_POS 8
  1072. #define _PLOT_X 0
  1073. #define _MAP_X 1
  1074. #define _LABEL(X,Y,C) lcd_put_lchar(X, Y, C)
  1075. #define _XLABEL(X,Y) _LABEL('X',X,Y)
  1076. #define _YLABEL(X,Y) _LABEL('Y',X,Y)
  1077. #define _ZLABEL(X,Y) _LABEL('Z',X,Y)
  1078. #endif
  1079. #if LCD_HEIGHT <= 3 // 16x2 or 20x2 display
  1080. /**
  1081. * Show X and Y positions
  1082. */
  1083. _XLABEL(_PLOT_X, 0);
  1084. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
  1085. _YLABEL(_LCD_W_POS, 0);
  1086. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
  1087. lcd_moveto(_PLOT_X, 0);
  1088. #else // 16x4 or 20x4 display
  1089. coordinate upper_left, lower_right, bottom_right_corner;
  1090. custom_char new_char;
  1091. uint8_t i, n, n_rows, n_cols;
  1092. lcd_uint_t j, k, l, m, bottom_line, right_edge,
  1093. x_map_pixels, y_map_pixels,
  1094. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt,
  1095. suppress_x_offset = 0, suppress_y_offset = 0;
  1096. const uint8_t y_plot_inv = (GRID_MAX_POINTS_Y) - 1 - y_plot;
  1097. upper_left.column = 0;
  1098. upper_left.row = 0;
  1099. lower_right.column = 0;
  1100. lower_right.row = 0;
  1101. clear_lcd();
  1102. x_map_pixels = (HD44780_CHAR_WIDTH) * (MESH_MAP_COLS) - 2; // Minus 2 because we are drawing a box around the map
  1103. y_map_pixels = (HD44780_CHAR_HEIGHT) * (MESH_MAP_ROWS) - 2;
  1104. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X);
  1105. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y);
  1106. if (pixels_per_x_mesh_pnt >= HD44780_CHAR_WIDTH) { // There are only 2 custom characters available, so the X
  1107. pixels_per_x_mesh_pnt = HD44780_CHAR_WIDTH; // Size of the mesh point needs to fit within them independent
  1108. suppress_x_offset = 1; // Of where the starting pixel is located.
  1109. }
  1110. if (pixels_per_y_mesh_pnt >= HD44780_CHAR_HEIGHT) { // There are only 2 custom characters available, so the Y
  1111. pixels_per_y_mesh_pnt = HD44780_CHAR_HEIGHT; // Size of the mesh point needs to fit within them independent
  1112. suppress_y_offset = 1; // Of where the starting pixel is located.
  1113. }
  1114. x_map_pixels = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X); // Now we have the right number of pixels to make both
  1115. y_map_pixels = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y); // Directions fit nicely
  1116. right_edge = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X) + 1; // Find location of right edge within the character cell
  1117. bottom_line = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 1; // Find location of bottom line within the character cell
  1118. n_rows = bottom_line / (HD44780_CHAR_HEIGHT) + 1;
  1119. n_cols = right_edge / (HD44780_CHAR_WIDTH) + 1;
  1120. for (i = 0; i < n_cols; i++) {
  1121. lcd_put_lchar(i, 0, CHAR_LINE_TOP); // Box Top line
  1122. lcd_put_lchar(i, n_rows - 1, CHAR_LINE_BOT); // Box Bottom line
  1123. }
  1124. for (j = 0; j < n_rows; j++) {
  1125. lcd_put_lchar(0, j, CHAR_EDGE_L); // Box Left edge
  1126. lcd_put_lchar(n_cols - 1, j, CHAR_EDGE_R); // Box Right edge
  1127. }
  1128. /**
  1129. * If the entire 4th row is not in use, do not put vertical bars all the way down to the bottom of the display
  1130. */
  1131. k = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 2;
  1132. l = (HD44780_CHAR_HEIGHT) * n_rows;
  1133. if (l > k && l - k >= (HD44780_CHAR_HEIGHT) / 2) {
  1134. lcd_put_lchar(0, n_rows - 1, ' '); // Box Left edge
  1135. lcd_put_lchar(n_cols - 1, n_rows - 1, ' '); // Box Right edge
  1136. }
  1137. clear_custom_char(&new_char);
  1138. new_char.custom_char_bits[0] = 0b11111U; // Char #0 is used for the box top line
  1139. lcd.createChar(CHAR_LINE_TOP, (uint8_t*)&new_char);
  1140. clear_custom_char(&new_char);
  1141. k = (GRID_MAX_POINTS_Y) * pixels_per_y_mesh_pnt + 1; // Row of pixels for the bottom box line
  1142. l = k % (HD44780_CHAR_HEIGHT); // Row within relevant character cell
  1143. new_char.custom_char_bits[l] = 0b11111U; // Char #1 is used for the box bottom line
  1144. lcd.createChar(CHAR_LINE_BOT, (uint8_t*)&new_char);
  1145. clear_custom_char(&new_char);
  1146. for (j = 0; j < HD44780_CHAR_HEIGHT; j++)
  1147. new_char.custom_char_bits[j] = 0b10000U; // Char #2 is used for the box left edge
  1148. lcd.createChar(CHAR_EDGE_L, (uint8_t*)&new_char);
  1149. clear_custom_char(&new_char);
  1150. m = (GRID_MAX_POINTS_X) * pixels_per_x_mesh_pnt + 1; // Column of pixels for the right box line
  1151. n = m % (HD44780_CHAR_WIDTH); // Column within relevant character cell
  1152. i = HD44780_CHAR_WIDTH - 1 - n; // Column within relevant character cell (0 on the right)
  1153. for (j = 0; j < HD44780_CHAR_HEIGHT; j++)
  1154. new_char.custom_char_bits[j] = (uint8_t)_BV(i); // Char #3 is used for the box right edge
  1155. lcd.createChar(CHAR_EDGE_R, (uint8_t*)&new_char);
  1156. i = x_plot * pixels_per_x_mesh_pnt - suppress_x_offset;
  1157. j = y_plot_inv * pixels_per_y_mesh_pnt - suppress_y_offset;
  1158. upper_left = pixel_location(i, j);
  1159. k = (x_plot + 1) * pixels_per_x_mesh_pnt - 1 - suppress_x_offset;
  1160. l = (y_plot_inv + 1) * pixels_per_y_mesh_pnt - 1 - suppress_y_offset;
  1161. lower_right = pixel_location(k, l);
  1162. bottom_right_corner = pixel_location(x_map_pixels, y_map_pixels);
  1163. /**
  1164. * First, handle the simple case where everything is within a single character cell.
  1165. * If part of the Mesh Plot is outside of this character cell, we will follow up
  1166. * and deal with that next.
  1167. */
  1168. clear_custom_char(&new_char);
  1169. const lcd_uint_t ypix = _MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, HD44780_CHAR_HEIGHT);
  1170. for (j = upper_left.y_pixel_offset; j < ypix; j++) {
  1171. i = upper_left.x_pixel_mask;
  1172. for (k = 0; k < pixels_per_x_mesh_pnt; k++) {
  1173. new_char.custom_char_bits[j] |= i;
  1174. i >>= 1;
  1175. }
  1176. }
  1177. prep_and_put_map_char(new_char, upper_left, lower_right, bottom_right_corner, TOP_LEFT, CHAR_UL_UL, upper_left.column, upper_left.row);
  1178. /**
  1179. * Next, check for two side by side character cells being used to display the Mesh Point
  1180. * If found... do the right hand character cell next.
  1181. */
  1182. if (upper_left.column == lower_right.column - 1) {
  1183. l = upper_left.x_pixel_offset;
  1184. clear_custom_char(&new_char);
  1185. for (j = upper_left.y_pixel_offset; j < ypix; j++) {
  1186. i = _BV(HD44780_CHAR_WIDTH - 1); // Fill in the left side of the right character cell
  1187. for (k = 0; k < pixels_per_x_mesh_pnt - 1 - l; k++) {
  1188. new_char.custom_char_bits[j] |= i;
  1189. i >>= 1;
  1190. }
  1191. }
  1192. prep_and_put_map_char(new_char, upper_left, lower_right, bottom_right_corner, TOP_RIGHT, CHAR_LR_UL, lower_right.column, upper_left.row);
  1193. }
  1194. /**
  1195. * Next, check for two character cells stacked on top of each other being used to display the Mesh Point
  1196. */
  1197. if (upper_left.row == lower_right.row - 1) {
  1198. l = HD44780_CHAR_HEIGHT - upper_left.y_pixel_offset; // Number of pixel rows in top character cell
  1199. k = pixels_per_y_mesh_pnt - l; // Number of pixel rows in bottom character cell
  1200. clear_custom_char(&new_char);
  1201. for (j = 0; j < k; j++) {
  1202. i = upper_left.x_pixel_mask;
  1203. for (m = 0; m < pixels_per_x_mesh_pnt; m++) { // Fill in the top side of the bottom character cell
  1204. new_char.custom_char_bits[j] |= i;
  1205. if (!(i >>= 1)) break;
  1206. }
  1207. }
  1208. prep_and_put_map_char(new_char, upper_left, lower_right, bottom_right_corner, LOWER_LEFT, CHAR_UL_LR, upper_left.column, lower_right.row);
  1209. }
  1210. /**
  1211. * Next, check for four character cells being used to display the Mesh Point. If that is
  1212. * what is here, we work to fill in the character cell that is down one and to the right one
  1213. * from the upper_left character cell.
  1214. */
  1215. if (upper_left.column == lower_right.column - 1 && upper_left.row == lower_right.row - 1) {
  1216. l = HD44780_CHAR_HEIGHT - upper_left.y_pixel_offset; // Number of pixel rows in top character cell
  1217. k = pixels_per_y_mesh_pnt - l; // Number of pixel rows in bottom character cell
  1218. clear_custom_char(&new_char);
  1219. for (j = 0; j < k; j++) {
  1220. l = upper_left.x_pixel_offset;
  1221. i = _BV(HD44780_CHAR_WIDTH - 1); // Fill in the left side of the right character cell
  1222. for (m = 0; m < pixels_per_x_mesh_pnt - 1 - l; m++) { // Fill in the top side of the bottom character cell
  1223. new_char.custom_char_bits[j] |= i;
  1224. i >>= 1;
  1225. }
  1226. }
  1227. prep_and_put_map_char(new_char, upper_left, lower_right, bottom_right_corner, LOWER_RIGHT, CHAR_LR_LR, lower_right.column, lower_right.row);
  1228. }
  1229. #endif
  1230. /**
  1231. * Print plot position
  1232. */
  1233. lcd_put_lchar(_LCD_W_POS, 0, '(');
  1234. lcd_put_u8str(ui8tostr3rj(x_plot));
  1235. lcd_put_lchar(',');
  1236. lcd_put_u8str(ui8tostr3rj(y_plot));
  1237. lcd_put_lchar(')');
  1238. #if LCD_HEIGHT <= 3 // 16x2 or 20x2 display
  1239. /**
  1240. * Print Z values
  1241. */
  1242. _ZLABEL(_LCD_W_POS, 1);
  1243. if (!isnan(bedlevel.z_values[x_plot][y_plot]))
  1244. lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
  1245. else
  1246. lcd_put_u8str(F(" -----"));
  1247. #else // 16x4 or 20x4 display
  1248. /**
  1249. * Show all values at right of screen
  1250. */
  1251. _XLABEL(_LCD_W_POS, 1);
  1252. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(bedlevel.get_mesh_x(x_plot))));
  1253. _YLABEL(_LCD_W_POS, 2);
  1254. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(bedlevel.get_mesh_y(y_plot))));
  1255. /**
  1256. * Show the location value
  1257. */
  1258. _ZLABEL(_LCD_W_POS, 3);
  1259. if (!isnan(bedlevel.z_values[x_plot][y_plot]))
  1260. lcd_put_u8str(ftostr43sign(bedlevel.z_values[x_plot][y_plot]));
  1261. else
  1262. lcd_put_u8str(F(" -----"));
  1263. #endif // LCD_HEIGHT > 3
  1264. }
  1265. void add_edges_to_custom_char(custom_char &custom, const coordinate &ul, const coordinate &lr, const coordinate &brc, const uint8_t cell_location) {
  1266. uint8_t i, k;
  1267. int16_t n_rows = lr.row - ul.row + 1,
  1268. n_cols = lr.column - ul.column + 1;
  1269. /**
  1270. * Check if Top line of box needs to be filled in
  1271. */
  1272. if (ul.row == 0 && (cell_location & (TOP_LEFT|TOP_RIGHT))) { // Only fill in the top line for the top character cells
  1273. if (n_cols == 1) {
  1274. if (ul.column != brc.column)
  1275. custom.custom_char_bits[0] = 0xFF; // Single column in middle
  1276. else
  1277. for (i = brc.x_pixel_offset; i < HD44780_CHAR_WIDTH; i++) // Single column on right side
  1278. SBI(custom.custom_char_bits[0], i);
  1279. }
  1280. else if ((cell_location & TOP_LEFT) || lr.column != brc.column) // Multiple column in the middle or with right cell in middle
  1281. custom.custom_char_bits[0] = 0xFF;
  1282. else
  1283. for (i = brc.x_pixel_offset; i < HD44780_CHAR_WIDTH; i++)
  1284. SBI(custom.custom_char_bits[0], i);
  1285. }
  1286. /**
  1287. * Check if left line of box needs to be filled in
  1288. */
  1289. if (cell_location & (TOP_LEFT|LOWER_LEFT)) {
  1290. if (ul.column == 0) { // Left column of characters on LCD Display
  1291. k = ul.row == brc.row ? brc.y_pixel_offset : HD44780_CHAR_HEIGHT; // If it isn't the last row... do the full character cell
  1292. for (i = 0; i < k; i++)
  1293. SBI(custom.custom_char_bits[i], HD44780_CHAR_WIDTH - 1);
  1294. }
  1295. }
  1296. /**
  1297. * Check if bottom line of box needs to be filled in
  1298. */
  1299. // Single row of mesh plot cells
  1300. if (n_rows == 1 /* && (cell_location & (TOP_LEFT|TOP_RIGHT)) */ && ul.row == brc.row) {
  1301. if (n_cols == 1) // Single row, single column case
  1302. k = ul.column == brc.column ? brc.x_pixel_mask : 0x01;
  1303. else if (cell_location & TOP_RIGHT) // Single row, multiple column case
  1304. k = lr.column == brc.column ? brc.x_pixel_mask : 0x01;
  1305. else // Single row, left of multiple columns
  1306. k = 0x01;
  1307. while (k < _BV(HD44780_CHAR_WIDTH)) {
  1308. custom.custom_char_bits[brc.y_pixel_offset] |= k;
  1309. k <<= 1;
  1310. }
  1311. }
  1312. // Double row of characters on LCD Display
  1313. // And this is a bottom custom character
  1314. if (n_rows == 2 && (cell_location & (LOWER_LEFT|LOWER_RIGHT)) && lr.row == brc.row) {
  1315. if (n_cols == 1) // Double row, single column case
  1316. k = ul.column == brc.column ? brc.x_pixel_mask : 0x01;
  1317. else if (cell_location & LOWER_RIGHT) // Double row, multiple column case
  1318. k = lr.column == brc.column ? brc.x_pixel_mask : 0x01;
  1319. else // Double row, left of multiple columns
  1320. k = 0x01;
  1321. while (k < _BV(HD44780_CHAR_WIDTH)) {
  1322. custom.custom_char_bits[brc.y_pixel_offset] |= k;
  1323. k <<= 1;
  1324. }
  1325. }
  1326. /**
  1327. * Check if right line of box needs to be filled in
  1328. */
  1329. // Nothing to do if the lower right part of the mesh pnt isn't in the same column as the box line
  1330. if (lr.column == brc.column) {
  1331. // This mesh point is in the same character cell as the right box line
  1332. if (ul.column == brc.column || (cell_location & (TOP_RIGHT|LOWER_RIGHT))) {
  1333. // If not the last row... do the full character cell
  1334. k = ul.row == brc.row ? brc.y_pixel_offset : HD44780_CHAR_HEIGHT;
  1335. for (i = 0; i < k; i++) custom.custom_char_bits[i] |= brc.x_pixel_mask;
  1336. }
  1337. }
  1338. }
  1339. #endif // AUTO_BED_LEVELING_UBL
  1340. #endif // HAS_MARLINUI_MENU
  1341. #endif // HAS_MARLINUI_HD44780