FastLED 3.9.15
Loading...
Searching...
No Matches
file_system.h
Go to the documentation of this file.
1#pragma once
2
3// Note, fs.h breaks ESPAsyncWebServer so we use file_system.h instead.
4
5#include <stdint.h>
6#include <stddef.h>
7
8#include "fl/namespace.h"
9#include "fl/ptr.h"
10#include "fx/video.h"
11#include "fl/str.h"
12
13
14namespace fl {
15
17// PLATFORM INTERFACE
18// You need to define this for your platform.
19// Otherwise a null filesystem will be used that will do nothing but spew warnings, but otherwise
20// won't crash the system.
21FsImplPtr make_sdcard_filesystem(int cs_pin);
22}
23
25struct CRGB;
27
28namespace fl {
29
30class ScreenMap;
33class Video;
34template<typename Key, typename Value, size_t N> class FixedMap;
35
36
37
38
39class JsonDocument;
40
42 public:
43 FileSystem();
44 bool beginSd(int cs_pin); // Signal to begin using the filesystem resource.
45 bool begin(FsImplPtr platform_filesystem); // Signal to begin using the filesystem resource.
46 void end(); // Signal to end use of the file system.
47
48
49 FileHandlePtr openRead(const char *path); // Null if file could not be opened.
50 Video openVideo(const char *path, size_t pixelsPerFrame, float fps = 30.0f, size_t nFrameHistory = 0); // Null if video could not be opened.
51 bool readText(const char *path, Str* out);
52 bool readJson(const char *path, JsonDocument* doc);
53 bool readScreenMaps(const char *path, FixedMap<Str, ScreenMap, 16>* out, Str* error = nullptr);
54 bool readScreenMap(const char *path, const char* name, ScreenMap* out, Str* error = nullptr);
55 void close(FileHandlePtr file);
56
57 private:
58 FsImplPtr mFs; // System dependent filesystem.
59};
60
61
62
63// An abstract class that represents a file handle.
64// Devices like the SD card will return one of these.
65class FileHandle: public Referent {
66 public:
67 virtual ~FileHandle() {}
68 virtual bool available() const = 0;
69 virtual size_t bytesLeft() const;
70 virtual size_t size() const = 0;
71 virtual size_t read(uint8_t *dst, size_t bytesToRead) = 0;
72 virtual size_t pos() const = 0;
73 virtual const char* path() const = 0;
74 virtual bool seek(size_t pos) = 0;
75 virtual void close() = 0;
76 virtual bool valid() const = 0;
77
78 // convenience functions
79 size_t readCRGB(CRGB* dst, size_t n) {
80 return read((uint8_t*)dst, n * 3) / 3;
81 }
82};
83
84// Platforms will subclass this to implement the filesystem.
85class FsImpl : public Referent {
86 public:
87 struct Visitor {
88 virtual ~Visitor() {}
89 virtual void accept(const char* path) = 0;
90 };
91 FsImpl() = default;
92 virtual ~FsImpl() {} // Use default pins for spi.
93 virtual bool begin() = 0;
94 // End use of card
95 virtual void end() = 0;
96 virtual void close(FileHandlePtr file) = 0;
97 virtual FileHandlePtr openRead(const char *path) = 0;
98
99 virtual bool ls(Visitor &visitor) {
100 // todo: implement.
101 (void)visitor;
102 return false;
103 }
104};
105
106} // namespace fl
virtual ~FileHandle()
Definition file_system.h:67
size_t readCRGB(CRGB *dst, size_t n)
Definition file_system.h:79
virtual bool seek(size_t pos)=0
virtual size_t size() const =0
virtual bool available() const =0
virtual size_t bytesLeft() const
virtual size_t read(uint8_t *dst, size_t bytesToRead)=0
virtual void close()=0
virtual const char * path() const =0
virtual bool valid() const =0
virtual size_t pos() const =0
FileHandlePtr openRead(const char *path)
bool beginSd(int cs_pin)
Video openVideo(const char *path, size_t pixelsPerFrame, float fps=30.0f, size_t nFrameHistory=0)
bool readScreenMap(const char *path, const char *name, ScreenMap *out, Str *error=nullptr)
bool readScreenMaps(const char *path, FixedMap< Str, ScreenMap, 16 > *out, Str *error=nullptr)
bool readText(const char *path, Str *out)
bool readJson(const char *path, JsonDocument *doc)
bool begin(FsImplPtr platform_filesystem)
FsImplPtr mFs
Definition file_system.h:58
void close(FileHandlePtr file)
FsImpl()=default
virtual bool begin()=0
virtual void close(FileHandlePtr file)=0
virtual ~FsImpl()
Definition file_system.h:92
virtual FileHandlePtr openRead(const char *path)=0
virtual void end()=0
virtual bool ls(Visitor &visitor)
Definition file_system.h:99
Referent()
Definition ref.cpp:7
Definition str.h:368
#define FASTLED_SMART_PTR(type)
Definition ptr.h:17
#define FASTLED_NAMESPACE_END
Definition namespace.h:22
Implements the FastLED namespace macros.
FsImplPtr make_sdcard_filesystem(int cs_pin)
Implements a simple red square effect for 2D LED grids.
Definition crgb.h:16
Representation of an RGB pixel (Red, Green, Blue)
Definition crgb.h:54
virtual void accept(const char *path)=0