From c58453a7265ae4c39104781b90833cb02333c8b8 Mon Sep 17 00:00:00 2001 From: Andre Sklenar Date: Wed, 14 Dec 2016 14:38:36 +0100 Subject: [PATCH 1/2] main: add chunk write to sd card --- Firmware/Marlin_main.cpp | 138 +++++++++++++++++++++++++++++++++++++-- Firmware/cardreader.cpp | 13 ++++ Firmware/cardreader.h | 1 + 3 files changed, 147 insertions(+), 5 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index 62a8bed4..efe9f259 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -261,6 +261,8 @@ int lcd_change_fil_state = 0; int feedmultiplyBckp = 100; unsigned char lang_selected = 0; +bool prusa_sd_card_upload = false; + unsigned long total_filament_used; unsigned int heating_status; @@ -1069,6 +1071,80 @@ void setup() update_current_firmware_version_to_eeprom(); } +void trace(); + +#define CHUNK_SIZE 64 // bytes +#define SAFETY_MARGIN 1 +char chunk[CHUNK_SIZE+SAFETY_MARGIN]; +int chunkHead = 0; + +int serial_read_stream() { + + setTargetHotend(0, 0); + setTargetBed(0); + + lcd_implementation_clear(); + lcd_printPGM(PSTR(" Upload in progress")); + + // first wait for how many bytes we will receive + uint32_t bytesToReceive; + + // receive the four bytes + char bytesToReceiveBuffer[4]; + for (int i=0; i<4; i++) { + int data; + while ((data = MYSERIAL.read()) == -1) {}; + bytesToReceiveBuffer[i] = data; + + } + + // make it a uint32 + memcpy(&bytesToReceive, &bytesToReceiveBuffer, 4); + + // we're ready, notify the sender + MYSERIAL.write('+'); + + // lock in the routine + uint32_t receivedBytes = 0; + while (prusa_sd_card_upload) { + int i; + for (i=0; i"); + MYSERIAL.println(description); + MYSERIAL.print("<"); + + } else if (code_seen("M28")) { + trace(); + prusa_sd_card_upload = true; + card.openFile(strchr_pointer+4,false); + } else if (code_seen("mkdir")) { + card.mkdir(strchr_pointer+6); + } else if(code_seen("Fir")){ SERIAL_PROTOCOLLN(FW_version); @@ -1679,14 +1798,23 @@ void process_commands() lcd_force_language_selection(); } else if(code_seen("Lz")) { EEPROM_save_B(EEPROM_BABYSTEP_Z,0); - } + } else if (code_seen("SERIAL LOW")) { + MYSERIAL.println("SERIAL LOW"); + MYSERIAL.begin(BAUDRATE); + return; + } else if (code_seen("SERIAL HIGH")) { + MYSERIAL.println("SERIAL HIGH"); + MYSERIAL.begin(1152000); + return; + } //else if (code_seen('Cal')) { // lcd_calibration(); // } } - else - if(code_seen('G')) + else if (code_seen('^')) { + // nothing, this is a version line + } else if(code_seen('G')) { switch((int)code_value()) { diff --git a/Firmware/cardreader.cpp b/Firmware/cardreader.cpp index 85bfbe30..a9ee7e57 100644 --- a/Firmware/cardreader.cpp +++ b/Firmware/cardreader.cpp @@ -501,6 +501,19 @@ void CardReader::write_command(char *buf) } } +#define CHUNK_SIZE 64 + +void CardReader::write_command_no_newline(char *buf) +{ + file.write(buf, CHUNK_SIZE); + if (file.writeError) + { + SERIAL_ERROR_START; + SERIAL_ERRORLNRPGM(MSG_SD_ERR_WRITE_TO_FILE); + MYSERIAL.println("An error while writing to the SD Card."); + } +} + void CardReader::checkautostart(bool force) { diff --git a/Firmware/cardreader.h b/Firmware/cardreader.h index a488bee6..3e87b331 100644 --- a/Firmware/cardreader.h +++ b/Firmware/cardreader.h @@ -14,6 +14,7 @@ public: void initsd(); void write_command(char *buf); + void write_command_no_newline(char *buf); //files auto[0-9].g on the sd card are performed in a row //this is to delay autostart and hence the initialisaiton of the sd card to some seconds after the normal init, so the device is available quick after a reset From 16e34501a044b20aea93ba25b494f5c738a1c00f Mon Sep 17 00:00:00 2001 From: Andre Sklenar Date: Wed, 14 Dec 2016 14:49:23 +0100 Subject: [PATCH 2/2] main: remove features that are not complete yet Signed-off-by: Andre Sklenar --- Firmware/Marlin_main.cpp | 11 +---------- 1 file changed, 1 insertion(+), 10 deletions(-) diff --git a/Firmware/Marlin_main.cpp b/Firmware/Marlin_main.cpp index efe9f259..3729c6d9 100644 --- a/Firmware/Marlin_main.cpp +++ b/Firmware/Marlin_main.cpp @@ -1200,6 +1200,7 @@ void loop() cmdqueue_pop_front(); cmdbuffer_front_already_processed = false; } +} //check heater every n milliseconds manage_heater(); manage_inactivity(); @@ -1772,20 +1773,10 @@ void process_commands() #endif // SDSUPPORT - } else if(code_seen("fd")) { - char description[30]; - memset(description, ' ', 30); - getFileDescription(strchr_pointer + 3, description); - MYSERIAL.print(">"); - MYSERIAL.println(description); - MYSERIAL.print("<"); - } else if (code_seen("M28")) { trace(); prusa_sd_card_upload = true; card.openFile(strchr_pointer+4,false); - } else if (code_seen("mkdir")) { - card.mkdir(strchr_pointer+6); } else if(code_seen("Fir")){ SERIAL_PROTOCOLLN(FW_version);