1#include "fl/file_system.h"
7#include "platforms/wasm/fs_wasm.h"
8#elif __has_include(<SD.h>)
16#include "fl/screenmap.h"
27 bool available()
const override {
return false; }
28 size_t size()
const override {
return 0; }
29 size_t read(uint8_t *dst,
size_t bytesToRead)
override {
31 FASTLED_UNUSED(bytesToRead);
34 size_t pos()
const override {
return 0; }
35 const char *path()
const override {
36 return "NULL FILE HANDLE";
38 bool seek(
size_t pos)
override {
42 void close()
override {}
43 bool valid()
const override {
44 FASTLED_WARN(
"NullFileHandle is not valid");
54 FASTLED_WARN(
"NullFileSystem instantiated as a placeholder, please implement a file system for your platform.");
58 bool begin()
override {
return true; }
59 void end()
override {}
61 void close(FileHandlePtr file)
override {
64 FASTLED_WARN(
"NullFileSystem::close");
67 FileHandlePtr openRead(
const char *_path)
override {
68 FASTLED_UNUSED(_path);
69 FileHandlePtr out = FileHandlePtr::TakeOwnership(
new NullFileHandle());
76bool FileSystem::beginSd(
int cs_pin) {
77 mFs = make_sdcard_filesystem(cs_pin);
85bool FileSystem::begin(FsImplPtr platform_filesystem) {
86 mFs = platform_filesystem;
94size_t FileHandle::bytesLeft()
const {
return size() - pos(); }
96FileSystem::FileSystem() : mFs() {}
99void FileSystem::end() {
105bool FileSystem::readJson(
const char *path,
JsonDocument* doc) {
107 if (!readText(path, &text)) {
110 return parseJson(text.c_str(), doc);
115 if (!readText(path, &text)) {
116 FASTLED_WARN(
"Failed to read file: " << path);
118 *error =
"Failed to read file: ";
124 bool ok = ScreenMap::ParseJson(text.c_str(), out, &err);
126 FASTLED_WARN(
"Failed to parse screen map: " << err.c_str());
133bool FileSystem::readScreenMap(
const char *path,
const char* name,
ScreenMap* out,
Str* error) {
135 if (!readText(path, &text)) {
136 FASTLED_WARN(
"Failed to read file: " << path);
138 *error =
"Failed to read file: ";
144 bool ok = ScreenMap::ParseJson(text.c_str(), name, out, &err);
146 FASTLED_WARN(
"Failed to parse screen map: " << err.c_str());
153void FileSystem::close(FileHandlePtr file) { mFs->close(file); }
155FileHandlePtr FileSystem::openRead(
const char *path) {
return mFs->openRead(path); }
156Video FileSystem::openVideo(
const char *path,
size_t pixelsPerFrame,
float fps,
size_t nFrameHistory) {
157 Video video(pixelsPerFrame, fps, nFrameHistory);
158 FileHandlePtr file = openRead(path);
160 video.setError(
fl::Str(
"Could not open file: ").append(path));
167bool FileSystem::readText(
const char *path,
fl::Str* out) {
168 FileHandlePtr file = openRead(path);
170 FASTLED_WARN(
"Failed to open file: " << path);
173 size_t size = file->size();
174 out->reserve(size + out->size());
176 while (file->available()) {
178 size_t n = file->read(buf,
sizeof(buf));
180 out->append((
const char*)buf, n);
184 FASTLED_DBG_IF(!wrote,
"Failed to write any data to the output string.");
190__attribute__((weak)) FsImplPtr make_sdcard_filesystem(
int cs_pin) {
191 FASTLED_UNUSED(cs_pin);
Implements the FastLED namespace macros.
Implements a simple red square effect for 2D LED grids.