/**
 * Author : Anatole SCHRAMM-HENRY
 * Created the : 29/05/2021
 * This TEST program aims to verify all the basic functions of the weather station by displaying all the sensors values to a serial console :
 * - The battery level sensing
 * - The light level with the LDR 
 * - The temperature of the BMP280
 * - The temperature of the HTU21
 * - The pressure
 * - The humidity
 */
#include "definition.h"
#include "BoardConfig.h"
#include "WSPeripherals.h"

BoardConfig defaultBC; //Default config is applied
WSPeripherals WSP(defaultBC);
float BMPTemperature(0), ATMPressure(0);

void setup()
{
  Serial.begin(SERIAL_BAUD_RATE);
  Serial.println("Setup begin");
  uint8_t code = WSP.init();
  Serial.print("WSP init returned : ");Serial.println(code);
  WSP.externalPeripherals(WSPeripherals::ON);
  code = WSP.initExternalPeripherals();
  Serial.print("WSP init external peripheral returned : ");Serial.println(code);
  Serial.println("Setup end");
}

void loop()
{
  Serial.println("##############DATA##############");
  Serial.print("BATT : ");
  Serial.print(WSP.batteryVoltage());
  Serial.println(" V");
 
  Serial.print("LDR : ");
  Serial.println(WSP.sunlightMeasurement());

  WSP.temperatureAndATMPressureFromBMP280(&BMPTemperature, &ATMPressure);

  Serial.print("BMP TEMP : ");
  Serial.print(BMPTemperature);
  Serial.println(" *C");

  Serial.print("HTU TEMP : ");
  Serial.print(WSP.temperatureFromHTU21());
  Serial.println(" *C");
  
  Serial.print("BMP PRESS : ");
  Serial.print(ATMPressure);
  Serial.println(" Pa");

  Serial.print("HUM : ");Serial.println(WSP.humidity());
  Serial.print("COM HUM : ");Serial.println(WSP.compensatedHumidity());
  
  if(!WSP.getRadio().isChipConnected())
  {
    Serial.println("Radio is missing");
  }
  else
  {
    Serial.println("Radio is present");
  }
  
  delay(1000);
}
