diff --git a/docs/software/nrf52-TODO.md b/docs/software/nrf52-TODO.md index 2e469f57..515378d9 100644 --- a/docs/software/nrf52-TODO.md +++ b/docs/software/nrf52-TODO.md @@ -21,7 +21,6 @@ Needed to be fully functional at least at the same level of the ESP32 boards. At - DONE get serial API working - get full BLE api working -- make a file system implementation (preferably one that can see the files the bootloader also sees) - preferably https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/libraries/InternalFileSytem/examples/Internal_ReadWrite/Internal_ReadWrite.ino else use https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_fds_usage.html?cp=7_5_0_3_55_3 - make power management/sleep work properly - make a settimeofday implementation - DONE increase preamble length? - will break other clients? so all devices must update @@ -125,6 +124,7 @@ Nice ideas worth considering someday... - DONE use SX126x::startReceiveDutyCycleAuto to save power by sleeping and briefly waking to check for preamble bits. Change xmit rules to have more preamble bits. - scheduleOSCallback doesn't work yet - it is way too fast (causes rapid polling of busyTx, high power draw etc...) - find out why we reboot while debugging - it was bluetooth/softdevice +- make a file system implementation (preferably one that can see the files the bootloader also sees) - preferably https://github.com/adafruit/Adafruit_nRF52_Arduino/blob/master/libraries/InternalFileSytem/examples/Internal_ReadWrite/Internal_ReadWrite.ino else use https://infocenter.nordicsemi.com/topic/com.nordic.infocenter.sdk5.v15.3.0/lib_fds_usage.html?cp=7_5_0_3_55_3 ``` diff --git a/src/mesh/NodeDB.cpp b/src/mesh/NodeDB.cpp index d9e45dd5..f46d1d8d 100644 --- a/src/mesh/NodeDB.cpp +++ b/src/mesh/NodeDB.cpp @@ -33,6 +33,14 @@ DeviceState versions used to be defined in the .proto file but really only this #ifndef NO_ESP32 #define FS SPIFFS +#define FSBegin() FS.begin(true) +#define FILE_O_WRITE "w" +#define FILE_O_READ "r" +#else +#include "InternalFileSystem.h" +#define FS InternalFS +#define FSBegin() FS.begin() +using namespace Adafruit_LittleFS_Namespace; #endif // FIXME - move this somewhere else @@ -135,8 +143,15 @@ void NodeDB::init() info->user = owner; info->has_user = true; + if (!FSBegin()) // FIXME - do this in main? + { + DEBUG_MSG("ERROR filesystem mount Failed\n"); + // FIXME - report failure to phone + } + // saveToDisk(); loadFromDisk(); + // saveToDisk(); // We set these _after_ loading from disk - because they come from the build and are more trusted than // what is stored in flash @@ -180,13 +195,7 @@ void NodeDB::loadFromDisk() #ifdef FS static DeviceState scratch; - if (!FS.begin(true)) // FIXME - do this in main? - { - DEBUG_MSG("ERROR SPIFFS Mount Failed\n"); - // FIXME - report failure to phone - } - - File f = FS.open(preffile); + auto f = FS.open(preffile); if (f) { DEBUG_MSG("Loading saved preferences\n"); pb_istream_t stream = {&readcb, &f, DeviceState_size}; @@ -220,7 +229,7 @@ void NodeDB::loadFromDisk() void NodeDB::saveToDisk() { #ifdef FS - File f = FS.open(preftmp, "w"); + auto f = FS.open(preftmp, FILE_O_WRITE); if (f) { DEBUG_MSG("Writing preferences\n"); diff --git a/src/mesh/mesh-pb-constants.cpp b/src/mesh/mesh-pb-constants.cpp index 86431785..dc0d188a 100644 --- a/src/mesh/mesh-pb-constants.cpp +++ b/src/mesh/mesh-pb-constants.cpp @@ -6,6 +6,11 @@ #include #include +#ifdef NO_ESP32 +#include "Adafruit_LittleFS.h" +using namespace Adafruit_LittleFS_Namespace; // To get File type +#endif + /// helper function for encoding a record as a protobuf, any failures to encode are fatal and we will panic /// returns the encoded packet size size_t pb_encode_to_bytes(uint8_t *destbuf, size_t destbufsize, const pb_msgdesc_t *fields, const void *src_struct) @@ -36,7 +41,6 @@ bool pb_decode_from_bytes(const uint8_t *srcbuf, size_t srcbufsize, const pb_msg bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count) { bool status = false; -#ifndef NO_ESP32 File *file = (File *)stream->state; if (buf == NULL) { @@ -45,24 +49,20 @@ bool readcb(pb_istream_t *stream, uint8_t *buf, size_t count) return count == 0; } - status = (file->read(buf, count) == count); + status = (file->read(buf, count) == (int) count); if (file->available() == 0) stream->bytes_left = 0; -#endif + return status; } /// Write to an arduino file bool writecb(pb_ostream_t *stream, const uint8_t *buf, size_t count) { -#ifndef NO_ESP32 File *file = (File *)stream->state; // DEBUG_MSG("writing %d bytes to protobuf file\n", count); return file->write(buf, count) == count; -#else - return false; -#endif } bool is_in_helper(uint32_t n, const uint32_t *array, pb_size_t count)