-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathmanagement.ino
197 lines (175 loc) · 4.23 KB
/
management.ino
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
void sensorManagement()
{
static long lastSensorTime;
if(millis()-lastSensorTime > sensorPeriod)
{
lastSensorTime = millis();
batRead();
mpuRead();
hmcRead();
}
}
void displayManagement()
{
static long lastDispTime;
static boolean messageDisplayed;
if(millis()-lastDispTime > dispPeriod)
{
lastDispTime = millis();
if(millis()-messageStartTime < messageTime) // display message
{
displayMessage();
messageDisplayed = true;
}
else
{
if(messageDisplayed) // remove message only once
{
osdClear();
messageDisplayed = false;
}
if(input == MAIN_IN) // main input
{
if(mainDispMode == STANDARD) // standard mode
{
displayCrosshair();
displayPitch();
displayHeading();
displayBattery_down_long();
}
else if(mainDispMode == TRACKER) // target tracking
{
displayTarget();
displayHeading();
displayPitch();
displayBattery_down_long();
}
else if(mainDispMode == MOTION) // Motion detectors
{
displayMotion();
displayCrosshair();
displayPitch();
displayHeading();
displayBattery_down_long();
}
else if(mainDispMode == INFO) // Informations
{
displayInfo();
}
}
else // auxiliary input
{
if(auxDispMode == OSDOFF)
{
// nothing displayed
}
else if(auxDispMode == SENTRY) // sentry control
{
displaySentry();
displayBattery_down_long();
}
else if(auxDispMode == RIFLE) // Firing computer
{
displayRifle();
displayBattery_down_long();
}
}
}
}
}
void wirelessManagement()
{
static long lastTXTime, lastRXReqTime;
// TX
if(millis()-lastTXTime > TX_PERIOD)
{
lastTXTime = millis();
if(input == MAIN_IN) // main input
{
// nothing for now
}
else // auxiliary input
{
if(auxDispMode == SENTRY) sentryTX();
}
}
// RX
if(millis()-lastRXReqTime > RX_PERIOD)
{
lastRXReqTime = millis();
if(input == MAIN_IN) // main input
{
if(mainDispMode == TRACKER) trackerRX();
else if(mainDispMode == MOTION) motionRX();
}
else // auxiliary input
{
if(auxDispMode == RIFLE) rifleRX();
}
}
}
void changeManagement()
{
static int lastInput, lastMainDispMode, lastAuxDispMode;
if(input != lastInput || lastMainDispMode != mainDispMode || lastAuxDispMode!= auxDispMode)
{
lastInput = input;
lastMainDispMode = mainDispMode;
lastAuxDispMode = auxDispMode;
osdClear();
messageStartTime = millis();
lastTrackerRX = -RX_TIMEOUT_TRACKER;
lastMotion1RX = -RX_TIMEOUT_MOTION;
lastMotion2RX = -RX_TIMEOUT_MOTION;
lastRifleRX = -RX_TIMEOUT_RIFLE;
// Wirless parameters
if(input == MAIN_IN) // on main input
{
digitalWrite(MAX7456CS,LOW); // enable device
writeToMAX7456(VM0, PAL | SYNC_EXTERNAL | ENABLE | SYNC_VSYNC); // Original
digitalWrite(MAX7456CS,HIGH); // disable device
if(mainDispMode == TRACKER)
{
Mirf.setRADDR((byte *)"argtr");
Mirf.payload = 3;
Mirf.config();
}
else if(mainDispMode == MOTION)
{
Mirf.setRADDR((byte *)"msr01");
Mirf.payload = 1;
Mirf.config();
}
else
{
Mirf.setRADDR((byte *)"arg01");
Mirf.payload = 2;
Mirf.config();
}
}
else // on auxiliary input
{
digitalWrite(MAX7456CS,LOW); // enable device
writeToMAX7456(VM0, NTSC | SYNC_EXTERNAL | ENABLE | SYNC_VSYNC); // Altered
digitalWrite(MAX7456CS,HIGH); // disable device
if(auxDispMode == SENTRY)
{
headingZeroTX = headingDegMean; // zero sentry
Mirf.payload = 2;
Mirf.config();
}
else if(auxDispMode == RIFLE)
{
Mirf.setRADDR((byte *)"argfc");
Mirf.payload = 2;
Mirf.config();
}
else
{
Mirf.setRADDR((byte *)"arg01");
Mirf.payload = 2;
Mirf.config();
}
}
}
}