I would like to store a couple of persistent variables in the itsybitsy NRF52840's QSPI Flash and am trying trying to use/understand the LittleFS example here: https://github.com/adafruit/Adafruit_nR ... _ReadWrite
The sketch code that I can't duplicate for simple variable storage is this (code snip from Internal_ReadWrite.ino example):
Code: Select all
// Initialize Internal File System
InternalFS.begin();
file.open(FILENAME, FILE_O_READ);
// file existed
if ( file )
{
Serial.println(FILENAME " file exists");
uint32_t readlen;
char buffer[64] = { 0 };
readlen = file.read(buffer, sizeof(buffer));
buffer[readlen] = 0;
Serial.println(buffer);
file.close();
}else
{
Serial.print("Open " FILENAME " file to write ... ");
if( file.open(FILENAME, FILE_O_WRITE) )
{
Serial.println("OK");
file.write(CONTENTS, strlen(CONTENTS));
file.close();
}else
{
Serial.println("Failed!");
}
}
Serial.println("Done");
file.open(FILENAME, FILE_O_READ);
"file.open" is straightforward ... open the file.
"FILENAME" ... the name of the file previously defined (example uses: "/adafruit.txt")
But what does "FILE_O_READ" do?
Similarly for "file.open(FILENAME, FILE_O_WRITE)" what is FILE_O_WRITE doing?
I'm just wanting to store two simple integer calibration variables, but can't work out how to use Adafruit LittleFS to write or read the persistent data to an int variable in my sketch.
Any advice or links to examples would be very appreciated!