-
Notifications
You must be signed in to change notification settings - Fork 0
/
sensorFunctions.cpp
81 lines (52 loc) · 2.13 KB
/
sensorFunctions.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
// Local declations
#include "sensorFunctions.h" // Sensor functions
#include "drawBitmap.h" // Draw drawBitmap
#include "global.h" // Global
// Debug serial prints
#define DEBUG 0
#if DEBUG==1
#define outputDebug(x); Serial.print(x);
#define outputDebugLn(x); Serial.println(x);
#else
#define outputDebug(x);
#define outputDebugLn(x);
#endif
/*---------------------------------------------------------------- */
// Function to check Arduino Nano is still alive
void sensorCheckCall(boolean interruptDetected, const unsigned long interruptCheckPeriod, const byte interruptCount, byte nanoResetPin) {
static unsigned long lastCheckTime = 0;
static byte interruptIntervals = 0;
if (millis() - lastCheckTime >= interruptCheckPeriod) {
lastCheckTime = millis();
if (!interruptDetected) {
outputDebugLn("");
outputDebug("Arduino BLE Sense not responding #");
outputDebug(interruptIntervals);
outputDebugLn("");
interruptIntervals++;
drawBitmap(tft, PULSE_ICON_Y, PULSE_ICON_X, pulseAmber, PULSE_ICON_W, PULSE_ICON_H);
if (interruptIntervals > interruptCount) {
drawBitmap(tft, PULSE_ICON_Y, PULSE_ICON_X, pulseRed, PULSE_ICON_W, PULSE_ICON_H);
delay(1500);
playTone(buzzerP, buzzerF, buzzerD);
outputDebugLn("");
outputDebug("Rebooting Arduino BLE Sense...");
outputDebugLn("");
digitalWrite(nanoResetPin, LOW);
delay(10);
digitalWrite(nanoResetPin, HIGH);
interruptIntervals = 0;
}
}
else {
outputDebugLn("");
outputDebug("Interrupt signal detected...");
outputDebug(interruptIntervals);
outputDebugLn("");
interruptDetected = false;
interruptIntervals = 0;
drawBitmap(tft, PULSE_ICON_Y, PULSE_ICON_X, pulseGreen, PULSE_ICON_W, PULSE_ICON_H);
}
}
} // Close function
/*---------------------------------------------------------------- */