-
Notifications
You must be signed in to change notification settings - Fork 0
/
fsx.h
135 lines (114 loc) · 3.82 KB
/
fsx.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
#ifndef FSX_H
#define FSX_H
//#define HTTP_UPLOAD_BUFLEN (1436 * 4)
#include <WiFi.h>
#include <WiFiClient.h>
#include <esp_wifi.h>
#include <WiFiMulti.h>
#include <AsyncTCP.h>
#include <ESPAsyncWebServer.h>
#include <ESPmDNS.h>
#include <Update.h>
#include "soc/timer_group_struct.h"
#include "soc/timer_group_reg.h"
#include <esp_task_wdt.h>
#include <dirent.h>
#include <FS.h>
#include <FFat.h>
#include <SPIFFS.h>
#include <LITTLEFS.h>
#include <esp_littlefs.h>
#include <SD_MMC.h>
#include <vector>
#include <string.h>
#include <errno.h>
#include <stdio.h>
#include <hwcrypto/aes.h>
#include <freertos/queue.h>
#include <freertos/task.h>
#include <freertos/portmacro.h>
#include <freertos/semphr.h>
#include <wificredentials.h>
#include "listFS.h"
#define FSDSD_MMC 0
#define FSDSPIFFS 1
#define FSDLITTLEFS 2
#define FSDFFAT 3
struct fsd{
fs::FS *f;
char fsname[16]; // file system name (without trailing ':') for use with Arduino C++ interface
char fsmount[16]; // topdirectoryname (with preceding '/') when using C-style file operations
uint8_t fsnumber; // fs number one of FSD... defines above
uint64_t totalBytes;
uint64_t freeBytes;
uint64_t usedBytes;
};
struct appconfig{
uint32_t pauseseconds;
bool portland;
bool adapt_rotation;
uint8_t portrait;
uint8_t landscape;
};
extern struct appconfig settings;
static const char* settings_format PROGMEM="{\n\t\"portland\" : %d,\n\t\"pauseseconds\" : %d,\n \t\"adapt_rotation\" : %d,\n \t\"portrait\" : %d,\n\t\"landscape\" : %d\n}\n";
static const char* updateform PROGMEM= "<form method='POST' action='/update' enctype='multipart/form-data'><input type='file' name='update'><input type='submit' value='Update'></form>";
static const char *cperror[7] PROGMEM = {"ok" ,
"source directory not found" ,
"source file not found" ,
"source directory in targetdirectory" ,
"error allocating memory for readbuffer"
"error reading source file" ,
"error writing target file",
"error creating target directory"};
static const char uploadpage[] PROGMEM =
R"(
<!DOCTYPE html>
<html>
<head>
<meta charset='UTF-8'>
<meta name='viewport' content='width=device-width, initial-scale=1.0'>
<style>
body {
font-family: Arial, Helvetica, sans-serif;
background: lightgrey;
}
</style>
</head>
<html>
<h2>Upload file</h2>
<form method='POST' action='/upload' enctype='multipart/form-data' id='f' '>
<table>
<tr><td>Local file to upload </td><td><input type='file' name='blob' style='width: 300px;' id='pt'></td></tr>
<tr><td colspan=2> <input type='submit' value='Upload'></td></tr>
</table>
</form>
</html>)";
extern std::vector<struct fsd> fsdlist;
extern AsyncWebServer fsxserver;
extern TaskHandle_t startwifiTask;
extern TaskHandle_t FSXServerTask;
extern TaskHandle_t tftshowTask;
extern SemaphoreHandle_t updateSemaphore;
extern SemaphoreHandle_t tftSemaphore;
void fs2json( fs::FS &fs, const char *fsmount, const char *dirname, char **s , int depth = 0);
void allfs2json( char **s);
bool write_list( char *readbuffer, size_t len );
void mount_fs();
fs::FS *fsfromfile( const char *fullfilename );
char *nameoffs( fs::FS *ff );
size_t fileoffset( const char *fullfilename );
bool isdir( const char *fullfilename );
bool sourceintarget( String& sourcepath, String& targetpath );
int makepath( fs::FS &ff, String &pstring );
void maketargetpath( String& filename, String& targetdir, String& newpath );
void deltree( fs::FS *ff, const char *path );
int copyfile( fs::FS *sourcefs, String &sourcefspath, fs::FS *targetfs, String &targetfspath);
int copytree( fs::FS *sourcefs, String &sourcefspath, fs::FS *targetfs, String &targetfspath);
void startWiFi();
void startFSXServer();
void startTFT();
void init_config();
bool read_config();
bool write_config();
#endif