diff options
Diffstat (limited to 'src/GCodes/GCodeBuffer/GCodeBuffer.cpp')
-rw-r--r-- | src/GCodes/GCodeBuffer/GCodeBuffer.cpp | 101 |
1 files changed, 85 insertions, 16 deletions
diff --git a/src/GCodes/GCodeBuffer/GCodeBuffer.cpp b/src/GCodes/GCodeBuffer/GCodeBuffer.cpp index 37e616c2..bc607448 100644 --- a/src/GCodes/GCodeBuffer/GCodeBuffer.cpp +++ b/src/GCodes/GCodeBuffer/GCodeBuffer.cpp @@ -19,6 +19,7 @@ #include <GCodes/GCodeException.h> #include <Platform/RepRap.h> #include <Platform/Platform.h> +#include <Movement/StepTimer.h> // Macros to reduce the amount of explicit conditional compilation in this file #if HAS_LINUX_INTERFACE @@ -49,17 +50,17 @@ constexpr ObjectModelTableEntry GCodeBuffer::objectModelTable[] = { // Within each group, these entries must be in alphabetical order // 0. inputs[] root - { "axesRelative", OBJECT_MODEL_FUNC((bool)self->machineState->axesRelative), ObjectModelEntryFlags::none }, - { "compatibility", OBJECT_MODEL_FUNC(self->machineState->compatibility.ToString()), ObjectModelEntryFlags::none }, - { "distanceUnit", OBJECT_MODEL_FUNC((self->machineState->usingInches) ? "inch" : "mm"), ObjectModelEntryFlags::none }, - { "drivesRelative", OBJECT_MODEL_FUNC((bool)self->machineState->drivesRelative), ObjectModelEntryFlags::none }, - { "feedRate", OBJECT_MODEL_FUNC(self->machineState->feedRate, 1), ObjectModelEntryFlags::live }, - { "inMacro", OBJECT_MODEL_FUNC((bool)self->machineState->doingFileMacro), ObjectModelEntryFlags::none }, - { "lineNumber", OBJECT_MODEL_FUNC((int32_t)self->GetLineNumber()), ObjectModelEntryFlags::live }, - { "name", OBJECT_MODEL_FUNC(self->codeChannel.ToString()), ObjectModelEntryFlags::none }, - { "stackDepth", OBJECT_MODEL_FUNC((int32_t)self->GetStackDepth()), ObjectModelEntryFlags::none }, - { "state", OBJECT_MODEL_FUNC(self->GetStateText()), ObjectModelEntryFlags::live }, - { "volumetric", OBJECT_MODEL_FUNC((bool)self->machineState->volumetricExtrusion), ObjectModelEntryFlags::none }, + { "axesRelative", OBJECT_MODEL_FUNC((bool)self->machineState->axesRelative), ObjectModelEntryFlags::none }, + { "compatibility", OBJECT_MODEL_FUNC(self->machineState->compatibility.ToString()), ObjectModelEntryFlags::none }, + { "distanceUnit", OBJECT_MODEL_FUNC(self->GetDistanceUnits()), ObjectModelEntryFlags::none }, + { "drivesRelative", OBJECT_MODEL_FUNC((bool)self->machineState->drivesRelative), ObjectModelEntryFlags::none }, + { "feedRate", OBJECT_MODEL_FUNC(InverseConvertSpeedToMmPerSec(self->machineState->feedRate), 1), ObjectModelEntryFlags::live }, + { "inMacro", OBJECT_MODEL_FUNC((bool)self->machineState->doingFileMacro), ObjectModelEntryFlags::none }, + { "lineNumber", OBJECT_MODEL_FUNC((int32_t)self->GetLineNumber()), ObjectModelEntryFlags::live }, + { "name", OBJECT_MODEL_FUNC(self->codeChannel.ToString()), ObjectModelEntryFlags::none }, + { "stackDepth", OBJECT_MODEL_FUNC((int32_t)self->GetStackDepth()), ObjectModelEntryFlags::none }, + { "state", OBJECT_MODEL_FUNC(self->GetStateText()), ObjectModelEntryFlags::live }, + { "volumetric", OBJECT_MODEL_FUNC((bool)self->machineState->volumetricExtrusion), ObjectModelEntryFlags::none }, }; constexpr uint8_t GCodeBuffer::objectModelTableDescriptor[] = { 1, 11 }; @@ -344,6 +345,12 @@ bool GCodeBuffer::Seen(char c) noexcept return PARSER_OPERATION(Seen(c)); } +// Return true if any of the parameter letters in the bitmap were seen +bool GCodeBuffer::SeenAny(Bitmap<uint32_t> bm) const noexcept +{ + return PARSER_OPERATION(SeenAny(bm)); +} + // Test for character present, throw error if not void GCodeBuffer::MustSee(char c) THROWS(GCodeException) { @@ -388,6 +395,24 @@ float GCodeBuffer::GetDistance() THROWS(GCodeException) return ConvertDistance(GetFValue()); } +// Get a speed in mm/min or inches/min and convert it to mm/step_clock +float GCodeBuffer::GetSpeed() THROWS(GCodeException) +{ + return ConvertSpeed(GetFValue()); +} + +// Get a speed in mm/min mm/sec and convert it to mm/step_clock +float GCodeBuffer::GetSpeedFromMm(bool useSeconds) THROWS(GCodeException) +{ + return ConvertSpeedFromMm(GetFValue(), useSeconds); +} + +// Get an acceleration in mm/sec^2 and convert it to mm/step_clock^2 +float GCodeBuffer::GetAcceleration() THROWS(GCodeException) +{ + return ConvertAcceleration(GetFValue()); +} + // Get an integer after a key letter int32_t GCodeBuffer::GetIValue() THROWS(GCodeException) { @@ -482,19 +507,46 @@ void GCodeBuffer::GetReducedString(const StringRef& str) THROWS(GCodeException) // Get a colon-separated list of floats after a key letter void GCodeBuffer::GetFloatArray(float arr[], size_t& length, bool doPad) THROWS(GCodeException) { - PARSER_OPERATION(GetFloatArray(arr, length, doPad)); + const size_t maxLength = length; + PARSER_OPERATION(GetFloatArray(arr, length)); + // If there is one entry and doPad is true, fill the rest of the array with the first entry. + if (doPad && length == 1) + { + while (length < maxLength) + { + arr[length++] = arr[0]; + } + } } // Get a :-separated list of ints after a key letter void GCodeBuffer::GetIntArray(int32_t arr[], size_t& length, bool doPad) THROWS(GCodeException) { - PARSER_OPERATION(GetIntArray(arr, length, doPad)); + const size_t maxLength = length; + PARSER_OPERATION(GetIntArray(arr, length)); + // If there is one entry and doPad is true, fill the rest of the array with the first entry. + if (doPad && length == 1) + { + while (length < maxLength) + { + arr[length++] = arr[0]; + } + } } // Get a :-separated list of unsigned ints after a key letter void GCodeBuffer::GetUnsignedArray(uint32_t arr[], size_t& length, bool doPad) THROWS(GCodeException) { - PARSER_OPERATION(GetUnsignedArray(arr, length, doPad)); + const size_t maxLength = length; + PARSER_OPERATION(GetUnsignedArray(arr, length)); + // If there is one entry and doPad is true, fill the rest of the array with the first entry. + if (doPad && length == 1) + { + while (length < maxLength) + { + arr[length++] = arr[0]; + } + } } // Get a :-separated list of drivers after a key letter @@ -727,13 +779,30 @@ GCodeMachineState& GCodeBuffer::CurrentFileMachineState() const noexcept // Convert from inches to mm if necessary float GCodeBuffer::ConvertDistance(float distance) const noexcept { - return (machineState->usingInches) ? distance * InchToMm : distance; + return (UsingInches()) ? distance * InchToMm : distance; } // Convert from mm to inches if necessary float GCodeBuffer::InverseConvertDistance(float distance) const noexcept { - return (machineState->usingInches) ? distance/InchToMm : distance; + return (UsingInches()) ? distance/InchToMm : distance; +} + +// Convert speed from mm/min or inches/min to mm per step clock +float GCodeBuffer::ConvertSpeed(float speed) const noexcept +{ + return speed * ((UsingInches()) ? InchToMm/(StepClockRate * iMinutesToSeconds) : 1.0/(StepClockRate * iMinutesToSeconds)); +} + +// Convert speed to mm/min or inches/min +float GCodeBuffer::InverseConvertSpeed(float speed) const noexcept +{ + return speed * ((UsingInches()) ? (StepClockRate * iMinutesToSeconds)/InchToMm : (float)(StepClockRate * iMinutesToSeconds)); +} + +const char *GCodeBuffer::GetDistanceUnits() const noexcept +{ + return (UsingInches()) ? "in" : "mm"; } // Return the current stack depth |