-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathremote.h
88 lines (73 loc) · 1.97 KB
/
remote.h
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
86
87
88
#include <Wire.h>
#include "Adafruit_Debounce.h"
Adafruit_Debounce *remote_debounce_locked = new Adafruit_Debounce(REMOTE_PIN_LOCKED, LOW);;
Adafruit_Debounce *remote_debounce_single = new Adafruit_Debounce(REMOTE_PIN_SINGLE, LOW);;
Adafruit_Debounce *remote_debounce_active = new Adafruit_Debounce(REMOTE_PIN_ACTIVE, LOW);;
// HANDLER ------------------------------------------------------------------------------
void remote_handle_locked() {
if (state_is_locked()) {
return;
}
if (state_is_single()) {
state_set(STATE_BUZZERS_LOCKED_INACTIVE);
return;
}
if (state_is_active()) {
state_set(STATE_BUZZERS_LOCKED, STATE_POSITION_NONE);
return;
}
}
void remote_handle_single() {
if (state_is_locked()) {
state_set(STATE_BUZZERS_SINGLE_RANDOM);
return;
}
if (state_is_single()) {
state_set(STATE_BUZZERS_SINGLE);
return;
}
if (state_is_active()) {
state_set(STATE_BUZZERS_SINGLE_RANDOM);
return;
}
}
void remote_handle_active() {
if (state_is_locked()) {
state_set(STATE_BUZZERS_ACTIVE, STATE_POSITION_NONE);
return;
}
if (state_is_single()) {
state_set(STATE_BUZZERS_ACTIVE_RESET);
return;
}
if (state_is_active()) {
state_set(STATE_BUZZERS_ACTIVE_RESET);
return;
}
}
// MAIN ---------------------------------------------------------------------------------
void setup_remote() {
remote_debounce_locked->begin();
remote_debounce_single->begin();
remote_debounce_active->begin();
}
void loop_remote() {
remote_debounce_locked->update();
remote_debounce_single->update();
remote_debounce_active->update();
if (remote_debounce_locked->justPressed()) {
debug_println("Pressed LOCKED");
remote_handle_locked();
return;
}
if (remote_debounce_single->justPressed()) {
debug_println("Pressed SINGLE");
remote_handle_single();
return;
}
if (remote_debounce_active->justPressed()) {
debug_println("Pressed ACTIVE");
remote_handle_active();
return;
}
}