Skip to content

Commit

Permalink
Initialise NVS. (#166)
Browse files Browse the repository at this point in the history
Migration to IDF means we need to manually initialize the NVS ourselves.
Otherwise, we can't save anything ...
  • Loading branch information
gkoh authored Jan 16, 2025
1 parent 9289322 commit 649c17d
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
1 change: 0 additions & 1 deletion src/FurbleGPS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ void GPS::serviceSerial(void) {
size_t available = m_SerialPort.available();
if (available > 0) {
size_t bytes = m_SerialPort.readBytes(buffer.data(), std::min(buffer.size(), available));
ESP_LOGI("gps", "bytes = %u", bytes);

for (size_t i = 0; i < bytes; i++) {
m_GPS.encode(buffer[i]);
Expand Down
9 changes: 9 additions & 0 deletions src/FurbleSettings.cpp
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
#include <esp_bt.h>
#include <nvs_flash.h>

#include "FurbleTypes.h"

Expand Down Expand Up @@ -144,6 +145,14 @@ void Settings::save<std::string>(const type_t type, const std::string &value) {
}

void Settings::init(void) {
// Initialize NVS
esp_err_t ret = nvs_flash_init();
if (ret == ESP_ERR_NVS_NO_FREE_PAGES || ret == ESP_ERR_NVS_NEW_VERSION_FOUND) {
ESP_ERROR_CHECK(nvs_flash_erase());
ret = nvs_flash_init();
}
ESP_ERROR_CHECK(ret);

// Set default values for all settings
for (const auto &it : m_Setting) {
auto &setting = it.second;
Expand Down

0 comments on commit 649c17d

Please sign in to comment.