Skip to content

Commit 9776131

Browse files
committed
Add UIntTParameter
1 parent 51ca69c commit 9776131

2 files changed

Lines changed: 45 additions & 7 deletions

File tree

examples/IotWebConf03TypedParameters/IotWebConf03TypedParameters.ino

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -146,15 +146,15 @@ void handleRoot()
146146
s += "<title>IotWebConf 03 Custom Parameters</title></head><body>Hello world!";
147147
s += "<ul>";
148148
s += "<li>String param value: ";
149-
s += stringParam.getValue();
149+
s += stringParam.value();
150150
s += "<li>Int param value: ";
151-
s += intParam.getValue();
151+
s += intParam.value();
152152
s += "<li>Float param value: ";
153-
s += floatParam.getValue();
153+
s += floatParam.value();
154154
s += "<li>CheckBox selected: ";
155155
s += checkboxParam.isChecked();
156156
s += "<li>Option selected: ";
157-
s += chooserParam.getValue();
157+
s += chooserParam.value();
158158
s += "</ul>";
159159
s += "Go to <a href='config'>configure page</a> to change values.";
160160
s += "</body></html>\n";

src/IotWebConfTParameter.h

Lines changed: 41 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,11 @@ class DataType : virtual public ConfigItemBridge
7979
{
8080
}
8181

82-
ValueType& getValue() { return this->_value; }
82+
/**
83+
* value() can be used to get the value, but it can also
84+
* be used set it like this: p.value() = newValue
85+
*/
86+
ValueType& value() { return this->_value; }
8387
ValueType& operator*() { return this->_value; }
8488

8589
protected:
@@ -478,7 +482,7 @@ class CheckboxTParameter : public BoolDataType, public InputParameter
478482
ConfigItemBridge(id),
479483
BoolDataType::BoolDataType(id, defaultValue),
480484
InputParameter::InputParameter(id, label) { }
481-
bool isChecked() { return this->getValue(); }
485+
bool isChecked() { return this->value(); }
482486

483487
protected:
484488
virtual const char* getInputType() override { return "checkbox"; }
@@ -689,6 +693,40 @@ class IntTParameter :
689693
virtual const char* getInputType() override { return "number"; }
690694
};
691695

696+
template <typename ValueType, int base = 10>
697+
class UIntTParameter :
698+
public virtual UnsignedIntDataType<ValueType, base>,
699+
public PrimitiveInputParameter<ValueType>
700+
{
701+
public:
702+
UIntTParameter(const char* id, const char* label, ValueType defaultValue) :
703+
ConfigItemBridge(id),
704+
SignedIntDataType<ValueType, base>::SignedIntDataType(id, defaultValue),
705+
PrimitiveInputParameter<ValueType>::PrimitiveInputParameter(id, label) { }
706+
707+
// TODO: somehow organize these methods into common parent.
708+
virtual ValueType getMin() override
709+
{
710+
return PrimitiveDataType<ValueType>::getMin();
711+
}
712+
virtual ValueType getMax() override
713+
{
714+
return PrimitiveDataType<ValueType>::getMax();
715+
}
716+
717+
virtual bool isMinDefined() override
718+
{
719+
return PrimitiveDataType<ValueType>::isMinDefined();
720+
}
721+
virtual bool isMaxDefined() override
722+
{
723+
return PrimitiveDataType<ValueType>::isMaxDefined();
724+
}
725+
726+
protected:
727+
virtual const char* getInputType() override { return "number"; }
728+
};
729+
692730
class FloatTParameter :
693731
public FloatDataType,
694732
public PrimitiveInputParameter<float>
@@ -822,7 +860,7 @@ class SelectTParameter : public OptionsTParameter<len>
822860
// oitem.replace("{n}", "?");
823861
// }
824862
if ((hasValueFromPost && (valueFromPost == optionValue)) ||
825-
(strncmp(this->getValue(), optionValue, len) == 0))
863+
(strncmp(this->value(), optionValue, len) == 0))
826864
{
827865
// -- Value from previous submit
828866
oitem.replace("{s}", " selected");

0 commit comments

Comments
 (0)