Fix Malyan LCD, allow no SD Card

This commit is contained in:
Scott Lahteine 2018-05-24 04:35:15 -05:00
parent 27c5ede796
commit 181516f7cb

View File

@ -45,8 +45,13 @@
#if ENABLED(MALYAN_LCD)
#if ENABLED(SDSUPPORT)
#include "cardreader.h"
#include "SdFatConfig.h"
#else
#define LONG_FILENAME_LENGTH 0
#endif
#include "temperature.h"
#include "planner.h"
#include "stepper.h"
@ -57,6 +62,15 @@
#include "Marlin.h"
#if USE_MARLINSERIAL
// Make an exception to use HardwareSerial too
#undef HardwareSerial_h
#include <HardwareSerial.h>
#define USB_STATUS true
#else
#define USB_STATUS Serial
#endif
// On the Malyan M200, this will be Serial1. On a RAMPS board,
// it might not be.
#define LCD_SERIAL Serial1
@ -132,8 +146,6 @@ void process_lcd_c_command(const char* command) {
void process_lcd_eb_command(const char* command) {
char elapsed_buffer[10];
duration_t elapsed;
bool has_days;
uint8_t len;
switch (command[0]) {
case '0': {
elapsed = print_job_timer.duration();
@ -144,9 +156,17 @@ void process_lcd_eb_command(const char* command) {
PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}{TQ:%03i}{TT:%s}"),
thermalManager.degHotend(0),
thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
thermalManager.degBed(),
thermalManager.degTargetBed(),
#else
0, 0,
#endif
#if ENABLED(SDSUPPORT)
card.percentDone(),
#else
0,
#endif
elapsed_buffer);
write_to_lcd(message_buffer);
} break;
@ -223,6 +243,7 @@ void process_lcd_p_command(const char* command) {
switch (command[0]) {
case 'X':
#if ENABLED(SDSUPPORT)
// cancel print
write_to_lcd_P(PSTR("{SYS:CANCELING}"));
card.stopSDPrint(
@ -239,12 +260,14 @@ void process_lcd_p_command(const char* command) {
#endif
wait_for_heatup = false;
write_to_lcd_P(PSTR("{SYS:STARTED}"));
#endif
break;
case 'H':
// Home all axis
enqueue_and_echo_commands_now_P(PSTR("G28"));
break;
default: {
#if ENABLED(SDSUPPORT)
// Print file 000 - a three digit number indicating which
// file to print in the SD card. If it's a directory,
// then switch to the directory.
@ -268,6 +291,7 @@ void process_lcd_p_command(const char* command) {
write_to_lcd_P(PSTR("{SYS:BUILD}"));
card.openAndPrintFile(card.filename);
}
#endif
} break; // default
} // switch
}
@ -292,7 +316,11 @@ void process_lcd_s_command(const char* command) {
char message_buffer[MAX_CURLY_COMMAND];
sprintf_P(message_buffer, PSTR("{T0:%03.0f/%03i}{T1:000/000}{TP:%03.0f/%03i}"),
thermalManager.degHotend(0), thermalManager.degTargetHotend(0),
#if HAS_HEATED_BED
thermalManager.degBed(), thermalManager.degTargetBed()
#else
0, 0
#endif
);
write_to_lcd(message_buffer);
} break;
@ -303,6 +331,7 @@ void process_lcd_s_command(const char* command) {
break;
case 'L': {
#if ENABLED(SDSUPPORT)
if (!card.cardOK) card.initsd();
// A more efficient way to do this would be to
@ -320,6 +349,7 @@ void process_lcd_s_command(const char* command) {
}
write_to_lcd_P(PSTR("{SYS:OK}"));
#endif
} break;
default:
@ -371,15 +401,15 @@ void process_lcd_command(const char* command) {
/**
* UC means connected.
* UD means disconnected
* The stock firmware considers USB initialied as "connected."
* The stock firmware considers USB initialized as "connected."
*/
void update_usb_status(const bool forceUpdate) {
static bool last_usb_connected_status = false;
// This is mildly different than stock, which
// appears to use the usb discovery status.
// This is more logical.
if (last_usb_connected_status != Serial || forceUpdate) {
last_usb_connected_status = Serial;
if (last_usb_connected_status != USB_STATUS || forceUpdate) {
last_usb_connected_status = USB_STATUS;
write_to_lcd_P(last_usb_connected_status ? PSTR("{R:UC}\r\n") : PSTR("{R:UD}\r\n"));
}
}
@ -390,7 +420,7 @@ void update_usb_status(const bool forceUpdate) {
* The optimize attribute fixes a register Compile
* error for amtel.
*/
void lcd_update() _O2 {
void _O2 lcd_update() {
static char inbound_buffer[MAX_CURLY_COMMAND];
// First report USB status.
@ -408,6 +438,7 @@ void lcd_update() _O2 {
}
}
#if ENABLED(SDSUPPORT)
// If there's a print in progress, we need to emit the status as
// {TQ:<PERCENT>}
if (card.sdprinting) {
@ -417,6 +448,7 @@ void lcd_update() _O2 {
sprintf_P(message_buffer, PSTR("{TQ:%03i}"), card.percentDone());
write_to_lcd(message_buffer);
}
#endif
}
/**