123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635 |
- #ifndef ULTRALCD_IMPL_HD44780_H
- #define ULTRALCD_IMPL_HD44780_H
- #include "utility.h"
- #include "duration_t.h"
- #if ENABLED(AUTO_BED_LEVELING_UBL)
- #include "ubl.h"
- #if ENABLED(ULTIPANEL)
- #define ULTRA_X_PIXELS_PER_CHAR 5
- #define ULTRA_Y_PIXELS_PER_CHAR 8
- #define ULTRA_COLUMNS_FOR_MESH_MAP 7
- #define ULTRA_ROWS_FOR_MESH_MAP 4
- #define N_USER_CHARS 8
- #define TOP_LEFT _BV(0)
- #define TOP_RIGHT _BV(1)
- #define LOWER_LEFT _BV(2)
- #define LOWER_RIGHT _BV(3)
- #endif
- #endif
- extern volatile uint8_t buttons;
- #if ENABLED(ULTIPANEL)
-
-
-
- #if ENABLED(LCD_I2C_VIKI)
- #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
-
- #define B_LE (BUTTON_LEFT << B_I2C_BTN_OFFSET) // The remaining normalized buttons are all read via I2C
- #define B_UP (BUTTON_UP << B_I2C_BTN_OFFSET)
- #define B_MI (BUTTON_SELECT << B_I2C_BTN_OFFSET)
- #define B_DW (BUTTON_DOWN << B_I2C_BTN_OFFSET)
- #define B_RI (BUTTON_RIGHT << B_I2C_BTN_OFFSET)
- #undef LCD_CLICKED
- #if BUTTON_EXISTS(ENC)
-
- #define B_ST (EN_C) // Map the pause/stop/resume button into its normalized functional name
- #define LCD_CLICKED (buttons & (B_MI|B_RI|B_ST)) // pause/stop button also acts as click until we implement proper pause/stop.
- #else
- #define LCD_CLICKED (buttons & (B_MI|B_RI))
- #endif
-
- #define LCD_HAS_SLOW_BUTTONS
- #elif ENABLED(LCD_I2C_PANELOLU2)
- #if !BUTTON_EXISTS(ENC) // Use I2C if not directly connected to a pin
- #define B_I2C_BTN_OFFSET 3 // (the first three bit positions reserved for EN_A, EN_B, EN_C)
- #define B_MI (PANELOLU2_ENCODER_C << B_I2C_BTN_OFFSET) // requires LiquidTWI2 library v1.2.3 or later
- #undef LCD_CLICKED
- #define LCD_CLICKED (buttons & B_MI)
-
- #define LCD_HAS_SLOW_BUTTONS
- #endif
- #elif DISABLED(NEWPANEL) // old style ULTIPANEL
-
- #define BL_LE 7 // Left
- #define BL_UP 6 // Up
- #define BL_MI 5 // Middle
- #define BL_DW 4 // Down
- #define BL_RI 3 // Right
- #define BL_ST 2 // Red Button
- #define B_LE (_BV(BL_LE))
- #define B_UP (_BV(BL_UP))
- #define B_MI (_BV(BL_MI))
- #define B_DW (_BV(BL_DW))
- #define B_RI (_BV(BL_RI))
- #define B_ST (_BV(BL_ST))
- #define LCD_CLICKED (buttons & (B_MI|B_ST))
- #endif
- #endif // ULTIPANEL
- #if ENABLED(LCD_I2C_TYPE_PCF8575)
-
- #define LCD_I2C_PIN_BL 3
- #define LCD_I2C_PIN_EN 2
- #define LCD_I2C_PIN_RW 1
- #define LCD_I2C_PIN_RS 0
- #define LCD_I2C_PIN_D4 4
- #define LCD_I2C_PIN_D5 5
- #define LCD_I2C_PIN_D6 6
- #define LCD_I2C_PIN_D7 7
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h>
- #define LCD_CLASS LiquidCrystal_I2C
- 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);
- #elif ENABLED(LCD_I2C_TYPE_MCP23017)
-
- #define LED_A 0x04 //100
- #define LED_B 0x02 //010
- #define LED_C 0x01 //001
- #define LCD_HAS_STATUS_INDICATORS
- #include <Wire.h>
- #include <LiquidTWI2.h>
- #define LCD_CLASS LiquidTWI2
- #if ENABLED(DETECT_DEVICE)
- LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
- #else
- LCD_CLASS lcd(LCD_I2C_ADDRESS);
- #endif
- #elif ENABLED(LCD_I2C_TYPE_MCP23008)
- #include <Wire.h>
- #include <LiquidTWI2.h>
- #define LCD_CLASS LiquidTWI2
- #if ENABLED(DETECT_DEVICE)
- LCD_CLASS lcd(LCD_I2C_ADDRESS, 1);
- #else
- LCD_CLASS lcd(LCD_I2C_ADDRESS);
- #endif
- #elif ENABLED(LCD_I2C_TYPE_PCA8574)
- #include <LiquidCrystal_I2C.h>
- #define LCD_CLASS LiquidCrystal_I2C
- LCD_CLASS lcd(LCD_I2C_ADDRESS, LCD_WIDTH, LCD_HEIGHT);
- #elif ENABLED(SR_LCD_2W_NL)
- extern "C" void __cxa_pure_virtual() { while (1); }
- #include <LCD.h>
- #include <LiquidCrystal_SR.h>
- #define LCD_CLASS LiquidCrystal_SR
- #if PIN_EXISTS(SR_STROBE)
- LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN, SR_STROBE_PIN);
- #else
- LCD_CLASS lcd(SR_DATA_PIN, SR_CLK_PIN);
- #endif
- #elif ENABLED(LCM1602)
- #include <Wire.h>
- #include <LCD.h>
- #include <LiquidCrystal_I2C.h>
- #define LCD_CLASS LiquidCrystal_I2C
- LCD_CLASS lcd(0x27, 2, 1, 0, 4, 5, 6, 7, 3, POSITIVE);
- #else
-
- #include <LiquidCrystal.h>
- #define LCD_CLASS LiquidCrystal
- LCD_CLASS lcd(LCD_PINS_RS, LCD_PINS_ENABLE, LCD_PINS_D4, LCD_PINS_D5, LCD_PINS_D6, LCD_PINS_D7);
- #endif
- #include "utf_mapper.h"
- #if ENABLED(LCD_PROGRESS_BAR)
- static millis_t progress_bar_ms = 0;
- #if PROGRESS_MSG_EXPIRE > 0
- static millis_t expire_status_ms = 0;
- #endif
- #define LCD_STR_PROGRESS "\x03\x04\x05"
- #endif
- #if ENABLED(LCD_HAS_STATUS_INDICATORS)
- static void lcd_implementation_update_indicators();
- #endif
- static void createChar_P(const char c, const byte * const ptr) {
- byte temp[8];
- for (uint8_t i = 0; i < 8; i++)
- temp[i] = pgm_read_byte(&ptr[i]);
- lcd.createChar(c, temp);
- }
- #define CHARSET_MENU 0
- #define CHARSET_INFO 1
- #define CHARSET_BOOT 2
- static void lcd_set_custom_characters(
- #if ENABLED(LCD_PROGRESS_BAR) || ENABLED(SHOW_BOOTSCREEN)
- const uint8_t screen_charset=CHARSET_INFO
- #endif
- ) {
-
- #if ENABLED(SHOW_BOOTSCREEN)
- const static PROGMEM byte corner[4][8] = { {
- B00000,
- B00000,
- B00000,
- B00000,
- B00001,
- B00010,
- B00100,
- B00100
- }, {
- B00000,
- B00000,
- B00000,
- B11100,
- B11100,
- B01100,
- B00100,
- B00100
- }, {
- B00100,
- B00010,
- B00001,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- }, {
- B00100,
- B01000,
- B10000,
- B00000,
- B00000,
- B00000,
- B00000,
- B00000
- } };
- #endif // SHOW_BOOTSCREEN
-
- const static PROGMEM byte bedTemp[8] = {
- B00000,
- B11111,
- B10101,
- B10001,
- B10101,
- B11111,
- B00000,
- B00000
- };
- const static PROGMEM byte degree[8] = {
- B01100,
- B10010,
- B10010,
- B01100,
- B00000,
- B00000,
- B00000,
- B00000
- };
- const static PROGMEM byte thermometer[8] = {
- B00100,
- B01010,
- B01010,
- B01010,
- B01010,
- B10001,
- B10001,
- B01110
- };
- const static PROGMEM byte uplevel[8] = {
- B00100,
- B01110,
- B11111,
- B00100,
- B11100,
- B00000,
- B00000,
- B00000
- };
- const static PROGMEM byte feedrate[8] = {
- B11100,
- B10000,
- B11000,
- B10111,
- B00101,
- B00110,
- B00101,
- B00000
- };
- const static PROGMEM byte clock[8] = {
- B00000,
- B01110,
- B10011,
- B10101,
- B10001,
- B01110,
- B00000,
- B00000
- };
- #if ENABLED(LCD_PROGRESS_BAR)
-
- const static PROGMEM byte progress[3][8] = { {
- B00000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B10000,
- B00000
- }, {
- B00000,
- B10100,
- B10100,
- B10100,
- B10100,
- B10100,
- B10100,
- B00000
- }, {
- B00000,
- B10101,
- B10101,
- B10101,
- B10101,
- B10101,
- B10101,
- B00000
- } };
- #endif // LCD_PROGRESS_BAR
- #if ENABLED(SDSUPPORT)
-
- const static PROGMEM byte refresh[8] = {
- B00000,
- B00110,
- B11001,
- B11000,
- B00011,
- B10011,
- B01100,
- B00000,
- };
- const static PROGMEM byte folder[8] = {
- B00000,
- B11100,
- B11111,
- B10001,
- B10001,
- B11111,
- B00000,
- B00000
- };
- #endif // SDSUPPORT
- #if ENABLED(SHOW_BOOTSCREEN)
-
- if (screen_charset == CHARSET_BOOT) {
- for (uint8_t i = 4; i--;)
- createChar_P(i, corner[i]);
- }
- else
- #endif
- {
- createChar_P(LCD_BEDTEMP_CHAR, bedTemp);
- createChar_P(LCD_DEGREE_CHAR, degree);
- createChar_P(LCD_STR_THERMOMETER[0], thermometer);
- createChar_P(LCD_FEEDRATE_CHAR, feedrate);
- createChar_P(LCD_CLOCK_CHAR, clock);
- #if ENABLED(LCD_PROGRESS_BAR)
- if (screen_charset == CHARSET_INFO) {
- for (int16_t i = 3; i--;)
- createChar_P(LCD_STR_PROGRESS[i], progress[i]);
- }
- else
- #endif
- {
- createChar_P(LCD_UPLEVEL_CHAR, uplevel);
- #if ENABLED(SDSUPPORT)
-
- createChar_P(LCD_STR_REFRESH[0], refresh);
- createChar_P(LCD_STR_FOLDER[0], folder);
- #endif
- }
- }
- }
- static void lcd_implementation_init(
- #if ENABLED(LCD_PROGRESS_BAR)
- const uint8_t screen_charset=CHARSET_INFO
- #endif
- ) {
- #if ENABLED(LCD_I2C_TYPE_PCF8575)
- lcd.begin(LCD_WIDTH, LCD_HEIGHT);
- #ifdef LCD_I2C_PIN_BL
- lcd.setBacklightPin(LCD_I2C_PIN_BL, POSITIVE);
- lcd.setBacklight(HIGH);
- #endif
- #elif ENABLED(LCD_I2C_TYPE_MCP23017)
- lcd.setMCPType(LTI_TYPE_MCP23017);
- lcd.begin(LCD_WIDTH, LCD_HEIGHT);
- lcd_implementation_update_indicators();
- #elif ENABLED(LCD_I2C_TYPE_MCP23008)
- lcd.setMCPType(LTI_TYPE_MCP23008);
- lcd.begin(LCD_WIDTH, LCD_HEIGHT);
- #elif ENABLED(LCD_I2C_TYPE_PCA8574)
- lcd.init();
- lcd.backlight();
- #else
- lcd.begin(LCD_WIDTH, LCD_HEIGHT);
- #endif
- lcd_set_custom_characters(
- #if ENABLED(LCD_PROGRESS_BAR)
- screen_charset
- #endif
- );
- lcd.clear();
- }
- void lcd_implementation_clear() { lcd.clear(); }
- void lcd_print(const char c) { charset_mapper(c); }
- void lcd_print(const char *str) { while (*str) lcd.print(*str++); }
- void lcd_printPGM(const char *str) { while (const char c = pgm_read_byte(str)) lcd.print(c), ++str; }
- void lcd_print_utf(const char *str, uint8_t n=LCD_WIDTH) {
- char c;
- while (n && (c = *str)) n -= charset_mapper(c), ++str;
- }
- void lcd_printPGM_utf(const char *str, uint8_t n=LCD_WIDTH) {
- char c;
- while (n && (c = pgm_read_byte(str))) n -= charset_mapper(c), ++str;
- }
- #if ENABLED(SHOW_BOOTSCREEN)
- void lcd_erase_line(const int16_t line) {
- lcd.setCursor(0, line);
- for (uint8_t i = LCD_WIDTH + 1; --i;)
- lcd.write(' ');
- }
-
- void lcd_scroll(const int16_t col, const int16_t line, const char* const text, const int16_t len, const int16_t time) {
- uint8_t slen = utf8_strlen_P(text);
- if (slen < len) {
-
- lcd.setCursor(col, line);
- lcd_printPGM_utf(text, len);
- while (slen < len) {
- lcd.write(' ');
- ++slen;
- }
- safe_delay(time);
- }
- else {
- const char* p = text;
- int dly = time / MAX(slen, 1);
- for (uint8_t i = 0; i <= slen; i++) {
-
- lcd.setCursor(col, line);
-
- lcd_printPGM_utf(p, len);
-
- uint8_t ix = slen - i;
- while (ix < len) {
- lcd.write(' ');
- ++ix;
- }
-
- safe_delay(dly);
-
- p++;
- while (!START_OF_UTF8_CHAR(pgm_read_byte(p))) p++;
- }
- }
- }
- static void logo_lines(const char* const extra) {
- int16_t indent = (LCD_WIDTH - 8 - utf8_strlen_P(extra)) / 2;
- lcd.setCursor(indent, 0); lcd.print('\x00'); lcd_printPGM(PSTR( "------" )); lcd.write('\x01');
- lcd.setCursor(indent, 1); lcd_printPGM(PSTR("|Marlin|")); lcd_printPGM(extra);
- lcd.setCursor(indent, 2); lcd.write('\x02'); lcd_printPGM(PSTR( "------" )); lcd.write('\x03');
- }
- void lcd_bootscreen() {
- lcd_set_custom_characters(CHARSET_BOOT);
- lcd.clear();
- #define LCD_EXTRA_SPACE (LCD_WIDTH-8)
- #define CENTER_OR_SCROLL(STRING,DELAY) \
- lcd_erase_line(3); \
- if (strlen(STRING) <= LCD_WIDTH) { \
- lcd.setCursor((LCD_WIDTH - utf8_strlen_P(PSTR(STRING))) / 2, 3); \
- lcd_printPGM_utf(PSTR(STRING)); \
- safe_delay(DELAY); \
- } \
- else { \
- lcd_scroll(0, 3, PSTR(STRING), LCD_WIDTH, DELAY); \
- }
- #ifdef STRING_SPLASH_LINE1
-
-
-
- if (LCD_EXTRA_SPACE >= strlen(STRING_SPLASH_LINE1) + 1) {
-
-
-
- logo_lines(PSTR(" " STRING_SPLASH_LINE1));
- #ifdef STRING_SPLASH_LINE2
- CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 2000);
- #else
- safe_delay(2000);
- #endif
- }
- else {
-
-
-
-
- #ifdef STRING_SPLASH_LINE2
- #define _SPLASH_WAIT_1 1500
- #else
- #define _SPLASH_WAIT_1 2000
- #endif
- logo_lines(PSTR(""));
- CENTER_OR_SCROLL(STRING_SPLASH_LINE1, _SPLASH_WAIT_1);
- #ifdef STRING_SPLASH_LINE2
- CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 1500);
- #endif
- }
- #elif defined(STRING_SPLASH_LINE2)
-
-
-
- if (LCD_EXTRA_SPACE >= strlen(STRING_SPLASH_LINE2) + 1) {
- logo_lines(PSTR(" " STRING_SPLASH_LINE2));
- safe_delay(2000);
- }
- else {
- logo_lines(PSTR(""));
- CENTER_OR_SCROLL(STRING_SPLASH_LINE2, 2000);
- }
- #else
-
-
-
- logo_lines(PSTR(""));
- safe_delay(2000);
- #endif
- lcd.clear();
- safe_delay(100);
- lcd_set_custom_characters();
- lcd.clear();
- }
- #endif // SHOW_BOOTSCREEN
- void lcd_kill_screen() {
- lcd.setCursor(0, 0);
- lcd_print_utf(lcd_status_message);
- #if LCD_HEIGHT < 4
- lcd.setCursor(0, 2);
- #else
- lcd.setCursor(0, 2);
- lcd_printPGM_utf(PSTR(MSG_HALTED));
- lcd.setCursor(0, 3);
- #endif
- lcd_printPGM_utf(PSTR(MSG_PLEASE_RESET));
- }
- FORCE_INLINE void _draw_axis_value(const AxisEnum axis, const char *value, const bool blink) {
- lcd_print('X' + uint8_t(axis));
- if (blink)
- lcd.print(value);
- else {
- if (!TEST(axis_homed, axis))
- while (const char c = *value++) lcd_print(c <= '.' ? c : '?');
- else {
- #if DISABLED(HOME_AFTER_DEACTIVATE) && DISABLED(DISABLE_REDUCED_ACCURACY_WARNING)
- if (!TEST(axis_known_position, axis))
- lcd_printPGM(axis == Z_AXIS ? PSTR(" ") : PSTR(" "));
- else
- #endif
- lcd.print(value);
- }
- }
- }
- FORCE_INLINE void _draw_heater_status(const int8_t heater, const char prefix, const bool blink) {
- #if HAS_HEATED_BED
- const bool isBed = heater < 0;
- const float t1 = (isBed ? thermalManager.degBed() : thermalManager.degHotend(heater)),
- t2 = (isBed ? thermalManager.degTargetBed() : thermalManager.degTargetHotend(heater));
- #else
- const float t1 = thermalManager.degHotend(heater), t2 = thermalManager.degTargetHotend(heater);
- #endif
- if (prefix >= 0) lcd.print(prefix);
- lcd.print(itostr3(t1 + 0.5));
- lcd.write('/');
- #if !HEATER_IDLE_HANDLER
- UNUSED(blink);
- #else
- const bool is_idle = (
- #if HAS_HEATED_BED
- isBed ? thermalManager.is_bed_idle() :
- #endif
- thermalManager.is_heater_idle(heater)
- );
- if (!blink && is_idle) {
- lcd.write(' ');
- if (t2 >= 10) lcd.write(' ');
- if (t2 >= 100) lcd.write(' ');
- }
- else
- #endif
- lcd.print(itostr3left(t2 + 0.5));
- if (prefix >= 0) {
- lcd.print((char)LCD_DEGREE_CHAR);
- lcd.write(' ');
- if (t2 < 10) lcd.write(' ');
- }
- }
- #if ENABLED(LCD_PROGRESS_BAR)
- inline void lcd_draw_progress_bar(const uint8_t percent) {
- const int16_t tix = (int16_t)(percent * (LCD_WIDTH) * 3) / 100,
- cel = tix / 3,
- rem = tix % 3;
- uint8_t i = LCD_WIDTH;
- char msg[LCD_WIDTH + 1], b = ' ';
- msg[LCD_WIDTH] = '\0';
- while (i--) {
- if (i == cel - 1)
- b = LCD_STR_PROGRESS[2];
- else if (i == cel && rem != 0)
- b = LCD_STR_PROGRESS[rem - 1];
- msg[i] = b;
- }
- lcd.print(msg);
- }
- #endif // LCD_PROGRESS_BAR
- static void lcd_implementation_status_screen() {
- const bool blink = lcd_blink();
-
-
-
- lcd.setCursor(0, 0);
- #if LCD_WIDTH < 20
-
-
-
- _draw_heater_status(0, -1, blink);
-
-
-
- #if HOTENDS > 1 || HAS_HEATED_BED
- lcd.setCursor(8, 0);
- #if HOTENDS > 1
- lcd.print((char)LCD_STR_THERMOMETER[0]);
- _draw_heater_status(1, -1, blink);
- #else
- lcd.print((char)LCD_BEDTEMP_CHAR);
- _draw_heater_status(-1, -1, blink);
- #endif
- #endif // HOTENDS > 1 || HAS_HEATED_BED
- #else // LCD_WIDTH >= 20
-
-
-
- _draw_heater_status(0, LCD_STR_THERMOMETER[0], blink);
-
-
-
- #if HOTENDS > 1 || HAS_HEATED_BED
- lcd.setCursor(10, 0);
- #if HOTENDS > 1
- _draw_heater_status(1, LCD_STR_THERMOMETER[0], blink);
- #else
- _draw_heater_status(-1, (
- #if HAS_LEVELING
- planner.leveling_active && blink ? '_' :
- #endif
- LCD_BEDTEMP_CHAR
- ), blink);
- #endif
- #endif // HOTENDS > 1 || HAS_HEATED_BED
- #endif // LCD_WIDTH >= 20
-
-
-
- #if LCD_HEIGHT > 2
- #if LCD_WIDTH < 20
- #if ENABLED(SDSUPPORT)
- lcd.setCursor(0, 2);
- lcd_printPGM(PSTR("SD"));
- if (IS_SD_PRINTING())
- lcd.print(itostr3(card.percentDone()));
- else
- lcd_printPGM(PSTR("---"));
- lcd.write('%');
- #endif // SDSUPPORT
- #else // LCD_WIDTH >= 20
- lcd.setCursor(0, 1);
-
-
- #if HOTENDS > 2 || (HOTENDS > 1 && HAS_HEATED_BED)
- #if HOTENDS > 2
- _draw_heater_status(2, LCD_STR_THERMOMETER[0], blink);
- lcd.setCursor(10, 1);
- #endif
- _draw_heater_status(-1, (
- #if HAS_LEVELING
- planner.leveling_active && blink ? '_' :
- #endif
- LCD_BEDTEMP_CHAR
- ), blink);
- #else // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
- _draw_axis_value(X_AXIS, ftostr4sign(LOGICAL_X_POSITION(current_position[X_AXIS])), blink);
- lcd.write(' ');
- _draw_axis_value(Y_AXIS, ftostr4sign(LOGICAL_Y_POSITION(current_position[Y_AXIS])), blink);
- #endif // HOTENDS <= 2 && (HOTENDS <= 1 || !HAS_HEATED_BED)
- #endif // LCD_WIDTH >= 20
- lcd.setCursor(LCD_WIDTH - 8, 1);
- _draw_axis_value(Z_AXIS, ftostr52sp(LOGICAL_Z_POSITION(current_position[Z_AXIS])), blink);
- #if HAS_LEVELING && !HAS_HEATED_BED
- lcd.write(planner.leveling_active || blink ? '_' : ' ');
- #endif
- #endif // LCD_HEIGHT > 2
-
-
-
- #if LCD_HEIGHT > 3
- lcd.setCursor(0, 2);
- lcd.print((char)LCD_FEEDRATE_CHAR);
- lcd.print(itostr3(feedrate_percentage));
- lcd.write('%');
- #if LCD_WIDTH >= 20 && ENABLED(SDSUPPORT)
- lcd.setCursor(7, 2);
- lcd_printPGM(PSTR("SD"));
- if (IS_SD_PRINTING())
- lcd.print(itostr3(card.percentDone()));
- else
- lcd_printPGM(PSTR("---"));
- lcd.write('%');
- #endif // LCD_WIDTH >= 20 && SDSUPPORT
- char buffer[10];
- duration_t elapsed = print_job_timer.duration();
- uint8_t len = elapsed.toDigital(buffer);
- lcd.setCursor(LCD_WIDTH - len - 1, 2);
- lcd.print((char)LCD_CLOCK_CHAR);
- lcd_print(buffer);
- #endif // LCD_HEIGHT > 3
-
-
-
-
- lcd.setCursor(0, LCD_HEIGHT - 1);
- #if ENABLED(LCD_PROGRESS_BAR)
-
-
- #if DISABLED(LCD_SET_PROGRESS_MANUALLY)
- const uint8_t progress_bar_percent = card.percentDone();
- #endif
- if (progress_bar_percent > 2 && (ELAPSED(millis(), progress_bar_ms + PROGRESS_BAR_MSG_TIME) || !lcd_status_message[0]))
- return lcd_draw_progress_bar(progress_bar_percent);
- #elif ENABLED(FILAMENT_LCD_DISPLAY) && ENABLED(SDSUPPORT)
-
-
- if (ELAPSED(millis(), previous_lcd_status_ms + 5000UL)) {
- lcd_printPGM(PSTR("Dia "));
- lcd.print(ftostr12ns(filament_width_meas));
- lcd_printPGM(PSTR(" V"));
- lcd.print(itostr3(100.0 * (
- parser.volumetric_enabled
- ? planner.volumetric_area_nominal / planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
- : planner.volumetric_multiplier[FILAMENT_SENSOR_EXTRUDER_NUM]
- )
- ));
- lcd.write('%');
- return;
- }
- #endif // FILAMENT_LCD_DISPLAY && SDSUPPORT
- #if ENABLED(STATUS_MESSAGE_SCROLLING)
- static bool last_blink = false;
-
- uint8_t slen = utf8_strlen(lcd_status_message);
-
- if (slen <= LCD_WIDTH) {
-
- lcd_print_utf(lcd_status_message);
-
- while (slen < LCD_WIDTH) {
- lcd.write(' ');
- ++slen;
- }
- }
- else {
-
-
- const char *stat = lcd_status_message + status_scroll_offset;
-
- const uint8_t rlen = utf8_strlen(stat);
-
- if (rlen >= LCD_WIDTH) {
-
- lcd_print_utf(stat, LCD_WIDTH);
- }
- else {
-
- lcd_print_utf(stat, LCD_WIDTH);
- uint8_t chars = LCD_WIDTH - rlen;
- lcd.write('.');
- if (--chars) {
- lcd.write('.');
- if (--chars)
- lcd_print_utf(lcd_status_message, chars);
- }
- }
- if (last_blink != blink) {
- last_blink = blink;
-
- if (status_scroll_offset < slen) {
- status_scroll_offset++;
- while (!START_OF_UTF8_CHAR(lcd_status_message[status_scroll_offset]))
- status_scroll_offset++;
- }
- else
- status_scroll_offset = 0;
- }
- }
- #else
- UNUSED(blink);
-
- uint8_t slen = utf8_strlen(lcd_status_message);
-
- lcd_print_utf(lcd_status_message, LCD_WIDTH);
-
- while (slen < LCD_WIDTH) {
- lcd.write(' ');
- ++slen;
- }
- #endif
- }
- #if ENABLED(ULTIPANEL)
- #if ENABLED(ADVANCED_PAUSE_FEATURE)
- static void lcd_implementation_hotend_status(const uint8_t row, const uint8_t extruder=active_extruder) {
- if (row < LCD_HEIGHT) {
- lcd.setCursor(LCD_WIDTH - 9, row);
- _draw_heater_status(extruder, LCD_STR_THERMOMETER[0], lcd_blink());
- }
- }
- #endif // ADVANCED_PAUSE_FEATURE
- 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) {
- UNUSED(invert);
- char c;
- int8_t n = LCD_WIDTH;
- lcd.setCursor(0, row);
- if (center && !valstr) {
- int8_t pad = (LCD_WIDTH - utf8_strlen_P(pstr)) / 2;
- while (--pad >= 0) { lcd.write(' '); n--; }
- }
- while (n > 0 && (c = pgm_read_byte(pstr))) {
- n -= charset_mapper(c);
- pstr++;
- }
- if (valstr) while (n > 0 && (c = *valstr)) {
- n -= charset_mapper(c);
- valstr++;
- }
- while (n-- > 0) lcd.write(' ');
- }
- static void lcd_implementation_drawmenu_generic(const bool sel, const uint8_t row, const char* pstr, const char pre_char, const char post_char) {
- char c;
- uint8_t n = LCD_WIDTH - 2;
- lcd.setCursor(0, row);
- lcd.print(sel ? pre_char : ' ');
- while ((c = pgm_read_byte(pstr)) && n > 0) {
- n -= charset_mapper(c);
- pstr++;
- }
- while (n--) lcd.write(' ');
- lcd.print(post_char);
- }
- 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) {
- char c;
- uint8_t n = LCD_WIDTH - 2 - utf8_strlen(data);
- lcd.setCursor(0, row);
- lcd.print(sel ? pre_char : ' ');
- while ((c = pgm_read_byte(pstr)) && n > 0) {
- n -= charset_mapper(c);
- pstr++;
- }
- lcd.write(':');
- while (n--) lcd.write(' ');
- lcd_print(data);
- }
- 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) {
- char c;
- uint8_t n = LCD_WIDTH - 2 - utf8_strlen_P(data);
- lcd.setCursor(0, row);
- lcd.print(sel ? pre_char : ' ');
- while ((c = pgm_read_byte(pstr)) && n > 0) {
- n -= charset_mapper(c);
- pstr++;
- }
- lcd.write(':');
- while (n--) lcd.write(' ');
- lcd_printPGM(data);
- }
- #define DRAWMENU_SETTING_EDIT_GENERIC(_src) lcd_implementation_drawmenu_setting_edit_generic(sel, row, pstr, '>', _src)
- #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))
- void lcd_implementation_drawedit(const char* pstr, const char* const value=NULL) {
- lcd.setCursor(1, 1);
- lcd_printPGM_utf(pstr);
- if (value != NULL) {
- lcd.write(':');
- const uint8_t valrow = (utf8_strlen_P(pstr) + 1 + utf8_strlen(value) + 1) > (LCD_WIDTH - 2) ? 2 : 1;
- lcd.setCursor((LCD_WIDTH - 1) - (utf8_strlen(value) + 1), valrow);
- lcd.write(' ');
- lcd_print(value);
- }
- }
- #if ENABLED(SDSUPPORT)
- static void lcd_implementation_drawmenu_sd(const bool sel, const uint8_t row, const char* const pstr, CardReader& theCard, const uint8_t concat, const char post_char) {
- UNUSED(pstr);
- lcd.setCursor(0, row);
- lcd.print(sel ? '>' : ' ');
- uint8_t n = LCD_WIDTH - concat;
- const char *outstr = theCard.longest_filename();
- if (theCard.longFilename[0]) {
- #if ENABLED(SCROLL_LONG_FILENAMES)
- if (sel) {
- uint8_t name_hash = row;
- for (uint8_t l = FILENAME_LENGTH; l--;)
- name_hash = ((name_hash << 1) | (name_hash >> 7)) ^ theCard.filename[l];
- if (filename_scroll_hash != name_hash) {
- filename_scroll_hash = name_hash;
- filename_scroll_max = MAX(0, utf8_strlen(theCard.longFilename) - n);
- filename_scroll_pos = 0;
- lcd_status_update_delay = 8;
- }
- outstr += filename_scroll_pos;
- }
- #else
- theCard.longFilename[n] = '\0';
- #endif
- }
- char c;
- while (n && (c = *outstr)) {
- n -= charset_mapper(c);
- ++outstr;
- }
- while (n) { --n; lcd.write(' '); }
- lcd.print(post_char);
- }
- static void lcd_implementation_drawmenu_sdfile(const bool sel, const uint8_t row, const char* pstr, CardReader& theCard) {
- lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, ' ');
- }
- static void lcd_implementation_drawmenu_sddirectory(const bool sel, const uint8_t row, const char* pstr, CardReader& theCard) {
- lcd_implementation_drawmenu_sd(sel, row, pstr, theCard, 2, LCD_STR_FOLDER[0]);
- }
- #endif // SDSUPPORT
- #define lcd_implementation_drawmenu_back(sel, row, pstr, dummy) lcd_implementation_drawmenu_generic(sel, row, pstr, LCD_UPLEVEL_CHAR, LCD_UPLEVEL_CHAR)
- #define lcd_implementation_drawmenu_submenu(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', LCD_STR_ARROW_RIGHT[0])
- #define lcd_implementation_drawmenu_gcode(sel, row, pstr, gcode) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
- #define lcd_implementation_drawmenu_function(sel, row, pstr, data) lcd_implementation_drawmenu_generic(sel, row, pstr, '>', ' ')
- #if ENABLED(LCD_HAS_SLOW_BUTTONS)
- extern millis_t next_button_update_ms;
- static uint8_t lcd_implementation_read_slow_buttons() {
- #if ENABLED(LCD_I2C_TYPE_MCP23017)
-
-
- uint8_t slow_bits = lcd.readButtons() << B_I2C_BTN_OFFSET;
- #if ENABLED(LCD_I2C_VIKI)
- if ((slow_bits & (B_MI | B_RI)) && PENDING(millis(), next_button_update_ms))
- slow_bits &= ~(B_MI | B_RI);
- #endif // LCD_I2C_VIKI
- return slow_bits;
- #endif // LCD_I2C_TYPE_MCP23017
- }
- #endif // LCD_HAS_SLOW_BUTTONS
- #if ENABLED(LCD_HAS_STATUS_INDICATORS)
- static void lcd_implementation_update_indicators() {
-
- static uint8_t ledsprev = 0;
- uint8_t leds = 0;
- if (thermalManager.degTargetBed() > 0) leds |= LED_A;
- if (thermalManager.degTargetHotend(0) > 0) leds |= LED_B;
- #if FAN_COUNT > 0
- if (0
- #if HAS_FAN0
- || fanSpeeds[0]
- #endif
- #if HAS_FAN1
- || fanSpeeds[1]
- #endif
- #if HAS_FAN2
- || fanSpeeds[2]
- #endif
- ) leds |= LED_C;
- #endif // FAN_COUNT > 0
- #if HOTENDS > 1
- if (thermalManager.degTargetHotend(1) > 0) leds |= LED_C;
- #endif
- if (leds != ledsprev) {
- lcd.setBacklight(leds);
- ledsprev = leds;
- }
- }
- #endif // LCD_HAS_STATUS_INDICATORS
- #if ENABLED(AUTO_BED_LEVELING_UBL)
-
- typedef struct {
- uint8_t custom_char_bits[ULTRA_Y_PIXELS_PER_CHAR];
- } custom_char;
- typedef struct {
- uint8_t column, row;
- uint8_t y_pixel_offset, x_pixel_offset;
- uint8_t x_pixel_mask;
- } coordinate;
- void add_edges_to_custom_char(custom_char * const custom, coordinate * const ul, coordinate * const lr, coordinate * const brc, const uint8_t cell_location);
- FORCE_INLINE static void clear_custom_char(custom_char * const cc) { ZERO(cc->custom_char_bits); }
-
|