init
This commit is contained in:
@@ -0,0 +1,53 @@
|
||||
#pragma once
|
||||
|
||||
#include <Wire.h>
|
||||
#include <time.h>
|
||||
#include <sys/time.h>
|
||||
#include <logger.hpp>
|
||||
|
||||
#define DS1307_ADDRESS 0x68
|
||||
#define EEPROM_ADDRESS 0x50
|
||||
|
||||
class HardwareRTC {
|
||||
public:
|
||||
HardwareRTC(TwoWire& wire = Wire);
|
||||
~HardwareRTC();
|
||||
|
||||
void begin();
|
||||
|
||||
// Set RTC time from a 64-bit Unix timestamp
|
||||
bool setTime(time_t unixTimestamp);
|
||||
|
||||
// Get current time as a 64-bit Unix timestamp
|
||||
time_t getTime();
|
||||
|
||||
static time_t getSystemTime() {
|
||||
struct timeval tv;
|
||||
if (gettimeofday(&tv, nullptr) != 0) {
|
||||
LOG_ERROR("Failed to get system time for log entry");
|
||||
return 0; // Fallback-Wert
|
||||
} else {
|
||||
return tv.tv_sec; // Unix-Timestamp in Sekunden
|
||||
}
|
||||
gettimeofday(&tv, NULL);
|
||||
return tv.tv_sec;
|
||||
}
|
||||
// Helper method to convert time_t to date string
|
||||
static String toDateString(time_t timestamp);
|
||||
|
||||
|
||||
void setSystemTime(int timezoneOffsetHours = 0);
|
||||
bool isRunning();
|
||||
void setTimezone(const char* timezone);
|
||||
void update(); // Placeholder for future use
|
||||
|
||||
private:
|
||||
bool initialized;
|
||||
TwoWire& wire;
|
||||
|
||||
uint8_t bcdToDec(uint8_t bcd);
|
||||
uint8_t decToBcd(uint8_t dec);
|
||||
|
||||
void readRegisters(uint8_t* buffer, uint8_t length);
|
||||
void writeRegisters(uint8_t* buffer, uint8_t length);
|
||||
};
|
||||
Reference in New Issue
Block a user