nRF52 using Adafruit_LittleFs for storing cal variables

Post here about your Arduino projects, get help - for Adafruit customers!

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
argotwo
 
Posts: 12
Joined: Sat Aug 30, 2014 3:15 am

nRF52 using Adafruit_LittleFs for storing cal variables

Post by argotwo »

Hi

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");
Key gaps in my understanding are:

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!

User avatar
adafruit_support_bill
 
Posts: 88087
Joined: Sat Feb 07, 2009 10:11 am

Re: nRF52 using Adafruit_LittleFs for storing cal variables

Post by adafruit_support_bill »

But what does "FILE_O_READ" do?
It tells the file system that you want to open the file for read access.
Similarly for "file.open(FILENAME, FILE_O_WRITE)" what is FILE_O_WRITE doing?
That tells the file system that you want to open the file for write access.

See the example here:
https://github.com/adafruit/Adafruit_nR ... dWrite.ino

User avatar
argotwo
 
Posts: 12
Joined: Sat Aug 30, 2014 3:15 am

Re: nRF52 using Adafruit_LittleFs for storing cal variables

Post by argotwo »

Thank you Bill :)

Lucky there is no such thing as a silly question - pretty obvious!
For some reason, I was expecting to see that part of the command to outside the brackets.

Locked
Please be positive and constructive with your questions and comments.

Return to “Arduino”