Code to handle lists of parameters added to GCodes.
This commit is contained in:
parent
36dba7f895
commit
27191db607
4 changed files with 66 additions and 4 deletions
|
@ -80,6 +80,12 @@ enum Compatibility
|
|||
#define HOME_Z_G "homez.g"
|
||||
#define HOME_ALL_G "homeall.g"
|
||||
|
||||
#define LIST_SEPARATOR ':' // Lists in G Codes
|
||||
#define FILE_LIST_SEPARATOR ',' // Put this between file names when listing them
|
||||
#define FILE_LIST_BRACKET '"' // Put these round file names when listing them
|
||||
|
||||
#define GCODE_LETTERS { 'X', 'Y', 'Z', 'E', 'F' } // The drives and feedrate in a GCode
|
||||
|
||||
#define LONG_TIME 300.0 // Seconds
|
||||
|
||||
#define EOF_STRING "<!-- **EoF** -->"
|
||||
|
|
58
GCodes.cpp
58
GCodes.cpp
|
@ -2022,6 +2022,7 @@ float GCodeBuffer::GetFValue()
|
|||
if(readPointer < 0)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: Attempt to read a GCode float before a search.\n");
|
||||
readPointer = -1;
|
||||
return 0.0;
|
||||
}
|
||||
float result = (float)strtod(&gcodeBuffer[readPointer + 1], 0);
|
||||
|
@ -2029,6 +2030,60 @@ float GCodeBuffer::GetFValue()
|
|||
return result;
|
||||
}
|
||||
|
||||
// Get a :-separated list of floats after a key letter
|
||||
|
||||
const void GCodeBuffer::GetFloatArray(float a[], int& length)
|
||||
{
|
||||
length = -1;
|
||||
if(readPointer < 0)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: Attempt to read a GCode float array before a search.\n");
|
||||
readPointer = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
bool inList = true;
|
||||
while(inList)
|
||||
{
|
||||
length++;
|
||||
a[length] = (float)strtod(&gcodeBuffer[readPointer + 1], 0);
|
||||
readPointer++;
|
||||
while(gcodeBuffer[readPointer] && (gcodeBuffer[readPointer] != ' ') && (gcodeBuffer[readPointer] != LIST_SEPARATOR))
|
||||
readPointer++;
|
||||
if(gcodeBuffer[readPointer] != LIST_SEPARATOR)
|
||||
inList = false;
|
||||
}
|
||||
length++;
|
||||
readPointer = -1;
|
||||
}
|
||||
|
||||
// Get a :-separated list of longs after a key letter
|
||||
|
||||
const void GCodeBuffer::GetLongArray(long l[], int& length)
|
||||
{
|
||||
length = -1;
|
||||
if(readPointer < 0)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: Attempt to read a GCode long array before a search.\n");
|
||||
readPointer = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
bool inList = true;
|
||||
while(inList)
|
||||
{
|
||||
length++;
|
||||
l[length] = strtol(&gcodeBuffer[readPointer + 1], 0, 0);
|
||||
readPointer++;
|
||||
while(gcodeBuffer[readPointer] && (gcodeBuffer[readPointer] != ' ') && (gcodeBuffer[readPointer] != LIST_SEPARATOR))
|
||||
readPointer++;
|
||||
if(gcodeBuffer[readPointer] != LIST_SEPARATOR)
|
||||
inList = false;
|
||||
}
|
||||
length++;
|
||||
readPointer = -1;
|
||||
}
|
||||
|
||||
// Get a string after a G Code letter found by a call to Seen().
|
||||
// It will be the whole of the rest of the GCode string, so strings
|
||||
// should always be the last parameter.
|
||||
|
@ -2038,6 +2093,7 @@ const char* GCodeBuffer::GetString()
|
|||
if(readPointer < 0)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: Attempt to read a GCode string before a search.\n");
|
||||
readPointer = -1;
|
||||
return "";
|
||||
}
|
||||
const char* result = &gcodeBuffer[readPointer+1];
|
||||
|
@ -2065,6 +2121,7 @@ const char* GCodeBuffer::GetUnprecedentedString()
|
|||
if(!gcodeBuffer[readPointer])
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: String expected but not seen.\n");
|
||||
readPointer = -1;
|
||||
return gcodeBuffer; // Good idea?
|
||||
}
|
||||
|
||||
|
@ -2081,6 +2138,7 @@ long GCodeBuffer::GetLValue()
|
|||
if(readPointer < 0)
|
||||
{
|
||||
platform->Message(HOST_MESSAGE, "GCodes: Attempt to read a GCode int before a search.\n");
|
||||
readPointer = -1;
|
||||
return 0;
|
||||
}
|
||||
long result = strtol(&gcodeBuffer[readPointer + 1], 0, 0);
|
||||
|
|
4
GCodes.h
4
GCodes.h
|
@ -25,8 +25,6 @@ Licence: GPL
|
|||
#define STACK 5
|
||||
#define GCODE_LENGTH 100 // Maximum length of internally-generated G Code string
|
||||
|
||||
#define GCODE_LETTERS { 'X', 'Y', 'Z', 'E', 'F' } // The drives and feedrate in a GCode
|
||||
|
||||
// Small class to hold an individual GCode and provide functions to allow it to be parsed
|
||||
|
||||
class GCodeBuffer
|
||||
|
@ -41,6 +39,8 @@ class GCodeBuffer
|
|||
long GetLValue(); // Get a long integer after a key letter
|
||||
const char* GetUnprecedentedString(); // Get a string with no preceeding key letter
|
||||
const char* GetString(); // Get a string after a key letter
|
||||
const void GetFloatArray(float a[], int& length); // Get a :-separated list of floats after a key letter
|
||||
const void GetLongArray(long l[], int& length); // Get a :-separated list of longs after a key letter
|
||||
const char* Buffer(); // All of the G Code itself
|
||||
bool Finished() const; // Has the G Code been executed?
|
||||
void SetFinished(bool f); // Set the G Code executed (or not)
|
||||
|
|
|
@ -158,8 +158,6 @@ Licence: GPL
|
|||
#define GCODE_DIR "0:/gcodes/" // Ditto - g-codes
|
||||
#define SYS_DIR "0:/sys/" // Ditto - system files
|
||||
#define TEMP_DIR "0:/tmp/" // Ditto - temporary files
|
||||
#define FILE_LIST_SEPARATOR ',' // Put this between file names when listing them
|
||||
#define FILE_LIST_BRACKET '"' // Put these round file names when listing them
|
||||
#define FILE_LIST_LENGTH (1000) // Maximum length of file list
|
||||
#define MAX_FILES (42) // Maximum number of files displayed
|
||||
|
||||
|
|
Reference in a new issue