diff options
author | Christian Hammacher <bmasterc@gmail.com> | 2022-02-06 18:32:27 +0300 |
---|---|---|
committer | Christian Hammacher <bmasterc@gmail.com> | 2022-02-06 18:32:27 +0300 |
commit | 435628494d4c4ee40979ff102de5b245bd6c2e1b (patch) | |
tree | 6b5a24eadfa1c625784cc05bd84cc73b34faa7db /src/PrintMonitor | |
parent | 21df0021ca2c915318d983f182aaa815bca2fb1d (diff) |
Expose thumbnails and numLayers via object model
Bug fix: Init GCodeFileInfo in SBC mode before setting new props
Diffstat (limited to 'src/PrintMonitor')
-rw-r--r-- | src/PrintMonitor/PrintMonitor.cpp | 30 | ||||
-rw-r--r-- | src/PrintMonitor/PrintMonitor.h | 1 |
2 files changed, 28 insertions, 3 deletions
diff --git a/src/PrintMonitor/PrintMonitor.cpp b/src/PrintMonitor/PrintMonitor.cpp index c2c39f53..b14710ac 100644 --- a/src/PrintMonitor/PrintMonitor.cpp +++ b/src/PrintMonitor/PrintMonitor.cpp @@ -47,6 +47,21 @@ const ObjectModelArrayDescriptor PrintMonitor::filamentArrayDescriptor = { return ExpressionValue(((const PrintMonitor*)self)->printingFileInfo.filamentNeeded[context.GetIndex(0)], 1); } }; +const ObjectModelArrayDescriptor PrintMonitor::thumbnailArrayDescriptor = +{ + &printMonitorLock, + [] (const ObjectModel *self, const ObjectExplorationContext&) noexcept -> size_t + { + size_t count = 0; + while (count < GCodeFileInfo::MaxThumbnails && ((const PrintMonitor*)self)->printingFileInfo.thumbnails[count].IsValid()) + { + count++; + } + return count; + }, + [] (const ObjectModel *self, ObjectExplorationContext& context) noexcept -> ExpressionValue { return ExpressionValue(self, 2); } +}; + constexpr ObjectModelTableEntry PrintMonitor::objectModelTable[] = { // Within each group, these entries must be in alphabetical order @@ -65,7 +80,7 @@ constexpr ObjectModelTableEntry PrintMonitor::objectModelTable[] = { "layerTime", OBJECT_MODEL_FUNC_IF(self->IsPrinting() && self->currentLayer != 0, self->GetCurrentLayerTime(), 1), ObjectModelEntryFlags::live }, { "pauseDuration", OBJECT_MODEL_FUNC_IF(self->IsPrinting(), lrintf(self->GetPauseDuration())), ObjectModelEntryFlags::live }, { "rawExtrusion", OBJECT_MODEL_FUNC_IF(self->IsPrinting(), ExpressionValue(self->gCodes.GetTotalRawExtrusion(), 1)), ObjectModelEntryFlags::live }, - { "timesLeft", OBJECT_MODEL_FUNC(self, 2), ObjectModelEntryFlags::live }, + { "timesLeft", OBJECT_MODEL_FUNC(self, 3), ObjectModelEntryFlags::live }, { "warmUpDuration", OBJECT_MODEL_FUNC_IF(self->IsPrinting(), lrintf(self->GetWarmUpDuration())), ObjectModelEntryFlags::live }, // 1. ParsedFileInfo members @@ -75,18 +90,27 @@ constexpr ObjectModelTableEntry PrintMonitor::objectModelTable[] = { "height", OBJECT_MODEL_FUNC(self->printingFileInfo.objectHeight, 2), ObjectModelEntryFlags::none }, { "lastModified", OBJECT_MODEL_FUNC(DateTime(self->printingFileInfo.lastModifiedTime)), ObjectModelEntryFlags::none }, { "layerHeight", OBJECT_MODEL_FUNC(self->printingFileInfo.layerHeight, 2), ObjectModelEntryFlags::none }, + { "numLayers", OBJECT_MODEL_FUNC((uint32_t)self->printingFileInfo.numLayers), ObjectModelEntryFlags::none }, { "printTime", OBJECT_MODEL_FUNC_IF(self->printingFileInfo.printTime != 0, (int32_t)self->printingFileInfo.printTime), ObjectModelEntryFlags::none }, { "simulatedTime", OBJECT_MODEL_FUNC_IF(self->printingFileInfo.simulatedTime != 0, (int32_t)self->printingFileInfo.simulatedTime), ObjectModelEntryFlags::none }, { "size", OBJECT_MODEL_FUNC(self->printingFileInfo.fileSize), ObjectModelEntryFlags::none }, + { "thumbnails", OBJECT_MODEL_FUNC_NOSELF(&thumbnailArrayDescriptor), ObjectModelEntryFlags::none }, + + // 2. ParsedFileInfo.thumbnails[] members + { "format", OBJECT_MODEL_FUNC(self->printingFileInfo.thumbnails[context.GetLastIndex()].format.ToString()), ObjectModelEntryFlags::none }, + { "height", OBJECT_MODEL_FUNC((int32_t)self->printingFileInfo.thumbnails[context.GetLastIndex()].height), ObjectModelEntryFlags::none }, + { "offset", OBJECT_MODEL_FUNC(self->printingFileInfo.thumbnails[context.GetLastIndex()].offset), ObjectModelEntryFlags::none }, + { "size", OBJECT_MODEL_FUNC(self->printingFileInfo.thumbnails[context.GetLastIndex()].size), ObjectModelEntryFlags::none }, + { "width", OBJECT_MODEL_FUNC((int32_t)self->printingFileInfo.thumbnails[context.GetLastIndex()].width), ObjectModelEntryFlags::none }, - // 2. TimesLeft members + // 3. TimesLeft members { "filament", OBJECT_MODEL_FUNC(self->EstimateTimeLeftAsExpression(filamentBased)), ObjectModelEntryFlags::live }, { "file", OBJECT_MODEL_FUNC(self->EstimateTimeLeftAsExpression(fileBased)), ObjectModelEntryFlags::live }, { "layer", OBJECT_MODEL_FUNC_NOSELF(nullptr), ObjectModelEntryFlags::obsolete }, { "slicer", OBJECT_MODEL_FUNC(self->EstimateTimeLeftAsExpression(slicerBased)), ObjectModelEntryFlags::live }, }; -constexpr uint8_t PrintMonitor::objectModelTableDescriptor[] = { 3, 12 + TRACK_OBJECT_NAMES, 9, 4 }; +constexpr uint8_t PrintMonitor::objectModelTableDescriptor[] = { 4, 12 + TRACK_OBJECT_NAMES, 11, 5, 4 }; DEFINE_GET_OBJECT_MODEL_TABLE(PrintMonitor) diff --git a/src/PrintMonitor/PrintMonitor.h b/src/PrintMonitor/PrintMonitor.h index 5ff5406f..ec264f9a 100644 --- a/src/PrintMonitor/PrintMonitor.h +++ b/src/PrintMonitor/PrintMonitor.h @@ -67,6 +67,7 @@ public: protected: DECLARE_OBJECT_MODEL OBJECT_MODEL_ARRAY(filament) + OBJECT_MODEL_ARRAY(thumbnail) private: static constexpr float MinFilamentUsageForEstimation = 0.01; // Minimum per cent of filament to be printed before the filament-based estimation returns values |