FastLED 3.10.6
Loading...
Searching...
No Matches
fs.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/stl/int.h"
6
7#include "fl/stl/shared_ptr.h" // IWYU pragma: export
8#include "fl/fs/fstream.h" // IWYU pragma: export
9#include "fl/stl/flat_map.h" // IWYU pragma: export
10#include "fl/stl/string.h" // IWYU pragma: export
11#include "fl/fx/video.h" // IWYU pragma: export
12#include "fl/codec/jpeg.h" // IWYU pragma: export
13#include "fl/stl/compiler_control.h" // IWYU pragma: export
14#include "fl/stl/noexcept.h"
15#include "fl/fs/backend.h" // FsImpl, FsImplPtr // IWYU pragma: export
16
17// Test-only hooks live in their own header so this one declares only the
18// public API (FastLED #4003). Included under the same guard so existing
19// test code keeps resolving them transitively.
20#ifdef FASTLED_TESTING
21#include "fl/fs/testing.h" // IWYU pragma: export
22#endif
23
24// Forward declaration -- concrete Mp3Decoder lives in fl/codec/mp3.h
25namespace fl {
26class Mp3Decoder;
28}
29
30namespace fl {
31
32// PLATFORM INTERFACE
33// You need to define this for your platform.
34// Otherwise a null filesystem will be used that will do nothing but spew
35// warnings, but otherwise won't crash the system.
36FsImplPtr make_sdcard_filesystem(int cs_pin);
37
44inline FsImplPtr getSdFs(int cs_pin) FL_NO_EXCEPT {
45 return make_sdcard_filesystem(cs_pin);
46}
47
48
49} // namespace fl
50
51namespace fl {
52
53class ScreenMap;
54class Fled;
56class Video;
57template <typename Key, typename Value, fl::size N> class unsorted_map_fixed;
58
59namespace json2 {
60class json;
61}
62
64 public:
66
67 // Convenience factory: construct + beginSd in one call. Returns a
68 // default-constructed FileSystem if the SD card could not be opened
69 // (the typical begin() failure case). Sugar for code that wants to
70 // chain straight into loadFled / openVideo / openRead.
71 static FileSystem sd(int cs_pin) FL_NO_EXCEPT;
72
73 bool beginSd(int cs_pin) FL_NO_EXCEPT; // Signal to begin using the filesystem resource.
74 bool begin(FsImplPtr platform_filesystem); // Signal to begin using the
75 // filesystem resource.
76 void end(); // Signal to end use of the file system.
77
79 openRead(const char *path); // Returns closed ifstream if file could not be opened.
80 Video
81 openVideo(const char *path, fl::size pixelsPerFrame, float fps = 30.0f,
82 fl::size nFrameHistory = 0); // Null if video could not be opened.
83 Video
84 openMpeg1Video(const char *path, fl::size pixelsPerFrame, float fps = 30.0f,
85 fl::size nFrameHistory = 0); // Open MPEG1 video file
86 bool readText(const char *path, string *out);
87 bool readJson(const char *path, json *doc);
88 bool readScreenMaps(const char *path, fl::flat_map<string, ScreenMap> *out,
89 string *error = nullptr);
90 bool readScreenMap(const char *path, const char *name, ScreenMap *out,
91 string *error = nullptr);
92 // Load JPEG image from file path directly to Frame
93 FramePtr loadJpeg(const char *path, const JpegConfig &config = JpegConfig(),
94 fl::string *error_message = nullptr);
95
96 // Open MP3 audio file and return streaming decoder
97 fl::Mp3DecoderPtr openMp3(const char *path,
98 fl::string *error_message = nullptr);
99
100 // One-line sugar for fl::Fled::load(*this, path). Returns a null
101 // Fled if the file could not be opened or is malformed - the Fled
102 // class itself owns all the failure-mode bookkeeping.
103 fl::Fled loadFled(const char *path) FL_NO_EXCEPT;
104
105 private:
106 FsImplPtr mFs; // System dependent filesystem.
107};
108
109
110// Standalone helper function to load JPEG from SD card
111// Combines SD card initialization and JPEG loading in one convenient function
112FramePtr loadJpegFromSD(int cs_pin, const char *filepath,
113 const JpegConfig &config = JpegConfig(),
114 fl::string *error_message = nullptr) FL_NO_EXCEPT;
115
116} // namespace fl
The interface a storage backend implements.
bool readText(const char *path, string *out)
Definition fs.cpp.hpp:191
static FileSystem sd(int cs_pin) FL_NO_EXCEPT
Video openMpeg1Video(const char *path, fl::size pixelsPerFrame, float fps=30.0f, fl::size nFrameHistory=0)
bool beginSd(int cs_pin) FL_NO_EXCEPT
bool readJson(const char *path, json *doc)
Definition fs.cpp.hpp:117
fl::ifstream openRead(const char *path)
Definition fs.cpp.hpp:170
bool readScreenMap(const char *path, const char *name, ScreenMap *out, string *error=nullptr)
Definition fs.cpp.hpp:149
fl::Mp3DecoderPtr openMp3(const char *path, fl::string *error_message=nullptr)
bool begin(FsImplPtr platform_filesystem)
Definition fs.cpp.hpp:96
Video openVideo(const char *path, fl::size pixelsPerFrame, float fps=30.0f, fl::size nFrameHistory=0)
Definition fs.cpp.hpp:179
FramePtr loadJpeg(const char *path, const JpegConfig &config=JpegConfig(), fl::string *error_message=nullptr)
FsImplPtr mFs
Definition fs.h:106
bool readScreenMaps(const char *path, fl::flat_map< string, ScreenMap > *out, string *error=nullptr)
Definition fs.cpp.hpp:128
FileSystem() FL_NO_EXCEPT
Definition fs.cpp.hpp:109
fl::Fled loadFled(const char *path) FL_NO_EXCEPT
Definition fs.cpp.hpp:105
Definition fs.h:59
FramePtr loadJpegFromSD(int cs_pin, const char *filepath, const JpegConfig &config, fl::string *error_message) FL_NO_EXCEPT
Definition fs.cpp.hpp:215
FsImplPtr getSdFs(int cs_pin) FL_NO_EXCEPT
Removable SD card on the given chip-select pin.
Definition fs.h:44
InputGamut g FL_NO_EXCEPT
Definition rgbw.h:121
FsImplPtr make_sdcard_filesystem(int cs_pin)
fl::shared_ptr< Mp3Decoder > Mp3DecoderPtr
Definition fs.h:27
Base definition for an LED controller.
Definition crgb.hpp:179
#define FASTLED_SHARED_PTR(type)
Definition shared_ptr.h:565
Test-only filesystem hooks.