-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbasic_usage.ino
127 lines (122 loc) · 3.1 KB
/
basic_usage.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
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
#include "M365.h"
SYSTEM_THREAD(ENABLED);
M365 scooter;
command_t command;
stats_t stats;
String stats_str, command_str;
void setup(){
scooter.setup(Serial1, "A5", "A4", "D2", "D5", "D4", "D3", "D6", "D7");
Particle.function("cloudCommand", cloudCommand);
Particle.variable("stats", stats_str);
Particle.variable("commands", command_str);
}
void loop(){
static unsigned long loopDelay = 0;
if(millis() - loopDelay > 1000){
scooter.getStats(&stats);
stats_str = serializeStructure(stats);
command_str = serializeStructure(command);
loopDelay = millis();
}
}
void serialEvent1(){
scooter.process();
}
int cloudCommand(String userCommand){
int confirmation = -1;
if(userCommand.equals("unlock")){
command.lock = 0;
confirmation = 0;
}
else if(userCommand.equals("lock")){
command.lock = 1;
confirmation = 1;
}
else if(userCommand.equals("tailoff")){
command.tail = 0;
confirmation = 2;
}
else if(userCommand.equals("tailon")){
command.tail = 1;
confirmation = 3;
}
else if(userCommand.equals("cruiseoff")){
command.cruise = 0;
confirmation = 4;
}
else if(userCommand.equals("cruiseon")){
command.cruise = 1;
confirmation = 5;
}
else if(userCommand.equals("ecolow")){
command.ecoMode = 0;
confirmation = 6;
}
else if(userCommand.equals("ecomed")){
command.ecoMode = 1;
confirmation = 7;
}
else if(userCommand.equals("ecohigh")){
command.ecoMode = 2;
confirmation = 8;
}
else if(userCommand.equals("ecooff")){
command.eco = 0;
confirmation = 9;
}
else if(userCommand.equals("ecoon")){
command.eco = 1;
confirmation = 10;
}
else if(userCommand.equals("nightoff")){
command.night = 0;
confirmation = 11;
}
else if(userCommand.equals("nighton")){
command.night = 1;
confirmation = 12;
}
else if(userCommand.equals("poweroff")){
command.lock = 0;
command.power = 0;
confirmation = 13;
}
else if(userCommand.equals("poweron")){
command.power = 1;
confirmation = 14;
}
else if(userCommand.equals("reset")){
System.reset();
confirmation = 15;
}
else if(userCommand.equals("headoff")){
command.head = 0;
confirmation = 16;
}
else if(userCommand.equals("headon")){
command.head = 1;
confirmation = 17;
}
else if(userCommand.equals("ledoff")){
command.led = 0;
confirmation = 18;
}
else if(userCommand.equals("ledon")){
command.led = 1;
confirmation = 19;
}
else if(userCommand.equals("alarmoff")){
command.alarm = 0;
confirmation = 20;
}
else if(userCommand.equals("alarmon")){
command.alarm = 1;
confirmation = 21;
}
else if(userCommand.equals("alarm")){
tone(D2, 20, 5000);
confirmation = 22;
}
scooter.setCommand(&command);
return confirmation;
}