-
Notifications
You must be signed in to change notification settings - Fork 0
/
SetIntervalView.cpp
106 lines (87 loc) · 2.67 KB
/
SetIntervalView.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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
//
// Lucky Resistor's Deluxe Data Logger
// ---------------------------------------------------------------------------
// (c)2015 by Lucky Resistor. See LICENSE for details.
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
//
#include "SetIntervalView.h"
#include "Application.h"
#include "Settings.h"
#include "SharpDisplay.h"
#include "ViewManager.h"
namespace lr {
namespace SetIntervalView {
// The intervals encoded as number, unit tuples.
static const uint8_t cIntervals[] PROGMEM = {
10, 's',
30, 's',
1, 'm',
10, 'm',
1, 'h',
8, 'h',
24, 'h'
};
// The index from the settings.
static uint8_t gSettingsIndex;
// The currently selected index.
static uint8_t gSelectedIndex;
void viewWillAppear()
{
gSettingsIndex = Settings::getInterval();
gSelectedIndex = gSettingsIndex;
}
void updateDisplay()
{
SharpDisplay::setLineText(0, PSTR("Interval"));
SharpDisplay::fillRow(1, '\x89');
for (uint8_t i = 0; i < 7; ++i) {
String text;
if (i == gSettingsIndex) {
text = String(F("\x9e "));
} else {
text = String(F(" "));
}
text += String(pgm_read_byte(&cIntervals[i*2]), DEC);
text += static_cast<char>(pgm_read_byte(&cIntervals[i*2+1]));
SharpDisplay::setTextInverse(i == gSelectedIndex);
SharpDisplay::setLineText(i+2, text);
}
}
void handleKey(KeyPad::Key key)
{
switch (key) {
case KeyPad::Up:
if (gSelectedIndex > 0) {
--gSelectedIndex;
}
break;
case KeyPad::Down:
if (gSelectedIndex < 6) {
++gSelectedIndex;
}
break;
case KeyPad::Enter:
Settings::setInterval(static_cast<Settings::Interval>(gSelectedIndex));
case KeyPad::Left:
ViewManager::setNextView(ViewManager::MainMenuView);
break;
default:
break;
}
ViewManager::setNeedsDisplayUpdate();
}
}
}