#ifndef _STRUCTS_H_
#define _STRUCTS_H_

// Global variables for serial communication
typedef struct{
    uint8_t idx = 0;                        // Index for new data pointer
    uint16_t bufStartFrame;                 // Buffer Start Frame
    byte *p;                                // Pointer declaration for the new received data
    byte incomingByte;
    byte incomingBytePrev;
    long lastValidDataSerial_time;
} SerialRead;
SerialRead SerialcomFront;
SerialRead SerialcomRear;


typedef struct{
   uint16_t start;
   int16_t  speedLeft;
   int16_t  speedRight;
   uint16_t checksum;
} SerialCommand;
SerialCommand CommandFront;
SerialCommand CommandRear;


typedef struct{ //match this struct to hoverboard-firmware SerialFeedback struct in main.c
   uint16_t start;
   int16_t  cmd1;
   int16_t  cmd2;
   int16_t  speedL_meas; //left speed is positive when driving forward
   int16_t  speedR_meas; //right speed is negatie when driving forward
   int16_t  batVoltage;
   int16_t  boardTemp;
   int16_t  curL_DC; //negative values are current consumed. positive values mean generated current
   int16_t  curR_DC;
   uint16_t cmdLed;
   uint16_t  checksum;
} SerialFeedback;
SerialFeedback FeedbackFront;
SerialFeedback NewFeedbackFront;
SerialFeedback FeedbackRear;
SerialFeedback NewFeedbackRear;


typedef struct{
  int16_t curL_DC[CURRENT_FILTER_SIZE] = {0}; //current will be inverted for this so positive value means consumed current
  int16_t curR_DC[CURRENT_FILTER_SIZE] = {0};
  uint8_t cur_pos=0;
  int16_t cmdL=0;
  int16_t cmdR=0;
  float filtered_curL=0;
  float filtered_curR=0;
  unsigned long millis=0; //time when last message received
} MotorParameter;
MotorParameter motorparamsFront;
MotorParameter motorparamsRear;


#endif