-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathMenuino.cpp
185 lines (152 loc) · 4.65 KB
/
Menuino.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
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
#include <Arduino.h>
#include "ScreenObjects.h"
#include "Menuino.h"
//----------------------------------------------
// Constructor
//----------------------------------------------
Menuino::Menuino() {}
//----------------------------------------------
// Initialize the instance
//----------------------------------------------
void Menuino::Initialize(OpenSmart32* tft)
{
// Initialize the screen parameters
params = new ScreenParams();
// Initialize the screens
scrMenu = new MenuScreen();
scrMenu->Initialize(tft);
scrSelect = new SelectScreen();
scrSelect->Initialize(tft);
scrDrive = new DriveScreen();
scrDrive->Initialize(tft);
scrInput = new InputScreen();
scrInput->Initialize(tft);
scrSetup = new SetupScreen();
scrSetup->Initialize(tft);
scrInfo = new InfoScreen();
scrInfo->Initialize(tft);
// Draw no connection icon
scrMenu->DrawNotifyIcon(0, COLOR_NAVBAR_DISABLED, BMP_XPN_OFF);
// Show initial screen
params->gotoScr = SCR_MENU_ID;
ShowScreen(params);
xpn = XpnManager::getInstance();
}
//----------------------------------------------
// Dispatch encoder movements and update menu
//----------------------------------------------
void Menuino::Dispatch()
{
// hardware.Dispatch();
// scrCurrent->Dispatch();
}
//----------------------------------------------
// Handle the screen clicks
//----------------------------------------------
void Menuino::HandleDisplayClick(uint16_t xpos, uint16_t ypos)
{
uint8_t objId = scrCurrent->GetScreenClickedObjectID(xpos, ypos);
if (objId == UI_OBJECT_NULL) return;
params = scrCurrent->ClickHandler(objId);
if (params == NULL) return;
ShowScreen(params);
}
//----------------------------------------------
// Handle the encoder movement
//----------------------------------------------
void Menuino::HandleEncoderMoved(EncoderMenuSwitch::EncoderDirection dir)
{
scrCurrent->EncoderMovementHandler(dir);
}
//----------------------------------------------
// Handle the encoder click
//----------------------------------------------
void Menuino::HandleEncoderClick()
{
scrCurrent->EncoderClickHandler();
}
//----------------------------------------------
// Handle engine notification received
//----------------------------------------------
void Menuino::HandleEngineNotify(XpnEngine *engine)
{
scrCurrent->HandleEngineNotify(engine);
}
//----------------------------------------------
// Handle central status notifications
//----------------------------------------------
void Menuino::HandleMasterStatusNotify(uint8_t status)
{
// xpn->master.status = status;
switch (xpn->master.status)
{
case csNormal:
scrCurrent->DrawNotifyIcon(0, COLOR_NAVBAR_NORMAL, BMP_XPN_ON);
break;
case csShortCircuit: // Corto circuito - OFF
scrCurrent->DrawNotifyIcon(0, COLOR_NAVBAR_ERROR, BMP_XPN_SHORT);
break;
case csTrackVoltageOff: // Sin tension en via - OFF
scrCurrent->DrawNotifyIcon(0, COLOR_NAVBAR_WARNING, BMP_XPN_WARN);
break;
case csEmergencyStop: // Parada emergencia - StoP
scrCurrent->DrawNotifyIcon(0, COLOR_NAVBAR_WARNING, BMP_XPN_WARN);
break;
case csServiceMode: // Programacion en modo servicio - Pro
scrCurrent->DrawNotifyIcon(0, COLOR_NAVBAR_NORMAL, BMP_XPN_SERVICE);
break;
}
}
////----------------------------------------------
//// Handle central status information
////----------------------------------------------
//void Menuino::HandleXPNInfo(uint8_t ver, uint8_t hdwtype)
//{
// hardware.xpnMaster.vermajor = ver >> 4;
// hardware.xpnMaster.verminor = (ver && 0xF0);
// hardware.xpnMaster.type = hdwtype;
//}
//----------------------------------------------
// Gets the current screen instance
//----------------------------------------------
Screen* Menuino::GetCurrentScreen()
{
return scrCurrent;
}
//----------------------------------------------
// Set new current screen
//----------------------------------------------
void Menuino::ShowScreen(ScreenParams* params)
{
switch (params->gotoScr)
{
case SCR_MENU_ID:
scrCurrent = scrMenu;
scrCurrent->Show(params);
break;
case SCR_SELECT_ID:
scrCurrent = scrSelect;
scrCurrent->Show(params);
break;
case SCR_DRIVE_ID:
scrCurrent = scrDrive;
scrCurrent->Show(params);
break;
case SCR_ADDRESS_ID:
scrCurrent = scrInput;
scrCurrent->Show(params);
break;
case SCR_WAIT_ID:
scrCurrent = scrWait;
scrCurrent->Show(params);
break;
case SCR_SETUP_ID:
scrCurrent = scrSetup;
scrCurrent->Show(params);
break;
case SCR_INFO_ID:
scrCurrent = scrInfo;
scrCurrent->Show(params);
break;
}
}