Open Font Render 1.2
Loading...
Searching...
No Matches
WioTerminal_SD_Preset.h
Go to the documentation of this file.
1// -------------------------------------------------------
2// WioTerminal_SD_Preset.h
3//
4// Copyright (c) 2021 takkaO
5//
6// If you use, modify, or redistribute this file independently
7// of the original repository, this program is licensed under
8// the MIT License.
9//
10// If you use, modify or redistribute this file as part of
11// the original repository, please follow the repository's license.
12//
13// -------------------------------------------------------
14
15#ifndef OFR_WIO_TERMINAL_SD_PRESET_H
16#define OFR_WIO_TERMINAL_SD_PRESET_H
17
18#include <SPI.h>
19#include <Seeed_Arduino_FS.h>
20#include <list>
21
22std::list<File> ofr_file_list; // For multiple file loading
23
24FT_FILE *OFR_fopen(const char *filename, const char *mode) {
25 File f;
26 if (strcmp(mode, "r") == 0) {
27 f = SD.open(filename, FA_READ);
28 } else if (strcmp(mode, "r+") == 0) {
29 f = SD.open(filename, FA_READ | FA_WRITE);
30 } else if (strcmp(mode, "w") == 0) {
31 f = SD.open(filename, FA_CREATE_ALWAYS | FA_WRITE);
32 } else if (strcmp(mode, "w+") == 0) {
33 f = SD.open(filename, FA_CREATE_ALWAYS | FA_WRITE | FA_READ);
34 } else if (strcmp(mode, "a") == 0) {
35 f = SD.open(filename, FA_OPEN_APPEND | FA_WRITE);
36 } else if (strcmp(mode, "a+") == 0) {
37 f = SD.open(filename, FA_OPEN_APPEND | FA_WRITE | FA_READ);
38 } else if (strcmp(mode, "wx") == 0) {
39 f = SD.open(filename, FA_CREATE_NEW | FA_WRITE);
40 } else if (strcmp(mode, "w+x") == 0) {
41 f = SD.open(filename, FA_CREATE_NEW | FA_WRITE | FA_READ);
42 } else {
43 f = SD.open(filename, FA_READ);
44 }
45 ofr_file_list.push_back(f);
46 return &ofr_file_list.back();
47}
48
49void OFR_fclose(FT_FILE *stream) {
50 ((File *)stream)->close();
51}
52
53size_t OFR_fread(void *ptr, size_t size, size_t nmemb, FT_FILE *stream) {
54 return ((File *)stream)->read((uint8_t *)ptr, size * nmemb);
55}
56
57int OFR_fseek(FT_FILE *stream, long int offset, int whence) {
58 return ((File *)stream)->seek(offset, (SeekMode)whence);
59}
60
61long int OFR_ftell(FT_FILE *stream) {
62 return ((File *)stream)->position();
63}
64
65#endif /* OFR_M5STACK_SD_PRESET_H */
#define FT_FILE
Definition: FileSupport.h:16
int OFR_fseek(FT_FILE *stream, long int offset, int whence)
Moves the cursor to the specified position.
Definition: WioTerminal_SD_Preset.h:57
long int OFR_ftell(FT_FILE *stream)
Get file cursor position.
Definition: WioTerminal_SD_Preset.h:61
size_t OFR_fread(void *ptr, size_t size, size_t nmemb, FT_FILE *stream)
Read data from a file and store it in a buffer.
Definition: WioTerminal_SD_Preset.h:53
FT_FILE * OFR_fopen(const char *filename, const char *mode)
Open file and get file pointer.
Definition: WioTerminal_SD_Preset.h:24
std::list< File > ofr_file_list
Definition: WioTerminal_SD_Preset.h:22
void OFR_fclose(FT_FILE *stream)
Close file.
Definition: WioTerminal_SD_Preset.h:49