-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathM365.h
117 lines (102 loc) · 2.72 KB
/
M365.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
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
#ifndef SCOOTER_CONNECT_M365_H
#define SCOOTER_CONNECT_M365_H
#include "Particle.h"
struct stats_t{
uint8_t alarmStatus,
averageVelocity,
battery,
beep,
brakeConnected,
cruise,
eco,
ecoMode,
hasConnected,
isConnected,
led,
lock,
night,
odometer,
tail,
temperature,
throttleConnected,
velocity;
};
struct command_t{
uint8_t alarm = 1,
cruise = 1,
eco = 0,
ecoMode = 0,
head = 0,
led = 1,
lock = 1,
night = 0,
power = 1,
sound = 1,
tail = 1;
};
class M365{
private:
USARTSerial * serial;
uint8_t serialBuffer[256], serialIndex = 0;
Timer * messageTimer;
stats_t stats;
command_t command;
struct input_t{
uint8_t brake = 0,
throttle = 0,
buzzer = 0,
headlight = 0,
power = 0,
rled = 0,
bled = 0,
gled = 0;
} input;
struct input_stats_t{
uint16_t minBrake = 1600,
maxBrake = 2400,
minSpeed = 1600,
maxSpeed = 2400;
} input_stats;
unsigned long lastMessageSentTimeStamp = 0;
unsigned long lastValidMessageTimeStamp = 0;
uint8_t setAnalogPin(const uint8_t);
uint8_t setDigitalPin(const uint8_t);
bool isConnected();
uint8_t getBrake();
uint8_t getThrottle();
void read(uint8_t);
bool check(const uint8_t * message, uint8_t size);
void translate(const uint8_t * message, uint8_t size);
void compare();
void send();
void addSum(uint8_t *, uint8_t);
void transmit(const uint8_t *, uint8_t, bool = false);
public:
M365();
~M365();
void setup(USARTSerial &, String, String, String,
String, String, String, String, String);
void setSerial(USARTSerial &);
void setBrake(String);
void setThrottle(String);
void setBuzzer(String);
void setRGB(String, String, String);
void setHeadlight(String);
void setPower(String);
void process();
void setCommand(const command_t *);
void getStats(stats_t *);
};
template<class T>
String serializeStructure(T object){
String result = "";
int size = sizeof(object);
uint8_t array[size];
memcpy(array, &object, size);
for(int i = 0; i < size; i++){
result += (int) array[i];
if(i != size - 1) result += ",";
}
return result;
}
#endif