-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathDLChoiceMenuItem.cpp
57 lines (46 loc) · 1.32 KB
/
DLChoiceMenuItem.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
#include "DLMenu.h"
///
/// ChoiceMenuItem
///
DLChoiceMenuItem::DLChoiceMenuItem(LiquidCrystal *lcd, const char *label, int address, const char *const *choiceTable, int nChoices) : DLMenuItem(lcd, label, address){
choices = choiceTable;
len = nChoices;
sections = 1;
s = 0;
// load from EEPROM
selected = EEPROM[address];
if (selected > len - 1)
selected = 0; // the default choice
}
void DLChoiceMenuItem::show(bool endFirst = false){
// endFirst is ignored here because this item has one section only
lcd->clear();
// print label
progmem_to_lcd(lcd, 0, label);
// print current setting
//lcd->setCursor(0, 1);
//lcd->print(choices[selected]);
progmem_table_to_lcd(lcd, 1, choices, selected);
// show cursor (only symbolic)
lcd->setCursor(0, 1);
lcd->cursor();
}
void DLChoiceMenuItem::hide(void){
save();
lcd->clear();
}
void DLChoiceMenuItem::add(int i){
selected = constrain(selected + i, 0, len - 1);
show();
}
void DLChoiceMenuItem::increase(void) { add(1); }
void DLChoiceMenuItem::decrease(void) { add(-1); }
void DLChoiceMenuItem::save(void){
if (EEPROM[address] != selected)
EEPROM[address] = selected;
};
void DLChoiceMenuItem::setValue(byte value){
if(value > len-1) value = len-1;
selected = value;
save();
}