OXRecorder::OXConfigManager
Central configuration store + hardware reset via long-press
Overview
OXConfigManager is the system's single place for general
configuration and for the hardware reset feature. It holds
a key/value settings store and owns a reset switch: a long press on the
reset GPIO (GPIO5 by default, held 10 seconds) triggers a
reset callback.
- Key/value config store (string / int / bool) so subsystems read and write settings through one API.
- Hardware reset: built on OXSwitchManager's long-press detection, filtered to the reset pin.
- Extensible: register extra GPIO long-press actions, add typed getters, or layer persistence on top — without changing callers.
- Cooperative: call
begin(), then pumppoll(millis())fromloop().
Declared in include/OXConfigManager.h; implemented in
src/OXConfigManager.cpp. It borrows an
OXSwitchManager (injected or default).
How the reset feature works
The reset path is a chain that ends in your callback. The long press on
GPIO5 is detected by OXSwitchManager, routed by
OXConfigManager to the reset pin, and delivered to the handler
you registered with onReset() — this is the
switchLongPressDetected behavior "inherited" for GPIO5:
GPIO5 held 10 s
│ OXSwitchManager debounce + long-press timer
▼
onLongPress(pin=5) // generic long-press event
│ OXConfigManager routes by pin (pin == resetSwitchPin?)
▼
triggerReset()
│
▼
your onReset(ctx) // e.g. clear config + ESP.restart()
Because reset goes through triggerReset(), you also have one
software entry point for the same action (e.g. a "reset" command from the
app or server).
ConfigOptions
| Field | Type | Default | Meaning |
|---|---|---|---|
resetSwitchPin | int | 5 | GPIO with the reset switch. <0 disables the hardware reset feature. |
resetHoldMs | uint32_t | 10000 | Hold time to trigger reset. |
resetActiveHigh | bool | false | Switch polarity. Default active-low (button to GND). |
resetUsePullup | bool | true | Use the internal pull-up. Default suits a button to GND with no external parts. |
API reference
bool begin(const ConfigOptions &opts = ConfigOptions{})
Initializes the manager, sets up the reset switch (if resetSwitchPin >= 0) on the underlying switch manager, and routes its long press to the reset callback. Returns false if the switch manager could not start.
void poll(uint32_t nowMs)
Pumps the switch manager. Call from loop() with millis().
void onReset(ConfigResetCallback cb, void *ctx = nullptr)
Registers the reset handler void(void *ctx), fired once when the reset switch is held for resetHoldMs.
void triggerReset()
Manually invokes the reset path (same callback) — one entry point for software-initiated resets.
void onSwitchLongPress(SwitchLongPressCallback cb, void *ctx = nullptr)
Observe long presses on ANY tracked switch (including the reset pin). Lets new features add GPIO long-press actions without subclassing.
bool addSwitch(int pin, uint32_t longPressMs)
Monitor another switch beyond the reset pin (for custom actions). Its long press surfaces via onSwitchLongPress().
Key/value store
bool set(key, value), bool setInt(key, long),
bool setBool(key, bool) · const char *get(key, fallback=""),
long getInt(key, fallback=0), bool getBool(key, fallback=false) ·
bool has(key), bool remove(key),
void clearAll(), size_t count().
Up to 32 entries; keys < 32 chars, values < 96 chars. clearAll() erases the in-RAM config (the data part of a reset).
Example — GPIO5 reset (from main.cpp)
Try it
Flash, open the monitor, then hold the GPIO5 switch for 10 seconds — you'll see long press detected. The reset routing and config store are covered on the host by pio test -e native.
#include <Arduino.h>
#include "OXConfigManager.h"
#include "OXLog.h"
using namespace OXRecorder;
OXConfigManager config;
// Inherited switchLongPressDetected behavior for the reset GPIO.
void onReset(void *ctx) {
OXLog::info("long press detected");
// A real reset: config.clearAll(); ESP.restart();
}
void setup() {
OXLog::begin(115200);
ConfigOptions opts;
opts.resetSwitchPin = 5; // GPIO5
opts.resetHoldMs = 10000; // 10 seconds
config.begin(opts);
config.onReset(onReset);
// The store is ready for general settings too:
// config.set("device_name", "ox-001");
// config.setInt("sample_rate", 16000);
}
void loop() {
config.poll(millis()); // samples the switch; non-blocking
delay(10);
}
Sample output
[1012][I] OXConfigManager: reset switch on GPIO5, hold 10000 ms
[1012][I] hold the GPIO5 switch for 10 s to trigger reset
[8740][I] OXConfigManager: reset triggered
[8740][I] long press detected