#include <Define.h>
#include <Helper.h>
#include <SerialUart.h>
#include <BME280I2C.h>
//
//----------------------------------------------
// Variable
//----------------------------------------------
CSerialUart UartPC(SerialUartPC);
CBME280I2C BME280;   
//
float Pressure, Temperature, Humidity;
// 
//----------------------------------------------
// Main - Setup
//----------------------------------------------
void setup() 
{ //--------------------------------------------
  //  UartPC Initialisation
  //--------------------------------------------
  UartPC.begin(BAUDRATE_115200);
  Message(HEADER_00);
  Message(HEADER_01);
  Message(HEADER_00);
  Message(HEADER_02);
  Message(HEADER_03);
  Message(HEADER_04);
  Message(HEADER_00);
  Message("UartPC started");
  //--------------------------------------------
  //  BMP280 Initialisation 
  //--------------------------------------------
  Wire.begin(21, 22);   // ESP32 I2C Pins: 21-SDA / 22-SCL
  if (!BME280.Open()) 
  {
    Serial.println("Error: BME280 not detected!");
    while (1);
  }
  Message("BME280 started");
}

void loop() 
{
  long unsigned Seconds = (long unsigned)(0.5 + millis()/1000.0);
  int HS = (int)(Seconds / 3600);
  int R = Seconds % 3600;
  int MS = (int)(R / 60);
  int SS = R % 60;
  //
  UartPC.print("Time[");
  UartPC.printf("%2.2i", HS);
  UartPC.print(":");
  UartPC.printf("%2.2i", MS);
  UartPC.print(":");
  UartPC.printf("%2.2i]", SS);
  //
  BME280.read(Pressure, Temperature, Humidity);  
  
  UartPC.print(" Temperature[");
  UartPC.print(Temperature);
  UartPC.print("]C Pressure[");
  UartPC.print(Pressure);
  UartPC.print("]mbar Humidity[");
  UartPC.print(Humidity);
  UartPC.println("]%");               
  //
  delay(2000);
}
//

