2025-01-13 14:07:48 +11:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <MeshCore.h>
|
|
|
|
|
#include <Arduino.h>
|
|
|
|
|
|
|
|
|
|
#if defined(ESP_PLATFORM)
|
|
|
|
|
|
|
|
|
|
#include <rom/rtc.h>
|
|
|
|
|
#include <sys/time.h>
|
|
|
|
|
|
2025-01-19 16:44:25 +11:00
|
|
|
class ESP32Board : public mesh::MainBoard {
|
|
|
|
|
protected:
|
|
|
|
|
uint8_t startup_reason;
|
|
|
|
|
|
2025-01-13 14:07:48 +11:00
|
|
|
public:
|
|
|
|
|
void begin() {
|
|
|
|
|
// for future use, sub-classes SHOULD call this from their begin()
|
2025-01-19 16:44:25 +11:00
|
|
|
startup_reason = BD_STARTUP_NORMAL;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint8_t getStartupReason() const override { return startup_reason; }
|
|
|
|
|
|
|
|
|
|
uint16_t getBattMilliVolts() override {
|
|
|
|
|
return 0; // not supported
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
const char* getManufacturerName() const override {
|
|
|
|
|
return "Generic ESP32";
|
2025-01-13 14:07:48 +11:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void reboot() override {
|
|
|
|
|
esp_restart();
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
class ESP32RTCClock : public mesh::RTCClock {
|
|
|
|
|
public:
|
|
|
|
|
ESP32RTCClock() { }
|
|
|
|
|
void begin() {
|
|
|
|
|
esp_reset_reason_t reason = esp_reset_reason();
|
|
|
|
|
if (reason == ESP_RST_POWERON) {
|
|
|
|
|
// start with some date/time in the recent past
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
tv.tv_sec = 1715770351; // 15 May 2024, 8:50pm
|
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
settimeofday(&tv, NULL);
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
uint32_t getCurrentTime() override {
|
|
|
|
|
time_t _now;
|
|
|
|
|
time(&_now);
|
|
|
|
|
return _now;
|
|
|
|
|
}
|
|
|
|
|
void setCurrentTime(uint32_t time) override {
|
|
|
|
|
struct timeval tv;
|
|
|
|
|
tv.tv_sec = time;
|
|
|
|
|
tv.tv_usec = 0;
|
|
|
|
|
settimeofday(&tv, NULL);
|
|
|
|
|
}
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
#endif
|