File upload mechanism also now works with the web code. If we can open a user's GCode file in the Javascript this will allow web uploads. Horay! See: http://www.html5rocks.com/en/tutorials/file/dndfiles/

This commit is contained in:
Adrian Bowyer 2013-11-18 17:40:14 +00:00
parent 3dc0c7a27e
commit 21424714f7
2 changed files with 31 additions and 9 deletions

View file

@ -120,10 +120,15 @@ void GCodes::Spin()
if(webserver->GCodeAvailable()) if(webserver->GCodeAvailable())
{ {
if(webGCode->Put(webserver->ReadGCode())) if(webGCode->Put(webserver->ReadGCode()))
webGCode->SetFinished(ActOnGcode(webGCode)); {
platform->ClassReport("GCodes", longWait); if(webGCode->WritingFile())
return; WriteGCodeToFile(webGCode);
else
webGCode->SetFinished(ActOnGcode(webGCode));
}
platform->ClassReport("GCodes", longWait);
return;
} }
if(platform->GetLine()->Status() & byteAvailable) if(platform->GetLine()->Status() & byteAvailable)
@ -131,7 +136,7 @@ void GCodes::Spin()
platform->GetLine()->Read(b); platform->GetLine()->Read(b);
if(serialGCode->Put(b)) if(serialGCode->Put(b))
{ {
if(fileBeingWritten) if(serialGCode->WritingFile())
WriteGCodeToFile(serialGCode); WriteGCodeToFile(serialGCode);
else else
serialGCode->SetFinished(ActOnGcode(serialGCode)); serialGCode->SetFinished(ActOnGcode(serialGCode));
@ -494,11 +499,13 @@ char* GCodes::GetCurrentCoordinates()
return scratchString; return scratchString;
} }
char* GCodes::OpenFileToWrite(char* fileName) char* GCodes::OpenFileToWrite(char* fileName, GCodeBuffer *gb)
{ {
fileBeingWritten = platform->GetFileStore(platform->GetGCodeDir(), fileName, true); fileBeingWritten = platform->GetFileStore(platform->GetGCodeDir(), fileName, true);
if(fileBeingWritten == NULL) if(fileBeingWritten == NULL)
platform->Message(HOST_MESSAGE, "Can't open GCode file for writing.\n"); 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->Close();
fileBeingWritten = NULL; fileBeingWritten = NULL;
gb->SetWritingFile(false);
char* r = reply; char* r = reply;
if(platform->Emulating() == marlin) if(platform->Emulating() == marlin)
r = "Done saving file."; r = "Done saving file.";
@ -993,7 +1001,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
case 28: // Write to file case 28: // Write to file
str = gb->GetUnprecedentedString(); str = gb->GetUnprecedentedString();
OpenFileToWrite(str); OpenFileToWrite(str, gb);
snprintf(reply, STRING_LENGTH, "Writing to file: %s", str); snprintf(reply, STRING_LENGTH, "Writing to file: %s", str);
break; break;
@ -1328,6 +1336,7 @@ GCodeBuffer::GCodeBuffer(Platform* p, char* id)
{ {
platform = p; platform = p;
identity = id; identity = id;
writingFile = false; // Has to be done here as Init() is called every line.
} }
void GCodeBuffer::Init() void GCodeBuffer::Init()

View file

@ -43,6 +43,8 @@ class GCodeBuffer
char* Buffer(); char* Buffer();
bool Finished(); bool Finished();
void SetFinished(bool f); void SetFinished(bool f);
bool WritingFile();
void SetWritingFile(bool wf);
private: private:
int CheckSum(); int CheckSum();
@ -53,6 +55,7 @@ class GCodeBuffer
int readPointer; int readPointer;
bool inComment; bool inComment;
bool finished; bool finished;
bool writingFile;
}; };
//**************************************************************************************************** //****************************************************************************************************
@ -95,7 +98,7 @@ class GCodes
bool StandbyHeaters(); bool StandbyHeaters();
void SetEthernetAddress(GCodeBuffer *gb, int mCode); void SetEthernetAddress(GCodeBuffer *gb, int mCode);
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code, bool resend); 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); void WriteGCodeToFile(GCodeBuffer *gb);
int8_t Heater(int8_t head); int8_t Heater(int8_t head);
@ -160,6 +163,16 @@ inline void GCodeBuffer::SetFinished(bool f)
finished = f; finished = f;
} }
inline bool GCodeBuffer::WritingFile()
{
return writingFile;
}
inline void GCodeBuffer::SetWritingFile(bool wf)
{
writingFile = wf;
}
inline bool GCodes::PrintingAFile() inline bool GCodes::PrintingAFile()
{ {
return fileBeingPrinted != NULL; return fileBeingPrinted != NULL;