From 68c513bef59553121c8bc8bbbb6a3052d8db04c6 Mon Sep 17 00:00:00 2001 From: Christoph Schweppe Date: Mon, 25 Apr 2022 15:00:13 +0200 Subject: [PATCH] Allow setting a minimum value --- src/MenuItems.cpp | 8 ++++++++ src/MenuItems.h | 6 ++++++ src/graphics/DialogRuntimeEditor.h | 2 +- 3 files changed, 15 insertions(+), 1 deletion(-) diff --git a/src/MenuItems.cpp b/src/MenuItems.cpp index c15dc97..05b0b40 100755 --- a/src/MenuItems.cpp +++ b/src/MenuItems.cpp @@ -80,6 +80,11 @@ uint16_t MenuItem::getId() const return (isInfoProgMem()) ? get_info_uint(&info->id) : info->id; } +uint16_t MenuItem::getMinimumValue() const +{ + return (isInfoProgMem()) ? get_info_uint(&info->minValue) : info->minValue; +} + uint16_t MenuItem::getMaximumValue() const { if (isMenuRuntime(this)) { @@ -292,6 +297,9 @@ void ValueMenuItem::setCurrentValue(uint16_t val, bool silent) { if (val == currentValue || val > getMaximumValue()) { return; } + if (val < getMinimumValue()) { + val = getMinimumValue(); + } currentValue = val; changeOccurred(silent); } diff --git a/src/MenuItems.h b/src/MenuItems.h index d17921b..83c6ded 100755 --- a/src/MenuItems.h +++ b/src/MenuItems.h @@ -50,6 +50,8 @@ struct AnyMenuInfo { menuid_t id; /** eeprom address for this item or -1 if not stored */ uint16_t eepromAddr; + /** minimum value that this type can store */ + uint16_t minValue; /** maximum value that this type can store */ uint16_t maxValue; /** the callback function */ @@ -70,6 +72,8 @@ struct AnalogMenuInfo { menuid_t id; /** eeprom address for this item or -1 if not stored */ uint16_t eepromAddr; + /** minimum value that this type can store */ + uint16_t minValue; /** maximum value that this type can store */ uint16_t maxValue; /** the callback function */ @@ -355,6 +359,8 @@ class MenuItem { uint8_t copyNameToBuffer(char* sz, int offset, int size) const; /** Retrieves the ID from the info block */ menuid_t getId() const; + /** Retrieves the minimum value for this menu type */ + uint16_t getMinimumValue() const; /** Retrieves the maximum value for this menu type */ uint16_t getMaximumValue() const; /** Retrieves the eeprom storage position for this menu (or 0xffff if not applicable) */ diff --git a/src/graphics/DialogRuntimeEditor.h b/src/graphics/DialogRuntimeEditor.h index 4da34cb..90537bc 100644 --- a/src/graphics/DialogRuntimeEditor.h +++ b/src/graphics/DialogRuntimeEditor.h @@ -22,7 +22,7 @@ class DialogMultiPartEditor : BaseDialogController { private: MenuBasedDialog *dialog; EditableMultiPartMenuItem* menuItemBeingEdited; - AnalogMenuInfo scrollingInfo = {"Item Value", nextRandomId(), 0xffff, 1, onScrollingChanged, 0, 1, "" }; + AnalogMenuInfo scrollingInfo = {"Item Value", nextRandomId(), 0xffff, 0, 1, onScrollingChanged, 0, 1, "" }; AnalogMenuItem scrollingEditor = AnalogMenuItem(&scrollingInfo, 0, nullptr, INFO_LOCATION_RAM); public: