-
Notifications
You must be signed in to change notification settings - Fork 4
/
NumericSelector.cpp
executable file
·61 lines (45 loc) · 1.37 KB
/
NumericSelector.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#include "NumericSelector.h"
NumericSelector::NumericSelector(MenuItem* parent, const FlashString* text, uint8_t& variable, uint8_t min, uint8_t max, NumberSelectedCallback callback) : MenuItem(parent, text), variable(variable) {
this->min = min;
this->max = max;
this->callback = callback;
oldValue = variable;
};
uint8_t NumericSelector::getValue() { return variable; }
uint8_t NumericSelector::getMin() { return min; }
uint8_t NumericSelector::getMax() { return max; }
const char* NumericSelector::getSecondaryText() {
snprintf_P(valueStr, 5, PSTR("<%d>"), variable);
return valueStr;
}
bool NumericSelector::activate() {
oldValue = variable;
return 1;
}
void NumericSelector::deactivate() {
variable = oldValue;
// On cancel restore the value
if (this->callback)
this->callback(false);
}
void NumericSelector::doNext() {
if(variable == this->max)
variable = this->min;
else
variable++;
if (this->callback)
this->callback(false);
}
void NumericSelector::doPrev() {
if(variable == this->min)
variable = this->max;
else
variable--;
if (this->callback)
this->callback(false);
}
MenuItem* NumericSelector::action() {
if (this->callback)
this->callback(true);
return this->getParent();
}