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_impl_HD44780.h 45KB

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