-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathaccurate_timing.cpp
More file actions
64 lines (51 loc) · 1.73 KB
/
accurate_timing.cpp
File metadata and controls
64 lines (51 loc) · 1.73 KB
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
#include "accurate_timing.h"
unsigned long _interrupt_millis; // this value is cleared once the sensor trip is handled.
unsigned long _last_interrupt_millis; // this value is not cleared after the sensor trip is handled
// LAST SENSOR DATE/TIME
TimeResult last_sensor_time;
// Method which we can use in order to get the current year/date/time.
#include "uni_gps.h"
extern UniGps gps;
// A pulse-per-second (PPS) signal occurs every 1 second,
// And we want to use this to synchronize our clock
// so that when the sensor interrupt is fired,
// we can determine the current time accurately.
// NOTE: The GPS PPS signal will ONLY fire when there is GPS lock.
void pps_interrupt() {
unsigned long now = millis();
gps.synchronizeClocks(now);
}
#include "uni_config.h"
extern UniConfig config;
void sensor_interrupt() {
unsigned long now = millis();
// Don't trigger 2x in 0.5 seconds (by default 500ms)
unsigned long required_spacing = config.get_finish_line_spacing();
if (now - _last_interrupt_millis < required_spacing) {
Serial.println("Ignoring as too close to previous crossing");
return;
}
_interrupt_millis = now;
_last_interrupt_millis = now;
gps.current_time(&last_sensor_time, now);
}
bool sensor_has_triggered() {
return _interrupt_millis != 0;
}
unsigned long sensor_interrupt_millis() {
return _interrupt_millis;
}
void clear_sensor_interrupt_millis() {
_interrupt_millis = 0;
}
bool lastSensorTime(TimeResult *output) {
output->hour = last_sensor_time.hour;
output->minute = last_sensor_time.minute;
output->second = last_sensor_time.second;
output->millisecond = last_sensor_time.millisecond;
return true;
}
bool currentTime(TimeResult *output) {
gps.current_time(output, millis());
return true;
}