66 lines
1.6 KiB
C++
66 lines
1.6 KiB
C++
#pragma once
|
|
#include <Arduino.h>
|
|
#include <Preferences.h>
|
|
|
|
constexpr size_t BOOMCAST_WAVEFORM_POINTS = 64;
|
|
|
|
struct BoomStateSnapshot {
|
|
bool wifiConnected = false;
|
|
bool apMode = false;
|
|
bool sdReady = false;
|
|
bool capturing = false;
|
|
bool syncing = false;
|
|
String ip;
|
|
String ssid;
|
|
String lastSyncMessage;
|
|
int queueCount = 0;
|
|
int todayEvents = 0;
|
|
uint32_t audioReadErrors = 0;
|
|
uint32_t recordingErrors = 0;
|
|
uint8_t sensitivity = 55;
|
|
int8_t waveform[BOOMCAST_WAVEFORM_POINTS] = {0};
|
|
};
|
|
|
|
class BoomState {
|
|
public:
|
|
void begin();
|
|
BoomStateSnapshot snapshot();
|
|
|
|
void setWifi(bool connected, bool apMode, const String& ssid, const String& ip);
|
|
void setSdReady(bool ready);
|
|
void setQueueCount(int count);
|
|
void setCapturing(bool value);
|
|
void setAudioDiagnostics(uint32_t readErrors, uint32_t recordingErrors);
|
|
void setSyncing(bool value, const String& message = "");
|
|
void setWaveform(const int8_t* points, size_t count);
|
|
|
|
uint8_t sensitivity();
|
|
void setSensitivity(uint8_t value, bool persist = true);
|
|
|
|
void rollDayIfNeeded();
|
|
void incrementTodayEvents();
|
|
void discardTodayEvents(int count);
|
|
void resetTodayEvents();
|
|
|
|
void requestSync(const String& filename = "");
|
|
bool takeSyncRequest(String& filename);
|
|
|
|
void requestReboot(uint32_t delayMs = 750);
|
|
bool rebootDue() const;
|
|
|
|
Preferences& prefs() { return preferences_; }
|
|
|
|
private:
|
|
SemaphoreHandle_t mutex_ = nullptr;
|
|
Preferences preferences_;
|
|
BoomStateSnapshot state_;
|
|
String dayKey_;
|
|
bool syncRequested_ = false;
|
|
String syncFilename_;
|
|
uint32_t rebootAtMs_ = 0;
|
|
|
|
String currentDayKey();
|
|
};
|
|
|
|
extern BoomState boomState;
|