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

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