forked from DCC-EX/CommandStation-EX
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhmi.Interface.cpp
128 lines (104 loc) · 3.85 KB
/
hmi.Interface.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
#include "defines.h"
#include "DCC.h"
#include "hmi.h"
#include "hmiConfig.h"
#include "HmiInterface.hpp"
#ifdef USE_HMI
bool hmi::HmiInterfaceLoop()
{
_HMIDEBUG_FCT_PRINTLN("hmi::HmiInterfaceLoop().. Begin");
/*#ifdef ARDUINO_ARCH_ESP32
int core = xPortGetCoreID();
if (core != this->executionCore || this->pHmiInterfaceEventBuffer == NULL)
return false;
#endif*/
HmiInterfaceMessage msg;
char mess[LineCarNbMax];
uint8_t speed;
bool dir;
if (!this->pHmiInterfaceEventBuffer->GetBytes((byte*)&msg, sizeof(msg)))
return false;
switch (msg.event)
{
case HmiInterfaceEvent_WifiStartConnection:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: WifiStartConnection");
this->addNotification(0, HMI_WifiWaiting, 0);
break;
case HmiInterfaceEvent_WifiConnected:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: WifiConnected");
addNotification(HMI_WifiOk);
sprintf(mess, "%d.%d.%d.%d", msg.data.ip[0], msg.data.ip[1], msg.data.ip[2], msg.data.ip[3]);
addNotification(mess);
addNotification(TXT_BoxAddr);
break;
case HmiInterfaceEvent_WifiEndConnection:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: WifiEndConnection");
this->addNotification(HMI_noWifi);
break;
case HmiInterfaceEvent_NewClient:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: NewClient");
sprintf(mess, "#%d: %d.%d.%d.%d", msg.data.client.clientId, msg.data.client.ip[0], msg.data.client.ip[1], msg.data.client.ip[2], msg.data.client.ip[3]);
this->addNotification(mess);
break;
case HmiInterfaceEvent_CloseClient:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: CloseClient");
sprintf(mess, "#%d closed", msg.data.client.clientId);
this->addNotification(mess);
break;
case HmiInterfaceEvent_ChangeSpeed:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: ChangeSpeed");
speed = DCC::getThrottleSpeed(msg.data.dcc.addr);
dir = DCC::getThrottleDirection(msg.data.dcc.addr);
addNotification(msg.data.dcc.addr, dir ? HMI_OrderForward : HMI_OrderBack, speed);
break;
case HmiInterfaceEvent_ChangeDirection:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: ChangeDirection");
dir = DCC::getThrottleDirection(msg.data.dcc.addr);
addNotification(msg.data.dcc.addr, msg.data.dcc.forward ? HMI_OrderForward : HMI_OrderBack, dir);
break;
case HmiInterfaceEvent_ChangeFunction:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: ChangeFunction");
addNotification(msg.data.dcc.addr, HMI_OrderFunction, msg.data.dcc.function, msg.data.dcc.state);
break;
case HmiInterfaceEvent_DccOn:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: DccOn");
addNotification(HMI_StartDCC);
break;
case HmiInterfaceEvent_DccOff:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: DccOff");
addNotification(HMI_OrderStopAll);
break;
case HmiInterfaceEvent_DccShort:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: Short");
addNotification(HMI_ShortCurcuit);
break;
case HmiInterfaceEvent_DccEmergencyStop:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: EmergencyStop");
// Todo : missing order emergency stop !
addNotification(HMI_OrderStopAll);
break;
case HmiInterfaceEvent_DccGeneralStop:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: GeneralStop");
addNotification(HMI_OrderStopAll);
break;
case HmiInterfaceEvent_LocoAdd:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: LocoAdd");
speed = DCC::getThrottleSpeed(msg.data.dcc.addr);
dir = DCC::getThrottleDirection(msg.data.dcc.addr);
addNotification(msg.data.dcc.addr,
dir ? HMI_OrderForward : HMI_OrderBack,
speed);
break;
case HmiInterfaceEvent_LocoRemove:
_HMIDEBUG_LEVEL1_PRINTLN("HmiInterface :: LocoRemove");
addNotification(msg.data.dcc.addr, HMI_OrderStop, 0);
break;
}
_HMIDEBUG_FCT_PRINTLN("hmi::HmiInterfaceLoop().. End");
return true;
}
void hmi::HmiInterfaceUpdateDrawing()
{
this->update();
}
#endif