forked from dfrencham/rad-gate
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGate.cpp
More file actions
71 lines (55 loc) · 1.57 KB
/
Copy pathGate.cpp
File metadata and controls
71 lines (55 loc) · 1.57 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
69
/*****************************************
* RemoteArDuino (RAD) Gate
* (c) Danny Frencham 2017
*****************************************/
#include "constants.h"
#include "utility.h"
#include "Gate.h"
bool FLAG_ABORT_PENDING = false;
bool FLAG_SEQUENCE_RUNNING = false;
bool FLAG_IS_ABORTABLE = false;
// FLAG_GATE_DOWN see constants.cpp
Gate::Gate(){}
void Gate::random_wait() {
int rand_delay = random(DELAY_RAND_MIN, DELAY_RAND_MAX+1);
uint32_t wait_timer = millis() + rand_delay;
// serial_print_val("Random wait = ",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 = false;
FLAG_IS_ABORTABLE = false;
}
void Gate::arm() {
//serial_print("Deactivate solenoid");
digitalWrite(PIN_RELAY, !GATE_ACTIVE_LEVEL);
}
void Gate::abort() {
FLAG_ABORT_PENDING = true;
}
void Gate::drop() {
FLAG_GATE_DOWN = true;
serial_print("Gate Drop"); // Activate solenoid or Deactivate electromagnet
digitalWrite(PIN_RELAY, GATE_ACTIVE_LEVEL);
}
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 = true;
}
void Gate::set_abortable(bool abortable) {
FLAG_IS_ABORTABLE = abortable;
}