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(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()

View file

@ -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;