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