diff --git a/GCodes.cpp b/GCodes.cpp index 46b239b..ab97893 100644 --- a/GCodes.cpp +++ b/GCodes.cpp @@ -120,10 +120,15 @@ void GCodes::Spin() if(webserver->GCodeAvailable()) { - if(webGCode->Put(webserver->ReadGCode())) - webGCode->SetFinished(ActOnGcode(webGCode)); - platform->ClassReport("GCodes", longWait); - return; + if(webGCode->Put(webserver->ReadGCode())) + { + if(webGCode->WritingFile()) + WriteGCodeToFile(webGCode); + else + webGCode->SetFinished(ActOnGcode(webGCode)); + } + platform->ClassReport("GCodes", longWait); + return; } if(platform->GetLine()->Status() & byteAvailable) @@ -131,7 +136,7 @@ void GCodes::Spin() platform->GetLine()->Read(b); if(serialGCode->Put(b)) { - if(fileBeingWritten) + if(serialGCode->WritingFile()) WriteGCodeToFile(serialGCode); else serialGCode->SetFinished(ActOnGcode(serialGCode)); @@ -494,11 +499,13 @@ char* GCodes::GetCurrentCoordinates() return scratchString; } -char* GCodes::OpenFileToWrite(char* fileName) +char* GCodes::OpenFileToWrite(char* fileName, GCodeBuffer *gb) { fileBeingWritten = platform->GetFileStore(platform->GetGCodeDir(), fileName, true); if(fileBeingWritten == NULL) platform->Message(HOST_MESSAGE, "Can't open GCode file for writing.\n"); + else + gb->SetWritingFile(true); } @@ -521,6 +528,7 @@ void GCodes::WriteGCodeToFile(GCodeBuffer *gb) { fileBeingWritten->Close(); fileBeingWritten = NULL; + gb->SetWritingFile(false); char* r = reply; if(platform->Emulating() == marlin) r = "Done saving file."; @@ -993,7 +1001,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb) case 28: // Write to file str = gb->GetUnprecedentedString(); - OpenFileToWrite(str); + OpenFileToWrite(str, gb); snprintf(reply, STRING_LENGTH, "Writing to file: %s", str); break; @@ -1327,7 +1335,8 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb) GCodeBuffer::GCodeBuffer(Platform* p, char* id) { platform = p; - identity = id; + identity = id; + writingFile = false; // Has to be done here as Init() is called every line. } void GCodeBuffer::Init() diff --git a/GCodes.h b/GCodes.h index 801ec52..6293b1d 100644 --- a/GCodes.h +++ b/GCodes.h @@ -43,6 +43,8 @@ class GCodeBuffer char* Buffer(); bool Finished(); void SetFinished(bool f); + bool WritingFile(); + void SetWritingFile(bool wf); private: int CheckSum(); @@ -53,6 +55,7 @@ class GCodeBuffer int readPointer; bool inComment; bool finished; + bool writingFile; }; //**************************************************************************************************** @@ -95,7 +98,7 @@ class GCodes bool StandbyHeaters(); void SetEthernetAddress(GCodeBuffer *gb, int mCode); void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code, bool resend); - char* OpenFileToWrite(char* fileName); + char* OpenFileToWrite(char* fileName, GCodeBuffer *gb); void WriteGCodeToFile(GCodeBuffer *gb); int8_t Heater(int8_t head); @@ -160,6 +163,16 @@ inline void GCodeBuffer::SetFinished(bool f) finished = f; } +inline bool GCodeBuffer::WritingFile() +{ + return writingFile; +} + +inline void GCodeBuffer::SetWritingFile(bool wf) +{ + writingFile = wf; +} + inline bool GCodes::PrintingAFile() { return fileBeingPrinted != NULL;