/
singlwolf
/
Radiola-2S3
Обзор
Документация
Войти
/
singlwolf
/
Radiola-2S3
Код
Запросы
0
Задачи
Вики
Пакеты
0
Релизы
0
Аналитика
Безопасность
main
src/eeStorage.h
337 строк
7 KB
SinglWolf
v1.0.6
15 апр 2026, 05:04
15 апр 2026, 05:04
55b96c5
Код
Авторство
О чём код?
/** * eeStorage.h **/ #pragma once #include <ArduinoJson.h> #include <string> #include <BME280I2C.h> #include "tda7313.h" #include <Preferences.h> #define VER_MAJOR 1 #define VER_MINOR 0 #define VER_PATH 6 #define MAX_STA 128 #define PROGNAME "Radiola-2S3" #define USERAGENT PROGNAME "/" df2str(VER_MAJOR) "." df2str(VER_MINOR) #define PATH_CONFIG "/configs/config.json" #define PATH_IRCODES "/configs/ircodes.json" #define PATH_KBD_BTN "/configs/keyboard.json" // template <typename T> class PSRAMAllocator { public: using value_type = T; PSRAMAllocator() = default; template <typename U> PSRAMAllocator(const PSRAMAllocator<U> &) noexcept {} T *allocate(size_t n) { if (n == 0) return nullptr; void *p = heap_caps_malloc(n * sizeof(T), MALLOC_CAP_SPIRAM); if (p == nullptr) { Serial.println("PSRAM allocation failed!"); return nullptr; } return static_cast<T *>(p); } void deallocate(T *p, size_t n) noexcept { heap_caps_free(p); } template <typename U> bool operator==(const PSRAMAllocator<U> &) const noexcept { return true; } template <typename U> bool operator!=(const PSRAMAllocator<U> &) const noexcept { return false; } }; using StringPS = std::basic_string<char, std::char_traits<char>, PSRAMAllocator<char>>; // using wifi_mode_e = enum wifi_mode : uint8_t { STA1, STA2, APMODE, }; using work_mode_e = enum work_mode : uint8_t { WEB_RADIO, SD_PLAYER, FM_RADIO, }; // using tda_mode_e = enum tda_mode : uint8_t { INP, VOL, BAS, TRE, ALF, ARF, ALR, ARR, SLA, LOU, MUT, REA, NON = 0xFF, }; // using config_ = struct conf { bool sd; work_mode_e mode; uint32_t flash_size; int8_t firmware; uint8_t lang = 0; bool license; struct lcd { bool dark; bool rotat; bool Long; uint8_t div; float inch; } lcd; struct beep { bool on; bool kbd; bool enc; bool ir; } beep; struct kbd { bool on; bool kb1; bool kb2; } kbd; struct enc { bool on; } enc; struct ir { bool on; uint8_t set; } ir; struct led { bool on; bool ldr; uint8_t mode; uint8_t hand; uint8_t day; uint8_t night; uint8_t begin; uint8_t end; } led; struct i2c { uint8_t bmp = 0; bool ds3231 = false; bool eeprom = false; bool rda5807 = false; bool tda7313 = false; } i2c; struct sensor { bool on; bool temp; bool press; bool wet; bool degree; bool cels; bool torr; uint8_t time; uint8_t offset; } sensor; struct alarm { bool on; bool week; bool day[7]; uint8_t hours; uint8_t minutes; } alarm; struct sleep { bool on; uint8_t hours; uint8_t minutes; } sleep; struct weather { bool on; // char *key = ""; // char *city = ""; // char *lat = ""; // char *lon = ""; } weather; struct color { char clock[2][8]; char temp[2][8]; char press[2][8]; char wet[2][8]; } color; }; // using wifi_ = struct wifi { bool autowifi = false; std::string ntp[4] = { "0.pool.ntp.org", "1.pool.ntp.org", "2.pool.ntp.org", "3.pool.ntp.org", }; std::string ua = USERAGENT; std::string host = ""; std::string ssid = ""; std::string pass = ""; std::string mac = ""; std::string tz = "YEKT-5"; struct { bool on = false; bool run = false; time_t last = 0LL; } rts; }; // using current_ = struct current_ { bool autoplay = false; bool info = false; uint8_t maxvol = 254; uint8_t volume = 70; int8_t balance = 0; struct { int8_t band[5]{}; int8_t set[5]{}; // пользовательский пресет uint8_t mode = 0; // 0=OFF, 1=MUSIC, 2=DYNAMIC, 3=VOCAL, 4=CUSTOM uint8_t spatial_mode = 0; // 0=Normal, 1=Surround, 2=3D, 3=Reserved } eq; uint8_t CurrentPlayList = 0; // Массив строк: 4 плейлиста, по 33 символа char PlayListName[4][33] = { "playlist1", "playlist2", "playlist3", "playlist4"}; uint8_t all[4] = {0}; uint8_t sel[4] = {1}; uint8_t show_rows[4] = {8}; uint8_t ir_set = 0; }; // extern wifi_ *ee; extern config_ *Config; // STATION #define MAXSTATIONS 128 // Максимальное количество станций const unsigned long SYNC_INTERVAL = 7 * 24 * 60 * 60; // 1 неделя extern uint8_t dark_theme; extern JsonDocument IR_KEY; extern JsonDocument KBD_BTN; // extern JsonDocument Config; class eeStorage { public: eeStorage(); ~eeStorage() {}; bool time_sync = false; TDA7313 *tda = nullptr; BME280I2C *bme = nullptr; private: DeserializationError save(const char *name, const JsonDocument &doc); DeserializationError load(const char *name, JsonDocument &doc); uint32_t calculateCRC(const uint8_t *data, size_t length); bool erase(); bool CheckCurrConfig(); void CheckConfig(); Preferences _preferences; bool _initialized; bool _usingExternal; public: void begin(bool sd); StringPS GetList(); StringPS GetStaName(uint8_t ID); uint8_t GetID(); uint8_t GetTotalSta(); uint8_t GetVolume(); int8_t GetBalanse(); bool GetInfo(); void SetBalanse(int8_t val); void SetInfo(bool ena); uint8_t GetMaxVolume(); uint8_t GetShowRows(); void SetShowRows(uint8_t rows); void setIRSet(uint8_t set); uint8_t getIRSet(); uint8_t GetTotalSta(uint8_t num); uint8_t GetCurrentPlayList(); bool GetAutoPlay(); void SetAutoPlay(bool set); // void GetTone(int8_t &bass, int8_t &middle, int8_t &trebble); // void SetTone(int8_t bass, int8_t middle, int8_t trebble); void SetCurrentPlayList(uint8_t num); void SetID(uint8_t ID); void SetVolume(uint8_t val); void SetMaxVolume(uint8_t val); StringPS GetPlayListName(uint8_t ID); StringPS GetCurrentPlayListName(); StringPS GetStaLogo(uint8_t ID); StringPS GetStaUrl(uint8_t ID); size_t GetListSize(); size_t GetListBytes(); void InitConfig(bool def = false, StringPS *conf = nullptr); void InitCurrConfig(bool def = false); void InitPlaylist(); void InitKeyboard(bool def = false); void InitIrcodes(bool def = false); void initEEdata(bool def = false, StringPS *conf = nullptr); void EraseAll(bool def = false); StringPS SaveConfig(bool def = true); StringPS SaveEEdata(bool def = true); StringPS SaveCurrConfig(); void SaveIR(); void SaveKBD(); time_t SyncSysDateTime(); bool RTCwrite(const tm *info); // Управление полосами эквалайзера (аналог старого GetTone / SetTone) void GetEqData(int8_t *band, int8_t *set, uint8_t &mode); void SetEqData(int8_t *bands, int8_t *set, uint8_t mode); // Отдать данные ИЗ хранилища ВО внешнюю структуру void GetEqData(void *dest); // Записать данные ИЗ внешней структуры В хранилище (в память current) void SetEqData(void *src); // Управление режимом эквалайзера uint8_t GetEqMode(); void SetEqMode(uint8_t mode); // Управление пользовательским пресетом void GetEqPreset(int8_t preset[5]); void SetEqPreset(int8_t preset[5]); // SemaphoreHandle_t eeNVS = nullptr; SemaphoreHandle_t eeI2C = nullptr; }; extern eeStorage eeprom;