From 7325d7102ef119188b9ed0f6bbdb02ba90f00ca6 Mon Sep 17 00:00:00 2001 From: neildarlow Date: Mon, 3 Mar 2014 21:01:27 +0000 Subject: [PATCH 1/3] Activate LiquidTWI2 device detection and space-pad LCD status line. --- Marlin/Marlin_main.cpp | 2 ++ Marlin/ultralcd.cpp | 19 +++++++++++++++++++ Marlin/ultralcd.h | 2 ++ .../ultralcd_implementation_hitachi_HD44780.h | 12 ++++++++++-- 4 files changed, 33 insertions(+), 2 deletions(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index d62447071..20ee9ae7a 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -1627,6 +1627,8 @@ void process_commands() lcd_update(); } }else{ + if (!lcd_detected()) + break; while(!lcd_clicked()){ manage_heater(); manage_inactivity(); diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 3262f2d24..607b49eeb 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1148,6 +1148,11 @@ void lcd_setstatus(const char* message) if (lcd_status_message_level > 0) return; strncpy(lcd_status_message, message, LCD_WIDTH); + + size_t i = strlen(lcd_status_message); + memset(lcd_status_message + i, ' ', LCD_WIDTH - i); + lcd_status_message[LCD_WIDTH] = '\0'; + lcdDrawUpdate = 2; } void lcd_setstatuspgm(const char* message) @@ -1155,6 +1160,11 @@ void lcd_setstatuspgm(const char* message) if (lcd_status_message_level > 0) return; strncpy_P(lcd_status_message, message, LCD_WIDTH); + + size_t i = strlen(lcd_status_message); + memset(lcd_status_message + i, ' ', LCD_WIDTH - i); + lcd_status_message[LCD_WIDTH] = '\0'; + lcdDrawUpdate = 2; } void lcd_setalertstatuspgm(const char* message) @@ -1263,6 +1273,15 @@ void lcd_buttons_update() lastEncoderBits = enc; } +bool lcd_detected(void) +{ +#if (defined(LCD_I2C_TYPE_MCP23017) || defined(LCD_I2C_TYPE_MCP23008)) && defined(DETECT_DEVICE) + return lcd.LcdDetected() == 1; +#else + return true; +#endif +} + void lcd_buzz(long duration, uint16_t freq) { #ifdef LCD_USE_I2C_BUZZER diff --git a/Marlin/ultralcd.h b/Marlin/ultralcd.h index f4570f6a5..fce23bab0 100644 --- a/Marlin/ultralcd.h +++ b/Marlin/ultralcd.h @@ -11,6 +11,7 @@ void lcd_setstatuspgm(const char* message); void lcd_setalertstatuspgm(const char* message); void lcd_reset_alert_level(); + bool lcd_detected(void); #ifdef DOGLCD extern int lcd_contrast; @@ -92,6 +93,7 @@ FORCE_INLINE void lcd_buttons_update() {} FORCE_INLINE void lcd_reset_alert_level() {} FORCE_INLINE void lcd_buzz(long duration,uint16_t freq) {} + FORCE_INLINE bool lcd_detected(void) { return true; } #define LCD_MESSAGEPGM(x) #define LCD_ALERTMESSAGEPGM(x) diff --git a/Marlin/ultralcd_implementation_hitachi_HD44780.h b/Marlin/ultralcd_implementation_hitachi_HD44780.h index 932895b9b..fd3374454 100644 --- a/Marlin/ultralcd_implementation_hitachi_HD44780.h +++ b/Marlin/ultralcd_implementation_hitachi_HD44780.h @@ -166,13 +166,21 @@ extern volatile uint16_t buttons; //an extended version of the last checked but #include #include #define LCD_CLASS LiquidTWI2 - LCD_CLASS lcd(LCD_I2C_ADDRESS); + #if defined(DETECT_DEVICE) + LCD_CLASS lcd(LCD_I2C_ADDRESS, 1); + #else + LCD_CLASS lcd(LCD_I2C_ADDRESS); + #endif #elif defined(LCD_I2C_TYPE_MCP23008) #include #include #define LCD_CLASS LiquidTWI2 - LCD_CLASS lcd(LCD_I2C_ADDRESS); + #if defined(DETECT_DEVICE) + LCD_CLASS lcd(LCD_I2C_ADDRESS, 1); + #else + LCD_CLASS lcd(LCD_I2C_ADDRESS); + #endif #elif defined(LCD_I2C_TYPE_PCA8574) #include From 0ddee3c7db26466b0c406180295b59cb4c87d5c4 Mon Sep 17 00:00:00 2001 From: whosawhatsis Date: Fri, 14 Mar 2014 18:27:11 -0700 Subject: [PATCH 2/3] Prevent SD card insertion from causing a hang when using LiquidTWI2 device detection --- Marlin/ultralcd.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Marlin/ultralcd.cpp b/Marlin/ultralcd.cpp index 607b49eeb..4e07ac306 100644 --- a/Marlin/ultralcd.cpp +++ b/Marlin/ultralcd.cpp @@ -1051,7 +1051,7 @@ void lcd_update() lcd_buttons_update(); #if (SDCARDDETECT > 0) - if((IS_SD_INSERTED != lcd_oldcardstatus)) + if((IS_SD_INSERTED != lcd_oldcardstatus && lcd_detected())) { lcdDrawUpdate = 2; lcd_oldcardstatus = IS_SD_INSERTED; From 89f78b0b80522fd63330d2cb31befa79c7a63576 Mon Sep 17 00:00:00 2001 From: Neil Darlow Date: Thu, 27 Mar 2014 17:02:17 +0000 Subject: [PATCH 3/3] Allow use of either SD Card slot when LCD Panel is configured. Preference is for Controller SD slot before LCD Panel slot when both are occupied. --- Marlin/cardreader.cpp | 12 ++++++++++-- Marlin/pins.h | 6 +++--- 2 files changed, 13 insertions(+), 5 deletions(-) diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 5fb8dcc0f..036a34e5c 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -150,9 +150,17 @@ void CardReader::initsd() if(root.isOpen()) root.close(); #ifdef SDSLOW - if (!card.init(SPI_HALF_SPEED,SDSS)) + if (!card.init(SPI_HALF_SPEED,SDSS) + #if defined(LCD_SDSS) && (LCD_SDSS != SDSS) + && !card.init(SPI_HALF_SPEED,LCD_SDSS) + #endif + ) #else - if (!card.init(SPI_FULL_SPEED,SDSS)) + if (!card.init(SPI_FULL_SPEED,SDSS) + #if defined(LCD_SDSS) && (LCD_SDSS != SDSS) + && !card.init(SPI_FULL_SPEED,LCD_SDSS) + #endif + ) #endif { //if (!card.init(SPI_HALF_SPEED,SDSS)) diff --git a/Marlin/pins.h b/Marlin/pins.h index 9976d431d..d276621ed 100644 --- a/Marlin/pins.h +++ b/Marlin/pins.h @@ -614,14 +614,14 @@ #define BTN_EN1 47 //reverse if the encoder turns the wrong way. #define BTN_EN2 43 #define BTN_ENC 32 - #define SDSS 53 + #define LCD_SDSS 53 #define SDCARDDETECT -1 #define KILL_PIN 41 #elif defined(LCD_I2C_VIKI) #define BTN_EN1 22 //reverse if the encoder turns the wrong way. #define BTN_EN2 7 #define BTN_ENC -1 - #define SDSS 53 + #define LCD_SDSS 53 #define SDCARDDETECT 49 #else //arduino pin which triggers an piezzo beeper @@ -1123,7 +1123,7 @@ #ifdef LCD_I2C_PANELOLU2 #ifdef MELZI #define BTN_ENC 29 //the click switch - #define SDSS 30 //to use the SD card reader on the Panelolu2 rather than the melzi board + #define LCD_SDSS 30 //to use the SD card reader on the Panelolu2 rather than the melzi board #else #define BTN_ENC 30 //the click switch #endif