#include "Dezibot.h"
// Output CSV-Data about the power state on secondary UART mapped to bottom
// header

// Using alternate Serial pins to not be powered by the USB port
#define RXD_HEADER 16
#define TXD_HEADER 17

Dezibot dezibot = Dezibot();
void setup() {
  // put your setup code here, to run once:
  dezibot.begin();
  Serial1.begin(9600, SERIAL_8N1, RXD_HEADER, TXD_HEADER);
  Serial1.printf("Timestamp (ms),Current (mA),charge (%%),charge (C),voltage (V),isUSBPowered,isBatteryPowered,isBatteryCharging,isBatteryDischarging,isBatteryFullyCharged\r\n");
}

void loop() {
  Serial1.printf("%d,%f,%f,%f,%f,%d,%d,%d,%d,%d\r\n",
                 millis(),
                 dezibot.power.getCurrentCurrent(),
                 dezibot.power.getBatteryChargePercent(),
                 dezibot.power.getBatteryChargeCoulombs(),
                 dezibot.power.getBatteryVoltage(),
                 dezibot.power.isUSBPowered(), dezibot.power.isBatteryPowered(),
                 dezibot.power.isBatteryCharging(),
                 dezibot.power.isBatteryDischarging(),
                 dezibot.power.isBatteryFullyCharged());
  sleep(1);
}