FastLED
3.9.3
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 "namespace.h"
9
#include "ref.h"
10
#include "fx/video.h"
11
12
FASTLED_NAMESPACE_BEGIN
13
14
FASTLED_SMART_REF(
FsImpl
);
15
16
// Platforms need to implement this to create an instance of the filesystem.
17
FsImplRef make_sdcard_filesystem(
int
cs_pin);
18
19
FASTLED_SMART_REF(
FileHandle
);
20
class
Video
;
21
22
// Instantiate this with a pin number to create a filesystem.
23
class
FileSystem
{
24
public
:
25
FileSystem
();
26
bool
beginSd(
int
cs_pin);
// Signal to begin using the filesystem resource.
27
bool
begin(FsImplRef platform_filesystem);
// Signal to begin using the filesystem resource.
28
void
end();
// Signal to end use of the file system.
29
30
31
FileHandleRef openRead(
const
char
*path);
// Null if file could not be opened.
32
Video
openVideo(
const
char
*path,
size_t
pixelsPerFrame,
float
fps = 30.0f,
size_t
nFrameHistory = 0);
// Null if video could not be opened.
33
void
close(FileHandleRef file);
34
35
private
:
36
FsImplRef mFs;
// System dependent filesystem.
37
};
38
39
40
41
// An abstract class that represents a file handle.
42
// Devices like the SD card will return one of these.
43
class
FileHandle
:
public
Referent
{
44
public
:
45
virtual
~FileHandle
() {}
46
virtual
bool
available()
const
= 0;
47
virtual
size_t
bytesLeft()
const
;
48
virtual
size_t
size()
const
= 0;
49
virtual
size_t
read(uint8_t *dst,
size_t
bytesToRead) = 0;
50
virtual
size_t
pos()
const
= 0;
51
virtual
const
char
* path()
const
= 0;
52
virtual
void
seek(
size_t
pos) = 0;
53
virtual
void
close() = 0;
54
};
55
56
// Platforms will subclass this to implement the filesystem.
57
class
FsImpl
:
public
Referent
{
58
public
:
59
struct
Visitor
{
60
virtual
void
accept(
const
char
* path) = 0;
61
};
62
FsImpl
() =
default
;
63
virtual
~FsImpl
() {}
// Use default pins for spi.
64
virtual
bool
begin() = 0;
65
// End use of card
66
virtual
void
end() = 0;
67
virtual
void
close(FileHandleRef file) = 0;
68
virtual
FileHandleRef openRead(
const
char
*path) = 0;
69
70
virtual
bool
ls(Visitor &visitor) {
71
// todo: implement.
72
(void)visitor;
73
return
false
;
74
}
75
};
76
77
FASTLED_NAMESPACE_END
FileHandle
Definition
file_system.h:43
FileSystem
Definition
file_system.h:23
FsImpl
Definition
file_system.h:57
Referent
Definition
ref.h:384
Video
Definition
video.h:23
FsImpl::Visitor
Definition
file_system.h:59
src
file_system.h
Generated on Thu Nov 14 2024 00:00:34 for FastLED by
1.11.0