Fixed nested file bug, other minor changes

Fixed a bug when one file was called from another
M111 S2 command now displays time since last reset
M106 'I' parameter now only inverts fan PWM when >0
Non-homing moves when bed probing are now done at max speed
M999 reset command now delays 0.5 second to allow response to be sent
back to browser, otherwise it may retry the reset
This commit is contained in:
David Crocker 2014-04-29 23:21:31 +01:00
parent 81b213752b
commit 406a0c074f
7 changed files with 75 additions and 43 deletions

View file

@ -24,8 +24,8 @@ Licence: GPL
#define CONFIGURATION_H #define CONFIGURATION_H
#define NAME "RepRapFirmware" #define NAME "RepRapFirmware"
#define VERSION "0.58c-dc42" #define VERSION "0.58d-dc42"
#define DATE "2014-04-28" #define DATE "2014-04-29"
#define LAST_AUTHOR "dc42" #define LAST_AUTHOR "dc42"
// Other firmware that we might switch to be compatible with. // Other firmware that we might switch to be compatible with.

View file

@ -34,7 +34,6 @@ GCodes::GCodes(Platform* p, Webserver* w)
fileGCode = new GCodeBuffer(platform, "file: "); fileGCode = new GCodeBuffer(platform, "file: ");
serialGCode = new GCodeBuffer(platform, "serial: "); serialGCode = new GCodeBuffer(platform, "serial: ");
cannedCycleGCode = new GCodeBuffer(platform, "macro: "); cannedCycleGCode = new GCodeBuffer(platform, "macro: ");
coolingInverted = false;
} }
void GCodes::Exit() void GCodes::Exit()
@ -69,6 +68,7 @@ void GCodes::Init()
dwellTime = longWait; dwellTime = longWait;
axisIsHomed[X_AXIS] = axisIsHomed[Y_AXIS] = axisIsHomed[Z_AXIS] = false; axisIsHomed[X_AXIS] = axisIsHomed[Y_AXIS] = axisIsHomed[Z_AXIS] = false;
fanMaxPwm = 1.0; fanMaxPwm = 1.0;
coolingInverted = false;
} }
// This is called from Init and when doing an emergency stop // This is called from Init and when doing an emergency stop
@ -106,12 +106,16 @@ void GCodes::doFilePrint(GCodeBuffer* gb)
if (fileBeingPrinted.Read(b)) if (fileBeingPrinted.Read(b))
{ {
if (gb->Put(b)) if (gb->Put(b))
{
gb->SetFinished(ActOnGcode(gb)); gb->SetFinished(ActOnGcode(gb));
}
} }
else else
{ {
if (gb->Put('\n')) // In case there wasn't one ending the file if (gb->Put('\n')) // In case there wasn't one ending the file
{
gb->SetFinished(ActOnGcode(gb)); gb->SetFinished(ActOnGcode(gb));
}
fileBeingPrinted.Close(); fileBeingPrinted.Close();
} }
} }
@ -276,7 +280,7 @@ bool GCodes::Push()
drivesRelativeStack[stackPointer] = drivesRelative; drivesRelativeStack[stackPointer] = drivesRelative;
axesRelativeStack[stackPointer] = axesRelative; axesRelativeStack[stackPointer] = axesRelative;
feedrateStack[stackPointer] = gFeedRate; feedrateStack[stackPointer] = gFeedRate;
fileStack[stackPointer].MoveFrom(fileBeingPrinted); fileStack[stackPointer].CopyFrom(fileBeingPrinted);
stackPointer++; stackPointer++;
platform->PushMessageIndent(); platform->PushMessageIndent();
return true; return true;
@ -298,7 +302,7 @@ bool GCodes::Pop()
stackPointer--; stackPointer--;
drivesRelative = drivesRelativeStack[stackPointer]; drivesRelative = drivesRelativeStack[stackPointer];
axesRelative = axesRelativeStack[stackPointer]; axesRelative = axesRelativeStack[stackPointer];
fileBeingPrinted.MoveFrom(fileStack[stackPointer]); fileBeingPrinted.CopyFrom(fileStack[stackPointer]);
platform->PopMessageIndent(); platform->PopMessageIndent();
// Remember for next time if we have just been switched // Remember for next time if we have just been switched
// to absolute drive moves // to absolute drive moves
@ -686,7 +690,7 @@ bool GCodes::DoSingleZProbeAtPoint()
case 0: // Raise Z to 5mm. This only does anything on the first move; on all the others Z is already there case 0: // Raise Z to 5mm. This only does anything on the first move; on all the others Z is already there
moveToDo[Z_AXIS] = Z_DIVE; moveToDo[Z_AXIS] = Z_DIVE;
activeDrive[Z_AXIS] = true; activeDrive[Z_AXIS] = true;
moveToDo[DRIVES] = platform->HomeFeedRate(Z_AXIS); moveToDo[DRIVES] = platform->MaxFeedrate(Z_AXIS);
activeDrive[DRIVES] = true; activeDrive[DRIVES] = true;
reprap.GetMove()->SetZProbing(false); reprap.GetMove()->SetZProbing(false);
if (DoCannedCycleMove(false)) if (DoCannedCycleMove(false))
@ -700,7 +704,7 @@ bool GCodes::DoSingleZProbeAtPoint()
activeDrive[X_AXIS] = true; activeDrive[X_AXIS] = true;
activeDrive[Y_AXIS] = true; activeDrive[Y_AXIS] = true;
// NB - we don't use the Z value // NB - we don't use the Z value
moveToDo[DRIVES] = platform->HomeFeedRate(X_AXIS); moveToDo[DRIVES] = platform->MaxFeedrate(X_AXIS);
activeDrive[DRIVES] = true; activeDrive[DRIVES] = true;
reprap.GetMove()->SetZProbing(false); reprap.GetMove()->SetZProbing(false);
if (DoCannedCycleMove(false)) if (DoCannedCycleMove(false))
@ -726,7 +730,7 @@ bool GCodes::DoSingleZProbeAtPoint()
case 3: // Raise the head 5mm case 3: // Raise the head 5mm
moveToDo[Z_AXIS] = Z_DIVE; moveToDo[Z_AXIS] = Z_DIVE;
activeDrive[Z_AXIS] = true; activeDrive[Z_AXIS] = true;
moveToDo[DRIVES] = platform->HomeFeedRate(Z_AXIS); moveToDo[DRIVES] = platform->MaxFeedrate(Z_AXIS);
activeDrive[DRIVES] = true; activeDrive[DRIVES] = true;
reprap.GetMove()->SetZProbing(false); reprap.GetMove()->SetZProbing(false);
if (DoCannedCycleMove(false)) if (DoCannedCycleMove(false))
@ -856,7 +860,9 @@ bool GCodes::DoMultipleZProbe()
} }
if (DoSingleZProbeAtPoint()) if (DoSingleZProbeAtPoint())
{
probeCount++; probeCount++;
}
if (probeCount >= reprap.GetMove()->NumberOfXYProbePoints()) if (probeCount >= reprap.GetMove()->NumberOfXYProbePoints())
{ {
probeCount = 0; probeCount = 0;
@ -1110,11 +1116,16 @@ bool GCodes::DoDwell(GCodeBuffer *gb)
float dwell = 0.001 * (float) gb->GetLValue(); // P values are in milliseconds; we need seconds float dwell = 0.001 * (float) gb->GetLValue(); // P values are in milliseconds; we need seconds
// Wait for all the queued moves to stop // Wait for all the queued moves to stop
if (!reprap.GetMove()->AllMovesAreFinished()) if (!reprap.GetMove()->AllMovesAreFinished())
return false; return false;
return DoDwellTime(dwell);
}
bool GCodes::DoDwellTime(float dwell)
{
// Are we already in the dwell? // Are we already in the dwell?
if (dwellWaiting) if (dwellWaiting)
@ -1563,7 +1574,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
case 1: // Sleep case 1: // Sleep
if (fileBeingPrinted.IsLive()) if (fileBeingPrinted.IsLive())
{ {
fileToPrint.MoveFrom(fileBeingPrinted); fileToPrint.CopyFrom(fileBeingPrinted);
} }
if (!DisableDrives()) if (!DisableDrives())
return false; return false;
@ -1598,11 +1609,11 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
case 24: // Print/resume-printing the selected file case 24: // Print/resume-printing the selected file
if (fileBeingPrinted.IsLive()) if (fileBeingPrinted.IsLive())
break; break;
fileBeingPrinted.MoveFrom(fileToPrint); fileBeingPrinted.CopyFrom(fileToPrint);
break; break;
case 25: // Pause the print case 25: // Pause the print
fileToPrint.MoveFrom(fileBeingPrinted); fileToPrint.CopyFrom(fileBeingPrinted);
break; break;
case 27: // Report print status - Deprecated case 27: // Report print status - Deprecated
@ -1712,14 +1723,18 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
} }
if (gb->Seen('I')) if (gb->Seen('I'))
{ {
coolingInverted = (gb->GetIValue() != 0); coolingInverted = (gb->GetIValue() > 0);
} }
if (gb->Seen('S')) if (gb->Seen('S'))
{ {
if (coolingInverted) if (coolingInverted)
{
platform->CoolingFan(1.0 - fmax(gb->GetFValue(), 0.0)/fanMaxPwm); platform->CoolingFan(1.0 - fmax(gb->GetFValue(), 0.0)/fanMaxPwm);
}
else else
{
platform->CoolingFan(fmax(gb->GetFValue(), 0.0)/fanMaxPwm); platform->CoolingFan(fmax(gb->GetFValue(), 0.0)/fanMaxPwm);
}
} }
break; break;
@ -2027,7 +2042,11 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
break; break;
case 999: case 999:
platform->SoftwareReset(SoftwareResetReason::user); // doesn't return result = DoDwellTime(0.5); // wait half a second to allow the response to be sent back to the web server, otherwise it may retry
if (result)
{
platform->SoftwareReset(SoftwareResetReason::user); // doesn't return
}
break; break;
case 117: // in Marlin mode this means display message on LCD. We don't have an LCD so just return OK. case 117: // in Marlin mode this means display message on LCD. We don't have an LCD so just return OK.

View file

@ -90,12 +90,15 @@ public:
return f->Read(b); return f->Read(b);
} }
// Assignment operator. This clears out the FileData object we are assigning from. // Assignment operator
void MoveFrom(FileData& other) void CopyFrom(const FileData& other)
{ {
Close(); Close();
f = other.f; f = other.f;
other.Init(); if (f != NULL)
{
f->Duplicate();
}
} }
private: private:
@ -149,6 +152,7 @@ class GCodes
bool ActOnGcode(GCodeBuffer* gb); bool ActOnGcode(GCodeBuffer* gb);
int SetUpMove(GCodeBuffer* gb); int SetUpMove(GCodeBuffer* gb);
bool DoDwell(GCodeBuffer *gb); bool DoDwell(GCodeBuffer *gb);
bool DoDwellTime(float dwell);
bool DoHome(char *reply, bool& error); bool DoHome(char *reply, bool& error);
bool DoSingleZProbeAtPoint(); bool DoSingleZProbeAtPoint();
bool DoSingleZProbe(); bool DoSingleZProbe();

View file

@ -754,9 +754,12 @@ void Platform::PrintMemoryUsage()
reprap.GetWebserver()->AppendReply(scratchString); reprap.GetWebserver()->AppendReply(scratchString);
Message(HOST_MESSAGE, scratchString); Message(HOST_MESSAGE, scratchString);
// Show the reason for the last reset // Show the up time and reason for the last reset
const uint32_t now = (uint32_t)Time(); // get up time in seconds
const char* resetReasons[8] = { "power up", "backup", "watchdog", "software", "external", "?", "?", "?" }; const char* resetReasons[8] = { "power up", "backup", "watchdog", "software", "external", "?", "?", "?" };
snprintf(scratchString, STRING_LENGTH, "Last reset reason: %s\n", resetReasons[(REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos]); snprintf(scratchString, STRING_LENGTH, "Last reset %02d:%02d:%02d ago, cause: %s\n",
(unsigned int)(now/3600), (unsigned int)((now % 3600)/60), (unsigned int)(now % 60),
resetReasons[(REG_RSTC_SR & RSTC_SR_RSTTYP_Msk) >> RSTC_SR_RSTTYP_Pos]);
reprap.GetWebserver()->AppendReply(scratchString); reprap.GetWebserver()->AppendReply(scratchString);
Message(HOST_MESSAGE, scratchString); Message(HOST_MESSAGE, scratchString);
@ -1036,18 +1039,6 @@ MassStorage* Platform::GetMassStorage()
return massStorage; return massStorage;
} }
void Platform::ReturnFileStore(FileStore* fs)
{
for (int i = 0; i < MAX_FILES; i++)
{
if (files[i] == fs)
{
files[i]->inUse = false;
return;
}
}
}
void Platform::Message(char type, const char* message) void Platform::Message(char type, const char* message)
{ {
switch (type) switch (type)
@ -1297,9 +1288,8 @@ bool MassStorage::Delete(const char* directory, const char* fileName)
//------------------------------------------------------------------------------------------------ //------------------------------------------------------------------------------------------------
FileStore::FileStore(Platform* p) FileStore::FileStore(Platform* p) : platform(p)
{ {
platform = p;
} }
void FileStore::Init() void FileStore::Init()
@ -1308,6 +1298,7 @@ void FileStore::Init()
inUse = false; inUse = false;
writing = false; writing = false;
lastBufferEntry = 0; lastBufferEntry = 0;
openCount = 0;
} }
// Open a local file (for example on an SD card). // Open a local file (for example on an SD card).
@ -1353,20 +1344,39 @@ bool FileStore::Open(const char* directory, const char* fileName, bool write)
} }
inUse = true; inUse = true;
openCount = 1;
return true; return true;
} }
void FileStore::Duplicate()
{
if (!inUse)
{
platform->Message(HOST_MESSAGE, "Attempt to dup a non-open file.\n");
return;
}
++openCount;
}
void FileStore::Close() void FileStore::Close()
{ {
if (writing) if (!inUse)
{ {
WriteBuffer(); platform->Message(HOST_MESSAGE, "Attempt to close a non-open file.\n");
return;
}
--openCount;
if (openCount == 0)
{
if (writing)
{
WriteBuffer();
}
f_close(&file);
inUse = false;
writing = false;
lastBufferEntry = 0;
} }
f_close(&file);
platform->ReturnFileStore(this);
inUse = false;
writing = false;
lastBufferEntry = 0;
} }
void FileStore::Seek(unsigned long pos) void FileStore::Seek(unsigned long pos)

View file

@ -334,6 +334,7 @@ public:
void Seek(unsigned long pos); void Seek(unsigned long pos);
void GoToEnd(); // Position the file at the end (so you can write on the end). void GoToEnd(); // Position the file at the end (so you can write on the end).
unsigned long Length(); // File size in bytes unsigned long Length(); // File size in bytes
void Duplicate();
friend class Platform; friend class Platform;
@ -356,6 +357,7 @@ private:
Platform* platform; Platform* platform;
bool writing; bool writing;
unsigned int lastBufferEntry; unsigned int lastBufferEntry;
unsigned int openCount;
}; };
@ -593,9 +595,6 @@ public:
const PidParameters& GetPidParameters(size_t heater); const PidParameters& GetPidParameters(size_t heater);
//------------------------------------------------------------------------------------------------------- //-------------------------------------------------------------------------------------------------------
protected:
void ReturnFileStore(FileStore* f);
private: private:

Binary file not shown.