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

ultralcd_HD44780.cpp 46KB

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