From 07e11c7cf56857dda097f8e99cc7b631d5e5484e Mon Sep 17 00:00:00 2001 From: Ketil Froyn Date: Sat, 16 Mar 2013 23:02:57 +0100 Subject: [PATCH] Add command M928 to enable logging to file of received gcode commands --- Marlin/Marlin_main.cpp | 19 ++++++++++++++++++- Marlin/cardreader.cpp | 7 +++++++ 2 files changed, 25 insertions(+), 1 deletion(-) diff --git a/Marlin/Marlin_main.cpp b/Marlin/Marlin_main.cpp index 372554617..c061e92a4 100644 --- a/Marlin/Marlin_main.cpp +++ b/Marlin/Marlin_main.cpp @@ -132,6 +132,7 @@ // M908 - Control digital trimpot directly. // M350 - Set microstepping mode. // M351 - Toggle MS1 MS2 pins directly. +// M928 - Start SD logging (M928 filename.g) - ended by M29 // M999 - Restart after being stopped by error //Stepper Movement Variables @@ -394,7 +395,14 @@ void loop() if(strstr_P(cmdbuffer[bufindr], PSTR("M29")) == NULL) { card.write_command(cmdbuffer[bufindr]); - SERIAL_PROTOCOLLNPGM(MSG_OK); + if(card.logging) + { + process_commands(); + } + else + { + SERIAL_PROTOCOLLNPGM(MSG_OK); + } } else { @@ -949,6 +957,15 @@ void process_commands() card.removeFile(strchr_pointer + 4); } break; + case 928: //M928 - Start SD write + starpos = (strchr(strchr_pointer + 5,'*')); + if(starpos != NULL){ + char* npos = strchr(cmdbuffer[bufindr], 'N'); + strchr_pointer = strchr(npos,' ') + 1; + *(starpos-1) = '\0'; + } + card.openLogFile(strchr_pointer+5); + break; #endif //SDSUPPORT diff --git a/Marlin/cardreader.cpp b/Marlin/cardreader.cpp index 5d9494a4c..2ffd617f6 100644 --- a/Marlin/cardreader.cpp +++ b/Marlin/cardreader.cpp @@ -16,6 +16,7 @@ CardReader::CardReader() sdprinting = false; cardOK = false; saving = false; + logging = false; autostart_atmillis=0; autostart_stilltocheck=true; //the sd start is delayed, because otherwise the serial cannot answer fast enought to make contact with the hostsoftware. @@ -212,6 +213,11 @@ void CardReader::pauseSDPrint() } +void CardReader::openLogFile(char* name) +{ + logging = true; + openFile(name, false); +} void CardReader::openFile(char* name,bool read) { @@ -471,6 +477,7 @@ void CardReader::closefile() file.sync(); file.close(); saving = false; + logging = false; } void CardReader::getfilename(const uint8_t nr)