123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566 |
- #ifndef KBF_NVS_H
- #define KBF_NVS_H
- #include <string>
- #include <atomic>
- #include <esp_log.h>
- #include <nvs_flash.h>
- using std::string;
- namespace kbf::nvs {
- /**
- * @brief Non-Volatile Storage read / write functions.
- */
- class NVS {
- public:
- /**
- * @brief Constructor. Calls init() if it hasn't been called yet.
- *
- * @param name NVS namespace name; default is "storage"
- */
- explicit NVS(const string &name = "storage");
- ~NVS();
- /**
- * @brief Reads a numeric value from NVS.
- *
- * @tparam T value type
- * @param key name
- * @param value value
- * @return true if successful; false if key not found
- */
- template<typename T>
- bool read(const string &key, T &value);
- /**
- * @brief Writes a numeric value to NVS.
- *
- * @tparam T value type
- * @param key name
- * @param value value
- */
- template<typename T>
- void write(const string &key, T &value);
- /** @brief NVS namespace name */
- const string name;
- private:
- nvs_handle_t handle{};
- };
- /**
- * @brief Initializes NVS. Will be called from NVS class ctor if it hasn't been called yet.
- */
- void init();
- /**
- * Erases NVS partition.
- */
- void erase();
- }
- #endif //KBF_NVS_H
|