mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-18 03:55:53 +08:00
Use global FILE_OPEN WRITE an APPEND
same meaning no need different define use only one for all filesystem
This commit is contained in:
parent
a27045080f
commit
867b523588
@ -42,6 +42,9 @@
|
||||
//TELNET_FEATURE : enable Telnet function
|
||||
#define TELNET_FEATURE
|
||||
|
||||
//FTP_FEATURE : enable FTP function
|
||||
//#define FTP_FEATURE
|
||||
|
||||
//WS_DATA_FEATURE: allow to connect serial from Websocket
|
||||
#define WS_DATA_FEATURE
|
||||
|
||||
@ -107,7 +110,7 @@
|
||||
//ESP_SD_NATIVE 1 //esp32 / esp8266
|
||||
//ESP_SDIO 2 //esp32 only
|
||||
//ESP_SDFAT 3 //esp8266 (same as native) / esp32
|
||||
#define SD_DEVICE ESP_SD_NATIVE
|
||||
#define SD_DEVICE ESP_SDFAT
|
||||
|
||||
//FILESYSTEM_TIMESTAMP_FEATURE: allow to get last write time from FILESYSTEM files
|
||||
//#define SD_TIMESTAMP_FEATURE
|
||||
@ -122,7 +125,7 @@
|
||||
//ESP_SPIFFS_FILESYSTEM 0
|
||||
//ESP_FAT_FILESYSTEM 1
|
||||
//ESP_LITTLEFS_FILESYSTEM 2
|
||||
#define FILESYSTEM_FEATURE ESP_FAT_FILESYSTEM
|
||||
#define FILESYSTEM_FEATURE ESP_SPIFFS_FILESYSTEM
|
||||
|
||||
//DIRECT_PIN_FEATURE: allow to access pin using ESP201 command
|
||||
#define DIRECT_PIN_FEATURE
|
||||
|
@ -59,7 +59,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
||||
output->printf("Directory on SD : %s", parameter.c_str());
|
||||
output->printLN("");
|
||||
if (ESP_SD::exists(parameter.c_str())) {
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ);
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
|
||||
uint countf = 0;
|
||||
uint countd = 0;
|
||||
if (f) {
|
||||
@ -77,7 +77,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type,
|
||||
sub = f.openNextFile();
|
||||
}
|
||||
f.close();
|
||||
f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_READ);
|
||||
f = ESP_SD::open(parameter.c_str(), ESP_FILE_READ);
|
||||
//Check files
|
||||
sub = f.openNextFile();
|
||||
while (sub) {
|
||||
|
@ -92,7 +92,7 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type,
|
||||
}
|
||||
parameter = get_param (cmd_params, "create=");
|
||||
if (parameter.length() != 0) {
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_WRITE);
|
||||
ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_FILE_WRITE);
|
||||
if (f.isOpen()) {
|
||||
f.close();
|
||||
output->printMSG ("ok");
|
||||
|
@ -116,4 +116,14 @@
|
||||
#define ESP_ERROR_START_UPLOAD 12
|
||||
#define ESP_ERROR_SIZE 13
|
||||
|
||||
//File system
|
||||
#define ESP_FILE_READ 0
|
||||
#define ESP_FILE_WRITE 1
|
||||
#define ESP_FILE_APPEND 2
|
||||
|
||||
#define FS_ROOT 0
|
||||
#define FS_FLASH 1
|
||||
#define FS_SD 2
|
||||
#define FS_USBDISK 3
|
||||
|
||||
#endif //_DEFINES_ESP3D_H
|
||||
|
@ -24,9 +24,6 @@
|
||||
#ifdef FILESYSTEM_TIMESTAMP_FEATURE
|
||||
#include <time.h>
|
||||
#endif //FILESYSTEM_TIMESTAMP_FEATURE
|
||||
#define ESP_FILE_READ 0
|
||||
#define ESP_FILE_WRITE 1
|
||||
#define ESP_FILE_APPEND 2
|
||||
|
||||
#define ESP_FLASH_FS_HEADER "/FS:"
|
||||
|
||||
|
@ -25,9 +25,6 @@
|
||||
#ifdef SD_TIMESTAMP_FEATURE
|
||||
#include <time.h>
|
||||
#endif //SD_TIMESTAMP_FEATURE
|
||||
#define ESP_SD_FILE_READ 0
|
||||
#define ESP_SD_FILE_WRITE 1
|
||||
#define ESP_SD_FILE_APPEND 2
|
||||
|
||||
#define ESP_SD_HEADER "/SD:"
|
||||
|
||||
@ -87,7 +84,7 @@ public:
|
||||
static uint64_t freeBytes();
|
||||
static const char * FilesystemName();
|
||||
static bool format(ESP3DOutput * output = nullptr);
|
||||
static ESP_SDFile open(const char* path, uint8_t mode = ESP_SD_FILE_READ);
|
||||
static ESP_SDFile open(const char* path, uint8_t mode = ESP_FILE_READ);
|
||||
static bool exists(const char* path);
|
||||
static bool remove(const char *path);
|
||||
static bool mkdir(const char *path);
|
||||
|
@ -111,14 +111,14 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
//do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_SD_FILE_WRITE) || (mode == ESP_SD_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
// path must start by '/'
|
||||
if (path[0] != '/') {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_SD_FILE_READ) {
|
||||
if (mode != ESP_FILE_READ) {
|
||||
//check container exists
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') +1);
|
||||
@ -127,8 +127,8 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
File tmp = SD.open(path, (mode == ESP_SD_FILE_READ)?FILE_READ:(mode == ESP_SD_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_SD_FILE_READ)?false:true, path);
|
||||
File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
@ -141,7 +141,7 @@ bool ESP_SD::exists(const char* path)
|
||||
}
|
||||
res = SD.exists(path);
|
||||
if (!res) {
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_SD_FILE_READ);
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
|
||||
if (root) {
|
||||
res = root.isDirectory();
|
||||
}
|
||||
|
@ -586,7 +586,7 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
//do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_SD_FILE_WRITE) || (mode == ESP_SD_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
_sizechanged = true;
|
||||
return ESP_SDFile();
|
||||
}
|
||||
@ -594,7 +594,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
if (path[0] != '/') {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_SD_FILE_READ) {
|
||||
if (mode != ESP_FILE_READ) {
|
||||
//check container exists
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') +1);
|
||||
@ -603,8 +603,8 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
sdfat::File tmp = SD.open(path, (mode == ESP_SD_FILE_READ)?FILE_READ:(mode == ESP_SD_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(),(mode == ESP_SD_FILE_READ)?false:true, path);
|
||||
sdfat::File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
@ -617,7 +617,7 @@ bool ESP_SD::exists(const char* path)
|
||||
}
|
||||
res = SD.exists(path);
|
||||
if (!res) {
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_SD_FILE_READ);
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
|
||||
if (root) {
|
||||
res = root.isDirectory();
|
||||
}
|
||||
|
@ -585,7 +585,7 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
//do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_SD_FILE_WRITE) || (mode == ESP_SD_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
_sizechanged = true;
|
||||
return ESP_SDFile();
|
||||
}
|
||||
@ -593,7 +593,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
if (path[0] != '/') {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_SD_FILE_READ) {
|
||||
if (mode != ESP_FILE_READ) {
|
||||
//check container exists
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') +1);
|
||||
@ -602,8 +602,8 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
File tmp = SD.open(path, (mode == ESP_SD_FILE_READ)?FILE_READ:(mode == ESP_SD_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(),(mode == ESP_SD_FILE_READ)?false:true, path);
|
||||
File tmp = SD.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_WRITE);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDir(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
@ -616,7 +616,7 @@ bool ESP_SD::exists(const char* path)
|
||||
}
|
||||
res = SD.exists(path);
|
||||
if (!res) {
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_SD_FILE_READ);
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
|
||||
if (root) {
|
||||
res = root.isDirectory();
|
||||
}
|
||||
|
@ -100,14 +100,14 @@ bool ESP_SD::format(ESP3DOutput * output)
|
||||
ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
{
|
||||
//do some check
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_SD_FILE_WRITE) || (mode == ESP_SD_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
if(((strcmp(path,"/") == 0) && ((mode == ESP_FILE_WRITE) || (mode == ESP_FILE_APPEND))) || (strlen(path) == 0)) {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
// path must start by '/'
|
||||
if (path[0] != '/') {
|
||||
return ESP_SDFile();
|
||||
}
|
||||
if (mode != ESP_SD_FILE_READ) {
|
||||
if (mode != ESP_FILE_READ) {
|
||||
//check container exists
|
||||
String p = path;
|
||||
p.remove(p.lastIndexOf('/') +1);
|
||||
@ -116,8 +116,8 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode)
|
||||
return ESP_SDFile();
|
||||
}
|
||||
}
|
||||
File tmp = SD_MMC.open(path, (mode == ESP_SD_FILE_READ)?FILE_READ:(mode == ESP_SD_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_SD_FILE_READ)?false:true, path);
|
||||
File tmp = SD_MMC.open(path, (mode == ESP_FILE_READ)?FILE_READ:(mode == ESP_FILE_WRITE)?FILE_WRITE:FILE_APPEND);
|
||||
ESP_SDFile esptmp(&tmp, tmp.isDirectory(),(mode == ESP_FILE_READ)?false:true, path);
|
||||
return esptmp;
|
||||
}
|
||||
|
||||
@ -130,7 +130,7 @@ bool ESP_SD::exists(const char* path)
|
||||
}
|
||||
res = SD_MMC.exists(path);
|
||||
if (!res) {
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_SD_FILE_READ);
|
||||
ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ);
|
||||
if (root) {
|
||||
res = root.isDirectory();
|
||||
}
|
||||
|
@ -144,7 +144,7 @@ void HTTP_Server::handleSDFileList ()
|
||||
_webserver->sendHeader("Cache-Control","no-cache");
|
||||
_webserver->send(200);
|
||||
if (ESP_SD::exists(ptmp.c_str())) {
|
||||
ESP_SDFile f = ESP_SD::open(ptmp.c_str(), ESP_SD_FILE_READ);
|
||||
ESP_SDFile f = ESP_SD::open(ptmp.c_str(), ESP_FILE_READ);
|
||||
//Parse files
|
||||
ESP_SDFile sub = f.openNextFile();
|
||||
if (f) {
|
||||
|
@ -78,7 +78,7 @@ void HTTP_Server::SDFileupload ()
|
||||
}
|
||||
if (_upload_status!=UPLOAD_STATUS_FAILED) {
|
||||
//create file
|
||||
fsUploadFile = ESP_SD::open(filename.c_str(), ESP_SD_FILE_WRITE);
|
||||
fsUploadFile = ESP_SD::open(filename.c_str(), ESP_FILE_WRITE);
|
||||
//check If creation succeed
|
||||
if (fsUploadFile) {
|
||||
//if yes upload is started
|
||||
|
Loading…
x
Reference in New Issue
Block a user