Marlin emulation implemented. Pretty much working, but not extensively tested.

This commit is contained in:
Adrian Bowyer 2013-11-14 23:32:50 +00:00
parent bd51a7c3f0
commit 68e0f833df
7 changed files with 131 additions and 37 deletions

View file

@ -28,6 +28,20 @@ Licence: GPL
#define DATE "2012-11-18"
#define LAST_AUTHOR "reprappro.com"
// Other firmware that we might switch to be compatible with.
enum Compatibility
{
me = 0,
reprapFirmware = 1,
marlin = 2,
teacup = 3,
sprinter = 4,
repetier = 5
};
// Some numbers...
#define ABS_ZERO -273.15 // Celsius
#define INCH_TO_MM 25.4
@ -59,7 +73,7 @@ Licence: GPL
*/
#define CALIB_Z 0
#define LONG_TIME 60.0 // Seconds
#define LONG_TIME 300.0 // Seconds
#endif

View file

@ -657,14 +657,70 @@ bool GCodes::StandbyHeaters()
return true;
}
void GCodes::HandleReply(bool error, bool fromLine, char* reply)
void GCodes::HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code)
{
if(!reply[0])
return;
if(error)
platform->GetLine()->Write("Error: ");
platform->GetLine()->Write(reply);
platform->GetLine()->Write("\n");
Compatibility c = platform->Emulating();
if(!fromLine)
c = me;
char* s = 0;
switch(c)
{
case me:
case reprapFirmware:
if(!reply[0])
return;
if(error)
platform->GetLine()->Write("Error: ");
platform->GetLine()->Write(reply);
platform->GetLine()->Write("\n");
break;
case marlin:
if(gMOrT == 'M' && code == 20)
{
platform->GetLine()->Write("Begin file list\n");
platform->GetLine()->Write(reply);
platform->GetLine()->Write("\nEnd file list\nok\n");
return;
}
if(gMOrT == 'M' && code == 105)
{
platform->GetLine()->Write("ok ");
platform->GetLine()->Write(reply);
platform->GetLine()->Write("\n");
return;
}
if(reply[0])
{
platform->GetLine()->Write(reply);
platform->GetLine()->Write("\n");
}
platform->GetLine()->Write("ok\n");
break;
case teacup:
s = "teacup";
break;
case sprinter:
s = "sprinter";
break;
case repetier:
s = "repetier";
break;
default:
s = "unknown";
}
if(s != 0)
{
snprintf(scratchString, STRING_LENGTH, "Emulation of %s is not yet supported.\n", s);
platform->Message(HOST_MESSAGE, scratchString);
}
}
// If the GCode to act on is completed, this returns true,
@ -759,7 +815,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
snprintf(reply, STRING_LENGTH, "invalid G Code: %s", gb->Buffer());
}
if(result == true)
HandleReply(error, gb == serialGCode, reply);
HandleReply(error, gb == serialGCode, reply, 'G', code);
return result;
}
@ -786,9 +842,15 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
break;
case 20: // Deprecated...
snprintf(reply, STRING_LENGTH, "GCode files:\n%s", platform->GetMassStorage()->FileList(platform->GetGCodeDir()));
if(platform->Emulating() == me || platform->Emulating() == reprapFirmware)
snprintf(reply, STRING_LENGTH, "GCode files:\n%s", platform->GetMassStorage()->FileList(platform->GetGCodeDir(), gb == serialGCode));
else
snprintf(reply, STRING_LENGTH, "%s", platform->GetMassStorage()->FileList(platform->GetGCodeDir(), gb == serialGCode));
break;
case 21: // Initialise SD - ignore
break;
case 23: // Set file to print
QueueFileToPrint(gb->GetUnprecedentedString());
break;
@ -834,6 +896,14 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
}
break;
case 104: // Depricated
if(gb->Seen('S'))
{
reprap.GetHeat()->SetActiveTemperature(1, gb->GetFValue()); // 0 is the bed
reprap.GetHeat()->Activate(1);
}
break;
case 105: // Deprecated...
strncpy(reply, "T:", STRING_LENGTH);
for(int8_t heater = HEATERS - 1; heater > 0; heater--)
@ -872,16 +942,22 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
result = false;
break;
case 109: // Depricated
if(gb->Seen('S'))
{
reprap.GetHeat()->SetActiveTemperature(1, gb->GetFValue()); // 0 is the bed
reprap.GetHeat()->Activate(1);
}
case 116: // Wait for everything, especially set temperatures
if(!AllMovesAreFinishedAndMoveBufferIsLoaded())
return false;
result = reprap.GetHeat()->AllHeatersAtSetTemperatures();
break;
if(!AllMovesAreFinishedAndMoveBufferIsLoaded())
return false;
result = reprap.GetHeat()->AllHeatersAtSetTemperatures();
break;
case 120:
result = Push();
break;
case 121:
result = Pop();
break;
@ -1015,7 +1091,7 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
snprintf(reply, STRING_LENGTH, "invalid M Code: %s", gb->Buffer());
}
if(result == true)
HandleReply(error, gb == serialGCode, reply);
HandleReply(error, gb == serialGCode, reply, 'M', code);
return result;
}
@ -1045,14 +1121,14 @@ bool GCodes::ActOnGcode(GCodeBuffer *gb)
snprintf(reply, STRING_LENGTH, "invalid T Code: %s", gb->Buffer());
if(result == true)
HandleReply(error, gb == serialGCode, reply);
HandleReply(error, gb == serialGCode, reply, 'T', code);
return result;
}
// An empty buffer jumps to here and gets discarded
if(result == true)
HandleReply(error, gb == serialGCode, reply);
HandleReply(error, gb == serialGCode, reply, 'X', code);
return result;
}

View file

@ -92,7 +92,7 @@ class GCodes
bool Pop();
bool DisableDrives();
bool StandbyHeaters();
void HandleReply(bool error, bool fromLine, char* reply);
void HandleReply(bool error, bool fromLine, char* reply, char gMOrT, int code);
int8_t Heater(int8_t head);
Platform* platform;

View file

@ -113,6 +113,9 @@ void PID::Init()
void PID::Spin()
{
if(temperatureFault)
return;
temperature = platform->GetTemperature(heater);
if(temperature < BAD_LOW_TEMPERATURE || temperature > BAD_HIGH_TEMPERATURE)

View file

@ -479,7 +479,7 @@ char* MassStorage::CombineName(char* directory, char* fileName)
// List the flat files in a directory. No sub-directories or recursion.
char* MassStorage::FileList(char* directory)
char* MassStorage::FileList(char* directory, bool fromLine)
{
// File dir, entry;
DIR dir;
@ -487,6 +487,17 @@ char* MassStorage::FileList(char* directory)
FRESULT res;
char loc[64];
int len = 0;
char fileListBracket = FILE_LIST_BRACKET;
char fileListSeparator = FILE_LIST_SEPARATOR;
if(fromLine)
{
if(platform->Emulating() == marlin)
{
fileListBracket = 0;
fileListSeparator = '\n';
}
}
len = strlen(directory);
strncpy(loc,directory,len-1);
@ -519,7 +530,8 @@ char* MassStorage::FileList(char* directory)
if(strlen(entry.fname) > 0)
{
int q = 0;
fileList[p++] = FILE_LIST_BRACKET;
if(fileListBracket)
fileList[p++] = fileListBracket;
while(entry.fname[q])
{
fileList[p++] = entry.fname[q];
@ -533,8 +545,9 @@ char* MassStorage::FileList(char* directory)
return "";
}
}
fileList[p++] = FILE_LIST_BRACKET;
fileList[p++] = FILE_LIST_SEPARATOR;
if(fileListBracket)
fileList[p++] = fileListBracket;
fileList[p++] = fileListSeparator;
}
}

View file

@ -171,18 +171,6 @@ Licence: GPL
#define BAUD_RATE 115200 // Communication speed of the USB if needed.
// Other firmware that we might switch to be compatible with.
enum Compatibility
{
me = 0,
reprapFirmware = 1,
marlin = 2,
teacup = 3,
sprinter = 4,
repetier = 5
};
/****************************************************************************************************/
enum EndStopHit
@ -327,7 +315,7 @@ class MassStorage
{
public:
char* FileList(char* directory); // Returns a ,-separated list of all the files in the named directory
char* FileList(char* directory, bool fromLine); // Returns a list of all the files in the named directory
char* CombineName(char* directory, char* fileName);
bool Delete(char* directory, char* fileName);

View file

@ -349,7 +349,7 @@ void Webserver::GetJsonResponse(char* request)
if(StringStartsWith(request, "files"))
{
char* fileList = platform->GetMassStorage()->FileList(platform->GetGCodeDir());
char* fileList = platform->GetMassStorage()->FileList(platform->GetGCodeDir(), false);
strncpy(jsonResponse, "{\"files\":[", STRING_LENGTH);
strncat(jsonResponse, fileList, STRING_LENGTH);
strncat(jsonResponse, "]}", STRING_LENGTH);