1
- // //////
2
- //
3
- // Written by Marco D'Alia and Davide Marcoccio
4
- // 2015
5
- //
6
- //
7
- // //////
8
-
9
1
#ifndef THREEDRACERS_H
10
2
#define THREEDRACERS_H
11
3
15
7
16
8
#include < Servo.h>
17
9
#include < Adafruit_NeoPixel.h>
10
+ #include < sha204_library.h>
18
11
19
12
#include " 3DRacers_Packets.h"
20
13
#include " BleHM10Driver.h"
14
+ #include " IRSensor.h"
21
15
22
16
// #include "variants/3DRacers_Pins_1.1.0.h"
23
17
// #include "variants/3DRacers_Pins_1.2.0.h"
24
18
// #include "variants/3DRacers_Pins_1.4.5.h"
25
- #include " variants/3DRacers_Pins_1.5.6.h"
19
+ // #include "variants/3DRacers_Pins_1.5.6.h"
20
+ // #include "variants/3DRacers_Pins_1.6.1.h"
21
+ #include " variants/3DRacers_Pins_1.6.2.h"
26
22
// #include "variants/3DRacers_Pins_Breadboard.h"
27
23
#include " Config.h"
28
24
@@ -48,8 +44,8 @@ typedef struct CarInfo
48
44
49
45
CarInfo ()
50
46
{
51
- maxBatteryLevel = 4200 ;
52
- minBatteryLevel = 2800 ;
47
+ maxBatteryLevel = 3330 ;
48
+ minBatteryLevel = 3200 ;
53
49
54
50
throttle = 0 ;
55
51
steerAngle = 45 ;
@@ -64,24 +60,25 @@ class ThreeDRacers
64
60
65
61
public:
66
62
67
- int gateMinDelay;
68
- int gatePower;
69
-
70
63
int servoPin;
71
64
int sensorPin;
72
65
int ledPin;
73
66
74
67
bool netDebug;
75
68
Servo servo;
76
69
70
+ #if !REDUCED_FEATURES
77
71
Adafruit_NeoPixel ledStrip;
72
+ #endif
78
73
74
+ atsha204Class identity;
75
+ void GetId (uint8_t * rx_buffer);
79
76
80
77
ThreeDRacers ();
81
78
82
79
// Use to start in your setup() function
83
80
void Begin (HardwareSerial &bleSerial, Serial_ &serial);
84
-
81
+
85
82
// Call it repeatly in your loop() function:
86
83
void Process ();
87
84
@@ -100,21 +97,26 @@ class ThreeDRacers
100
97
// to be used for low level control, use Motor* functions if possible
101
98
void MotorControl (int controlSpeed, bool brake);
102
99
103
-
100
+ char input[BLE_CMD_SIZE];
101
+
104
102
// CALLBACKS
105
103
106
104
// Set this callbacks to your functions to customize the bot behaviour:
107
- void OnConnect (void (*f)(CarInfo&, ConfigCommand&)){ processConnectCommand = f; }
108
- void OnDriveCommand (void (*f)(DriveCommand&, CarInfo&)){ processDriveCommand = f; }
109
- void OnConfigCommand (void (*f)(ConfigCommand&, CarInfo&)){ processConfigCommand = f; }
110
- void OnRaw1Command (void (*f)(void *, CarInfo&)){ processRaw1Command = f; }
111
- // void (*OnGateDetected)( CarInfo& car){ }
105
+ void OnConnect (void (*f)(CarInfo&, ConfigCommand&)) { processConnectCommand = f; }
106
+ void OnDriveCommand (void (*f)(DriveCommand&, CarInfo&)) { processDriveCommand = f; }
107
+ void OnConfigCommand (void (*f)(ConfigCommand&, CarInfo&)) { processConfigCommand = f; }
108
+ void OnRaw1Command (void (*f)(void *, CarInfo&)) { processRaw1Command = f; }
109
+ void OnGateDetected ( void (*f)(AckCommand& cmd, CarInfo& car)) { processOnGateDetected = f; }
112
110
113
111
// TX towards central device
114
- void OnAckNotification ();
115
-
112
+ void SendAckNotification ();
116
113
114
+ void Send (void * packet, unsigned int objSize);
115
+
116
+ BleHM10Driver wireless;
117
+
117
118
private:
119
+ unsigned int tickCount;
118
120
int connectionLedLoop;
119
121
bool wasConnected;
120
122
@@ -124,17 +126,21 @@ class ThreeDRacers
124
126
const int EEPROM_INVERT_STEERING;
125
127
const int EEPROM_INVERT_THROTTLE;
126
128
127
- char input[BLE_CMD_SIZE];
128
- unsigned long packetCount;
129
- unsigned long lastPacketCount;
129
+
130
+ unsigned int packetCount;
131
+ unsigned int lastPacketCount;
130
132
unsigned long nextConnectionCheck;
131
- BleHM10Driver wireless;
132
133
134
+ IRSensor sensor;
135
+
133
136
CarInfo carInfo;
134
137
DriveCommand driveCmd;
135
138
ConfigCommand configCmd;
136
139
AckCommand ackCmd;
137
140
NameCommand nameCmd;
141
+ IdentityCommand idCmd;
142
+
143
+ uint8_t idCurrentNonce[32 ];
138
144
139
145
//
140
146
/* ------------------------------------------------------*/
@@ -154,8 +160,11 @@ class ThreeDRacers
154
160
void (*processConnectCommand)(CarInfo& car, ConfigCommand& config);
155
161
void (*processDriveCommand)(DriveCommand& cmd, CarInfo& car);
156
162
void (*processConfigCommand)(ConfigCommand& cmd, CarInfo& car);
163
+ void (*processOnGateDetected)(AckCommand& cmd, CarInfo& car);
157
164
void (*processRaw1Command)(void * cmd, CarInfo& car);
158
165
166
+ void SendIdResponse (short msgPart, uint8_t * temp_message);
167
+
159
168
// called inside Begin()
160
169
void motorSetup ();
161
170
// unify 2 bytes into an int16
@@ -167,7 +176,7 @@ class ThreeDRacers
167
176
void ConnectionStatus ();
168
177
void connectionChanged (bool connected);
169
178
void debugConfigPck ();
170
- bool packetCheck (char * input);
179
+ bool packetCheck (char * input, unsigned int objSize );
171
180
172
181
// structs update funcs, called right before it's function ptr companion
173
182
bool updateDriveCommand (char * input);
@@ -177,7 +186,18 @@ class ThreeDRacers
177
186
void showInfoShellCommand ();
178
187
void checkMotorsCommand ();
179
188
189
+
190
+ void processSerial ();
191
+ void processPackets ();
192
+
180
193
long readVcc ();
194
+
195
+ void printId ();
196
+ void calculateSignature (uint8_t * temp_message, uint8_t * current_nonce);
197
+
198
+ byte CRC8 (const uint8_t * message, int len);
199
+
200
+ // bool setPin(String& command, bool value);
181
201
};
182
202
183
203
#endif
0 commit comments