-
Notifications
You must be signed in to change notification settings - Fork 8
/
commands.ino
84 lines (84 loc) · 2.4 KB
/
commands.ino
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
class MainBLECallback : public BLECharacteristicCallbacks {
void onWrite(BLECharacteristic *pCharacteristic) {
std::string value = pCharacteristic->getValue();
if (value.length() > 0) {
String command = "";
for (int i = 0; i < value.length(); i++) {
command = command + value[i];
}
commandIsSending = true;
if (command == "lock") {
lockBeeb();
delay(100);
unlockForEver = 0;
sendControllerCommand(offEscByte, sizeof(offEscByte));
delay(100);
isUnlocked = 0;
sendControllerCommand(lightOffEscByte, sizeof(lightOffEscByte));
delay(100);
lightIsOn = 0;
}
if (command == "unlock") {
unlockForEver = 0;
unlockBeeb();
delay(100);
if (!controllerIsOn) {
digitalWrite(LOCK_PIN, HIGH);
delay(3000);
controllerIsOn = 1;
}
sendControllerCommand(onEscByte, sizeof(onEscByte));
delay(100);
isUnlocked = 1;
sendControllerCommand(lightOnEscByte, sizeof(lightOnEscByte));
delay(100);
lightIsOn = 1;
}
if (command == "on") {
digitalWrite(LOCK_PIN, HIGH);
controllerIsOn = 1;
}
if (command == "off") {
digitalWrite(LOCK_PIN, LOW);
controllerIsOn = 0;
isUnlocked = 1;
}
if (command == "unlockforever") {
unlockForEver = 1;
unlockScooter();
tone(BUZZZER_PIN, 800, 100);
delay(100);
tone(BUZZZER_PIN, 800, 100);
delay(100);
}
if (command == "alarm") {
alarmBeeb();
}
if (command == "lighton") {
sendControllerCommand(lightOnEscByte, sizeof(lightOnEscByte));
delay(100);
lightIsOn = 1;
}
if (command == "lightoff") {
sendControllerCommand(lightOffEscByte, sizeof(lightOffEscByte));
delay(100);
lightIsOn = 0;
}
if (command == "shutdown") {
digitalWrite(LOCK_PIN, LOW);
controllerIsOn = 0;
isUnlocked = 0;
lightIsOn = 0;
esp_deep_sleep_start();
}
if (command == "reboot") {
digitalWrite(LOCK_PIN, LOW);
controllerIsOn = 0;
isUnlocked = 0;
lightIsOn = 0;
esp_deep_sleep_start();
}
commandIsSending = false;
}
}
};