From ec5f5fe536d73ab3563f6e751842d2ee2ef9f9b9 Mon Sep 17 00:00:00 2001 From: Adrian Bowyer Date: Tue, 19 Nov 2013 16:10:53 +0000 Subject: [PATCH] M503 implemented. Prints the config file to USB. --- GCodes.cpp | 43 +++++++++++++++++++++++++++++++++++++++++++ GCodes.h | 2 ++ Platform.cpp | 6 ++++-- 3 files changed, 49 insertions(+), 2 deletions(-) diff --git a/GCodes.cpp b/GCodes.cpp index 647b591..be21360 100644 --- a/GCodes.cpp +++ b/GCodes.cpp @@ -60,6 +60,7 @@ void GCodes::Init() fileBeingPrinted = NULL; fileToPrint = NULL; fileBeingWritten = NULL; + configFile = NULL; homeX = false; homeY = false; homeZ = false; @@ -581,6 +582,44 @@ void GCodes::RunConfigurationGCodes() fileToPrint = NULL; } +bool GCodes::SendConfigToLine() +{ + if(configFile == NULL) + { + configFile = platform->GetFileStore(platform->GetSysDir(), platform->GetConfigFile(), false); + if(configFile == NULL) + { + platform->Message(HOST_MESSAGE, "Configuration file not found\n"); + return true; + } + platform->GetLine()->Write('\n'); + } + + char b; + + while(configFile->Status() & byteAvailable) + { + if(configFile->Read(b)) + { + platform->GetLine()->Write(b); + if(b == '\n') + return false; + } else + { + platform->GetLine()->Write('\n'); + configFile->Close(); + configFile = NULL; + return true; + } + } + + // Should never get here + + configFile->Close(); + configFile = NULL; + return true; +} + // Function to handle dwell delays. Return true for // dwell finished, false otherwise. @@ -1194,6 +1233,10 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb) case 304: // Set thermistor parameters break; + case 503: // Print parameters + result = SendConfigToLine(); + break; + case 550: // Set machine name if(gb->Seen('P')) reprap.GetWebserver()->SetName(gb->GetString()); diff --git a/GCodes.h b/GCodes.h index 6293b1d..5affe5f 100644 --- a/GCodes.h +++ b/GCodes.h @@ -100,6 +100,7 @@ class GCodes void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code, bool resend); char* OpenFileToWrite(char* fileName, GCodeBuffer *gb); void WriteGCodeToFile(GCodeBuffer *gb); + bool SendConfigToLine(); int8_t Heater(int8_t head); Platform* platform; @@ -125,6 +126,7 @@ class GCodes FileStore* fileBeingPrinted; FileStore* fileToPrint; FileStore* fileBeingWritten; + FileStore* configFile; int8_t selectedHead; bool homeX; bool homeY; diff --git a/Platform.cpp b/Platform.cpp index 3932e9c..a835edb 100644 --- a/Platform.cpp +++ b/Platform.cpp @@ -622,6 +622,7 @@ bool FileStore::Open(char* directory, char* fileName, bool write) snprintf(scratchString, STRING_LENGTH, "%d", openReturn); platform->Message(HOST_MESSAGE, scratchString); platform->Message(HOST_MESSAGE, "\n"); + Close(); return false; } bufferPointer = 0; @@ -636,9 +637,10 @@ bool FileStore::Open(char* directory, char* fileName, bool write) snprintf(scratchString, STRING_LENGTH, "%d", openReturn); platform->Message(HOST_MESSAGE, scratchString); platform->Message(HOST_MESSAGE, "\n"); + Close(); return false; - } - bufferPointer = FILE_BUF_LEN; + } else + ReadBuffer(); } inUse = true;