Teensy 4.1 core updated for C++20
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

74 lines
1.5KB

  1. /* Experimental File & FS base classes.
  2. */
  3. #ifndef FS_H
  4. #define FS_H
  5. #ifdef __cplusplus
  6. #include <Arduino.h>
  7. #define FILE_READ 0
  8. #define FILE_WRITE 1
  9. enum SeekMode {
  10. SeekSet = 0,
  11. SeekCur = 1,
  12. SeekEnd = 2
  13. };
  14. class File;
  15. class File : public Stream {
  16. public:
  17. constexpr File() : f(nullptr) { }
  18. constexpr File(const File &file) : f(file.f) { }
  19. virtual ~File();
  20. virtual size_t read(void *buf, size_t nbyte);
  21. virtual size_t write(const void *buf, size_t size);
  22. virtual int available();
  23. virtual int read();
  24. virtual int peek();
  25. virtual void flush();
  26. virtual bool seek(uint32_t pos, int mode);
  27. virtual uint32_t position() const;
  28. virtual uint32_t size() const;
  29. virtual void close();
  30. virtual operator bool() const;
  31. virtual const char* name();
  32. virtual bool isDirectory();
  33. virtual File openNextFile(uint8_t mode=0);
  34. virtual void rewindDirectory(void);
  35. virtual bool seek(uint32_t pos) {
  36. return seek(pos, SeekSet);
  37. }
  38. virtual size_t write(uint8_t b) {
  39. return write(&b, 1);
  40. }
  41. virtual size_t write(const char *str) {
  42. return write(str, strlen(str));
  43. }
  44. virtual size_t readBytes(char *buffer, size_t length) {
  45. return read(buffer, length);
  46. }
  47. virtual void whoami(); // testing only
  48. //protected:
  49. File *f; // points to actual implementing class, or nullptr
  50. };
  51. class FS
  52. {
  53. public:
  54. FS() {}
  55. File open(const char *filename, uint8_t mode = FILE_READ);
  56. bool exists(const char *filepath);
  57. bool mkdir(const char *filepath);
  58. bool remove(const char *filepath);
  59. bool rmdir(const char *filepath);
  60. };
  61. #endif // __cplusplus
  62. #endif // FS_H