Skip to content

Commit ef75292

Browse files
authored
Merge pull request #1036 from oltaco/datastore-refactor
Refactor DataStore to use openRead() and openWrite()
2 parents 228b073 + 52a3df4 commit ef75292

File tree

1 file changed

+5
-33
lines changed

1 file changed

+5
-33
lines changed

examples/companion_radio/DataStore.cpp

Lines changed: 5 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -197,11 +197,7 @@ void DataStore::loadPrefs(NodePrefs& prefs, double& node_lat, double& node_lon)
197197
}
198198

199199
void DataStore::loadPrefsInt(const char *filename, NodePrefs& _prefs, double& node_lat, double& node_lon) {
200-
#if defined(RP2040_PLATFORM)
201-
File file = _fs->open(filename, "r");
202-
#else
203-
File file = _fs->open(filename);
204-
#endif
200+
File file = openRead(_fs, filename);
205201
if (file) {
206202
uint8_t pad[8];
207203

@@ -262,16 +258,7 @@ void DataStore::savePrefs(const NodePrefs& _prefs, double node_lat, double node_
262258
}
263259

264260
void DataStore::loadContacts(DataStoreHost* host) {
265-
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
266-
if (_getContactsChannelsFS()->exists("/contacts3")) {
267-
File file = _getContactsChannelsFS()->open("/contacts3");
268-
#elif defined(RP2040_PLATFORM)
269-
if (_fs->exists("/contacts3")) {
270-
File file = _fs->open("/contacts3", "r");
271-
#else
272-
if (_fs->exists("/contacts3")) {
273-
File file = _fs->open("/contacts3", "r", false);
274-
#endif
261+
File file = openRead(_getContactsChannelsFS(), "/contacts3");
275262
if (file) {
276263
bool full = false;
277264
while (!full) {
@@ -299,7 +286,6 @@ void DataStore::loadContacts(DataStoreHost* host) {
299286
}
300287
file.close();
301288
}
302-
}
303289
}
304290

305291
void DataStore::saveContacts(DataStoreHost* host) {
@@ -332,16 +318,7 @@ void DataStore::saveContacts(DataStoreHost* host) {
332318
}
333319

334320
void DataStore::loadChannels(DataStoreHost* host) {
335-
#if defined(NRF52_PLATFORM) || defined(STM32_PLATFORM)
336-
if (_getContactsChannelsFS()->exists("/channels2")) {
337-
File file = _getContactsChannelsFS()->open("/channels2");
338-
#elif defined(RP2040_PLATFORM)
339-
if (_fs->exists("/channels2")) {
340-
File file = _fs->open("/channels2", "r");
341-
#else
342-
if (_fs->exists("/channels2")) {
343-
File file = _fs->open("/channels2", "r", false);
344-
#endif
321+
File file = openRead(_getContactsChannelsFS(), "/channels2");
345322
if (file) {
346323
bool full = false;
347324
uint8_t channel_idx = 0;
@@ -363,7 +340,6 @@ void DataStore::loadChannels(DataStoreHost* host) {
363340
}
364341
file.close();
365342
}
366-
}
367343
}
368344

369345
void DataStore::saveChannels(DataStoreHost* host) {
@@ -520,7 +496,7 @@ void DataStore::migrateToSecondaryFS() {
520496
}
521497

522498
uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_buf[]) {
523-
File file = _getContactsChannelsFS()->open("/adv_blobs");
499+
File file = openRead(_getContactsChannelsFS(), "/adv_blobs");
524500
uint8_t len = 0; // 0 = not found
525501
if (file) {
526502
BlobRec tmp;
@@ -583,11 +559,7 @@ uint8_t DataStore::getBlobByKey(const uint8_t key[], int key_len, uint8_t dest_b
583559
sprintf(path, "/bl/%s", fname);
584560

585561
if (_fs->exists(path)) {
586-
#if defined(RP2040_PLATFORM)
587-
File f = _fs->open(path, "r");
588-
#else
589-
File f = _fs->open(path);
590-
#endif
562+
File f = openRead(_fs, path);
591563
if (f) {
592564
int len = f.read(dest_buf, 255); // currently MAX 255 byte blob len supported!!
593565
f.close();

0 commit comments

Comments
 (0)