-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathInputScreen.cpp
More file actions
204 lines (170 loc) · 5.68 KB
/
Copy pathInputScreen.cpp
File metadata and controls
204 lines (170 loc) · 5.68 KB
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
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
#include <Arduino.h>
#include <EEPROM.h>
#include "InputScreen.h"
#include "ScreenObjects.h"
//----------------------------------------------
// Constructor
//----------------------------------------------
InputScreen::InputScreen() {}
//----------------------------------------------
// Initialize the instance
//----------------------------------------------
void InputScreen::InitializeUI()
{
id = SCR_ADDRESS_ID;
caption = LNG_EN_INPUT_HEADER;
AddTextBox( UI_ADDR_TXTBOX, 18, 85, 134, 42, COLOR_TXT_BACKGROUND, COLOR_TXT_BORDER, "");
AddPushButton(UI_ADDR_DEL, 162, 85, 62, 42, COLOR_BTN_INFO_NORMAL, COLOR_BTN_INFO_PRESSED, 24, 24, BMP_DELETE);
AddPushButton(UI_ADDR_1, 18, 135, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "1");
AddPushButton(UI_ADDR_2, 90, 135, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "2");
AddPushButton(UI_ADDR_3, 162, 135, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "3");
AddPushButton(UI_ADDR_4, 18, 185, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "4");
AddPushButton(UI_ADDR_5, 90, 185, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "5");
AddPushButton(UI_ADDR_6, 162, 185, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "6");
AddPushButton(UI_ADDR_7, 18, 235, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "7");
AddPushButton(UI_ADDR_8, 90, 235, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "8");
AddPushButton(UI_ADDR_9, 162, 235, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "9");
AddPushButton(UI_ADDR_0, 90, 285, 62, 42, COLOR_BTN_NORMAL, COLOR_BTN_PRESSED, "0");
AddPushButton(UI_ADDR_CANCEL, 18, 285, 62, 42, COLOR_BTN_ERROR_NORMAL, COLOR_BTN_ERROR_PRESSED, 24, 24, BMP_CANCEL);
AddPushButton(UI_ADDR_OK, 162, 285, 62, 42, COLOR_BTN_SUCCESS_NORMAL, COLOR_BTN_SUCCESS_PRESSED, 24, 24, BMP_OK);
}
//----------------------------------------------------------------------------------------------------
// Virtual method that can be implemented by derived classes
// to show information when the screen is shown
//----------------------------------------------------------------------------------------------------
void InputScreen::Shown(ScreenParams *params)
{
mode = params->inputMode;
track = params->trackNum;
inputValue = params->address;
if (inputValue > 0)
{
itoa(inputValue, txtAddress, 10);
SetTextBoxText(UI_ADDR_TXTBOX, txtAddress);
}
switch (mode)
{
case INPUT_MODE_MANUAL_ADDR:
SetScreenCaption(LNG_EN_INPUT_HEADER_MANUAL);
break;
case INPUT_MODE_TRACK_ADDR:
switch (params->trackNum)
{
case 1:
SetScreenCaption(LNG_EN_INPUT_HEADER_TRACK_1);
break;
case 2:
SetScreenCaption(LNG_EN_INPUT_HEADER_TRACK_2);
break;
case 3:
SetScreenCaption(LNG_EN_INPUT_HEADER_TRACK_3);
break;
case 4:
SetScreenCaption(LNG_EN_INPUT_HEADER_TRACK_4);
break;
}
break;
case INPUT_MODE_DEVID:
SetScreenCaption(LNG_EN_INPUT_HEADER_DEVICE);
break;
}
display->tft.setTextSize(2);
}
//----------------------------------------------
// Hadle screen clicks
//----------------------------------------------
ScreenParams* InputScreen::ClickHandler(uint8_t objId)
{
switch (objId)
{
case UI_ADDR_0:
case UI_ADDR_1:
case UI_ADDR_2:
case UI_ADDR_3:
case UI_ADDR_4:
case UI_ADDR_5:
case UI_ADDR_6:
case UI_ADDR_7:
case UI_ADDR_8:
case UI_ADDR_9:
DigitPressed(objId);
break;
case UI_ADDR_OK:
return OkButtonPressed(objId);
case UI_ADDR_CANCEL:
ToggleButtonState(objId);
return GotoScreen(SCR_MENU_ID);
case UI_ADDR_DEL:
DeleteButtonPressed(objId);
break;
}
return NULL;
}
//----------------------------------------------
// Numeric button pressed
//----------------------------------------------
void InputScreen::DigitPressed(uint8_t objId)
{
ToggleButtonState(objId);
if (addPos == 4)
{
addPos = 0;
txtAddress[0] = txtAddress[1] = txtAddress[2] = txtAddress[3] = '\0';
}
txtAddress[addPos] = 48 + objId;
txtAddress[addPos + 1] = '\0';
addPos++;
SetTextBoxText(UI_ADDR_TXTBOX, txtAddress);
}
//----------------------------------------------
// Delete button pressed
//----------------------------------------------
void InputScreen::DeleteButtonPressed(uint8_t objId)
{
if (addPos == 0)
return;
ToggleButtonState(objId);
addPos--;
txtAddress[addPos] = '\0';
SetTextBoxText(UI_ADDR_TXTBOX, txtAddress);
}
//----------------------------------------------
// Delete button pressed
//----------------------------------------------
ScreenParams* InputScreen::OkButtonPressed(uint8_t objId)
{
switch (mode)
{
case INPUT_MODE_MANUAL_ADDR:
return GotoScreen(SCR_DRIVE_ID, GetInputValue());
case INPUT_MODE_TRACK_ADDR:
return GotoScreen(SCR_SETUP_ID, GetInputValue(), track);
case INPUT_MODE_DEVID:
return GotoScreen(SCR_SETUP_ID, id);
default:
return NULL;
}
}
//----------------------------------------------
// Convert screen address into an integer
//----------------------------------------------
uint16_t InputScreen::GetInputValue()
{
return atoi(txtAddress);
}
//----------------------------------------------
// Convert numeric addres into char array
//----------------------------------------------
void InputScreen::SetAddress(uint16_t addr)
{
ClearAddress();
itoa(addr, txtAddress, 10);
}
//----------------------------------------------
// Clear address char array
//----------------------------------------------
void InputScreen::ClearAddress()
{
for (byte i = 0; i <= TXT_DIGITS_MAX; i++)
txtAddress[i] = '\0';
}