My Marlin configs for Fabrikator Mini and CTC i3 Pro B
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ultralcd_HD44780.cpp 47KB

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