diff --git a/libraries/Bridge/keywords.txt b/libraries/Bridge/keywords.txt index c96a8ed9c..2dbccb50b 100644 --- a/libraries/Bridge/keywords.txt +++ b/libraries/Bridge/keywords.txt @@ -42,6 +42,7 @@ connected KEYWORD2 # FileIO Class File KEYWORD2 +BridgeFile KEYWORD2 seek KEYWORD2 position KEYWORD2 size KEYWORD2 diff --git a/libraries/Bridge/library.properties b/libraries/Bridge/library.properties index ac8ebd9bb..e1ce9571c 100644 --- a/libraries/Bridge/library.properties +++ b/libraries/Bridge/library.properties @@ -1,5 +1,5 @@ name=Bridge -version=1.0.7 +version=1.1.0 author=Arduino maintainer=Arduino sentence=Enables the communication between the Linux processor and the AVR. For Arduino Yún and TRE only. diff --git a/libraries/Bridge/src/FileIO.cpp b/libraries/Bridge/src/FileIO.cpp index 603657239..e1d441526 100644 --- a/libraries/Bridge/src/FileIO.cpp +++ b/libraries/Bridge/src/FileIO.cpp @@ -18,7 +18,7 @@ #include - +namespace BridgeLib { File::File(BridgeClass &b) : mode(255), bridge(b) { // Empty @@ -279,3 +279,5 @@ boolean FileSystemClass::rmdir(const char *filepath) { } FileSystemClass FileSystem; + +} diff --git a/libraries/Bridge/src/FileIO.h b/libraries/Bridge/src/FileIO.h index ac4e8fa9f..c5a8e9eac 100644 --- a/libraries/Bridge/src/FileIO.h +++ b/libraries/Bridge/src/FileIO.h @@ -25,6 +25,8 @@ #define FILE_WRITE 1 #define FILE_APPEND 2 +namespace BridgeLib { + class File : public Stream { public: @@ -100,4 +102,19 @@ class FileSystemClass { extern FileSystemClass FileSystem; +}; + +// We enclose File and FileSystem classes in namespace BridgeLib to avoid +// conflicts with legacy SD library. + +// This ensure compatibility with older sketches that uses only Bridge lib +// (the user can still use File instead of BridgeFile) +using namespace BridgeLib; + +// This allows sketches to use BridgeLib::File together with SD library +// (you must use BridgeFile instead of File when needed to disambiguate) +typedef BridgeLib::File BridgeFile; +typedef BridgeLib::FileSystemClass BridgeFileSystemClass; +#define BridgeFileSystem BridgeLib::FileSystem + #endif diff --git a/libraries/SD/keywords.txt b/libraries/SD/keywords.txt index 9893cc91d..91e74b830 100644 --- a/libraries/SD/keywords.txt +++ b/libraries/SD/keywords.txt @@ -8,6 +8,7 @@ SD KEYWORD1 SD File KEYWORD1 SD +SDFile KEYWORD1 SD ####################################### # Methods and Functions (KEYWORD2) diff --git a/libraries/SD/src/SD.cpp b/libraries/SD/src/SD.cpp index 3bf79aca2..0b3194b27 100644 --- a/libraries/SD/src/SD.cpp +++ b/libraries/SD/src/SD.cpp @@ -52,6 +52,8 @@ #include "SD.h" +namespace SDLib { + // Used by `getNextPathComponent` #define MAX_COMPONENT_LEN 12 // What is max length? #define PATH_COMPONENT_BUFFER_LEN MAX_COMPONENT_LEN+1 @@ -614,3 +616,5 @@ void File::rewindDirectory(void) { } SDClass SD; + +}; diff --git a/libraries/SD/src/SD.h b/libraries/SD/src/SD.h index a969b8621..999dac175 100644 --- a/libraries/SD/src/SD.h +++ b/libraries/SD/src/SD.h @@ -23,6 +23,8 @@ #define FILE_READ O_READ #define FILE_WRITE (O_READ | O_WRITE | O_CREAT) +namespace SDLib { + class File : public Stream { private: char _name[13]; // our name @@ -104,4 +106,18 @@ private: extern SDClass SD; +}; + +// We enclose File and SD classes in namespace SDLib to avoid conflicts +// with others legacy libraries that redefines File class. + +// This ensure compatibility with sketches that uses only SD library +using namespace SDLib; + +// This allows sketches to use SDLib::File with other libraries (in the +// sketch you must use SDFile instead of File to disambiguate) +typedef SDLib::File SDFile; +typedef SDLib::SDClass SDFileSystemClass; +#define SDFileSystem SDLib::SD + #endif