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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472
  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 uint8_t col, const uint8_t line, const char* const text, const uint8_t len, const int16_t time) {
  309. uint8_t slen = utf8_strlen_P(text);
  310. if (slen < len) {
  311. // Fits into,
  312. lcd_moveto(col, line);
  313. lcd_put_u8str_max_P(text, len);
  314. while (slen < len) {
  315. lcd_put_wchar(' ');
  316. ++slen;
  317. }
  318. safe_delay(time);
  319. }
  320. else {
  321. const char* p = text;
  322. int dly = time / MAX(slen, 1);
  323. for (uint8_t i = 0; i <= slen; i++) {
  324. // Go to the correct place
  325. lcd_moveto(col, line);
  326. // Print the text
  327. lcd_put_u8str_max_P(p, len);
  328. // Fill with spaces
  329. uint8_t ix = slen - i;
  330. while (ix < len) {
  331. lcd_put_wchar(' ');
  332. ++ix;
  333. }
  334. // Delay
  335. safe_delay(dly);
  336. // Advance to the next UTF8 valid position
  337. p++;
  338. while (!START_OF_UTF8_CHAR(pgm_read_byte(p))) p++;
  339. }
  340. }
  341. }
  342. static void logo_lines(const char* const extra) {
  343. int16_t indent = (LCD_WIDTH - 8 - utf8_strlen_P(extra)) / 2;
  344. lcd_moveto(indent, 0); lcd_put_wchar('\x00'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x01');
  345. lcd_moveto(indent, 1); lcd_put_u8str_P(PSTR("|Marlin|")); lcd_put_u8str_P(extra);
  346. lcd_moveto(indent, 2); lcd_put_wchar('\x02'); lcd_put_u8str_P(PSTR( "------" )); lcd_put_wchar('\x03');
  347. }
  348. void lcd_bootscreen() {
  349. lcd_set_custom_characters(CHARSET_BOOT);
  350. lcd.clear();
  351. #define LCD_EXTRA_SPACE (LCD_WIDTH-8)
  352. #define CENTER_OR_SCROLL(STRING,DELAY) \
  353. lcd_erase_line(3); \
  354. if (utf8_strlen(STRING) <= LCD_WIDTH) { \
  355. lcd_moveto((LCD_WIDTH - utf8_strlen_P(PSTR(STRING))) / 2, 3); \
  356. lcd_put_u8str_P(PSTR(STRING)); \
  357. safe_delay(DELAY); \
  358. } \
  359. else { \
  360. lcd_scroll(0, 3, PSTR(STRING), LCD_WIDTH, DELAY); \
  361. }
  362. #ifdef STRING_SPLASH_LINE1
  363. //
  364. // Show the Marlin logo with splash line 1
  365. //
  366. if (LCD_EXTRA_SPACE >= utf8_strlen(STRING_SPLASH_LINE1) + 1) {
  367. //
  368. // Show the Marlin logo, splash line1, and splash line 2
  369. //
  370. logo_lines(PSTR(" " STRING_SPLASH_LINE1));
  371. #ifdef STRING_SPLASH_LINE2
  372. CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 2000);
  373. #else
  374. safe_delay(2000);
  375. #endif
  376. }
  377. else {
  378. //
  379. // Show the Marlin logo with splash line 1
  380. // After a delay show splash line 2, if it exists
  381. //
  382. #ifdef STRING_SPLASH_LINE2
  383. #define _SPLASH_WAIT_1 1500
  384. #else
  385. #define _SPLASH_WAIT_1 2000
  386. #endif
  387. logo_lines(PSTR(""));
  388. CENTER_OR_SCROLL(STRING_SPLASH_LINE1, _SPLASH_WAIT_1);
  389. #ifdef STRING_SPLASH_LINE2
  390. CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 1500);
  391. #endif
  392. }
  393. #elif defined(STRING_SPLASH_LINE2)
  394. //
  395. // Show splash line 2 only, alongside the logo if possible
  396. //
  397. if (LCD_EXTRA_SPACE >= utf8_strlen(STRING_SPLASH_LINE2) + 1) {
  398. logo_lines(PSTR(" " STRING_SPLASH_LINE2));
  399. safe_delay(2000);
  400. }
  401. else {
  402. logo_lines(PSTR(""));
  403. CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 2000);
  404. }
  405. #else
  406. //
  407. // Show only the Marlin logo
  408. //
  409. logo_lines(PSTR(""));
  410. safe_delay(2000);
  411. #endif
  412. lcd.clear();
  413. safe_delay(100);
  414. lcd_set_custom_characters();
  415. lcd.clear();
  416. }
  417. #endif // SHOW_BOOTSCREEN
  418. void lcd_kill_screen() {
  419. lcd_moveto(0, 0);
  420. lcd_put_u8str(lcd_status_message);
  421. #if LCD_HEIGHT < 4
  422. lcd_moveto(0, 2);
  423. #else
  424. lcd_moveto(0, 2);
  425. lcd_put_u8str_P(PSTR(MSG_HALTED));
  426. lcd_moveto(0, 3);
  427. #endif
  428. lcd_put_u8str_P(PSTR(MSG_PLEASE_RESET));
  429. }
  430. //
  431. // Before homing, blink '123' <-> '???'.
  432. // Homed but unknown... '123' <-> ' '.
  433. // Homed and known, display constantly.
  434. //
  435. FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
  436. lcd_put_wchar('X' + uint8_t(axis));
  437. if (blink)
  438. lcd_put_u8str(value);
  439. else {
  440. if (!axis_homed[axis])
  441. while (const char c = *value++) lcd_put_wchar(c <= '.' ? c : '?');
  442. else {
  443. #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
  444. if (!axis_known_position[axis])
  445. lcd_put_u8str_P(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
  446. else
  447. #endif
  448. lcd_put_u8str(value);
  449. }
  450. }
  451. }
  452. FORCE_INLINE void _draw_heater_status(const int8_t heater, const char prefix, const bool blink) {
  453. #if HAS_HEATED_BED
  454. const bool isBed = heater < 0;
  455. const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)),
  456. t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater));
  457. #else
  458. const float t1 = thermalManager.degHotend(heater), t2 = thermalManager.degTargetHotend(heater);
  459. #endif
  460. if (prefix >= 0) lcd_put_wchar(prefix);
  461. lcd_put_u8str(itostr3(t1 + 0.5));
  462. lcd_put_wchar('/');
  463. #if !HEATER_IDLE_HANDLER
  464. UNUSED(blink);
  465. #else
  466. const bool is_idle = (
  467. #if HAS_HEATED_BED
  468. isBed ? thermalManager.is_bed_idle() :
  469. #endif
  470. thermalManager.is_heater_idle(heater)
  471. );
  472. if (!blink && is_idle) {
  473. lcd_put_wchar(' ');
  474. if (t2 >= 10) lcd_put_wchar(' ');
  475. if (t2 >= 100) lcd_put_wchar(' ');
  476. }
  477. else
  478. #endif
  479. lcd_put_u8str(itostr3left(t2 + 0.5));
  480. if (prefix >= 0) {
  481. lcd_put_wchar(LCD_DEGREE_CHAR);
  482. lcd_put_wchar(' ');
  483. if (t2 < 10) lcd_put_wchar(' ');
  484. }
  485. }
  486. #if ENABLED(LCD_PROGRESS_BAR)
  487. inline void lcd_draw_progress_bar(const uint8_t percent) {
  488. const int16_t tix = (int16_t)(percent * (LCD_WIDTH) * 3) / 100,
  489. cel = tix / 3,
  490. rem = tix % 3;
  491. uint8_t i = LCD_WIDTH;
  492. char msg[LCD_WIDTH + 1], b = ' ';
  493. msg[LCD_WIDTH] = '\0';
  494. while (i--) {
  495. if (i == cel - 1)
  496. b = LCD_STR_PROGRESS[2];
  497. else if (i == cel && rem != 0)
  498. b = LCD_STR_PROGRESS[rem - 1];
  499. msg[i] = b;
  500. }
  501. lcd_put_u8str(msg);
  502. }
  503. #endif // LCD_PROGRESS_BAR
  504. /**
  505. Possible status screens:
  506. 16x2 |000/000 B000/000|
  507. |0123456789012345|
  508. 16x4 |000/000 B000/000|
  509. |SD100% Z 000.00|
  510. |F100% T--:--|
  511. |0123456789012345|
  512. 20x2 |T000/000D B000/000D |
  513. |01234567890123456789|
  514. 20x4 |T000/000D B000/000D |
  515. |X 000 Y 000 Z 000.00|
  516. |F100% SD100% T--:--|
  517. |01234567890123456789|
  518. 20x4 |T000/000D B000/000D |
  519. |T000/000D Z 000.00|
  520. |F100% SD100% T--:--|
  521. |01234567890123456789|
  522. */
  523. static void lcd_implementation_status_screen() {
  524. const bool blink = lcd_blink();
  525. //
  526. // Line 1
  527. //
  528. lcd_moveto(0, 0);
  529. #if LCD_WIDTH < 20
  530. //
  531. // Hotend 0 Temperature
  532. //
  533. _draw_heater_status(0, -1, blink);
  534. //
  535. // Hotend 1 or Bed Temperature
  536. //
  537. #if HOTENDS > 1 || HAS_HEATED_BED
  538. lcd_moveto(8, 0);
  539. #if HOTENDS > 1
  540. lcd_put_wchar((char)LCD_STR_THERMOMETER[0]);
  541. _draw_heater_status(1, -1, blink);
  542. #else
  543. lcd_put_wchar((char)LCD_BEDTEMP_CHAR);
  544. _draw_heater_status(-1, -1, blink);
  545. #endif
  546. #endif // HOTENDS > 1 || HAS_HEATED_BED
  547. #else // LCD_WIDTH >= 20
  548. //
  549. // Hotend 0 Temperature
  550. //
  551. _draw_heater_status(0, LCD_STR_THERMOMETER[0], blink);
  552. //
  553. // Hotend 1 or Bed Temperature
  554. //
  555. #if HOTENDS > 1 || HAS_HEATED_BED
  556. lcd_moveto(10, 0);
  557. #if HOTENDS > 1
  558. _draw_heater_status(1, LCD_STR_THERMOMETER[0], blink);
  559. #else
  560. _draw_heater_status(-1, (
  561. #if HAS_LEVELING
  562. planner.leveling_active && blink ? '_' :
  563. #endif
  564. LCD_BEDTEMP_CHAR
  565. ), blink);
  566. #endif
  567. #endif // HOTENDS > 1 || HAS_HEATED_BED
  568. #endif // LCD_WIDTH >= 20
  569. //
  570. // Line 2
  571. //
  572. #if LCD_HEIGHT > 2
  573. #if LCD_WIDTH < 20
  574. #if ENABLED(SDSUPPORT)
  575. lcd_moveto(0, 2);
  576. lcd_put_u8str_P(PSTR("SD"));
  577. if (IS_SD_PRINTING)
  578. lcd_put_u8str(itostr3(card.percentDone()));
  579. else
  580. lcd_put_u8str_P(PSTR("---"));
  581. lcd_put_wchar('%');
  582. #endif // SDSUPPORT
  583. #else // LCD_WIDTH >= 20
  584. lcd_moveto(0, 1);
  585. // If the first line has two extruder temps,
  586. // show more temperatures on the next line
  587. #if HOTENDS > 2 || (HOTENDS > 1 && HAS_HEATED_BED)
  588. #if HOTENDS > 2
  589. _draw_heater_status(2, LCD_STR_THERMOMETER[0], blink);
  590. lcd_moveto(10, 1);
  591. #endif
  592. _draw_heater_status(-1, (
  593. #if HAS_LEVELING
  594. planner.leveling_active && blink ? '_' :
  595. #endif
  596. LCD_BEDTEMP_CHAR
  597. ), blink);
  598. #else // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
  599. _draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])), blink);
  600. lcd_put_wchar(' ');
  601. _draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])), blink);
  602. #endif // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
  603. #endif // LCD_WIDTH >= 20
  604. lcd_moveto(LCD_WIDTH - 8, 1);
  605. _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])), blink);
  606. #if HAS_LEVELING && !HAS_HEATED_BED
  607. lcd_put_wchar(planner.leveling_active || blink ? '_' : ' ');
  608. #endif
  609. #endif // LCD_HEIGHT > 2
  610. //
  611. // Line 3
  612. //
  613. #if LCD_HEIGHT > 3
  614. lcd_moveto(0, 2);
  615. lcd_put_wchar(LCD_FEEDRATE_CHAR);
  616. lcd_put_u8str(itostr3(feedrate_percentage));
  617. lcd_put_wchar('%');
  618. #if LCD_WIDTH >= 20 && ENABLED(SDSUPPORT)
  619. lcd_moveto(7, 2);
  620. lcd_put_u8str_P(PSTR("SD"));
  621. if (IS_SD_PRINTING)
  622. lcd_put_u8str(itostr3(card.percentDone()));
  623. else
  624. lcd_put_u8str_P(PSTR("---"));
  625. lcd_put_wchar('%');
  626. #endif // LCD_WIDTH >= 20 && SDSUPPORT
  627. char buffer[10];
  628. duration_t elapsed = print_job_timer.duration();
  629. uint8_t len = elapsed.toDigital(buffer);
  630. lcd_moveto(LCD_WIDTH - len - 1, 2);
  631. lcd_put_wchar(LCD_CLOCK_CHAR);
  632. lcd_put_u8str(buffer);
  633. #endif // LCD_HEIGHT > 3
  634. //
  635. // Last Line
  636. // Status Message (which may be a Progress Bar or Filament display)
  637. //
  638. lcd_moveto(0, LCD_HEIGHT - 1);
  639. #if ENABLED(LCD_PROGRESS_BAR)
  640. // Draw the progress bar if the message has shown long enough
  641. // or if there is no message set.
  642. #if DISABLED(LCD_SET_PROGRESS_MANUALLY)
  643. const uint8_t progress_bar_percent = card.percentDone();
  644. #endif
  645. if (progress_bar_percent > 2 && (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !lcd_status_message[0]))
  646. return lcd_draw_progress_bar(progress_bar_percent);
  647. #elif ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
  648. // Show Filament Diameter and Volumetric Multiplier %
  649. // After allowing lcd_status_message to show for 5 seconds
  650. if (ELAPSED(millis(), previous_lcd_status_ms + 5000UL)) {
  651. lcd_put_u8str_P(PSTR("Dia "));
  652. lcd_put_u8str(ftostr12ns(filament_width_meas));
  653. lcd_put_u8str_P(PSTR(" V"));
  654. lcd_put_u8str(itostr3(100.0 * (
  655. parser.volumetric_enabled
  656. ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  657. : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
  658. )
  659. ));
  660. lcd_put_wchar('%');
  661. return;
  662. }
  663. #endif // FILAMENT_LCD_DISPLAY && SDSUPPORT
  664. #if ENABLED(STATUS_MESSAGE_SCROLLING)
  665. static bool last_blink = false;
  666. // Get the UTF8 character count of the string
  667. uint8_t slen = utf8_strlen(lcd_status_message);
  668. // If the string fits into the LCD, just print it and do not scroll it
  669. if (slen <= LCD_WIDTH) {
  670. // The string isn't scrolling and may not fill the screen
  671. lcd_put_u8str(lcd_status_message);
  672. // Fill the rest with spaces
  673. while (slen < LCD_WIDTH) {
  674. lcd_put_wchar(' ');
  675. ++slen;
  676. }
  677. }
  678. else {
  679. // String is larger than the available space in screen.
  680. // Get a pointer to the next valid UTF8 character
  681. const char *stat = lcd_status_message + status_scroll_offset;
  682. // Get the string remaining length
  683. const uint8_t rlen = utf8_strlen(stat);
  684. // If we have enough characters to display
  685. if (rlen >= LCD_WIDTH) {
  686. // The remaining string fills the screen - Print it
  687. lcd_put_u8str_max(stat, LCD_WIDTH);
  688. }
  689. else {
  690. // The remaining string does not completely fill the screen
  691. lcd_put_u8str_max(stat, LCD_WIDTH); // The string leaves space
  692. uint8_t chars = LCD_WIDTH - rlen; // Amount of space left in characters
  693. lcd_put_wchar('.'); // Always at 1+ spaces left, draw a dot
  694. if (--chars) { // Draw a second dot if there's space
  695. lcd_put_wchar('.');
  696. if (--chars)
  697. lcd_put_u8str_max(lcd_status_message, chars); // Print a second copy of the message
  698. }
  699. }
  700. if (last_blink != blink) {
  701. last_blink = blink;
  702. // Adjust by complete UTF8 characters
  703. if (status_scroll_offset < slen) {
  704. status_scroll_offset++;
  705. while (!START_OF_UTF8_CHAR(lcd_status_message[status_scroll_offset]))
  706. status_scroll_offset++;
  707. }
  708. else
  709. status_scroll_offset = 0;
  710. }
  711. }
  712. #else
  713. UNUSED(blink);
  714. // Get the UTF8 character count of the string
  715. uint8_t slen = utf8_strlen(lcd_status_message);
  716. // Just print the string to the LCD
  717. lcd_put_u8str_max(lcd_status_message, LCD_WIDTH);
  718. // Fill the rest with spaces if there are missing spaces
  719. while (slen < LCD_WIDTH) {
  720. lcd_put_wchar(' ');
  721. ++slen;
  722. }
  723. #endif
  724. }
  725. #if ENABLED(ULTIPANEL)
  726. #if ENABLED(ADVANCED_PAUSE_FEATURE)
  727. static void lcd_implementation_hotend_status(const uint8_t row, const uint8_t extruder=active_extruder) {
  728. if (row < LCD_HEIGHT) {
  729. lcd_moveto(LCD_WIDTH - 9, row);
  730. _draw_heater_status(extruder, LCD_STR_THERMOMETER[0], lcd_blink());
  731. }
  732. }
  733. #endif // ADVANCED_PAUSE_FEATURE
  734. 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) {
  735. UNUSED(invert);
  736. int8_t n = LCD_WIDTH;
  737. lcd_moveto(0, row);
  738. if (center && !valstr) {
  739. int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
  740. while (--pad >= 0) { lcd_put_wchar(' '); n--; }
  741. }
  742. n -= lcd_put_u8str_max_P(pstr, n);
  743. if (valstr) n -= lcd_put_u8str_max(valstr, n);
  744. for (; n > 0; --n) lcd_put_wchar(' ');
  745. }
  746. static void lcd_implementation_drawmenu_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
  747. uint8_t n = LCD_WIDTH - 2;
  748. lcd_moveto(0, row);
  749. lcd_put_wchar(sel ? pre_char : ' ');
  750. n -= lcd_put_u8str_max_P(pstr, n);
  751. while (n--) lcd_put_wchar(' ');
  752. lcd_put_wchar(post_char);
  753. }
  754. 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) {
  755. uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data);
  756. lcd_moveto(0, row);
  757. lcd_put_wchar(sel ? pre_char : ' ');
  758. n -= lcd_put_u8str_max_P(pstr, n);
  759. lcd_put_wchar(':');
  760. while (n--) lcd_put_wchar(' ');
  761. lcd_put_u8str(data);
  762. }
  763. 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) {
  764. uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data);
  765. lcd_moveto(0, row);
  766. lcd_put_wchar(sel ? pre_char : ' ');
  767. n -= lcd_put_u8str_max_P(pstr, n);
  768. lcd_put_wchar(':');
  769. while (n--) lcd_put_wchar(' ');
  770. lcd_put_u8str_P(data);
  771. }
  772. #define DRAWMENU_SETTING_EDIT_GENERIC(_src) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', _src)
  773. #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))
  774. void lcd_implementation_drawedit(const char* pstr, const char* const value=NULL) {
  775. lcd_moveto(1, 1);
  776. lcd_put_u8str_P(pstr);
  777. if (value != NULL) {
  778. lcd_put_wchar(':');
  779. int len = utf8_strlen(value);
  780. 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
  781. lcd_moveto((LCD_WIDTH - 1) - (len + 1), valrow); // Right-justified, padded by spaces
  782. lcd_put_wchar(' '); // overwrite char if value gets shorter
  783. lcd_put_u8str(value);
  784. }
  785. }
  786. #if ENABLED(SDSUPPORT)
  787. 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) {
  788. UNUSED(pstr);
  789. lcd_moveto(0, row);
  790. lcd_put_wchar(sel ? '>' : ' ');
  791. uint8_t n = LCD_WIDTH - concat;
  792. const char *outstr = longFilename[0] ? longFilename : filename;
  793. if (longFilename[0]) {
  794. #if ENABLED(SCROLL_LONG_FILENAMES)
  795. if (sel) {
  796. uint8_t name_hash = row;
  797. for (uint8_t l = FILENAME_LENGTH; l--;)
  798. name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ filename[l]; // rotate, xor
  799. if (filename_scroll_hash != name_hash) { // If the hash changed...
  800. filename_scroll_hash = name_hash; // Save the new hash
  801. filename_scroll_max = MAX(0, utf8_strlen(longFilename) - n); // Update the scroll limit
  802. filename_scroll_pos = 0; // Reset scroll to the start
  803. lcd_status_update_delay = 8; // Don't scroll right away
  804. }
  805. outstr += filename_scroll_pos;
  806. }
  807. #else
  808. longFilename[n] = '\0'; // cutoff at screen edge
  809. #endif
  810. }
  811. lcd_moveto(0, row);
  812. lcd_put_wchar(sel ? '>' : ' ');
  813. n -= lcd_put_u8str_max(outstr, n);
  814. while (n) { --n; lcd_put_wchar(' '); }
  815. lcd_put_wchar(post_char);
  816. }
  817. static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
  818. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, ' ');
  819. }
  820. static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, const char* filename, char* const longFilename) {
  821. lcd_implementation_drawmenu_sd(sel, row, pstr, filename, longFilename, 2, LCD_STR_FOLDER[0]);
  822. }
  823. #endif // SDSUPPORT
  824. #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_UPLEVEL_CHAR, LCD_UPLEVEL_CHAR)
  825. #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
  826. #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  827. #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
  828. #if ENABLED(LCD_HAS_SLOW_BUTTONS)
  829. extern millis_t next_button_update_ms;
  830. static uint8_t lcd_implementation_read_slow_buttons() {
  831. #if ENABLED(LCD_I2C_TYPE_MCP23017)
  832. // Reading these buttons this is likely to be too slow to call inside interrupt context
  833. // so they are called during normal lcd_update
  834. uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
  835. #if ENABLED(LCD_I2C_VIKI)
  836. if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms)) // LCD clicked
  837. slow_bits &= ~(B_MI | B_RI); // Disable LCD clicked buttons if screen is updated
  838. #endif // LCD_I2C_VIKI
  839. return slow_bits;
  840. #endif // LCD_I2C_TYPE_MCP23017
  841. }
  842. #endif // LCD_HAS_SLOW_BUTTONS
  843. #if ENABLED(LCD_HAS_STATUS_INDICATORS)
  844. static void lcd_implementation_update_indicators() {
  845. // Set the LEDS - referred to as backlights by the LiquidTWI2 library
  846. static uint8_t ledsprev = 0;
  847. uint8_t leds = 0;
  848. if (thermalManager.degTargetBed() > 0) leds |= LED_A;
  849. if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
  850. #if FAN_COUNT > 0
  851. if (0
  852. #if HAS_FAN0
  853. || fanSpeeds[0]
  854. #endif
  855. #if HAS_FAN1
  856. || fanSpeeds[1]
  857. #endif
  858. #if HAS_FAN2
  859. || fanSpeeds[2]
  860. #endif
  861. ) leds |= LED_C;
  862. #endif // FAN_COUNT > 0
  863. #if HOTENDS > 1
  864. if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
  865. #endif
  866. if (leds != ledsprev) {
  867. lcd.setBacklight(leds);
  868. ledsprev = leds;
  869. }
  870. }
  871. #endif // LCD_HAS_STATUS_INDICATORS
  872. #if ENABLED(AUTO_BED_LEVELING_UBL)
  873. /**
  874. Possible map screens:
  875. 16x2 |X000.00 Y000.00|
  876. |(00,00) Z00.000|
  877. 20x2 | X:000.00 Y:000.00 |
  878. | (00,00) Z:00.000 |
  879. 16x4 |+-------+(00,00)|
  880. || |X000.00|
  881. || |Y000.00|
  882. |+-------+Z00.000|
  883. 20x4 | +-------+ (00,00) |
  884. | | | X:000.00|
  885. | | | Y:000.00|
  886. | +-------+ Z:00.000|
  887. */
  888. typedef struct {
  889. uint8_t custom_char_bits[ULTRA_Y_PIXELS_PER_CHAR];
  890. } custom_char;
  891. typedef struct {
  892. uint8_t column, row;
  893. uint8_t y_pixel_offset, x_pixel_offset;
  894. uint8_t x_pixel_mask;
  895. } coordinate;
  896. void add_edges_to_custom_char(custom_char * const custom, coordinate * const ul, coordinate * const lr, coordinate * const brc, const uint8_t cell_location);
  897. FORCE_INLINE static void clear_custom_char(custom_char * const cc) { ZERO(cc->custom_char_bits); }
  898. /*
  899. // This debug routine should be deleted by anybody that sees it. It doesn't belong here
  900. // But I'm leaving it for now until we know the 20x4 Radar Map is working right.
  901. // We may need it again if any funny lines show up on the mesh points.
  902. void dump_custom_char(char *title, custom_char *c) {
  903. SERIAL_PROTOCOLLN(title);
  904. for (uint8_t j = 0; j < 8; j++) {
  905. for (uint8_t i = 7; i >= 0; i--)
  906. SERIAL_PROTOCOLCHAR(TEST(c->custom_char_bits[j], i) ? '1' : '0');
  907. SERIAL_EOL();
  908. }
  909. SERIAL_EOL();
  910. }
  911. //*/
  912. coordinate pixel_location(int16_t x, int16_t y) {
  913. coordinate ret_val;
  914. int16_t xp, yp, r, c;
  915. x++; y++; // +1 because lines on the left and top
  916. c = x / (ULTRA_X_PIXELS_PER_CHAR);
  917. r = y / (ULTRA_Y_PIXELS_PER_CHAR);
  918. ret_val.column = c;
  919. ret_val.row = r;
  920. xp = x - c * (ULTRA_X_PIXELS_PER_CHAR); // get the pixel offsets into the character cell
  921. xp = ULTRA_X_PIXELS_PER_CHAR - 1 - xp; // column within relevant character cell (0 on the right)
  922. yp = y - r * (ULTRA_Y_PIXELS_PER_CHAR);
  923. ret_val.x_pixel_mask = _BV(xp);
  924. ret_val.x_pixel_offset = xp;
  925. ret_val.y_pixel_offset = yp;
  926. return ret_val;
  927. }
  928. inline coordinate pixel_location(const uint8_t x, const uint8_t y) { return pixel_location((int16_t)x, (int16_t)y); }
  929. void lcd_implementation_ubl_plot(const uint8_t x, const uint8_t inverted_y) {
  930. #if LCD_WIDTH >= 20
  931. #define _LCD_W_POS 12
  932. #define _PLOT_X 1
  933. #define _MAP_X 3
  934. #define _LABEL(C,X,Y) lcd_moveto(X, Y); lcd_put_u8str(C)
  935. #define _XLABEL(X,Y) _LABEL("X:",X,Y)
  936. #define _YLABEL(X,Y) _LABEL("Y:",X,Y)
  937. #define _ZLABEL(X,Y) _LABEL("Z:",X,Y)
  938. #else
  939. #define _LCD_W_POS 8
  940. #define _PLOT_X 0
  941. #define _MAP_X 1
  942. #define _LABEL(X,Y,C) lcd_moveto(X, Y); lcd_put_wchar(C)
  943. #define _XLABEL(X,Y) _LABEL('X',X,Y)
  944. #define _YLABEL(X,Y) _LABEL('Y',X,Y)
  945. #define _ZLABEL(X,Y) _LABEL('Z',X,Y)
  946. #endif
  947. #if LCD_HEIGHT <= 3 // 16x2 or 20x2 display
  948. /**
  949. * Show X and Y positions
  950. */
  951. _XLABEL(_PLOT_X, 0);
  952. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
  953. _YLABEL(_LCD_W_POS, 0);
  954. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
  955. lcd_moveto(_PLOT_X, 0);
  956. #else // 16x4 or 20x4 display
  957. coordinate upper_left, lower_right, bottom_right_corner;
  958. custom_char new_char;
  959. uint8_t i, j, k, l, m, n, n_rows, n_cols, y,
  960. bottom_line, right_edge,
  961. x_map_pixels, y_map_pixels,
  962. pixels_per_x_mesh_pnt, pixels_per_y_mesh_pnt,
  963. suppress_x_offset = 0, suppress_y_offset = 0;
  964. y = GRID_MAX_POINTS_Y - inverted_y - 1;
  965. upper_left.column = 0;
  966. upper_left.row = 0;
  967. lower_right.column = 0;
  968. lower_right.row = 0;
  969. lcd_implementation_clear();
  970. 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
  971. y_map_pixels = (ULTRA_Y_PIXELS_PER_CHAR) * (ULTRA_ROWS_FOR_MESH_MAP) - 2;
  972. pixels_per_x_mesh_pnt = x_map_pixels / (GRID_MAX_POINTS_X);
  973. pixels_per_y_mesh_pnt = y_map_pixels / (GRID_MAX_POINTS_Y);
  974. if (pixels_per_x_mesh_pnt >= ULTRA_X_PIXELS_PER_CHAR) { // There are only 2 custom characters available, so the X
  975. pixels_per_x_mesh_pnt = ULTRA_X_PIXELS_PER_CHAR; // size of the mesh point needs to fit within them independent
  976. suppress_x_offset = 1; // of where the starting pixel is located.
  977. }
  978. if (pixels_per_y_mesh_pnt >= ULTRA_Y_PIXELS_PER_CHAR) { // There are only 2 custom characters available, so the Y
  979. pixels_per_y_mesh_pnt = ULTRA_Y_PIXELS_PER_CHAR; // size of the mesh point needs to fit within them independent
  980. suppress_y_offset = 1; // of where the starting pixel is located.
  981. }
  982. x_map_pixels = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X); // now we have the right number of pixels to make both
  983. y_map_pixels = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y); // directions fit nicely
  984. right_edge = pixels_per_x_mesh_pnt * (GRID_MAX_POINTS_X) + 1; // find location of right edge within the character cell
  985. bottom_line= pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 1; // find location of bottome line within the character cell
  986. n_rows = bottom_line / (ULTRA_Y_PIXELS_PER_CHAR) + 1;
  987. n_cols = right_edge / (ULTRA_X_PIXELS_PER_CHAR) + 1;
  988. for (i = 0; i < n_cols; i++) {
  989. lcd_moveto(i, 0);
  990. lcd_put_wchar((char)0x00); // top line of the box
  991. lcd_moveto(i, n_rows - 1);
  992. lcd_put_wchar(0x01); // bottom line of the box
  993. }
  994. for (j = 0; j < n_rows; j++) {
  995. lcd_moveto(0, j);
  996. lcd_put_wchar(0x02); // Left edge of the box
  997. lcd_moveto(n_cols - 1, j);
  998. lcd_put_wchar(0x03); // right edge of the box
  999. }
  1000. /**
  1001. * If the entire 4th row is not in use, do not put vertical bars all the way down to the bottom of the display
  1002. */
  1003. k = pixels_per_y_mesh_pnt * (GRID_MAX_POINTS_Y) + 2;
  1004. l = (ULTRA_Y_PIXELS_PER_CHAR) * n_rows;
  1005. if (l > k && l - k >= (ULTRA_Y_PIXELS_PER_CHAR) / 2) {
  1006. lcd_moveto(0, n_rows - 1); // left edge of the box
  1007. lcd_put_wchar(' ');
  1008. lcd_moveto(n_cols - 1, n_rows - 1); // right edge of the box
  1009. lcd_put_wchar(' ');
  1010. }
  1011. clear_custom_char(&new_char);
  1012. new_char.custom_char_bits[0] = 0b11111U; // char #0 is used for the top line of the box
  1013. lcd.createChar(0, (uint8_t*)&new_char);
  1014. clear_custom_char(&new_char);
  1015. k = (GRID_MAX_POINTS_Y) * pixels_per_y_mesh_pnt + 1; // row of pixels for the bottom box line
  1016. l = k % (ULTRA_Y_PIXELS_PER_CHAR); // row within relevant character cell
  1017. new_char.custom_char_bits[l] = 0b11111U; // char #1 is used for the bottom line of the box
  1018. lcd.createChar(1, (uint8_t*)&new_char);
  1019. clear_custom_char(&new_char);
  1020. for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
  1021. new_char.custom_char_bits[j] = 0b10000U; // char #2 is used for the left edge of the box
  1022. lcd.createChar(2, (uint8_t*)&new_char);
  1023. clear_custom_char(&new_char);
  1024. m = (GRID_MAX_POINTS_X) * pixels_per_x_mesh_pnt + 1; // Column of pixels for the right box line
  1025. n = m % (ULTRA_X_PIXELS_PER_CHAR); // Column within relevant character cell
  1026. i = ULTRA_X_PIXELS_PER_CHAR - 1 - n; // Column within relevant character cell (0 on the right)
  1027. for (j = 0; j < ULTRA_Y_PIXELS_PER_CHAR; j++)
  1028. new_char.custom_char_bits[j] = (uint8_t)_BV(i); // Char #3 is used for the right edge of the box
  1029. lcd.createChar(3, (uint8_t*)&new_char);
  1030. i = x * pixels_per_x_mesh_pnt - suppress_x_offset;
  1031. j = y * pixels_per_y_mesh_pnt - suppress_y_offset;
  1032. upper_left = pixel_location(i, j);
  1033. k = (x + 1) * pixels_per_x_mesh_pnt - 1 - suppress_x_offset;
  1034. l = (y + 1) * pixels_per_y_mesh_pnt - 1 - suppress_y_offset;
  1035. lower_right = pixel_location(k, l);
  1036. bottom_right_corner = pixel_location(x_map_pixels, y_map_pixels);
  1037. /**
  1038. * First, handle the simple case where everything is within a single character cell.
  1039. * If part of the Mesh Plot is outside of this character cell, we will follow up
  1040. * and deal with that next.
  1041. */
  1042. //dump_custom_char("at entry:", &new_char);
  1043. clear_custom_char(&new_char);
  1044. const uint8_t ypix = MIN(upper_left.y_pixel_offset + pixels_per_y_mesh_pnt, ULTRA_Y_PIXELS_PER_CHAR);
  1045. for (j = upper_left.y_pixel_offset; j < ypix; j++) {
  1046. i = upper_left.x_pixel_mask;
  1047. for (k = 0; k < pixels_per_x_mesh_pnt; k++) {
  1048. new_char.custom_char_bits[j] |= i;
  1049. i >>= 1;
  1050. }
  1051. }
  1052. //dump_custom_char("after loops:", &new_char);
  1053. add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_LEFT);
  1054. //dump_custom_char("after add edges", &new_char);
  1055. lcd.createChar(4, (uint8_t*)&new_char);
  1056. lcd_moveto(upper_left.column, upper_left.row);
  1057. lcd_put_wchar(0x04);
  1058. //dump_custom_char("after lcd update:", &new_char);
  1059. /**
  1060. * Next, check for two side by side character cells being used to display the Mesh Point
  1061. * If found... do the right hand character cell next.
  1062. */
  1063. if (upper_left.column == lower_right.column - 1) {
  1064. l = upper_left.x_pixel_offset;
  1065. clear_custom_char(&new_char);
  1066. for (j = upper_left.y_pixel_offset; j < ypix; j++) {
  1067. i = _BV(ULTRA_X_PIXELS_PER_CHAR - 1); // Fill in the left side of the right character cell
  1068. for (k = 0; k < pixels_per_x_mesh_pnt - 1 - l; k++) {
  1069. new_char.custom_char_bits[j] |= i;
  1070. i >>= 1;
  1071. }
  1072. }
  1073. add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, TOP_RIGHT);
  1074. lcd.createChar(5, (uint8_t *) &new_char);
  1075. lcd_moveto(lower_right.column, upper_left.row);
  1076. lcd_put_wchar(0x05);
  1077. }
  1078. /**
  1079. * Next, check for two character cells stacked on top of each other being used to display the Mesh Point
  1080. */
  1081. if (upper_left.row == lower_right.row - 1) {
  1082. l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset; // Number of pixel rows in top character cell
  1083. k = pixels_per_y_mesh_pnt - l; // Number of pixel rows in bottom character cell
  1084. clear_custom_char(&new_char);
  1085. for (j = 0; j < k; j++) {
  1086. i = upper_left.x_pixel_mask;
  1087. for (m = 0; m < pixels_per_x_mesh_pnt; m++) { // Fill in the top side of the bottom character cell
  1088. new_char.custom_char_bits[j] |= i;
  1089. if (!(i >>= 1)) break;
  1090. }
  1091. }
  1092. add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_LEFT);
  1093. lcd.createChar(6, (uint8_t *) &new_char);
  1094. lcd_moveto(upper_left.column, lower_right.row);
  1095. lcd_put_wchar(0x06);
  1096. }
  1097. /**
  1098. * Next, check for four character cells being used to display the Mesh Point. If that is
  1099. * what is here, we work to fill in the character cell that is down one and to the right one
  1100. * from the upper_left character cell.
  1101. */
  1102. if (upper_left.column == lower_right.column - 1 && upper_left.row == lower_right.row - 1) {
  1103. l = ULTRA_Y_PIXELS_PER_CHAR - upper_left.y_pixel_offset; // Number of pixel rows in top character cell
  1104. k = pixels_per_y_mesh_pnt - l; // Number of pixel rows in bottom character cell
  1105. clear_custom_char(&new_char);
  1106. for (j = 0; j < k; j++) {
  1107. l = upper_left.x_pixel_offset;
  1108. i = _BV(ULTRA_X_PIXELS_PER_CHAR - 1); // Fill in the left side of the right character cell
  1109. for (m = 0; m < pixels_per_x_mesh_pnt - 1 - l; m++) { // Fill in the top side of the bottom character cell
  1110. new_char.custom_char_bits[j] |= i;
  1111. i >>= 1;
  1112. }
  1113. }
  1114. add_edges_to_custom_char(&new_char, &upper_left, &lower_right, &bottom_right_corner, LOWER_RIGHT);
  1115. lcd.createChar(7, (uint8_t*)&new_char);
  1116. lcd_moveto(lower_right.column, lower_right.row);
  1117. lcd_put_wchar(0x07);
  1118. }
  1119. #endif
  1120. /**
  1121. * Print plot position
  1122. */
  1123. lcd_moveto(_LCD_W_POS, 0);
  1124. lcd_put_wchar('(');
  1125. lcd_put_u8str(itostr3(x));
  1126. lcd_put_wchar(',');
  1127. lcd_put_u8str(itostr3(inverted_y));
  1128. lcd_put_wchar(')');
  1129. #if LCD_HEIGHT <= 3 // 16x2 or 20x2 display
  1130. /**
  1131. * Print Z values
  1132. */
  1133. _ZLABEL(_LCD_W_POS, 1);
  1134. if (!isnan(ubl.z_values[x][inverted_y]))
  1135. lcd_put_u8str(ftostr43sign(ubl.z_values[x][inverted_y]));
  1136. else
  1137. lcd_put_u8str_P(PSTR(" -----"));
  1138. #else // 16x4 or 20x4 display
  1139. /**
  1140. * Show all values at right of screen
  1141. */
  1142. _XLABEL(_LCD_W_POS, 1);
  1143. lcd_put_u8str(ftostr52(LOGICAL_X_POSITION(pgm_read_float(&ubl._mesh_index_to_xpos[x]))));
  1144. _YLABEL(_LCD_W_POS, 2);
  1145. lcd_put_u8str(ftostr52(LOGICAL_Y_POSITION(pgm_read_float(&ubl._mesh_index_to_ypos[inverted_y]))));
  1146. /**
  1147. * Show the location value
  1148. */
  1149. _ZLABEL(_LCD_W_POS, 3);
  1150. if (!isnan(ubl.z_values[x][inverted_y]))
  1151. lcd_put_u8str(ftostr43sign(ubl.z_values[x][inverted_y]));
  1152. else
  1153. lcd_put_u8str_P(PSTR(" -----"));
  1154. #endif // LCD_HEIGHT > 3
  1155. }
  1156. void add_edges_to_custom_char(custom_char * const custom, coordinate * const ul, coordinate * const lr, coordinate * const brc, uint8_t cell_location) {
  1157. uint8_t i, k;
  1158. int16_t n_rows = lr->row - ul->row + 1,
  1159. n_cols = lr->column - ul->column + 1;
  1160. /**
  1161. * Check if Top line of box needs to be filled in
  1162. */
  1163. if (ul->row == 0 && ((cell_location & TOP_LEFT) || (cell_location & TOP_RIGHT))) { // Only fill in the top line for the top character cells
  1164. if (n_cols == 1) {
  1165. if (ul->column != brc->column)
  1166. custom->custom_char_bits[0] = 0xFF; // Single column in middle
  1167. else
  1168. for (i = brc->x_pixel_offset; i < ULTRA_X_PIXELS_PER_CHAR; i++) // Single column on right side
  1169. SBI(custom->custom_char_bits[0], i);
  1170. }
  1171. else if ((cell_location & TOP_LEFT) || lr->column != brc->column) // Multiple column in the middle or with right cell in middle
  1172. custom->custom_char_bits[0] = 0xFF;
  1173. else
  1174. for (i = brc->x_pixel_offset; i < ULTRA_X_PIXELS_PER_CHAR; i++)
  1175. SBI(custom->custom_char_bits[0], i);
  1176. }
  1177. /**
  1178. * Check if left line of box needs to be filled in
  1179. */
  1180. if ((cell_location & TOP_LEFT) || (cell_location & LOWER_LEFT)) {
  1181. if (ul->column == 0) { // Left column of characters on LCD Display
  1182. 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
  1183. for (i = 0; i < k; i++)
  1184. SBI(custom->custom_char_bits[i], ULTRA_X_PIXELS_PER_CHAR - 1);
  1185. }
  1186. }
  1187. /**
  1188. * Check if bottom line of box needs to be filled in
  1189. */
  1190. // Single row of mesh plot cells
  1191. if (n_rows == 1 /* && (cell_location == TOP_LEFT || cell_location == TOP_RIGHT) */ && ul->row == brc->row) {
  1192. if (n_cols == 1) // Single row, single column case
  1193. k = ul->column == brc->column ? brc->x_pixel_mask : 0x01;
  1194. else if (cell_location & TOP_RIGHT) // Single row, multiple column case
  1195. k = lr->column == brc->column ? brc->x_pixel_mask : 0x01;
  1196. else // Single row, left of multiple columns
  1197. k = 0x01;
  1198. while (k < _BV(ULTRA_X_PIXELS_PER_CHAR)) {
  1199. custom->custom_char_bits[brc->y_pixel_offset] |= k;
  1200. k <<= 1;
  1201. }
  1202. }
  1203. // Double row of characters on LCD Display
  1204. // And this is a bottom custom character
  1205. if (n_rows == 2 && (cell_location == LOWER_LEFT || cell_location == LOWER_RIGHT) && lr->row == brc->row) {
  1206. if (n_cols == 1) // Double row, single column case
  1207. k = ul->column == brc->column ? brc->x_pixel_mask : 0x01;
  1208. else if (cell_location & LOWER_RIGHT) // Double row, multiple column case
  1209. k = lr->column == brc->column ? brc->x_pixel_mask : 0x01;
  1210. else // Double row, left of multiple columns
  1211. k = 0x01;
  1212. while (k < _BV(ULTRA_X_PIXELS_PER_CHAR)) {
  1213. custom->custom_char_bits[brc->y_pixel_offset] |= k;
  1214. k <<= 1;
  1215. }
  1216. }
  1217. /**
  1218. * Check if right line of box needs to be filled in
  1219. */
  1220. // Nothing to do if the lower right part of the mesh pnt isn't in the same column as the box line
  1221. if (lr->column == brc->column) {
  1222. // This mesh point is in the same character cell as the right box line
  1223. if (ul->column == brc->column || (cell_location & TOP_RIGHT) || (cell_location & LOWER_RIGHT)) {
  1224. // If not the last row... do the full character cell
  1225. k = ul->row == brc->row ? brc->y_pixel_offset : ULTRA_Y_PIXELS_PER_CHAR;
  1226. for (i = 0; i < k; i++) custom->custom_char_bits[i] |= brc->x_pixel_mask;
  1227. }
  1228. }
  1229. }
  1230. #endif // AUTO_BED_LEVELING_UBL
  1231. #endif // ULTIPANEL
  1232. #endif // ULTRALCD_IMPL_HD44780_H