1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636 |
- #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 HAS_HEATED_BED
- if (thermalManager.degTargetBed() > 0) leds |= LED_A;
- #endif
- 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); }
-
|