-
Notifications
You must be signed in to change notification settings - Fork 0
/
TCCommon.h
197 lines (161 loc) · 3.08 KB
/
TCCommon.h
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
#ifndef _TCCOMMON_H_
#define _TCCOMMON_H_
#if defined(ARDUINO) && ARDUINO >= 100
#include "arduino.h"
#else
#include "WProgram.h"
#endif
#define CPU_RESTART_ADDR (uint32_t *)0xE000ED0C
#define CPU_RESTART_VAL 0x5FA0004
#define CPU_RESTART() (*CPU_RESTART_ADDR = CPU_RESTART_VAL)
enum
{
eMaxControlSwitchCount = 12,
eMaxTrackTurnoutCount = 16,
eMaxControlSwitchToTurnoutMapCount = 64,
eMaxControlSwitchID = 512,
eMaxTurnoutID = 512,
eMaxTurnoutsPerSwitch = 8,
eMaxLEDsPerTurnout = 4,
eInvalidID = 0xFFFF,
eEEPROMVersion = 1,
eTurnDir_Straight = 0,
eTurnDir_Turnout,
eMsgType_Alive = 1,
eMsgType_SerialOut,
eMsgType_TableWrite,
eMsgType_TableRead,
eMsgType_TableUpdate,
eMsgType_TrackSensor,
eMsgType_TrackTurnout,
eMsgType_ControlSwitch,
eMsgType_TurnoutControlSwitchTouch,
eMsgType_StateVar,
eMsgType_ConfigVar,
eMsgType_SoftRestart,
eMsgType_ResetAllState,
eMsgType_DCCTrack,
eMsgType_DCCThrottle,
eMsgType_DCCService,
eTableType_ControlSwitch = 1,
eTableType_TrackTurnout,
eTableType_TrackTurnoutLEDMap,
eTableType_TrackSensor,
eTableType_ControlSwitchToTurnoutMap,
eTableType_DCC,
eDCCThrottle_Power = 1,
eDCCThrottle_EmergencyAllStop,
eDCCThrottle_ResetDecoder,
eDCCThrottle_EmergencyStop,
eDCCThrottle_SetSpeedAndDirection,
eDIOPinCount = 34,
};
struct SControlSwitchConfig
{
uint16_t id;
uint8_t straightDInPin;
uint8_t turnDInPin;
uint8_t touchID;
};
struct STrackTurnoutConfig
{
uint16_t id;
uint8_t straightDOutPin;
uint8_t turnDOutPin;
};
struct STrackTurnoutLEDMapConfig
{
uint16_t turnoutID;
uint8_t straightLEDNum[2];
uint8_t turnoutLEDNum[2];
};
struct STrackSensorConfig
{
uint16_t id;
uint8_t dInPin;
};
struct SControlSwitchToTurnoutMapConfig
{
uint16_t controlSwitchID;
uint16_t turnout1ID;
uint16_t turnout2ID;
};
struct SMsg_DCCCommandConfig
{
uint16_t commandID;
uint8_t waveformPin;
uint8_t powerPin;
uint8_t currentSensePin;
};
struct SMsg_ControlSwitch
{
uint32_t timeMS;
uint16_t id;
uint8_t direction;
};
struct SMsg_TrackTurnout
{
uint32_t timeMS;
uint16_t id;
uint8_t direction;
};
struct SMsg_TurnoutControlSwitchTouch
{
uint32_t timeMS;
uint16_t turnoutID;
uint8_t touched; // 1 is touch, 0 is release
};
struct SMsg_TrackSesnor
{
uint32_t timeMS;
uint16_t id;
uint16_t trigger;
};
struct SMsg_Table
{
uint8_t type;
uint8_t index;
union
{
SControlSwitchConfig controlSwitch;
STrackTurnoutConfig trackTurnout;
STrackSensorConfig trackSensor;
SControlSwitchToTurnoutMapConfig trackTurnoutMap;
STrackTurnoutLEDMapConfig trackTurnoutLEDMap;
SMsg_DCCCommandConfig dccCommand;
};
};
struct SMsg_ConfigVar
{
uint8_t setVar; // 1 is set, 0 is get
uint8_t configVar;
uint8_t value;
};
struct SMsg_StateVar
{
uint8_t stateVar;
uint8_t value;
};
struct SMsg_DCCCommand
{
uint16_t address;
uint8_t type;
uint8_t data;
};
struct SMsg_DCCServiceCommand
{
uint8_t type;
uint8_t data;
};
class ITouchSensor
{
public:
virtual void
Touch(
int inTouchID) = 0;
virtual void
Release(
int inTouchID) = 0;
};
extern char const* gVersionStr;
#endif /* _TCCOMMON_H_ */