Public Access
Add M0 services: settings, battery, clock, storage, power
lib/services holds the host-tested logic: - Settings: typed, validated, persisted, SettingChanged events, transmit gated on a confirmed Region - BatteryEstimator: LiPo curve, median smoothing against TX sags - ClockModel: source priority GNSS > NTP > mesh, relative ages, Europe/Brussels local time via POSIX TZ - StorageMonitor: warning once per boot at 80%, Logs stop at 90%, Captures stop with < 2 MiB left - PowerPolicy / PowerButton: dim/off timeouts, wake key swallowed only when the screen was off, G0 long press src/services wires them to the hardware (NVS, battery ADC, SD on the shared SPI bus with the LoRa CS held high, backlight, deep sleep), and main.cpp is a temporary diagnostics screen for the hardware checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EhqxQ49eCju4CzKYNjZzwT
This commit is contained in:
@@ -0,0 +1,33 @@
|
||||
#pragma once
|
||||
|
||||
#include <Preferences.h>
|
||||
|
||||
#include "key_value_store.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
// Settings persistence in the ESP32's internal flash (NVS).
|
||||
class NvsStore : public KeyValueStore {
|
||||
public:
|
||||
void begin() { prefs_.begin("roro", false); }
|
||||
|
||||
bool getInt(const char* key, int32_t& out) override {
|
||||
if (!prefs_.isKey(key)) return false;
|
||||
out = prefs_.getInt(key);
|
||||
return true;
|
||||
}
|
||||
bool getString(const char* key, std::string& out) override {
|
||||
if (!prefs_.isKey(key)) return false;
|
||||
out = prefs_.getString(key).c_str();
|
||||
return true;
|
||||
}
|
||||
void putInt(const char* key, int32_t value) override { prefs_.putInt(key, value); }
|
||||
void putString(const char* key, const std::string& value) override {
|
||||
prefs_.putString(key, value.c_str());
|
||||
}
|
||||
|
||||
private:
|
||||
Preferences prefs_;
|
||||
};
|
||||
|
||||
} // namespace roro
|
||||
@@ -0,0 +1,17 @@
|
||||
#pragma once
|
||||
|
||||
// Cardputer ADV + Cap LoRa-1262 pin map (see docs.m5stack.com).
|
||||
namespace roro::pins {
|
||||
|
||||
constexpr int kBatteryAdc = 10; // through a 1:2 divider
|
||||
|
||||
constexpr int kButtonG0 = 0;
|
||||
|
||||
// SPI bus shared by the microSD card and the LoRa radio.
|
||||
constexpr int kSpiSck = 40;
|
||||
constexpr int kSpiMiso = 39;
|
||||
constexpr int kSpiMosi = 14;
|
||||
constexpr int kSdCs = 12;
|
||||
constexpr int kLoraCs = 5;
|
||||
|
||||
} // namespace roro::pins
|
||||
@@ -0,0 +1,24 @@
|
||||
#pragma once
|
||||
|
||||
#include <SPI.h>
|
||||
|
||||
#include "pins.h"
|
||||
|
||||
namespace roro {
|
||||
|
||||
// The SPI bus used by the microSD card and (from M3) the LoRa radio. The display has its own bus.
|
||||
// Every user must wrap transfers in beginTransaction/endTransaction, which also locks the bus.
|
||||
inline SPIClass& sharedSpi() {
|
||||
static SPIClass spi(HSPI);
|
||||
static bool begun = false;
|
||||
if (!begun) {
|
||||
// Keep the radio deselected so it never answers SD card traffic.
|
||||
pinMode(pins::kLoraCs, OUTPUT);
|
||||
digitalWrite(pins::kLoraCs, HIGH);
|
||||
spi.begin(pins::kSpiSck, pins::kSpiMiso, pins::kSpiMosi, -1);
|
||||
begun = true;
|
||||
}
|
||||
return spi;
|
||||
}
|
||||
|
||||
} // namespace roro
|
||||
Reference in New Issue
Block a user