#pragma once #include #include #include "esp_err.h" /** * @brief Small NVS wrapper standing in for the Arduino `Preferences` class. * * The original code used `preferences.begin("armor", false)`, `putUInt`, * `getUInt`, `isKey`, `putBytes` and `getBytes`. Those map directly onto the * ESP-IDF NVS API; the handle is kept open for the lifetime of the program * exactly like `Preferences` did. */ namespace Storage { /** Open (creating if needed) the NVS namespace used by this application. */ esp_err_t begin(const char *name_space); /** True when @p key exists as either a u32 or a blob. */ bool hasKey(const char *key); /** Read a u32, returning @p default_value when the key is absent. */ uint32_t getUInt(const char *key, uint32_t default_value); /** Read a blob, returning the number of bytes read (0 when absent). */ size_t getBytes(const char *key, void *out, size_t max_len); /** Store a u32 and commit it. */ esp_err_t putUInt(const char *key, uint32_t value); /** Store a blob and commit it. */ esp_err_t putBytes(const char *key, const void *data, size_t len); } // namespace Storage