From 867b5235882492af850eb5005f1920c56d8f4f00 Mon Sep 17 00:00:00 2001 From: Luc Date: Mon, 28 Oct 2019 09:04:59 +0100 Subject: [PATCH] Use global FILE_OPEN WRITE an APPEND same meaning no need different define use only one for all filesystem --- esp3d/configuration.h | 7 +++++-- esp3d/src/core/espcmd/ESP740.cpp | 4 ++-- esp3d/src/core/espcmd/ESP750.cpp | 2 +- esp3d/src/include/defines.h | 10 ++++++++++ esp3d/src/modules/filesystem/esp_filesystem.h | 3 --- esp3d/src/modules/filesystem/esp_sd.h | 5 +---- esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp | 10 +++++----- esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp | 10 +++++----- esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp | 10 +++++----- esp3d/src/modules/filesystem/sd/sdio_esp32.cpp | 10 +++++----- esp3d/src/modules/http/handles/handle-SD-files.cpp | 2 +- esp3d/src/modules/http/handles/upload-SD-files.cpp | 2 +- 12 files changed, 41 insertions(+), 34 deletions(-) diff --git a/esp3d/configuration.h b/esp3d/configuration.h index 5844ce3c..131e4154 100644 --- a/esp3d/configuration.h +++ b/esp3d/configuration.h @@ -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 diff --git a/esp3d/src/core/espcmd/ESP740.cpp b/esp3d/src/core/espcmd/ESP740.cpp index c2fe58eb..386a9150 100644 --- a/esp3d/src/core/espcmd/ESP740.cpp +++ b/esp3d/src/core/espcmd/ESP740.cpp @@ -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) { diff --git a/esp3d/src/core/espcmd/ESP750.cpp b/esp3d/src/core/espcmd/ESP750.cpp index c0fa10e2..b0e64f17 100644 --- a/esp3d/src/core/espcmd/ESP750.cpp +++ b/esp3d/src/core/espcmd/ESP750.cpp @@ -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"); diff --git a/esp3d/src/include/defines.h b/esp3d/src/include/defines.h index 4638383c..28a3fd71 100644 --- a/esp3d/src/include/defines.h +++ b/esp3d/src/include/defines.h @@ -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 diff --git a/esp3d/src/modules/filesystem/esp_filesystem.h b/esp3d/src/modules/filesystem/esp_filesystem.h index 6867391c..b42eb56c 100644 --- a/esp3d/src/modules/filesystem/esp_filesystem.h +++ b/esp3d/src/modules/filesystem/esp_filesystem.h @@ -24,9 +24,6 @@ #ifdef FILESYSTEM_TIMESTAMP_FEATURE #include #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:" diff --git a/esp3d/src/modules/filesystem/esp_sd.h b/esp3d/src/modules/filesystem/esp_sd.h index 05b5b9b6..c22b01ff 100644 --- a/esp3d/src/modules/filesystem/esp_sd.h +++ b/esp3d/src/modules/filesystem/esp_sd.h @@ -25,9 +25,6 @@ #ifdef SD_TIMESTAMP_FEATURE #include #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); diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index 2e493e40..ed6e28e8 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -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(); } diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp index 57134f4c..cb4969fa 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp @@ -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(); } diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp index d497dd98..ebbbb0c8 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp @@ -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(); } diff --git a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp index 7de3ccf4..376d3e56 100644 --- a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp @@ -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(); } diff --git a/esp3d/src/modules/http/handles/handle-SD-files.cpp b/esp3d/src/modules/http/handles/handle-SD-files.cpp index 83d133fc..cdf46f5f 100644 --- a/esp3d/src/modules/http/handles/handle-SD-files.cpp +++ b/esp3d/src/modules/http/handles/handle-SD-files.cpp @@ -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) { diff --git a/esp3d/src/modules/http/handles/upload-SD-files.cpp b/esp3d/src/modules/http/handles/upload-SD-files.cpp index 21f440ce..666eb889 100644 --- a/esp3d/src/modules/http/handles/upload-SD-files.cpp +++ b/esp3d/src/modules/http/handles/upload-SD-files.cpp @@ -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