-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathSystemState.cpp
85 lines (65 loc) · 1.6 KB
/
SystemState.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
82
83
84
85
/*
Regatta Starter System State
This class is used to keep coherent the internal state of the system.
The class does not perform any actions with the hardware; it provides
solely a means to track the state machine.
*/
#include "SystemState.hpp"
#include <Arduino.h> // for millis()
void SystemState::initialize() {
is_timer_running = false;
is_horn_on = false;
is_beep_on = false;
timer_start_ms = -1;
sound_start_ms = -1;
}
void SystemState::startTimer() {
schedule->reset();
is_horn_on = false;
is_beep_on = false;
timer_start_ms = millis();
is_timer_running = true;
return;
}
void SystemState::stopTimer() {
is_timer_running = false;
}
long SystemState::getTimeRemaining_ms() const {
long time_since_start_ms = millis() - timer_start_ms;
return schedule->getTimerLength_ms() - time_since_start_ms;
}
bool SystemState::isTimerRunning() const {
return is_timer_running;
}
bool SystemState::isSoundOn() const {
return is_horn_on || is_beep_on;
}
bool SystemState::isHornOn() const {
return is_horn_on;
}
bool SystemState::isBeepOn() const {
return is_beep_on;
}
void SystemState::setHornOn() {
is_horn_on = true;
sound_start_ms = millis();
}
void SystemState::setBeepOn() {
is_beep_on = true;
sound_start_ms = millis();
}
void SystemState::setHornOff() {
is_horn_on = false;
}
void SystemState::setBeepOff() {
is_beep_on = false;
}
long SystemState::getTimeSinceSoundStart() const {
return millis() - sound_start_ms;
}
void SystemState::setSchedule(Schedule& sched) {
schedule = &sched;
}
Schedule* SystemState::getSchedule() {
return schedule;
}