-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathGate.cpp
More file actions
68 lines (54 loc) · 1.37 KB
/
Copy pathGate.cpp
File metadata and controls
68 lines (54 loc) · 1.37 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
65
66
67
68
/*****************************************
* RemoteArDuino (RAD) Gate
* (c) Danny Frencham 2017
*****************************************/
#include "constants.h"
#include "utility.h"
#include "Gate.h"
int FLAG_ABORT_PENDING = 0;
int FLAG_SEQUENCE_RUNNING = 0;
int FLAG_IS_ABORTABLE = 0;
Gate::Gate(){
}
void Gate::random_wait() {
int rand_delay = random(DELAY_RAND_MIN,DELAY_RAND_MAX+1);
unsigned long wait_timer = millis() + rand_delay;
serial_print_val("Gate sequence random wait time",rand_delay);
serial_print_val("Wait timer",wait_timer);
serial_print_val("Millis",millis());
while((millis() < wait_timer) && (!FLAG_ABORT_PENDING)) {
// waiting for random wait to finish
}
serial_print("Wait timer done");
}
void Gate::ready(){
FLAG_ABORT_PENDING = 0;
FLAG_IS_ABORTABLE = 0;
}
void Gate::arm() {
// set LED to red
// turn on electro magnet
// beep
}
void Gate::abort() {
FLAG_ABORT_PENDING = 1;
}
void Gate::drop() {
digitalWrite(PIN_RELAY, LOW);
}
bool Gate::is_sequence_running() {
return !!FLAG_SEQUENCE_RUNNING;
}
bool Gate::is_aborted() {
return !!FLAG_ABORT_PENDING;
}
bool Gate::is_abortable() {
return FLAG_IS_ABORTABLE && !FLAG_ABORT_PENDING;
}
void Gate::set_sequence_running(bool running) {
FLAG_SEQUENCE_RUNNING = running;
FLAG_IS_ABORTABLE = 1;
}
void Gate::set_abortable(bool abortable) {
FLAG_IS_ABORTABLE = abortable;
}