//
//----------------------------------------------
// Include
//----------------------------------------------
#include <Helper.h>
#include <SerialUart.h>
#include <RtcDS3231.h>
//
//---------------------------------
// Global Constant
//---------------------------------
#define SERIAL_UARTPC Serial
#define BAUDRATE_UARTPC 115200
//
//---------------------------------
// Global Instance
//---------------------------------
CSerialUart UartPC(SERIAL_UARTPC);
CRtcDS3231 RtcDS3231(&Wire, I2CADDRESS_RTCDS3231);
//
byte Year         = 26;
byte Month        =  5;
byte Day          = 19;
byte Hours        = 21;
byte Minutes      = 47;
byte Seconds      = 10;
byte DayOfWeek    = 2;
float Temperature = 18.00f;
//
//---------------------------------
// Main - Setup
//---------------------------------
void setup() 
{ //--------------------------------------------
  //  UartPC Initialisation
  //--------------------------------------------
  UartPC.begin(BAUDRATE_UARTPC);
  delay(INIT_SERIALUART_STARTUP);
  Message(HEADER_00);
  Message(HEADER_01);
  Message(HEADER_00);
  Message(HEADER_02);
  Message(HEADER_03);
  Message(HEADER_04);
  Message(HEADER_00);
  Message("UartPC started");
  // I2C
  Wire.begin();
  RtcDS3231.Open();
  Message("RtcDS3231 started");
  // Set only first the first DateTime-Preset:
  // [year, month, day, hours, minutes, seconds, dayofweek]
  // !!! RtcDS3231.WriteDS3231Time(26, 5, 19, 19, 0, 1, 2);
  // !!! RtcDS3231.WriteDS3231Time(26, 5, 19, 21, 47, 10, 2); // 19.05.2026 21:47:10 Tuesday
}
//
//---------------------------------
// Main - Loop
//---------------------------------
void loop() 
{   // DateTime
    RtcDS3231.ReadDateTime(Year, Month, Day, Hours, Minutes, Seconds, DayOfWeek);
    UartPC.print("Date: ");
    if (Day < 10) UartPC.print("0");
    UartPC.print(Day);
    UartPC.print(".");
    if (Month < 10) UartPC.print("0");
    UartPC.print(Month);
    UartPC.print(".");
    UartPC.print("20");
    if (Year < 10) UartPC.print("0");
    UartPC.print(Year);
    UartPC.print("   Time: ");
    if (Hours < 10) UartPC.print("0");
    UartPC.print(Hours);
    UartPC.print(":");
    if (Minutes < 10) UartPC.print("0");
    UartPC.print(Minutes);
    UartPC.print(":");
    if (Seconds < 10) UartPC.print("0");
    UartPC.print(Seconds);
    UartPC.print("   Day of Week: ");
    UartPC.print(DayOfWeek);
    // Temperature 
    Temperature = RtcDS3231.ReadTemperatureC();
    UartPC.print("  Temperature[°C]: ");
    UartPC.print(Temperature);
    //
    UartPC.println();
    delay(1000);
}