My Marlin configs for Fabrikator Mini and CTC i3 Pro B
選択できるのは25トピックまでです。 トピックは、先頭が英数字で、英数字とダッシュ('-')を使用した35文字以内のものにしてください。

ultralcd_HD44780.cpp 45KB

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