#include <hidboot.h>
#include <usbhub.h>

USB Usb;
USBHub Hub(&Usb);
HIDBoot<USB_HID_PROTOCOL_MOUSE> HidMouse(&Usb);

class MouseRptParser : public MouseReportParser
{
public:
  int16_t absX;
  int16_t absY;

protected:
  void OnMouseMove(MOUSEINFO *mi);
};
//starts only when moving mouse
void MouseRptParser::OnMouseMove(MOUSEINFO *mi)
{
  absX += mi->dX;
  absY += mi->dY;

  // the position is relative to the start position.
  Serial.print("X: ");
  Serial.print(absX);
  Serial.print(", Y: ");
  Serial.print(absY);
  // read the input on analog pin 0:
  int sensorValue = analogRead(A0);
  // Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
  float voltage = sensorValue * (5.0 / 1023.0);
  // print out the value you read:
  Serial.print(", Voltage: ");
  Serial.println(voltage);
}

MouseRptParser Prs;

void setup()
{
  Serial.begin(115200);

  if (Usb.Init() == -1)
  {
    Serial.println("USB initialization failed.");
    while (1);
  }

  delay(200);

  HidMouse.SetReportParser(0, &Prs);
  Prs.absX = 0;
  Prs.absY = 0;
}

void loop()
{
  Usb.Task();
  
  

}
