diff --git a/flash_filer.cpp b/flash_filer.cpp index d273a63..1d3bead 100644 --- a/flash_filer.cpp +++ b/flash_filer.cpp @@ -25,10 +25,10 @@ static Dir dir; bool flash_filer::seek(uint32_t pos) { #if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) - _pos = _len = 0; return file.seek(pos); -#endif +#else return false; +#endif } bool flash_filer::start() @@ -41,7 +41,6 @@ bool flash_filer::start() return false; #endif - _pos = _len = 0; return true; } @@ -54,15 +53,25 @@ void flash_filer::stop() bool flash_filer::more() { - if (_pos >= _len) { - _pos = 0; #if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) - _len = file.read(_buf, sizeof(_buf)); + return file.available() > 0; +#else + return false; +#endif +} + +uint8_t flash_filer::read() { +#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) + return file.read(); +#else + return 0xff; +#endif +} + +void flash_filer::write(uint8_t b) { +#if defined(USE_SD) || defined(USE_SPIFFS) || defined(USE_FS) + file.write(b); #endif - if (_len == 0) // eof - return false; - } - return true; } const char *flash_filer::advance() { @@ -73,7 +82,7 @@ const char *flash_filer::advance() { static char buf[32]; while (true) { if (dir.next()) { - file = dir.openFile("r"); + file = dir.openFile("rb+"); break; } dir = SPIFFS.openDir(_programs); diff --git a/flash_filer.h b/flash_filer.h index 5004605..f56f2e9 100644 --- a/flash_filer.h +++ b/flash_filer.h @@ -17,12 +17,11 @@ public: void stop(); bool seek(uint32_t pos); - uint8_t read() { return _buf[_pos++]; } bool more(); + uint8_t read(); + void write(uint8_t); private: const char *_programs; - unsigned _pos, _len; - uint8_t _buf[128]; }; #endif