From 11b0cd2bfc97403a5ad7f665871512f78805b13d Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Sun, 9 Apr 2017 14:57:57 +1000 Subject: [PATCH 1/2] Fixes FS / SD file definition conflict Using the implementation of FS and SD included as part of the Oak package in a single sketch was not possible, due to them having conflicting file definitions. This was fixed in a later commit on the ESP8266 Arduino core (https://github.com/esp8266/Arduino/commit/18297458bea82419b27d603d18cba81160829675). This commit simply imports those changes, plus some other minor additions that have occurred since as there is nothing that will break existing code. --- cores/oak/FS.cpp | 6 ++++++ cores/oak/FS.h | 18 ++++++++++++++---- cores/oak/FSImpl.h | 1 + 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/cores/oak/FS.cpp b/cores/oak/FS.cpp index 55bae8f..6ae11e1 100644 --- a/cores/oak/FS.cpp +++ b/cores/oak/FS.cpp @@ -167,6 +167,12 @@ bool FS::begin() { return _impl->begin(); } +void FS::end() { + if (_impl) { + _impl->end(); + } +} + bool FS::format() { if (!_impl) { return false; diff --git a/cores/oak/FS.h b/cores/oak/FS.h index 07b58c0..79620f9 100644 --- a/cores/oak/FS.h +++ b/cores/oak/FS.h @@ -21,8 +21,8 @@ #ifndef FS_H #define FS_H -#include #include +#include namespace fs { @@ -59,9 +59,14 @@ class File : public Stream int read() override; int peek() override; void flush() override; - + size_t readBytes(char *buffer, size_t length) override { + return read((uint8_t*)buffer, length); + } size_t read(uint8_t* buf, size_t size); bool seek(uint32_t pos, SeekMode mode); + bool seek(uint32_t pos) { + return seek(pos, SeekSet); + } size_t position() const; size_t size() const; void close(); @@ -100,7 +105,8 @@ class FS FS(FSImplPtr impl) : _impl(impl) { } bool begin(); - + void end(); + bool format(); bool info(FSInfo& info); @@ -125,6 +131,7 @@ class FS } // namespace fs +#ifndef FS_NO_GLOBALS using fs::FS; using fs::File; using fs::Dir; @@ -133,7 +140,10 @@ using fs::SeekSet; using fs::SeekCur; using fs::SeekEnd; using fs::FSInfo; +#endif //FS_NO_GLOBALS -extern FS SPIFFS; +#if !defined(NO_GLOBAL_INSTANCES) && !defined(NO_GLOBAL_SPIFFS) +extern fs::FS SPIFFS; +#endif #endif //FS_H diff --git a/cores/oak/FSImpl.h b/cores/oak/FSImpl.h index c96ea07..e5694b5 100644 --- a/cores/oak/FSImpl.h +++ b/cores/oak/FSImpl.h @@ -63,6 +63,7 @@ class DirImpl { class FSImpl { public: virtual bool begin() = 0; + virtual void end() = 0; virtual bool format() = 0; virtual bool info(FSInfo& info) = 0; virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0; From 2d40450736d634717cf09f19ee44f0387dbf4c6f Mon Sep 17 00:00:00 2001 From: Peter Feerick Date: Mon, 10 Apr 2017 11:05:17 +1000 Subject: [PATCH 2/2] Rolling back some additions form last commit It looks like I was a bit too hasty in saying no code-breaking changes... some of the changes were reliant on other changes in the core. So now this is *just* the global re-defines needed to remove SD/FS conflicts. --- cores/oak/FS.cpp | 6 ------ cores/oak/FS.h | 13 +++---------- cores/oak/FSImpl.h | 1 - 3 files changed, 3 insertions(+), 17 deletions(-) diff --git a/cores/oak/FS.cpp b/cores/oak/FS.cpp index 6ae11e1..55bae8f 100644 --- a/cores/oak/FS.cpp +++ b/cores/oak/FS.cpp @@ -167,12 +167,6 @@ bool FS::begin() { return _impl->begin(); } -void FS::end() { - if (_impl) { - _impl->end(); - } -} - bool FS::format() { if (!_impl) { return false; diff --git a/cores/oak/FS.h b/cores/oak/FS.h index 79620f9..07cd814 100644 --- a/cores/oak/FS.h +++ b/cores/oak/FS.h @@ -21,8 +21,8 @@ #ifndef FS_H #define FS_H -#include #include +#include namespace fs { @@ -59,14 +59,9 @@ class File : public Stream int read() override; int peek() override; void flush() override; - size_t readBytes(char *buffer, size_t length) override { - return read((uint8_t*)buffer, length); - } + size_t read(uint8_t* buf, size_t size); bool seek(uint32_t pos, SeekMode mode); - bool seek(uint32_t pos) { - return seek(pos, SeekSet); - } size_t position() const; size_t size() const; void close(); @@ -105,8 +100,7 @@ class FS FS(FSImplPtr impl) : _impl(impl) { } bool begin(); - void end(); - + bool format(); bool info(FSInfo& info); @@ -130,7 +124,6 @@ class FS }; } // namespace fs - #ifndef FS_NO_GLOBALS using fs::FS; using fs::File; diff --git a/cores/oak/FSImpl.h b/cores/oak/FSImpl.h index e5694b5..c96ea07 100644 --- a/cores/oak/FSImpl.h +++ b/cores/oak/FSImpl.h @@ -63,7 +63,6 @@ class DirImpl { class FSImpl { public: virtual bool begin() = 0; - virtual void end() = 0; virtual bool format() = 0; virtual bool info(FSInfo& info) = 0; virtual FileImplPtr open(const char* path, OpenMode openMode, AccessMode accessMode) = 0;