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 49KB

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