diff --git a/Configuration.h b/Configuration.h
index 5a82635..0d991d8 100644
--- a/Configuration.h
+++ b/Configuration.h
@@ -43,6 +43,8 @@ Licence: GPL
#define PASSWORD_PAGE "passwd.php"
#define INDEX_PAGE "control.php"
#define PRINT_PAGE "print.php"
+#define MESSAGE_FILE "messages.php"
+#define MESSAGE_TEMPLATE "messages.txt"
#define STRING_LENGTH 1000
#define PHP_TAG_LENGTH 200
#define POST_LENGTH 200
diff --git a/GCodes.h b/GCodes.h
index 90f2698..694e13b 100644
--- a/GCodes.h
+++ b/GCodes.h
@@ -36,6 +36,7 @@ class GCodes
void ActOnGcode();
Platform* platform;
+ boolean active;
Move* move;
Heat* heat;
Webserver* webserver;
diff --git a/GCodes.ino b/GCodes.ino
index 9198527..22f904f 100644
--- a/GCodes.ino
+++ b/GCodes.ino
@@ -23,6 +23,7 @@ Licence: GPL
GCodes::GCodes(Platform* p, Move* m, Heat* h, Webserver* w)
{
+ active = false;
//Serial.println("GCodes constructor");
platform = p;
move = m;
@@ -32,28 +33,32 @@ GCodes::GCodes(Platform* p, Move* m, Heat* h, Webserver* w)
void GCodes::Exit()
{
-
+ active = false;
}
void GCodes::Init()
{
lastTime = platform->Time();
gcodePointer = 0;
+ active = true;
}
void GCodes::ActOnGcode()
{
- platform->Message(HOST_MESSAGE, "\nGCode: ");
+ platform->Message(HOST_MESSAGE, "GCode: ");
platform->Message(HOST_MESSAGE, gcodeBuffer);
- platform->Message(HOST_MESSAGE, "\n");
+ platform->Message(HOST_MESSAGE, "
\n");
}
void GCodes::Spin()
{
+ if(!active)
+ return;
+
if(webserver->Available())
{
gcodeBuffer[gcodePointer] = webserver->Read();
diff --git a/Heat.h b/Heat.h
index 2957703..db0782c 100644
--- a/Heat.h
+++ b/Heat.h
@@ -44,6 +44,7 @@ class Heat
private:
Platform* platform;
+ boolean active;
unsigned long lastTime;
//float frac;
//float inc;
diff --git a/Heat.ino b/Heat.ino
index 2b52eac..5322852 100644
--- a/Heat.ino
+++ b/Heat.ino
@@ -24,22 +24,27 @@ Heat::Heat(Platform* p)
{
//Serial.println("Heat constructor");
platform = p;
+ active = false;
}
void Heat::Init()
{
lastTime = platform->Time();
//frac = 0;
- //inc = 0.01;
+ //inc = 0.01;
+ active = true;
}
void Heat::Exit()
{
-
+ active = false;
}
void Heat::Spin()
{
+ if(!active)
+ return;
+
unsigned long t = platform->Time();
if(t - lastTime < 3000)
return;
diff --git a/Move.h b/Move.h
index 67910b2..957f3f9 100644
--- a/Move.h
+++ b/Move.h
@@ -34,7 +34,7 @@ class Move
Platform* platform;
unsigned long lastTime;
-
+ boolean active;
};
#endif
diff --git a/Move.ino b/Move.ino
index 52e52b6..3085e47 100644
--- a/Move.ino
+++ b/Move.ino
@@ -24,6 +24,7 @@ Move::Move(Platform* p)
{
//Serial.println("Move constructor");
platform = p;
+ active = false;
}
void Move::Init()
@@ -32,16 +33,20 @@ void Move::Init()
platform->SetDirection(X_AXIS, FORWARDS);
platform->SetDirection(Y_AXIS, FORWARDS);
platform->SetDirection(Z_AXIS, FORWARDS);
- platform->SetDirection(3, FORWARDS);
+ platform->SetDirection(3, FORWARDS);
+ active = true;
}
void Move::Exit()
{
-
+ active = false;
}
void Move::Spin()
{
+ if(!active)
+ return;
+
unsigned long t = platform->Time();
if(t - lastTime < 300)
return;
diff --git a/Platform.h b/Platform.h
index ec57a20..192e447 100644
--- a/Platform.h
+++ b/Platform.h
@@ -188,6 +188,7 @@ class Platform
char* FileList(char* directory); // Returns a ;-separated list of all the files in the named directory (for example on an SD card).
int OpenFile(char* fileName, boolean write); // Open a local file (for example on an SD card).
+ void GoToEnd(int file); // Position the file at the end (so you can write on the end).
boolean Read(int file, unsigned char& b); // Read a single byte from a file into b,
// returned value is false for EoF, true otherwise
void WriteString(int file, char* s); // Write the string to a file.
@@ -198,6 +199,7 @@ class Platform
char* GetTempDir(); // Where temporary files are
void Close(int file); // Close a file or device, writing any unwritten buffer contents first.
boolean DeleteFile(char* fileName); // Delete a file
+ char* PrependRoot(char* root, char* fileName);
unsigned char ClientRead(); // Read a byte from the client
void SendToClient(char* message); // Send string to the host
@@ -229,6 +231,8 @@ class Platform
unsigned long lastTime;
+ boolean active;
+
// Load settings from local storage
bool LoadFromStore();
@@ -278,6 +282,7 @@ class Platform
char* sysDir;
char* tempDir;
char fileList[FILE_LIST_LENGTH];
+ char scratchString[STRING_LENGTH];
// Network connection
diff --git a/Platform.ino b/Platform.ino
index 2f3225b..7124fd5 100644
--- a/Platform.ino
+++ b/Platform.ino
@@ -39,11 +39,7 @@ void loop()
Platform::Platform(RepRap* r)
{
reprap = r;
-}
-
-RepRap* Platform::GetRepRap()
-{
- return reprap;
+ active = false;
}
void Platform::Init()
@@ -164,11 +160,36 @@ void Platform::Init()
if (!SD.begin(SD_SPI))
Serial.println("SD initialization failed.");
// SD.begin() returns with the SPI disabled, so you need not disable it here
+
+ // Reinitialise the message file
+
+ DeleteFile(PrependRoot(GetWebDir(), MESSAGE_FILE));
+ int m = OpenFile(PrependRoot(GetWebDir(), MESSAGE_TEMPLATE), false);
+ int n = OpenFile(PrependRoot(GetWebDir(), MESSAGE_FILE), true);
+ byte b;
+ while (Read(m, b))
+ Write(n,b);
+ Close(m);
+ Close(n);
+
+ active = true;
}
void Platform::Exit()
{
-
+ active = false;
+}
+
+RepRap* Platform::GetRepRap()
+{
+ return reprap;
+}
+
+
+char* Platform::PrependRoot(char* root, char* fileName)
+{
+ strcpy(scratchString, root);
+ return strcat(scratchString, fileName);
}
@@ -256,7 +277,7 @@ char* Platform::FileList(char* directory)
{
Message(HOST_MESSAGE, "FileList - directory: ");
Message(HOST_MESSAGE, directory);
- Message(HOST_MESSAGE, " has too many files!");
+ Message(HOST_MESSAGE, " has too many files!
\n");
return "";
}
}
@@ -284,7 +305,7 @@ boolean Platform::DeleteFile(char* fileName)
int Platform::OpenFile(char* fileName, boolean write)
{
int result = -1;
- for(int i=0; i < MAX_FILES; i++)
+ for(int i = 0; i < MAX_FILES; i++)
if(!inUse[i])
{
result = i;
@@ -292,7 +313,7 @@ int Platform::OpenFile(char* fileName, boolean write)
}
if(result < 0)
{
- Message(HOST_MESSAGE, "Max open file count exceeded.\n");
+ Message(HOST_MESSAGE, "Max open file count exceeded.
\n");
return -1;
}
@@ -300,15 +321,16 @@ int Platform::OpenFile(char* fileName, boolean write)
{
if(!write)
{
- Message(HOST_MESSAGE, "File not found for reading.\n");
+ Message(HOST_MESSAGE, "File not found for reading.
\n");
return -1;
}
files[result] = SD.open(fileName, FILE_WRITE);
} else
{
if(write)
+ {
files[result] = SD.open(fileName, FILE_WRITE);
- else
+ }else
files[result] = SD.open(fileName, FILE_READ);
}
@@ -316,6 +338,17 @@ int Platform::OpenFile(char* fileName, boolean write)
return result;
}
+void Platform::GoToEnd(int file)
+{
+ if(!inUse[file])
+ {
+ Message(HOST_MESSAGE, "Attempt to seek on a non-open file.
\n");
+ return;
+ }
+ unsigned long e = files[file].size();
+ files[file].seek(e);
+}
+
void Platform::Close(int file)
{
files[file].close();
@@ -327,7 +360,7 @@ boolean Platform::Read(int file, unsigned char& b)
{
if(!inUse[file])
{
- Message(HOST_MESSAGE, "Attempt to read from a non-open file.\n");
+ Message(HOST_MESSAGE, "Attempt to read from a non-open file.
\n");
return false;
}
@@ -341,7 +374,7 @@ void Platform::Write(int file, char b)
{
if(!inUse[file])
{
- Message(HOST_MESSAGE, "Attempt to write byte to a non-open file.\n");
+ Message(HOST_MESSAGE, "Attempt to write byte to a non-open file.
\n");
return;
}
@@ -352,7 +385,7 @@ void Platform::WriteString(int file, char* b)
{
if(!inUse[file])
{
- Message(HOST_MESSAGE, "Attempt to write string to a non-open file.\n");
+ Message(HOST_MESSAGE, "Attempt to write string to a non-open file.
\n");
return;
}
@@ -375,7 +408,12 @@ void Platform::Message(char type, char* message)
case HOST_MESSAGE:
default:
+
+ int m = OpenFile(PrependRoot(GetWebDir(), MESSAGE_FILE), true);
+ GoToEnd(m);
+ WriteString(m, message);
Serial.print(message);
+ Close(m);
}
}
@@ -390,7 +428,7 @@ void Platform::SendToClient(char* message)
//Serial.print("Sent: ");
//Serial.print(message);
} else
- Message(HOST_MESSAGE, "Attempt to send string to disconnected client.\n");
+ Message(HOST_MESSAGE, "Attempt to send string to disconnected client.
\n");
}
// Where the php/htm etc files are
@@ -429,6 +467,9 @@ char* Platform::GetTempDir()
void Platform::Spin()
{
+ if(!active)
+ return;
+
ClientMonitor();
if(Time() - lastTime < 2000000)
return;
diff --git a/RepRapFirmware.h b/RepRapFirmware.h
index b98b5eb..8542cd1 100644
--- a/RepRapFirmware.h
+++ b/RepRapFirmware.h
@@ -54,6 +54,7 @@ class RepRap
private:
Platform* platform;
+ boolean active;
Move* move;
Heat* heat;
GCodes* gcodes;
@@ -71,6 +72,7 @@ class RepRap
inline RepRap::RepRap()
{
+ active = false;
platform = new Platform(this);
move = new Move(platform);
heat = new Heat(platform);
diff --git a/RepRapFirmware.ino b/RepRapFirmware.ino
index 2fa66b3..13a0dfc 100644
--- a/RepRapFirmware.ino
+++ b/RepRapFirmware.ino
@@ -60,11 +60,13 @@ void RepRap::Init()
heat->Init();
gcodes->Init();
webserver->Init();
- platform->Message(HOST_MESSAGE, "RepRapPro RepRap Firmware (Re)Started\n\n");
+ platform->Message(HOST_MESSAGE, "RepRapPro RepRap Firmware (Re)Started
\n");
+ active = true;
}
void RepRap::Exit()
{
+ active = false;
webserver->Exit();
gcodes->Exit();
heat->Exit();
@@ -74,6 +76,9 @@ void RepRap::Exit()
void RepRap::Spin()
{
+ if(!active)
+ return;
+
platform->Spin();
move->Spin();
heat->Spin();
diff --git a/SD-image/www/control.php b/SD-image/www/control.php
index 592fe79..3002c05 100644
--- a/SD-image/www/control.php
+++ b/SD-image/www/control.php
@@ -18,6 +18,8 @@