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