|
|
|
|
@ -30,7 +30,7 @@
|
|
|
|
|
// // #define DEBUG_SERIAL_USART3
|
|
|
|
|
// *******************************************************************
|
|
|
|
|
|
|
|
|
|
#define VERSION_TAG "V test 0.1"
|
|
|
|
|
#define VERSION_TAG "V test 0.2"
|
|
|
|
|
#define BTN_PLUS 4
|
|
|
|
|
#define BTN_MOINS 5
|
|
|
|
|
#define BTN_MARCHE 6
|
|
|
|
|
@ -38,16 +38,16 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// ########################## DEFINES ##########################
|
|
|
|
|
#define HOVER_SERIAL_BAUD 38400 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
|
|
|
|
|
#define HOVER_SERIAL_BAUD 115200 // [-] Baud rate for HoverSerial (used to communicate with the hoverboard)
|
|
|
|
|
#define SERIAL_BAUD 115200 // [-] Baud rate for built-in Serial (used for the Serial Monitor)
|
|
|
|
|
#define START_FRAME 0xAAAA // [-] Start frme definition for reliable serial communication
|
|
|
|
|
#define START_FRAME 0xABCD // [-] Start frme definition for reliable serial communication
|
|
|
|
|
#define TIME_SEND 25 // [ms] Sending time interval
|
|
|
|
|
#define SPEED_MAX_TEST 300 // [-] Maximum speed for testing
|
|
|
|
|
//#define DEBUG_RX // [-] Debug received data. Prints all bytes to serial (comment-out to disable)
|
|
|
|
|
|
|
|
|
|
// ########################## macros ############################
|
|
|
|
|
|
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
#include <EEPROM.h>
|
|
|
|
|
|
|
|
|
|
#include <FastLED.h>
|
|
|
|
|
|
|
|
|
|
@ -76,13 +76,12 @@ typedef struct {
|
|
|
|
|
uint16_t start;
|
|
|
|
|
int16_t cmd1;
|
|
|
|
|
int16_t cmd2;
|
|
|
|
|
int16_t speedR;
|
|
|
|
|
int16_t speedL;
|
|
|
|
|
int16_t speedR_meas;
|
|
|
|
|
int16_t speedL_meas;
|
|
|
|
|
int16_t batVoltage;
|
|
|
|
|
int16_t boardTemp;
|
|
|
|
|
int16_t checksum;
|
|
|
|
|
uint16_t cmdLed;
|
|
|
|
|
uint16_t checksum;
|
|
|
|
|
} SerialFeedback;
|
|
|
|
|
SerialFeedback Feedback;
|
|
|
|
|
SerialFeedback NewFeedback;
|
|
|
|
|
@ -116,7 +115,7 @@ CRGB leds[NUM_LEDS];
|
|
|
|
|
|
|
|
|
|
// ########################## SETUP ##########################
|
|
|
|
|
void setup()
|
|
|
|
|
{
|
|
|
|
|
{
|
|
|
|
|
pinMode(BTN_MARCHE, INPUT_PULLUP);
|
|
|
|
|
pinMode(BTN_PLUS, INPUT_PULLUP);
|
|
|
|
|
pinMode(BTN_MOINS, INPUT_PULLUP);
|
|
|
|
|
@ -188,11 +187,8 @@ void Receive()
|
|
|
|
|
if (idx == sizeof(SerialFeedback)) {
|
|
|
|
|
uint16_t checksum;
|
|
|
|
|
checksum =
|
|
|
|
|
(uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.
|
|
|
|
|
cmd2 ^ NewFeedback.speedR ^ NewFeedback.
|
|
|
|
|
speedL ^ NewFeedback.speedR_meas ^ NewFeedback.
|
|
|
|
|
speedL_meas ^ NewFeedback.batVoltage ^ NewFeedback.
|
|
|
|
|
boardTemp);
|
|
|
|
|
(uint16_t) (NewFeedback.start ^ NewFeedback.cmd1 ^ NewFeedback.cmd2 ^ NewFeedback.speedR_meas ^ NewFeedback.speedL_meas
|
|
|
|
|
^ NewFeedback.batVoltage ^ NewFeedback.boardTemp ^ NewFeedback.cmdLed);
|
|
|
|
|
|
|
|
|
|
// Check validity of the new data
|
|
|
|
|
if (NewFeedback.start == START_FRAME
|
|
|
|
|
@ -207,17 +203,17 @@ void Receive()
|
|
|
|
|
Serial.print(" 2: ");
|
|
|
|
|
Serial.print(Feedback.cmd2);
|
|
|
|
|
Serial.print(" 3: ");
|
|
|
|
|
Serial.print(Feedback.speedR);
|
|
|
|
|
Serial.print(Feedback.speedR_meas);
|
|
|
|
|
Serial.print(" 4: ");
|
|
|
|
|
Serial.print(Feedback.speedL);
|
|
|
|
|
Serial.print(Feedback.speedL_meas);
|
|
|
|
|
Serial.print(" 5: ");
|
|
|
|
|
Serial.print(Feedback.speedR_meas);
|
|
|
|
|
Serial.print(Feedback.batVoltage);
|
|
|
|
|
Serial.print(" 6: ");
|
|
|
|
|
Serial.print(Feedback.speedL_meas);
|
|
|
|
|
Serial.print(Feedback.boardTemp);
|
|
|
|
|
Serial.print(" 7: ");
|
|
|
|
|
Serial.print(Feedback.batVoltage);
|
|
|
|
|
Serial.print(" 8: ");
|
|
|
|
|
Serial.println(Feedback.boardTemp);
|
|
|
|
|
Serial.println(Feedback.cmdLed);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
if (Serial)
|
|
|
|
|
@ -243,7 +239,7 @@ void EEPROMWriteInt(int p_address, int p_value)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//This function will read a 2 byte integer from the eeprom at the specified address and address + 1
|
|
|
|
|
unsigned int EEPROMReadInt(int p_address)
|
|
|
|
|
int EEPROMReadInt(int p_address)
|
|
|
|
|
{
|
|
|
|
|
byte lowByte = EEPROM.read(p_address);
|
|
|
|
|
byte highByte = EEPROM.read(p_address + 1);
|
|
|
|
|
@ -284,7 +280,7 @@ void run_control(void) {
|
|
|
|
|
last_marche = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void speed_control(void) {
|
|
|
|
|
if (run_mode){
|
|
|
|
|
if (!digitalRead(BTN_PLUS)){
|
|
|
|
|
@ -296,7 +292,7 @@ void speed_control(void) {
|
|
|
|
|
} else {
|
|
|
|
|
last_plus = true;
|
|
|
|
|
}
|
|
|
|
|
} else {
|
|
|
|
|
} else {
|
|
|
|
|
last_plus = false;
|
|
|
|
|
}
|
|
|
|
|
if (!digitalRead(BTN_MOINS)){
|
|
|
|
|
@ -309,7 +305,7 @@ void speed_control(void) {
|
|
|
|
|
last_moins = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
} else {
|
|
|
|
|
} else {
|
|
|
|
|
last_moins = false;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
@ -328,12 +324,9 @@ void loop(void)
|
|
|
|
|
// Check for new received data
|
|
|
|
|
Receive();
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (iTimeSend > timeNow)
|
|
|
|
|
return;
|
|
|
|
|
iTimeSend = timeNow + TIME_SEND;
|
|
|
|
|
// Nunchuk_display();
|
|
|
|
|
if (Serial) {
|
|
|
|
|
if (run_mode != last_run) {
|
|
|
|
|
last_run = run_mode;
|
|
|
|
|
@ -371,9 +364,9 @@ void loop(void)
|
|
|
|
|
speed_control();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
LEDS.show(); // update LEDS
|
|
|
|
|
LEDS.show(); // update LEDS
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Nunchuk_control();
|
|
|
|
|
// Blink the LED
|
|
|
|
|
digitalWrite(LED_BUILTIN, (timeNow % 2000) < 1000);
|
|
|
|
|
}
|
|
|
|
|
|