Sfoglia il codice sorgente

File base class (work in progress)

main
PaulStoffregen 4 anni fa
parent
commit
7d91561020
1 ha cambiato i file con 37 aggiunte e 36 eliminazioni
  1. +37
    -36
      teensy3/FS.h

+ 37
- 36
teensy3/FS.h Vedi File

@@ -1,27 +1,28 @@
/* Experimental File & Dir base classes. VERY experimental!

These are intended to someday allow libraries using files,
such as a JPEG decoder, to accept a File object from SD,
Bridge, USB Host, ESP SPIFFS, and others. Perhaps only a
distant dream at this point, but maybe someday....
/* Experimental File & FS base classes.
*/


#ifndef FS_H
#define FS_H
#ifdef __cplusplus

#include "Stream.h"
#include "WString.h"
#include <Arduino.h>

#define FILE_READ 0
#define FILE_WRITE 1

enum SeekMode {
SeekSet = 0,
SeekCur = 1,
SeekEnd = 2
};

class File;

class File : public Stream {
public:
constexpr File() {}
enum SeekMode {
SeekSet = 0,
SeekCur = 1,
SeekEnd = 2
};
constexpr File() : f(nullptr) { }
constexpr File(const File &file) : f(file.f) { }
virtual ~File();
virtual size_t read(void *buf, size_t nbyte);
virtual size_t write(const void *buf, size_t size);
virtual int available();
@@ -33,40 +34,40 @@ public:
virtual uint32_t size() const;
virtual void close();
virtual operator bool() const;
//virtual const char* name() const; // why does ESP have this in File?
virtual const char* name();
virtual bool isDirectory();
virtual File openNextFile(uint8_t mode=0);
virtual void rewindDirectory(void);

bool seek(uint32_t pos) {
virtual bool seek(uint32_t pos) {
return seek(pos, SeekSet);
}
size_t write(uint8_t b) {
virtual size_t write(uint8_t b) {
return write(&b, 1);
}
size_t write(const char *str) {
virtual size_t write(const char *str) {
return write(str, strlen(str));
}
size_t readBytes(char *buffer, size_t length) {
virtual size_t readBytes(char *buffer, size_t length) {
return read(buffer, length);
}

// needed for compatiblity with Arduino's SD & Bridge libs
virtual const char* name();
virtual bool isDirectory();
virtual File openNextFile(uint8_t mode=0);
virtual void rewindDirectory(void);
virtual void whoami(); // testing only
//protected:
File *f; // points to actual implementing class, or nullptr
};

class Dir {

class FS
{
public:
constexpr Dir() {}
virtual const char *name(); // from SD's File (and ESP's File)
virtual uint32_t fileSize();
virtual bool isDirectory(); // from SD, not in ESP
virtual File openFile(const char *mode);
virtual bool next();
String fileName() {
return String(name());
}
FS() {}
File open(const char *filename, uint8_t mode = FILE_READ);
bool exists(const char *filepath);
bool mkdir(const char *filepath);
bool remove(const char *filepath);
bool rmdir(const char *filepath);
};


#endif // __cplusplus
#endif // FS_H

Loading…
Annulla
Salva