FastLED 3.9.7
Loading...
Searching...
No Matches
file_system.h
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
16FASTLED_SMART_PTR(FsImpl);
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;
31FASTLED_SMART_PTR(FileSystem);
32FASTLED_SMART_PTR(FileHandle);
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
Definition str.h:336
Implements the FastLED namespace macros.
#define FASTLED_NAMESPACE_END
End of the FastLED namespace.
Definition namespace.h:16
#define FASTLED_NAMESPACE_BEGIN
Start of the FastLED namespace.
Definition namespace.h:14
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