diff --git a/src/hoverboard-esc-serial-comm.cpp b/src/hoverboard-esc-serial-comm.cpp index 60caf07..3b99bab 100644 --- a/src/hoverboard-esc-serial-comm.cpp +++ b/src/hoverboard-esc-serial-comm.cpp @@ -7,11 +7,25 @@ ESCSerialComm::ESCSerialComm(HardwareSerial &_serialRef) { //constructor wheelcircumference=0.5278; //8.4cm radius -> 0.084m*2*Pi } +void ESCSerialComm::init() { + serialRef->begin(SERIAL_CONTROL_BAUD); +} + void ESCSerialComm::setSpeed(int16_t uSpeedLeft, int16_t uSpeedRight) { Motorparams.cmdL=uSpeedLeft; Motorparams.cmdR=uSpeedRight; } +int16_t ESCSerialComm::getCmdL() { + return Motorparams.cmdL; +} +int16_t ESCSerialComm::getCmdR() { + return Motorparams.cmdR; +} + +bool ESCSerialComm::sendPending(long millis) { + return (millis - last_send > SENDPERIOD); +} bool ESCSerialComm::update(long millis) //returns true if something was sent or received { diff --git a/src/hoverboard-esc-serial-comm.h b/src/hoverboard-esc-serial-comm.h index bded846..4793be9 100644 --- a/src/hoverboard-esc-serial-comm.h +++ b/src/hoverboard-esc-serial-comm.h @@ -8,7 +8,6 @@ int sort_desc(const void *cmp1, const void *cmp2); float filterMedian(int16_t* values); #define SERIAL_CONTROL_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 0xABCD // [-] Start frme definition for reliable serial communication @@ -74,9 +73,13 @@ class ESCSerialComm { public: ESCSerialComm(HardwareSerial& _SerialRef); //constructor + void init(); bool update(long millis); bool feedbackAvailable(); void setSpeed(int16_t uSpeedLeft, int16_t uSpeedRight); + int16_t getCmdL(); + int16_t getCmdR(); + bool sendPending(long millis); private: unsigned long loopmillis;