fix #276 rename macro FILE_READ/WRITE to enum FILE_O_READ/WRITE
to avoid conflict with other filesystem define
This commit is contained in:
1 parent
9b37e28bc2
commit
b99cae32b6
8 files changed
+33
-26
No files matched your search
@@ -46,7 +46,7 @@ class Adafruit_LittleFS
|
|||||||
// Open the specified file/directory with the supplied mode (e.g. read or
|
// Open the specified file/directory with the supplied mode (e.g. read or
|
||||||
// write, etc). Returns a File object for interacting with the file.
|
// write, etc). Returns a File object for interacting with the file.
|
||||||
// Note that currently only one file can be open at a time.
|
// Note that currently only one file can be open at a time.
|
||||||
Adafruit_LittleFS_Namespace::File open (char const *filename, uint8_t mode = FILE_READ);
|
Adafruit_LittleFS_Namespace::File open (char const *filename, uint8_t mode = Adafruit_LittleFS_Namespace::FILE_O_READ);
|
||||||
|
|
||||||
// Methods to determine if the requested file path exists.
|
// Methods to determine if the requested file path exists.
|
||||||
bool exists (char const *filepath);
|
bool exists (char const *filepath);
|
||||||
|
|||||||
@@ -51,8 +51,8 @@ File::File (char const *filename, uint8_t mode, Adafruit_LittleFS &fs)
|
|||||||
|
|
||||||
bool File::_open_file (char const *filepath, uint8_t mode)
|
bool File::_open_file (char const *filepath, uint8_t mode)
|
||||||
{
|
{
|
||||||
int flags = (mode == FILE_READ) ? LFS_O_RDONLY :
|
int flags = (mode == FILE_O_READ) ? LFS_O_RDONLY :
|
||||||
(mode == FILE_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
|
(mode == FILE_O_WRITE) ? (LFS_O_RDWR | LFS_O_CREAT) : 0;
|
||||||
|
|
||||||
if ( flags )
|
if ( flags )
|
||||||
{
|
{
|
||||||
@@ -69,7 +69,7 @@ bool File::_open_file (char const *filepath, uint8_t mode)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// move to end of file
|
// move to end of file
|
||||||
if ( mode == FILE_WRITE ) lfs_file_seek(_fs->getFS(), _file, 0, LFS_SEEK_END);
|
if ( mode == FILE_O_WRITE ) lfs_file_seek(_fs->getFS(), _file, 0, LFS_SEEK_END);
|
||||||
|
|
||||||
_is_dir = false;
|
_is_dir = false;
|
||||||
}
|
}
|
||||||
@@ -116,8 +116,8 @@ bool File::open (char const *filepath, uint8_t mode)
|
|||||||
}
|
}
|
||||||
else if ( LFS_ERR_NOENT == rc )
|
else if ( LFS_ERR_NOENT == rc )
|
||||||
{
|
{
|
||||||
// file not existed, only proceed with FILE_WRITE mode
|
// file not existed, only proceed with FILE_O_WRITE mode
|
||||||
if ( mode == FILE_WRITE ) ret = _open_file(filepath, mode);
|
if ( mode == FILE_O_WRITE ) ret = _open_file(filepath, mode);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -25,15 +25,19 @@
|
|||||||
#ifndef ADAFRUIT_LITTLEFS_FILE_H_
|
#ifndef ADAFRUIT_LITTLEFS_FILE_H_
|
||||||
#define ADAFRUIT_LITTLEFS_FILE_H_
|
#define ADAFRUIT_LITTLEFS_FILE_H_
|
||||||
|
|
||||||
#define FILE_READ 0
|
|
||||||
#define FILE_WRITE 1
|
|
||||||
|
|
||||||
// Forward declaration
|
// Forward declaration
|
||||||
class Adafruit_LittleFS;
|
class Adafruit_LittleFS;
|
||||||
|
|
||||||
namespace Adafruit_LittleFS_Namespace
|
namespace Adafruit_LittleFS_Namespace
|
||||||
{
|
{
|
||||||
|
|
||||||
|
// avoid conflict with other FileSystem FILE_READ/FILE_WRITE
|
||||||
|
enum
|
||||||
|
{
|
||||||
|
FILE_O_READ = 0,
|
||||||
|
FILE_O_WRITE = 1,
|
||||||
|
};
|
||||||
|
|
||||||
class File : public Stream
|
class File : public Stream
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
@@ -69,7 +73,7 @@ class File : public Stream
|
|||||||
char const* name (void);
|
char const* name (void);
|
||||||
|
|
||||||
bool isDirectory (void);
|
bool isDirectory (void);
|
||||||
File openNextFile (uint8_t mode = FILE_READ);
|
File openNextFile (uint8_t mode = FILE_O_READ);
|
||||||
void rewindDirectory (void);
|
void rewindDirectory (void);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|||||||
@@ -13,7 +13,8 @@
|
|||||||
//#include <pstorage.h>
|
//#include <pstorage.h>
|
||||||
//#include <app_scheduler.h>
|
//#include <app_scheduler.h>
|
||||||
#include <nrf_soc.h>
|
#include <nrf_soc.h>
|
||||||
#include "Bluefruit_FileIO.h"
|
#include <Adafruit_LittleFS.h>
|
||||||
|
#include <InternalFileSystem.h>
|
||||||
#include "utility/debug.h"
|
#include "utility/debug.h"
|
||||||
|
|
||||||
#include "rtos.h"
|
#include "rtos.h"
|
||||||
@@ -21,6 +22,8 @@
|
|||||||
|
|
||||||
#include "crypto.h"
|
#include "crypto.h"
|
||||||
|
|
||||||
|
using namespace Adafruit_LittleFS_Namespace;
|
||||||
|
|
||||||
#define CRYPTO_INSTANCE 2 // Change this to force key regeneration on next run
|
#define CRYPTO_INSTANCE 2 // Change this to force key regeneration on next run
|
||||||
|
|
||||||
crypto_keys_t crypto_keys;
|
crypto_keys_t crypto_keys;
|
||||||
@@ -108,7 +111,7 @@ static uint8_t crypto_loadKeys(void)
|
|||||||
|
|
||||||
uint32_t keylen = sizeof(keys);
|
uint32_t keylen = sizeof(keys);
|
||||||
|
|
||||||
File file(CRYPTO_KEYFILE, FILE_READ, InternalFS);
|
File file(CRYPTO_KEYFILE, FILE_O_READ, InternalFS);
|
||||||
VERIFY(file, 0);
|
VERIFY(file, 0);
|
||||||
|
|
||||||
keylen = file.read(&keys, keylen);
|
keylen = file.read(&keys, keylen);
|
||||||
@@ -162,7 +165,7 @@ void crypto_storeKeys(void)
|
|||||||
keys.valid0 = 0x55;
|
keys.valid0 = 0x55;
|
||||||
keys.valid1 = 0xAA;
|
keys.valid1 = 0xAA;
|
||||||
|
|
||||||
File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
|
File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
|
||||||
VERIFY(file,);
|
VERIFY(file,);
|
||||||
|
|
||||||
file.write(&keys, sizeof(keys));
|
file.write(&keys, sizeof(keys));
|
||||||
|
|||||||
+1
-1
@@ -124,7 +124,7 @@ void setup()
|
|||||||
Bluefruit.setName("Bluefruit52");
|
Bluefruit.setName("Bluefruit52");
|
||||||
|
|
||||||
//InternalFS.remove(CRYPTO_KEYFILE);
|
//InternalFS.remove(CRYPTO_KEYFILE);
|
||||||
//File file(CRYPTO_KEYFILE, FILE_WRITE, InternalFS);
|
//File file(CRYPTO_KEYFILE, FILE_O_WRITE, InternalFS);
|
||||||
//file.write(&test_keys, sizeof(test_keys));
|
//file.write(&test_keys, sizeof(test_keys));
|
||||||
//file.close();
|
//file.close();
|
||||||
|
|
||||||
|
|||||||
@@ -104,7 +104,7 @@ static void bond_save_keys_dfr (uint8_t role, uint16_t conn_hdl, bond_keys_t* bk
|
|||||||
// delete if file already exists
|
// delete if file already exists
|
||||||
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
|
if ( InternalFS.exists(filename) ) InternalFS.remove(filename);
|
||||||
|
|
||||||
File file(filename, FILE_WRITE, InternalFS);
|
File file(filename, FILE_O_WRITE, InternalFS);
|
||||||
VERIFY(file,);
|
VERIFY(file,);
|
||||||
|
|
||||||
//------------- save keys -------------//
|
//------------- save keys -------------//
|
||||||
@@ -141,7 +141,7 @@ bool bond_load_keys(uint8_t role, uint16_t ediv, bond_keys_t* bkeys)
|
|||||||
char filename[BOND_FNAME_LEN];
|
char filename[BOND_FNAME_LEN];
|
||||||
get_fname(filename, role, ediv);
|
get_fname(filename, role, ediv);
|
||||||
|
|
||||||
File file(filename, FILE_READ, InternalFS);
|
File file(filename, FILE_O_READ, InternalFS);
|
||||||
VERIFY(file);
|
VERIFY(file);
|
||||||
|
|
||||||
int keylen = file.read();
|
int keylen = file.read();
|
||||||
@@ -171,7 +171,7 @@ static void bond_save_cccd_dfr (uint8_t role, uint16_t conn_hdl, uint16_t ediv)
|
|||||||
char filename[BOND_FNAME_LEN];
|
char filename[BOND_FNAME_LEN];
|
||||||
get_fname(filename, role, ediv);
|
get_fname(filename, role, ediv);
|
||||||
|
|
||||||
File file(filename, FILE_WRITE, InternalFS);
|
File file(filename, FILE_O_WRITE, InternalFS);
|
||||||
VERIFY(file,);
|
VERIFY(file,);
|
||||||
|
|
||||||
file.seek(0); // write mode start at the end, seek to beginning
|
file.seek(0); // write mode start at the end, seek to beginning
|
||||||
@@ -204,7 +204,7 @@ bool bond_load_cccd(uint8_t role, uint16_t conn_hdl, uint16_t ediv)
|
|||||||
char filename[BOND_FNAME_LEN];
|
char filename[BOND_FNAME_LEN];
|
||||||
get_fname(filename, role, ediv);
|
get_fname(filename, role, ediv);
|
||||||
|
|
||||||
File file(filename, FILE_READ, InternalFS);
|
File file(filename, FILE_O_READ, InternalFS);
|
||||||
|
|
||||||
if ( file )
|
if ( file )
|
||||||
{
|
{
|
||||||
@@ -241,10 +241,10 @@ void bond_print_list(uint8_t role)
|
|||||||
{
|
{
|
||||||
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
|
char const * dpath = (role == BLE_GAP_ROLE_PERIPH ? BOND_DIR_PRPH : BOND_DIR_CNTR);
|
||||||
|
|
||||||
File dir(dpath, FILE_READ, InternalFS);
|
File dir(dpath, FILE_O_READ, InternalFS);
|
||||||
File file(InternalFS);
|
File file(InternalFS);
|
||||||
|
|
||||||
while ( (file = dir.openNextFile(FILE_READ)) )
|
while ( (file = dir.openNextFile(FILE_O_READ)) )
|
||||||
{
|
{
|
||||||
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
|
if ( !file.isDirectory() && bdata_skip_field(&file) ) // skip key
|
||||||
{
|
{
|
||||||
@@ -272,10 +272,10 @@ bool bond_find_cntr(ble_gap_addr_t const * addr, bond_keys_t* bkeys)
|
|||||||
{
|
{
|
||||||
bool found = false;
|
bool found = false;
|
||||||
|
|
||||||
File dir(BOND_DIR_CNTR, FILE_READ, InternalFS);
|
File dir(BOND_DIR_CNTR, FILE_O_READ, InternalFS);
|
||||||
File file(InternalFS);
|
File file(InternalFS);
|
||||||
|
|
||||||
while ( (file = dir.openNextFile(FILE_READ)) )
|
while ( (file = dir.openNextFile(FILE_O_READ)) )
|
||||||
{
|
{
|
||||||
// Read bond data of each stored file
|
// Read bond data of each stored file
|
||||||
int keylen = file.read();
|
int keylen = file.read();
|
||||||
|
|||||||
@@ -70,7 +70,7 @@ void loop()
|
|||||||
void printTreeDir(const char* cwd, uint8_t level)
|
void printTreeDir(const char* cwd, uint8_t level)
|
||||||
{
|
{
|
||||||
// Open the input folder
|
// Open the input folder
|
||||||
File dir(cwd, FILE_READ, InternalFS);
|
File dir(cwd, FILE_O_READ, InternalFS);
|
||||||
|
|
||||||
// Print root
|
// Print root
|
||||||
if (level == 0) Serial.println("root");
|
if (level == 0) Serial.println("root");
|
||||||
@@ -79,7 +79,7 @@ void printTreeDir(const char* cwd, uint8_t level)
|
|||||||
File item(InternalFS);
|
File item(InternalFS);
|
||||||
|
|
||||||
// Loop through the directory
|
// Loop through the directory
|
||||||
while( (item = dir.openNextFile(FILE_READ)) )
|
while( (item = dir.openNextFile(FILE_O_READ)) )
|
||||||
{
|
{
|
||||||
// Indentation according to dir level
|
// Indentation according to dir level
|
||||||
for(int i=0; i<level; i++) Serial.print("| ");
|
for(int i=0; i<level; i++) Serial.print("| ");
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ void setup()
|
|||||||
// Initialize Internal File System
|
// Initialize Internal File System
|
||||||
InternalFS.begin();
|
InternalFS.begin();
|
||||||
|
|
||||||
file.open(FILENAME, FILE_READ);
|
file.open(FILENAME, FILE_O_READ);
|
||||||
|
|
||||||
// file existed
|
// file existed
|
||||||
if ( file )
|
if ( file )
|
||||||
@@ -62,7 +62,7 @@ void setup()
|
|||||||
{
|
{
|
||||||
Serial.print("Open " FILENAME " file to write ... ");
|
Serial.print("Open " FILENAME " file to write ... ");
|
||||||
|
|
||||||
if( file.open(FILENAME, FILE_WRITE) )
|
if( file.open(FILENAME, FILE_O_WRITE) )
|
||||||
{
|
{
|
||||||
Serial.println("OK");
|
Serial.println("OK");
|
||||||
file.write(CONTENTS, strlen(CONTENTS));
|
file.write(CONTENTS, strlen(CONTENTS));
|
||||||
|
|||||||
Reference in new issue
Block a user