Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/Duet3D/RepRapFirmware.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDavid Crocker <dcrocker@eschertech.com>2020-01-22 23:46:13 +0300
committerDavid Crocker <dcrocker@eschertech.com>2020-01-22 23:46:13 +0300
commitf11710c9cb9f16901437f39b5e07326f3d1ad6bf (patch)
tree27b6c95c661a56e3a5c3d24b85e934616697cf6b /src/ObjectModel
parentee1ccb5074a1824175c29e3e28fc47d888c15091 (diff)
Bug fix and more Object Model fields
Fixed bad JSON in M408 reports when no fans are configured Added more object model fields: kinematics, machine coordinates Refactored code that generates M408 responses
Diffstat (limited to 'src/ObjectModel')
-rw-r--r--src/ObjectModel/ObjectModel.cpp17
-rw-r--r--src/ObjectModel/ObjectModel.h6
2 files changed, 13 insertions, 10 deletions
diff --git a/src/ObjectModel/ObjectModel.cpp b/src/ObjectModel/ObjectModel.cpp
index 7cd35a93..fc9a096a 100644
--- a/src/ObjectModel/ObjectModel.cpp
+++ b/src/ObjectModel/ObjectModel.cpp
@@ -14,14 +14,6 @@
#include <cstring>
#include <General/SafeStrtod.h>
-// Get the format string to use assuming this is a floating point number
-const char *ExpressionValue::GetFloatFormatString() const noexcept
-{
- static constexpr const char *FormatStrings[] = { "%.7f", "%.1f", "%.2f", "%.3f", "%.4f", "%.5f", "%.6f", "%.7f" };
- static_assert(ARRAY_SIZE(FormatStrings) == MaxFloatDigitsDisplayedAfterPoint + 1);
- return FormatStrings[min<unsigned int>(param, MaxFloatDigitsDisplayedAfterPoint)];
-}
-
void ObjectExplorationContext::AddIndex(int32_t index)
{
if (numIndicesCounted == MaxIndices)
@@ -244,7 +236,14 @@ void ObjectModel::ReportItemAsJson(OutputBuffer *buf, ObjectExplorationContext&
break;
case TYPE_OF(float):
- buf->catf(val.GetFloatFormatString(), (double)val.fVal);
+ if (val.fVal == 0.0)
+ {
+ buf->cat('0'); // replace 0.000... in JSON by 0. This is mostly to save space when writing workplace coordinates.
+ }
+ else
+ {
+ buf->catf(val.GetFloatFormatString(), (double)val.fVal);
+ }
break;
case TYPE_OF(uint32_t):
diff --git a/src/ObjectModel/ObjectModel.h b/src/ObjectModel/ObjectModel.h
index 3d73d7d9..ad404be4 100644
--- a/src/ObjectModel/ObjectModel.h
+++ b/src/ObjectModel/ObjectModel.h
@@ -109,7 +109,7 @@ struct ExpressionValue
uint64_t Get56BitValue() const noexcept { return ((uint64_t)param << 32) | uVal; }
// Get the format string to use assuming this is a floating point number
- const char *GetFloatFormatString() const noexcept;
+ const char *GetFloatFormatString() const noexcept { return ::GetFloatFormatString(param); }
};
// Flags field of a table entry
@@ -263,6 +263,9 @@ public:
static const ObjectModelTableEntry objectModelTable[]; \
static const uint8_t objectModelTableDescriptor[];
+#define DECLARE_OBJECT_MODEL_VIRTUAL \
+ virtual const ObjectModelTableEntry *GetObjectModelTable(const uint8_t*& descriptor) const noexcept override = 0;
+
#define DESCRIPTOR_OK(_class) (ARRAY_SIZE(_class::objectModelTableDescriptor) == _class::objectModelTableDescriptor[0] + 1)
#define OMT_SIZE_OK(_class) (ARRAY_SIZE(_class::objectModelTable) == ArraySum(_class::objectModelTableDescriptor + 1, ARRAY_SIZE(_class::objectModelTableDescriptor) - 1))
#define OMT_ORDERING_OK(_class) (ObjectModelTableEntry::IsOrdered(_class::objectModelTableDescriptor, _class::objectModelTable))
@@ -288,6 +291,7 @@ public:
#define INHERIT_OBJECT_MODEL // nothing
#define DECLARE_OBJECT_MODEL // nothing
+#define DECLARE_OBJECT_MODEL_VIRTUAL // nothing
#define DEFINE_GET_OBJECT_MODEL_TABLE // nothing
#define OBJECT_MODEL_ARRAY(_name) // nothing