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

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