-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcutdown.ino
53 lines (47 loc) · 1.03 KB
/
cutdown.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
unsigned long CutdownOffAt=0;
void SetupCutdown(void)
{
#ifdef CUTDOWN
digitalWrite(CUTDOWN, 0);
pinMode(CUTDOWN, OUTPUT);
digitalWrite(CUTDOWN, 0);
#endif
}
void CutdownNow(unsigned long Period)
{
#ifdef CUTDOWN
Serial.println(F("CUTDOWN ON"));
digitalWrite(CUTDOWN, 1);
CutdownOffAt = millis() + Period;
#endif
}
void CheckCutdown(void)
{
#ifdef CUTDOWN
// Don't do anything unless we have GPS
if (GPS.Satellites >= 4)
{
// Arm ?
if ((GPS.Altitude > 2000) && (GPS.CutdownStatus == 0))
{
GPS.CutdownStatus = 1; // Armed
}
// Trigger only if armed
if (GPS.CutdownStatus == 1)
{
// ALTITUDE TEST
if ((Settings.CutdownAltitude > 2000) && (GPS.Altitude >= Settings.CutdownAltitude))
{
GPS.CutdownStatus = 2; // Altitude trigger
CutdownNow(Settings.CutdownPeriod);
}
}
}
if ((CutdownOffAt > 0) && (millis() >= CutdownOffAt))
{
digitalWrite(CUTDOWN, 0);
Serial.println(F("CUTDOWN OFF"));
CutdownOffAt = 0;
}
#endif
}