diff --git a/esp3d/src/include/esp3d_version.h b/esp3d/src/include/esp3d_version.h index 09cbf2dc..3671f4d4 100644 --- a/esp3d/src/include/esp3d_version.h +++ b/esp3d/src/include/esp3d_version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H // version and sources location -#define FW_VERSION "3.0.0.4b1" +#define FW_VERSION "3.0.0.5b1" #define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/esp_sd.cpp b/esp3d/src/modules/filesystem/esp_sd.cpp index 81744ee7..d0b29ce2 100644 --- a/esp3d/src/modules/filesystem/esp_sd.cpp +++ b/esp3d/src/modules/filesystem/esp_sd.cpp @@ -23,7 +23,7 @@ #include #include "esp_sd.h" - +/* #define ESP_MAX_SD_OPENHANDLE 4 #if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266) #define FS_NO_GLOBALS @@ -62,7 +62,7 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; #else #include File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; -#endif +#endif*/ #if defined(ESP3DLIB_ENV) #include "../../include/Marlin/cardreader.h" @@ -138,6 +138,8 @@ bool ESP_SD::disableSharedSD() { bool ESP_SD::_started = false; uint8_t ESP_SD::_state = ESP_SDCARD_NOT_PRESENT; uint8_t ESP_SD::_spi_speed_divider = 1; + + bool ESP_SD::_sizechanged = true; uint8_t ESP_SD::setState(uint8_t flag) { _state = flag; diff --git a/esp3d/src/modules/filesystem/esp_sd.h b/esp3d/src/modules/filesystem/esp_sd.h index 32bc3b6b..0e58d6e2 100644 --- a/esp3d/src/modules/filesystem/esp_sd.h +++ b/esp3d/src/modules/filesystem/esp_sd.h @@ -20,14 +20,9 @@ #ifndef _ESP_SD_H #define _ESP_SD_H -#include -#include "../../core/esp3d_message.h" #include "../../include/esp3d_config.h" - -#define ESP_SD_FS_HEADER "/SD" - -#define ESP_MAX_SD_OPENHANDLE 4 +#include "sd/esp_sd_common.h" class ESP_SDFile { public: diff --git a/esp3d/src/modules/filesystem/sd/esp_sd_common.h b/esp3d/src/modules/filesystem/sd/esp_sd_common.h new file mode 100644 index 00000000..e8f3dea9 --- /dev/null +++ b/esp3d/src/modules/filesystem/sd/esp_sd_common.h @@ -0,0 +1,85 @@ +/* + esp_sd_common.h - ESP3D SD support class + + Copyright (c) 2014 Luc Lebosse. All rights reserved. + + This code is free software; you can redistribute it and/or + modify it under the terms of the GNU Lesser General Public + License as published by the Free Software Foundation; either + version 2.1 of the License, or (at your option) any later version. + + This code is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + Lesser General Public License for more details. + + You should have received a copy of the GNU Lesser General Public + License along with This code; if not, write to the Free Software + Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA +*/ + +#pragma once +#include "../../../include/esp3d_config.h" + +#define ESP_SD_FS_HEADER "/SD" + +#define ESP_MAX_SD_OPENHANDLE 4 + + +#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266) +#define FS_NO_GLOBALS +#define NO_GLOBAL_SD +#include +using ESP3D_File = fs::File; +using ESP3D_SD_Class = SDClass; +#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP8266 + +#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266) +#define FS_NO_GLOBALS +#define NO_GLOBAL_SD +#define DISABLE_FS_H_WARNING 1 +#include +#if SDFAT_FILE_TYPE == 1 +using ESP3D_File = File32; +#elif SDFAT_FILE_TYPE == 2 +using ESP3D_File = ExFile; +#elif SDFAT_FILE_TYPE == 3 +using ESP3D_File = FsFile; +#else // SDFAT_FILE_TYPE +#error Invalid SDFAT_FILE_TYPE +#endif // SDFAT_FILE_TYPE +using ESP3D_SD_Class = SdFat; +#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP8266 + +#if ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32) +#define DISABLE_FS_H_WARNING 1 +#include +#if SDFAT_FILE_TYPE == 1 +using ESP3D_File = File32; +#elif SDFAT_FILE_TYPE == 2 +using ESP3D_File = ExFile; +#elif SDFAT_FILE_TYPE == 3 +using ESP3D_File = FsFile; +#else // SDFAT_FILE_TYPE +#error Invalid SDFAT_FILE_TYPE +#endif // SDFAT_FILE_TYPE +using ESP3D_SD_Class = SdFat; +#endif // ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && defined(ARDUINO_ARCH_ESP32 + +#if (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32) +#include +#include +using ESP3D_File = fs::File; +using ESP3D_SD_Class = fs::SDFS; +#endif // (SD_DEVICE == ESP_SD_NATIVE) && defined(ARDUINO_ARCH_ESP32 + +#if (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32) +#include +#include +using ESP3D_File = fs::File; +using ESP3D_SD_Class = fs::SDMMCFS; +#endif // (SD_DEVICE == ESP_SDIO) && defined(ARDUINO_ARCH_ESP32 + + +extern ESP3D_SD_Class ESP3D_SD_Card; +extern ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; \ No newline at end of file diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index c5871a5a..24eba40d 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -24,14 +24,13 @@ sd_native_esp32.cpp - ESP3D sd support class #include "../../../core/esp3d_settings.h" #include "../esp_sd.h" -#include "FS.h" -#include "SD.h" // TBC: base frequency // or use (1000000 * ESP.getCpuFreqMHz()) #define ESP_SPI_FREQ 4000000 -extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; +ESP3D_SD_Class ESP3D_SD_Card = SD; +ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; uint8_t ESP_SD::getState(bool refresh) { #if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1 @@ -53,7 +52,7 @@ uint8_t ESP_SD::getState(bool refresh) { } // SD is idle or not detected, let see if still the case - SD.end(); + ESP3D_SD_Card.end(); _state = ESP_SDCARD_NOT_PRESENT; // using default value for speed ? should be parameter // refresh content if card was removed @@ -62,9 +61,9 @@ uint8_t ESP_SD::getState(bool refresh) { ESP_SD_MISO_PIN != -1 ? ESP_SD_MISO_PIN : MISO, ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI, ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK); - if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SPI, + if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SPI, ESP_SPI_FREQ / _spi_speed_divider)) { - if (SD.cardSize() > 0) { + if (ESP3D_SD_Card.cardSize() > 0) { _state = ESP_SDCARD_IDLE; } } @@ -114,7 +113,7 @@ bool ESP_SD::begin() { } void ESP_SD::end() { - SD.end(); + ESP3D_SD_Card.end(); _state = ESP_SDCARD_NOT_PRESENT; _started = false; } @@ -129,7 +128,7 @@ void ESP_SD::refreshStats(bool force) { uint64_t ESP_SD::totalBytes(bool refresh) { static uint64_t _totalBytes = 0; if (refresh || _totalBytes == 0) { - _totalBytes = SD.totalBytes(); + _totalBytes = ESP3D_SD_Card.totalBytes(); ; } return _totalBytes; @@ -138,7 +137,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) { uint64_t ESP_SD::usedBytes(bool refresh) { static uint64_t _usedBytes = 0; if (refresh || _usedBytes == 0) { - _usedBytes = SD.usedBytes(); + _usedBytes = ESP3D_SD_Card.usedBytes(); } return _usedBytes; } @@ -151,7 +150,7 @@ uint ESP_SD::maxPathLength() { return 255; } bool ESP_SD::rename(const char *oldpath, const char *newpath) { esp3d_log("rename %s to %s", oldpath, newpath); - return SD.rename(oldpath, newpath); + return ESP3D_SD_Card.rename(oldpath, newpath); } bool ESP_SD::format() { @@ -180,7 +179,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) { return ESP_SDFile(); } } - File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ + ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ : (mode == ESP_FILE_WRITE) ? FILE_WRITE : FILE_APPEND); ESP_SDFile esptmp(&tmp, tmp.isDirectory(), @@ -198,23 +197,23 @@ bool ESP_SD::exists(const char *path) { if (p.endsWith("/")) { p.remove(p.length() - 1, 1); } - res = SD.exists(p); + res = ESP3D_SD_Card.exists(p); if (!res) { // check if it is a directory p += '/'; - res = SD.exists(p); + res = ESP3D_SD_Card.exists(p); } return res; } -bool ESP_SD::remove(const char *path) { return SD.remove(path); } +bool ESP_SD::remove(const char *path) { return ESP3D_SD_Card.remove(path); } bool ESP_SD::mkdir(const char *path) { String p = path; if (p.endsWith("/")) { p.remove(p.length() - 1, 1); } - return SD.mkdir(p.c_str()); + return ESP3D_SD_Card.mkdir(p.c_str()); } bool ESP_SD::rmdir(const char *path) { @@ -234,8 +233,8 @@ bool ESP_SD::rmdir(const char *path) { std::stack pathlist; pathlist.push(p); while (pathlist.size() > 0 && res) { - File dir = SD.open(pathlist.top().c_str()); - File f = dir.openNextFile(); + ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str()); + ESP3D_File f = dir.openNextFile(); bool candelete = true; while (f && res) { if (f.isDirectory()) { @@ -244,12 +243,12 @@ bool ESP_SD::rmdir(const char *path) { newdir += f.name(); pathlist.push(newdir); f.close(); - f = File(); + f =ESP3D_File(); } else { String filepath = pathlist.top() + '/'; filepath += f.name(); f.close(); - if (!SD.remove(filepath.c_str())) { + if (!ESP3D_SD_Card.remove(filepath.c_str())) { res = false; } f = dir.openNextFile(); @@ -257,7 +256,7 @@ bool ESP_SD::rmdir(const char *path) { } if (candelete) { if (pathlist.top() != "/") { - res = SD.rmdir(pathlist.top().c_str()); + res = ESP3D_SD_Card.rmdir(pathlist.top().c_str()); } pathlist.pop(); } @@ -271,7 +270,7 @@ bool ESP_SD::rmdir(const char *path) { void ESP_SD::closeAll() { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { tSDFile_handle[i].close(); - tSDFile_handle[i] = File(); + tSDFile_handle[i] =ESP3D_File(); } } @@ -291,7 +290,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode, bool set = false; for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) { if (!tSDFile_handle[i]) { - tSDFile_handle[i] = *((File *)handle); + tSDFile_handle[i] = *((ESP3D_File *)handle); // filename _name = tSDFile_handle[i].name(); _filename = path; @@ -331,14 +330,14 @@ void ESP_SDFile::close() { // reopen if mode = write // udate size + date if (_iswritemode && !_isdir) { - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); _lastwrite = ftmp.getLastWrite(); ftmp.close(); } } - tSDFile_handle[_index] = File(); + tSDFile_handle[_index] =ESP3D_File(); // esp3d_log("Closing File at index %d",_index); _index = -1; } @@ -349,7 +348,7 @@ ESP_SDFile ESP_SDFile::openNextFile() { esp3d_log("openNextFile failed"); return ESP_SDFile(); } - File tmp = tSDFile_handle[_index].openNextFile(); + ESP3D_File tmp = tSDFile_handle[_index].openNextFile(); if (tmp) { esp3d_log("tmp name :%s %s %s", tmp.name(), (tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str()); diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp index 0d02939d..7084bd12 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp @@ -20,16 +20,13 @@ sd_native_esp8266.cpp - ESP3D sd support class #include "../../../include/esp3d_config.h" #if defined(ARDUINO_ARCH_ESP8266) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SD_NATIVE) -#define FS_NO_GLOBALS -#include -#include - #include #include "../../../core/esp3d_settings.h" #include "../esp_sd.h" -extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; +ESP3D_SD_Class ESP3D_SD_Card; +ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; void dateTime(uint16_t* date, uint16_t* dtime) { struct tm tmstruct; @@ -41,30 +38,10 @@ void dateTime(uint16_t* date, uint16_t* dtime) { *dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); } -time_t getDateTimeFile(File& filehandle) { +time_t getDateTimeFile(ESP3D_File& filehandle) { static time_t dt = 0; #ifdef SD_TIMESTAMP_FEATURE - struct tm timefile; - dir_t d; - if (filehandle) { - if (filehandle.dirEntry(&d)) { - timefile.tm_year = FAT_YEAR(d.lastWriteDate) - 1900; - timefile.tm_mon = FAT_MONTH(d.lastWriteDate) - 1; - timefile.tm_mday = FAT_DAY(d.lastWriteDate); - timefile.tm_hour = FAT_HOUR(d.lastWriteTime); - timefile.tm_min = FAT_MINUTE(d.lastWriteTime); - timefile.tm_sec = FAT_SECOND(d.lastWriteTime); - timefile.tm_isdst = -1; - dt = mktime(&timefile); - if (dt == -1) { - esp3d_log_e("mktime failed"); - } - } else { - esp3d_log_e("stat file failed"); - } - } else { - esp3d_log("check file for stat failed"); - } + dt = filehandle.getLastWrite(); #endif // SD_TIMESTAMP_FEATURE return dt; } @@ -96,10 +73,10 @@ uint8_t ESP_SD::getState(bool refresh) { // SD is idle or not detected, let see if still the case _state = ESP_SDCARD_NOT_PRESENT; // refresh content if card was removed - if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, + if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SD_SCK_HZ(F_CPU / _spi_speed_divider))) { esp3d_log("Init SD State ok"); - if (SD.size64() > 0) { + if (ESP3D_SD_Card.size64() > 0) { esp3d_log("SD available"); _state = ESP_SDCARD_IDLE; } else { @@ -152,7 +129,7 @@ void ESP_SD::refreshStats(bool force) { uint64_t ESP_SD::totalBytes(bool refresh) { static uint64_t _totalBytes = 0; if (refresh || _totalBytes == 0) { - _totalBytes = SD.size64(); + _totalBytes = ESP3D_SD_Card.size64(); ; } return _totalBytes; @@ -207,7 +184,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) { return ESP_SDFile(); } } - File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ + ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ : (mode == ESP_FILE_WRITE) ? FILE_WRITE : FILE_WRITE); ESP_SDFile esptmp(&tmp, tmp.isDirectory(), @@ -222,7 +199,7 @@ bool ESP_SD::exists(const char* path) { return _started; } esp3d_log("%s exists ?", path); - res = SD.exists(path); + res = ESP3D_SD_Card.exists(path); if (!res) { esp3d_log("Seems not - trying open it"); ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ); @@ -236,10 +213,10 @@ bool ESP_SD::exists(const char* path) { bool ESP_SD::remove(const char* path) { _sizechanged = true; - return SD.remove(path); + return ESP3D_SD_Card.remove(path); } -bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); } +bool ESP_SD::mkdir(const char* path) { return ESP3D_SD_Card.mkdir(path); } bool ESP_SD::rmdir(const char* path) { String p = path; @@ -256,9 +233,9 @@ bool ESP_SD::rmdir(const char* path) { std::stack pathlist; pathlist.push(p); while (pathlist.size() > 0 && res) { - File dir = SD.open(pathlist.top().c_str()); + ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str()); dir.rewindDirectory(); - File f = dir.openNextFile(); + ESP3D_File f = dir.openNextFile(); bool candelete = true; while (f && res) { if (f.isDirectory()) { @@ -267,12 +244,12 @@ bool ESP_SD::rmdir(const char* path) { newdir += "/"; pathlist.push(newdir); f.close(); - f = File(); + f =ESP3D_File(); } else { _sizechanged = true; String filepath = pathlist.top() + f.name(); f.close(); - if (!SD.remove(filepath.c_str())) { + if (!ESP3D_SD_Card.remove(filepath.c_str())) { res = false; } f = dir.openNextFile(); @@ -280,7 +257,7 @@ bool ESP_SD::rmdir(const char* path) { } if (candelete) { if (pathlist.top() != "/") { - res = SD.rmdir(pathlist.top().c_str()); + res = ESP3D_SD_Card.rmdir(pathlist.top().c_str()); } pathlist.pop(); } @@ -298,7 +275,7 @@ bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) { void ESP_SD::closeAll() { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { tSDFile_handle[i].close(); - tSDFile_handle[i] = File(); + tSDFile_handle[i] =ESP3D_File(); } } @@ -318,7 +295,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, bool set = false; for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) { if (!tSDFile_handle[i]) { - tSDFile_handle[i] = *((File*)handle); + tSDFile_handle[i] = *((ESP3D_File*)handle); // filename _filename = path; // name @@ -366,15 +343,15 @@ void ESP_SDFile::close() { // reopen if mode = write // udate size + date if (_iswritemode && !_isdir) { - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); _lastwrite = getDateTimeFile(ftmp); ftmp.close(); } } - tSDFile_handle[_index] = File(); - // esp3d_log("Closing File at index %d",_index); + tSDFile_handle[_index] =ESP3D_File(); + // esp3d_log("ClosingESP3D_File at index %d",_index); _index = -1; } } @@ -384,7 +361,7 @@ ESP_SDFile ESP_SDFile::openNextFile() { esp3d_log_e("openNextFile failed"); return ESP_SDFile(); } - File tmp = tSDFile_handle[_index].openNextFile(); + ESP3D_File tmp = tSDFile_handle[_index].openNextFile(); if (tmp) { String name = tmp.name(); esp3d_log("tmp name :%s %s", name.c_str(), diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp index fae399ca..90d877ae 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp32.cpp @@ -21,24 +21,11 @@ sd_sdfat2_esp32.cpp - ESP3D sd support class #if defined(ARDUINO_ARCH_ESP32) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SDFAT2) -#include #include - #include - #include "../../../core/esp3d_settings.h" #include "../esp_sd.h" -#if SDFAT_FILE_TYPE == 1 -typedef File32 File; -#elif SDFAT_FILE_TYPE == 2 -typedef ExFile File; -#elif SDFAT_FILE_TYPE == 3 -typedef FsFile File; -#else // SDFAT_FILE_TYPE -#error Invalid SDFAT_FILE_TYPE -#endif // SDFAT_FILE_TYPE - // Try to select the best SD card configuration. #if HAS_SDIO_CLASS #define SD_CONFIG SdioConfig(FIFO_SDIO) @@ -50,11 +37,11 @@ typedef FsFile File; SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI) #endif // HAS_SDIO_CLASS -extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; +ESP3D_SD_Class ESP3D_SD_Card; +ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; // Max Freq Working #define FREQMZ 40 -SdFat SD; #undef FILE_WRITE #undef FILE_READ #undef FILE_APPEND @@ -72,7 +59,7 @@ void dateTime(uint16_t* date, uint16_t* dtime) { *dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); } -time_t getDateTimeFile(File& filehandle) { +time_t getDateTimeFile(ESP3D_File& filehandle) { static time_t dt = 0; #ifdef SD_TIMESTAMP_FEATURE struct tm timefile; @@ -127,7 +114,7 @@ uint8_t ESP_SD::getState(bool refresh) { ESP_SD_MOSI_PIN != -1 ? ESP_SD_MOSI_PIN : MOSI, ESP_SD_SCK_PIN != -1 ? ESP_SD_SCK_PIN : SCK); // refresh content if card was removed - if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, + if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SD_SCK_MHZ(FREQMZ / _spi_speed_divider))) { _state = ESP_SDCARD_IDLE; } @@ -180,12 +167,12 @@ void ESP_SD::refreshStats(bool force) { uint64_t ESP_SD::totalBytes(bool refresh) { static uint64_t _totalBytes = 0; - if (!SD.volumeBegin()) { + if (!ESP3D_SD_Card.volumeBegin()) { return 0; } if (refresh || _totalBytes == 0) { - _totalBytes = SD.clusterCount(); - uint8_t sectors = SD.sectorsPerCluster(); + _totalBytes = ESP3D_SD_Card.clusterCount(); + uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster(); _totalBytes = _totalBytes * sectors * 512; } return _totalBytes; @@ -197,12 +184,12 @@ uint64_t ESP_SD::usedBytes(bool refresh) { uint64_t ESP_SD::freeBytes(bool refresh) { static uint64_t _freeBytes = 0; - if (!SD.volumeBegin()) { + if (!ESP3D_SD_Card.volumeBegin()) { return 0; } if (refresh || _freeBytes == 0) { - _freeBytes = SD.freeClusterCount(); - uint8_t sectors = SD.sectorsPerCluster(); + _freeBytes = ESP3D_SD_Card.freeClusterCount(); + uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster(); _freeBytes = _freeBytes * sectors * 512; } return _freeBytes; @@ -211,7 +198,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) { uint ESP_SD::maxPathLength() { return 255; } bool ESP_SD::rename(const char* oldpath, const char* newpath) { - return SD.rename(oldpath, newpath); + return ESP3D_SD_Card.rename(oldpath, newpath); } bool ESP_SD::format() { @@ -305,7 +292,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) { return ESP_SDFile(); } } - File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ + ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ : (mode == ESP_FILE_WRITE) ? FILE_WRITE : FILE_WRITE); if (tmp) { @@ -325,7 +312,7 @@ bool ESP_SD::exists(const char* path) { if (strcmp(path, "/") == 0) { return _started; } - res = SD.exists(path); + res = ESP3D_SD_Card.exists(path); if (!res) { ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ); if (root) { @@ -337,10 +324,10 @@ bool ESP_SD::exists(const char* path) { bool ESP_SD::remove(const char* path) { _sizechanged = true; - return SD.remove(path); + return ESP3D_SD_Card.remove(path); } -bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); } +bool ESP_SD::mkdir(const char* path) { return ESP3D_SD_Card.mkdir(path); } bool ESP_SD::rmdir(const char* path) { String p = path; @@ -357,9 +344,9 @@ bool ESP_SD::rmdir(const char* path) { std::stack pathlist; pathlist.push(p); while (pathlist.size() > 0 && res) { - File dir = SD.open(pathlist.top().c_str()); + ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str()); dir.rewindDirectory(); - File f = dir.openNextFile(); + ESP3D_File f = dir.openNextFile(); bool candelete = true; while (f && res) { if (f.isDir()) { @@ -371,14 +358,14 @@ bool ESP_SD::rmdir(const char* path) { newdir += "/"; pathlist.push(newdir); f.close(); - f = File(); + f = ESP3D_File(); } else { char tmp[255]; f.getName(tmp, 254); _sizechanged = true; String filepath = pathlist.top() + tmp; f.close(); - if (!SD.remove(filepath.c_str())) { + if (!ESP3D_SD_Card.remove(filepath.c_str())) { res = false; } f = dir.openNextFile(); @@ -386,7 +373,7 @@ bool ESP_SD::rmdir(const char* path) { } if (candelete) { if (pathlist.top() != "/") { - res = SD.rmdir(pathlist.top().c_str()); + res = ESP3D_SD_Card.rmdir(pathlist.top().c_str()); } pathlist.pop(); } @@ -400,7 +387,7 @@ bool ESP_SD::rmdir(const char* path) { void ESP_SD::closeAll() { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { tSDFile_handle[i].close(); - tSDFile_handle[i] = File(); + tSDFile_handle[i] = ESP3D_File(); } } @@ -427,7 +414,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, bool set = false; for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) { if (!tSDFile_handle[i]) { - tSDFile_handle[i] = *((File*)handle); + tSDFile_handle[i] = *((ESP3D_File*)handle); // filename char tmp[255]; tSDFile_handle[i].getName(tmp, 254); @@ -470,7 +457,7 @@ const char* ESP_SDFile::shortname() const { return _name.c_str(); #else static char sname[13]; - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { ftmp.getSFN(sname, 12); ftmp.close(); @@ -491,14 +478,14 @@ void ESP_SDFile::close() { // reopen if mode = write // udate size + date if (_iswritemode && !_isdir) { - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); _lastwrite = getDateTimeFile(ftmp); ftmp.close(); } } - tSDFile_handle[_index] = File(); + tSDFile_handle[_index] = ESP3D_File(); // esp3d_log("Closing File at index %d",_index); _index = -1; } @@ -509,7 +496,7 @@ ESP_SDFile ESP_SDFile::openNextFile() { esp3d_log("openNextFile failed"); return ESP_SDFile(); } - File tmp = tSDFile_handle[_index].openNextFile(); + ESP3D_File tmp = tSDFile_handle[_index].openNextFile(); if (tmp) { char tmps[255]; tmp.getName(tmps, 254); diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp index 15927a83..f869475e 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat2_esp8266.cpp @@ -21,14 +21,11 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class #include "../../../include/esp3d_config.h" #if defined(ARDUINO_ARCH_ESP8266) && defined(SD_DEVICE) #if (SD_DEVICE == ESP_SDFAT2) -#define FS_NO_GLOBALS #include #include "../../../core/esp3d_settings.h" #include "../esp_sd.h" -#define NO_GLOBAL_SD -#include #include // Try to select the best SD card configuration. @@ -41,18 +38,9 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class #define SD_CONFIG \ SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI) #endif // HAS_SDIO_CLASS -#if SDFAT_FILE_TYPE == 1 -typedef File32 File; -#elif SDFAT_FILE_TYPE == 2 -typedef ExFile File; -#elif SDFAT_FILE_TYPE == 3 -typedef FsFile File; -#else // SDFAT_FILE_TYPE -#error Invalid SDFAT_FILE_TYPE -#endif // SDFAT_FILE_TYPE -extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; -SdFat SD; +ESP3D_SD_Class ESP3D_SD_Card; +ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; void dateTime(uint16_t* date, uint16_t* dtime) { struct tm tmstruct; @@ -64,7 +52,7 @@ void dateTime(uint16_t* date, uint16_t* dtime) { *dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); } -time_t getDateTimeFile(File& filehandle) { +time_t getDateTimeFile(ESP3D_File& filehandle) { static time_t dt = 0; #ifdef SD_TIMESTAMP_FEATURE struct tm timefile; @@ -120,7 +108,7 @@ uint8_t ESP_SD::getState(bool refresh) { // SD is idle or not detected, let see if still the case _state = ESP_SDCARD_NOT_PRESENT; // refresh content if card was removed - if (SD.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, + if (ESP3D_SD_Card.begin((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SD_SCK_HZ(F_CPU / _spi_speed_divider))) { esp3d_log("Init SD State ok"); _state = ESP_SDCARD_IDLE; @@ -170,12 +158,12 @@ void ESP_SD::refreshStats(bool force) { uint64_t ESP_SD::totalBytes(bool refresh) { static uint64_t _totalBytes = 0; - if (!SD.volumeBegin()) { + if (!ESP3D_SD_Card.volumeBegin()) { return 0; } if (refresh || _totalBytes == 0) { - _totalBytes = SD.clusterCount(); - uint8_t sectors = SD.sectorsPerCluster(); + _totalBytes = ESP3D_SD_Card.clusterCount(); + uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster(); _totalBytes = _totalBytes * sectors * 512; } return _totalBytes; @@ -187,12 +175,12 @@ uint64_t ESP_SD::usedBytes(bool refresh) { uint64_t ESP_SD::freeBytes(bool refresh) { static uint64_t _freeBytes = 0; - if (!SD.volumeBegin()) { + if (!ESP3D_SD_Card.volumeBegin()) { return 0; } if (refresh || _freeBytes == 0) { - _freeBytes = SD.freeClusterCount(); - uint8_t sectors = SD.sectorsPerCluster(); + _freeBytes = ESP3D_SD_Card.freeClusterCount(); + uint8_t sectors = ESP3D_SD_Card.sectorsPerCluster(); _freeBytes = _freeBytes * sectors * 512; } return _freeBytes; @@ -201,7 +189,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) { uint ESP_SD::maxPathLength() { return 255; } bool ESP_SD::rename(const char* oldpath, const char* newpath) { - return SD.rename(oldpath, newpath); + return ESP3D_SD_Card.rename(oldpath, newpath); } bool ESP_SD::format() { @@ -296,7 +284,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) { return ESP_SDFile(); } } - File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ + ESP3D_File tmp = ESP3D_SD_Card.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, @@ -311,7 +299,7 @@ bool ESP_SD::exists(const char* path) { return _started; } esp3d_log("%s exists ?", path); - res = SD.exists(path); + res = ESP3D_SD_Card.exists(path); if (!res) { esp3d_log("Seems not - trying open it"); ESP_SDFile root = ESP_SD::open(path, ESP_FILE_READ); @@ -325,10 +313,10 @@ bool ESP_SD::exists(const char* path) { bool ESP_SD::remove(const char* path) { _sizechanged = true; - return SD.remove(path); + return ESP3D_SD_Card.remove(path); } -bool ESP_SD::mkdir(const char* path) { return SD.mkdir(path); } +bool ESP_SD::mkdir(const char* path) { return ESP3D_SD_Card.mkdir(path); } bool ESP_SD::rmdir(const char* path) { String p = path; @@ -345,9 +333,9 @@ bool ESP_SD::rmdir(const char* path) { std::stack pathlist; pathlist.push(p); while (pathlist.size() > 0 && res) { - File dir = SD.open(pathlist.top().c_str()); + ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str()); dir.rewindDirectory(); - File f = dir.openNextFile(); + ESP3D_File f = dir.openNextFile(); bool candelete = true; while (f && res) { if (f.isDir()) { @@ -359,14 +347,14 @@ bool ESP_SD::rmdir(const char* path) { newdir += "/"; pathlist.push(newdir); f.close(); - f = File(); + f = ESP3D_File() ; } else { char tmp[255]; f.getName(tmp, 254); _sizechanged = true; String filepath = pathlist.top() + tmp; f.close(); - if (!SD.remove(filepath.c_str())) { + if (!ESP3D_SD_Card.remove(filepath.c_str())) { res = false; } f = dir.openNextFile(); @@ -374,7 +362,7 @@ bool ESP_SD::rmdir(const char* path) { } if (candelete) { if (pathlist.top() != "/") { - res = SD.rmdir(pathlist.top().c_str()); + res = ESP3D_SD_Card.rmdir(pathlist.top().c_str()); } pathlist.pop(); } @@ -399,7 +387,7 @@ bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) { void ESP_SD::closeAll() { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { tSDFile_handle[i].close(); - tSDFile_handle[i] = File(); + tSDFile_handle[i] = ESP3D_File() ; } } @@ -419,7 +407,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, bool set = false; for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) { if (!tSDFile_handle[i]) { - tSDFile_handle[i] = *((File*)handle); + tSDFile_handle[i] = *((ESP3D_File*)handle); // filename char tmp[255]; tSDFile_handle[i].getName(tmp, 254); @@ -462,7 +450,7 @@ const char* ESP_SDFile::shortname() const { return _name.c_str(); #else static char sname[13]; - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { ftmp.getSFN(sname, 12); ftmp.close(); @@ -483,14 +471,14 @@ void ESP_SDFile::close() { // reopen if mode = write // udate size + date if (_iswritemode && !_isdir) { - File ftmp = SD.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); _lastwrite = getDateTimeFile(ftmp); ftmp.close(); } } - tSDFile_handle[_index] = File(); + tSDFile_handle[_index] = ESP3D_File() ; // esp3d_log("Closing File at index %d",_index); _index = -1; } @@ -501,7 +489,7 @@ ESP_SDFile ESP_SDFile::openNextFile() { esp3d_log("openNextFile failed"); return ESP_SDFile(); } - File tmp = tSDFile_handle[_index].openNextFile(); + ESP3D_File tmp = tSDFile_handle[_index].openNextFile(); if (tmp) { char tmps[255]; tmp.getName(tmps, 254); diff --git a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp index 5d7019a1..11b746d1 100644 --- a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp @@ -24,10 +24,9 @@ sdio_esp32.cpp - ESP3D sd support class #include "../../../core/esp3d_settings.h" #include "../esp_sd.h" -#include "FS.h" -#include "SD_MMC.h" -extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; +ESP3D_SD_Class ESP3D_SD_Card = SD_MMC; +ESP3D_File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; #define SDMMC_FORCE_BEGIN @@ -60,10 +59,10 @@ uint8_t ESP_SD::getState(bool refresh) { // refresh content if card was removed if (!lastinitok) { esp3d_log("last init was failed try sd_mmc begin"); - SD_MMC.end(); - if (SD_MMC.begin("/sdcard", SDIO_BIT_MODE)) { + ESP3D_SD_Card.end(); + if (ESP3D_SD_Card.begin("/sdcard", SDIO_BIT_MODE)) { esp3d_log("sd_mmc begin succeed"); - if (SD_MMC.cardType() != CARD_NONE) { + if (ESP3D_SD_Card.cardType() != CARD_NONE) { _state = ESP_SDCARD_IDLE; lastinitok = true; esp3d_log("sd_mmc card type succeed"); @@ -75,16 +74,16 @@ uint8_t ESP_SD::getState(bool refresh) { } } else { esp3d_log("last init was ok try card type"); - if (SD_MMC.cardType() != CARD_NONE) { + if (ESP3D_SD_Card.cardType() != CARD_NONE) { esp3d_log("checking sd_mmc card type succeed"); _state = ESP_SDCARD_IDLE; } else { lastinitok = false; esp3d_log_e("Soft sd check failed"); - SD_MMC.end(); - if (SD_MMC.begin("/sdcard", SDIO_BIT_MODE)) { + ESP3D_SD_Card.end(); + if (ESP3D_SD_Card.begin("/sdcard", SDIO_BIT_MODE)) { esp3d_log("new sd_mmc begin succeed"); - if (SD_MMC.cardType() != CARD_NONE) { + if (ESP3D_SD_Card.cardType() != CARD_NONE) { _state = ESP_SDCARD_IDLE; lastinitok = true; esp3d_log("new sd_mmc card type succeed"); @@ -103,13 +102,13 @@ bool ESP_SD::begin() { #if SDIO_BIT_MODE == SD_ONE_BIT_MODE #if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || \ (ESP_SDIO_D0_PIN != -1) - SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN); + ESP3D_SD_Card.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN); #endif //(ESP_SDIO_CLK_PIN != -1) #else #if (ESP_SDIO_CLK_PIN != -1) || (ESP_SDIO_CMD_PIN != -1) || \ (ESP_SDIO_D0_PIN != -1) || (ESP_SDIO_D1_PIN != -1) || \ (ESP_SDIO_D2_PIN != -1) || (ESP_SDIO_D3_PIN != -1) - SD_MMC.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN, + ESP3D_SD_Card.setPins(ESP_SDIO_CLK_PIN, ESP_SDIO_CMD_PIN, ESP_SDIO_D0_PIN, ESP_SDIO_D1_PIN, ESP_SDIO_D2_PIN, ESP_SDIO_D3_PIN); #endif //(ESP_SDIO_CLK_PIN != -1) #endif // SD_ONE_BIT_MODE @@ -125,7 +124,7 @@ bool ESP_SD::begin() { } void ESP_SD::end() { - SD_MMC.end(); + ESP3D_SD_Card.end(); _state = ESP_SDCARD_NOT_PRESENT; _started = false; } @@ -140,7 +139,7 @@ void ESP_SD::refreshStats(bool force) { uint64_t ESP_SD::totalBytes(bool refresh) { static uint64_t _totalBytes = 0; if (refresh || _totalBytes == 0) { - _totalBytes = SD_MMC.totalBytes(); + _totalBytes = ESP3D_SD_Card.totalBytes(); ; } return _totalBytes; @@ -149,7 +148,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) { uint64_t ESP_SD::usedBytes(bool refresh) { static uint64_t _usedBytes = 0; if (refresh || _usedBytes == 0) { - _usedBytes = SD_MMC.usedBytes(); + _usedBytes = ESP3D_SD_Card.usedBytes(); } return _usedBytes; } @@ -161,7 +160,7 @@ uint64_t ESP_SD::freeBytes(bool refresh) { uint ESP_SD::maxPathLength() { return 255; } bool ESP_SD::rename(const char *oldpath, const char *newpath) { - return SD_MMC.rename(oldpath, newpath); + return ESP3D_SD_Card.rename(oldpath, newpath); } bool ESP_SD::format() { @@ -193,7 +192,7 @@ ESP_SDFile ESP_SD::open(const char *path, uint8_t mode) { return ESP_SDFile(); } } - File tmp = SD_MMC.open(path, (mode == ESP_FILE_READ) ? FILE_READ + ESP3D_File tmp = ESP3D_SD_Card.open(path, (mode == ESP_FILE_READ) ? FILE_READ : (mode == ESP_FILE_WRITE) ? FILE_WRITE : FILE_APPEND); ESP_SDFile esptmp(&tmp, tmp.isDirectory(), @@ -212,7 +211,7 @@ bool ESP_SD::exists(const char *path) { if (p.endsWith("/")) { p.remove(p.length() - 1, 1); } - res = SD_MMC.exists(p); + res = ESP3D_SD_Card.exists(p); if (!res) { ESP_SDFile root = ESP_SD::open(p.c_str(), ESP_FILE_READ); if (root) { @@ -222,14 +221,14 @@ bool ESP_SD::exists(const char *path) { return res; } -bool ESP_SD::remove(const char *path) { return SD_MMC.remove(path); } +bool ESP_SD::remove(const char *path) { return ESP3D_SD_Card.remove(path); } bool ESP_SD::mkdir(const char *path) { String p = path; if (p.endsWith("/")) { p.remove(p.length() - 1, 1); } - return SD_MMC.mkdir(p.c_str()); + return ESP3D_SD_Card.mkdir(p.c_str()); } bool ESP_SD::rmdir(const char *path) { @@ -244,8 +243,8 @@ bool ESP_SD::rmdir(const char *path) { } pathlist.push(p); while (pathlist.size() > 0 && res) { - File dir = SD_MMC.open(pathlist.top().c_str()); - File f = dir.openNextFile(); + ESP3D_File dir = ESP3D_SD_Card.open(pathlist.top().c_str()); + ESP3D_File f = dir.openNextFile(); bool candelete = true; while (f && res) { if (f.isDirectory()) { @@ -254,12 +253,12 @@ bool ESP_SD::rmdir(const char *path) { newdir += f.name(); pathlist.push(newdir); f.close(); - f = File(); + f =ESP3D_File(); } else { String filepath = pathlist.top() + '/'; filepath += f.name(); f.close(); - if (!SD_MMC.remove(filepath.c_str())) { + if (!ESP3D_SD_Card.remove(filepath.c_str())) { res = false; } f = dir.openNextFile(); @@ -267,7 +266,7 @@ bool ESP_SD::rmdir(const char *path) { } if (candelete) { if (pathlist.top() != "/") { - res = SD_MMC.rmdir(pathlist.top().c_str()); + res = ESP3D_SD_Card.rmdir(pathlist.top().c_str()); } pathlist.pop(); } @@ -281,7 +280,7 @@ bool ESP_SD::rmdir(const char *path) { void ESP_SD::closeAll() { for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) { tSDFile_handle[i].close(); - tSDFile_handle[i] = File(); + tSDFile_handle[i] =ESP3D_File(); } } @@ -301,7 +300,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode, bool set = false; for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) { if (!tSDFile_handle[i]) { - tSDFile_handle[i] = *((File *)handle); + tSDFile_handle[i] = *((ESP3D_File *)handle); // filename _name = tSDFile_handle[i].name(); _filename = path; @@ -331,7 +330,7 @@ ESP_SDFile::ESP_SDFile(void *handle, bool isdir, bool iswritemode, } bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) { - return tSDFile_handle[_index].seek(pos, (SeekMode)mode); + return tSDFile_handle[_index].seek(pos, (fs::SeekMode)mode); } void ESP_SDFile::close() { @@ -341,14 +340,14 @@ void ESP_SDFile::close() { // reopen if mode = write // udate size + date if (_iswritemode && !_isdir) { - File ftmp = SD_MMC.open(_filename.c_str()); + ESP3D_File ftmp = ESP3D_SD_Card.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); _lastwrite = ftmp.getLastWrite(); ftmp.close(); } } - tSDFile_handle[_index] = File(); + tSDFile_handle[_index] =ESP3D_File(); // esp3d_log("Closing File at index %d",_index); _index = -1; } @@ -359,7 +358,7 @@ ESP_SDFile ESP_SDFile::openNextFile() { esp3d_log("openNextFile failed"); return ESP_SDFile(); } - File tmp = tSDFile_handle[_index].openNextFile(); + ESP3D_File tmp = tSDFile_handle[_index].openNextFile(); if (tmp) { esp3d_log("tmp name :%s %s %s", tmp.name(), (tmp.isDirectory()) ? "isDir" : "isFile", _filename.c_str()); diff --git a/esp3d/src/modules/gcode_host/gcode_host.cpp b/esp3d/src/modules/gcode_host/gcode_host.cpp index d239e4fe..82dff019 100644 --- a/esp3d/src/modules/gcode_host/gcode_host.cpp +++ b/esp3d/src/modules/gcode_host/gcode_host.cpp @@ -290,7 +290,7 @@ void GcodeHost::readNextCommand() { } else { _processedSize++; _currentPosition++; - if (!(char)c == '\n' ) { + if ((char)c != '\n' ) { _currentCommand += (char)c; } else { processing = false; diff --git a/extra-libraries/ESP32/SdFat-2.2.3/src/SdFat.h b/extra-libraries/ESP32/SdFat-2.2.3/src/SdFat.h index d804a613..d17393df 100644 --- a/extra-libraries/ESP32/SdFat-2.2.3/src/SdFat.h +++ b/extra-libraries/ESP32/SdFat-2.2.3/src/SdFat.h @@ -24,7 +24,6 @@ */ #ifndef SdFat_h #define SdFat_h -#define DISABLE_FS_H_WARNING 1 /** * \file * \brief main SdFs include file. diff --git a/platformio.ini b/platformio.ini index ec4a7341..89661084 100644 --- a/platformio.ini +++ b/platformio.ini @@ -289,6 +289,7 @@ lib_ignore = esp32-usb-serial [env:esp8266dev] +;core 3.1.1 platform = espressif8266@4.1.0 board = esp12e framework = arduino