mirror of
https://git.mirrors.martin98.com/https://github.com/luc-github/ESP3D.git
synced 2025-08-12 20:29:03 +08:00
Fix SD Support broken on esp8266
Bump version
This commit is contained in:
parent
45db145a19
commit
fc8c387274
@ -22,7 +22,7 @@
|
|||||||
#define _VERSION_ESP3D_H
|
#define _VERSION_ESP3D_H
|
||||||
|
|
||||||
// version and sources location
|
// version and sources location
|
||||||
#define FW_VERSION "3.0.0.a231"
|
#define FW_VERSION "3.0.0.a232"
|
||||||
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
#define REPOSITORY "https://github.com/luc-github/ESP3D/tree/3.0"
|
||||||
|
|
||||||
#endif //_VERSION_ESP3D_H
|
#endif //_VERSION_ESP3D_H
|
||||||
|
@ -34,7 +34,16 @@ File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
|||||||
#define FS_NO_GLOBALS
|
#define FS_NO_GLOBALS
|
||||||
#define NO_GLOBAL_SD
|
#define NO_GLOBAL_SD
|
||||||
#include <SdFat.h>
|
#include <SdFat.h>
|
||||||
sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
#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
|
||||||
|
File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
|
#elif ((SD_DEVICE == ESP_SDFAT) || (SD_DEVICE == ESP_SDFAT2)) && \
|
||||||
defined(ARDUINO_ARCH_ESP32)
|
defined(ARDUINO_ARCH_ESP32)
|
||||||
#include <SdFat.h>
|
#include <SdFat.h>
|
||||||
|
@ -159,7 +159,7 @@ uint64_t ESP_SD::totalBytes(bool refresh) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint64_t ESP_SD::usedBytes(bool refresh) {
|
uint64_t ESP_SD::usedBytes(bool refresh) {
|
||||||
FSInfo64 info;
|
fs::FSInfo64 info;
|
||||||
static uint64_t _usedBytes = 0;
|
static uint64_t _usedBytes = 0;
|
||||||
if (refresh) {
|
if (refresh) {
|
||||||
if (!SDFS.info64(info)) {
|
if (!SDFS.info64(info)) {
|
||||||
|
@ -41,9 +41,17 @@ sd_sdfat2_esp8266.cpp - ESP3D sd support class
|
|||||||
#define SD_CONFIG \
|
#define SD_CONFIG \
|
||||||
SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI)
|
SdSpiConfig((ESP_SD_CS_PIN == -1) ? SS : ESP_SD_CS_PIN, SHARED_SPI)
|
||||||
#endif // HAS_SDIO_CLASS
|
#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 sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE];
|
||||||
using namespace sdfat;
|
|
||||||
SdFat SD;
|
SdFat SD;
|
||||||
|
|
||||||
void dateTime(uint16_t* date, uint16_t* dtime) {
|
void dateTime(uint16_t* date, uint16_t* dtime) {
|
||||||
@ -56,7 +64,7 @@ void dateTime(uint16_t* date, uint16_t* dtime) {
|
|||||||
*dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
*dtime = FAT_TIME(tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec);
|
||||||
}
|
}
|
||||||
|
|
||||||
time_t getDateTimeFile(sdfat::File& filehandle) {
|
time_t getDateTimeFile(File& filehandle) {
|
||||||
static time_t dt = 0;
|
static time_t dt = 0;
|
||||||
#ifdef SD_TIMESTAMP_FEATURE
|
#ifdef SD_TIMESTAMP_FEATURE
|
||||||
struct tm timefile;
|
struct tm timefile;
|
||||||
@ -225,7 +233,7 @@ bool ESP_SD::format() {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
esp3d_log_("Capacity detected : %d GB", cardSectorCount * 5.12e-7);
|
esp3d_log("Capacity detected : %d GB", cardSectorCount * 5.12e-7);
|
||||||
|
|
||||||
uint32_t firstBlock = 0;
|
uint32_t firstBlock = 0;
|
||||||
uint32_t lastBlock;
|
uint32_t lastBlock;
|
||||||
@ -248,7 +256,7 @@ bool ESP_SD::format() {
|
|||||||
} while (firstBlock < cardSectorCount);
|
} while (firstBlock < cardSectorCount);
|
||||||
|
|
||||||
if (!m_card->readSector(0, sectorBuffer)) {
|
if (!m_card->readSector(0, sectorBuffer)) {
|
||||||
esp3d_log_e(("readBlock");
|
esp3d_log_e("readBlock");
|
||||||
}
|
}
|
||||||
|
|
||||||
ExFatFormatter exFatFormatter;
|
ExFatFormatter exFatFormatter;
|
||||||
@ -260,14 +268,14 @@ bool ESP_SD::format() {
|
|||||||
: fatFormatter.format(m_card, sectorBuffer, nullptr);
|
: fatFormatter.format(m_card, sectorBuffer, nullptr);
|
||||||
|
|
||||||
if (!rtn) {
|
if (!rtn) {
|
||||||
esp3d_log_e(("erase failed");
|
esp3d_log_e("erase failed");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
esp3d_log_e(G("cannot erase");
|
esp3d_log_e("cannot erase");
|
||||||
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
@ -293,7 +301,7 @@ ESP_SDFile ESP_SD::open(const char* path, uint8_t mode) {
|
|||||||
return ESP_SDFile();
|
return ESP_SDFile();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
sdfat::File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
File tmp = SD.open(path, (mode == ESP_FILE_READ) ? FILE_READ
|
||||||
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
: (mode == ESP_FILE_WRITE) ? FILE_WRITE
|
||||||
: FILE_WRITE);
|
: FILE_WRITE);
|
||||||
ESP_SDFile esptmp(&tmp, tmp.isDir(), (mode == ESP_FILE_READ) ? false : true,
|
ESP_SDFile esptmp(&tmp, tmp.isDir(), (mode == ESP_FILE_READ) ? false : true,
|
||||||
@ -342,9 +350,9 @@ bool ESP_SD::rmdir(const char* path) {
|
|||||||
std::stack<String> pathlist;
|
std::stack<String> pathlist;
|
||||||
pathlist.push(p);
|
pathlist.push(p);
|
||||||
while (pathlist.size() > 0 && res) {
|
while (pathlist.size() > 0 && res) {
|
||||||
sdfat::File dir = SD.open(pathlist.top().c_str());
|
File dir = SD.open(pathlist.top().c_str());
|
||||||
dir.rewindDirectory();
|
dir.rewindDirectory();
|
||||||
sdfat::File f = dir.openNextFile();
|
File f = dir.openNextFile();
|
||||||
bool candelete = true;
|
bool candelete = true;
|
||||||
while (f && res) {
|
while (f && res) {
|
||||||
if (f.isDir()) {
|
if (f.isDir()) {
|
||||||
@ -356,7 +364,7 @@ bool ESP_SD::rmdir(const char* path) {
|
|||||||
newdir += "/";
|
newdir += "/";
|
||||||
pathlist.push(newdir);
|
pathlist.push(newdir);
|
||||||
f.close();
|
f.close();
|
||||||
f = sdfat::File();
|
f = File();
|
||||||
} else {
|
} else {
|
||||||
char tmp[255];
|
char tmp[255];
|
||||||
f.getName(tmp, 254);
|
f.getName(tmp, 254);
|
||||||
@ -396,7 +404,7 @@ bool ESP_SDFile::seek(uint32_t pos, uint8_t mode) {
|
|||||||
void ESP_SD::closeAll() {
|
void ESP_SD::closeAll() {
|
||||||
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
for (uint8_t i = 0; i < ESP_MAX_SD_OPENHANDLE; i++) {
|
||||||
tSDFile_handle[i].close();
|
tSDFile_handle[i].close();
|
||||||
tSDFile_handle[i] = sdfat::File();
|
tSDFile_handle[i] = File();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -416,7 +424,7 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode,
|
|||||||
bool set = false;
|
bool set = false;
|
||||||
for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
|
for (uint8_t i = 0; (i < ESP_MAX_SD_OPENHANDLE) && !set; i++) {
|
||||||
if (!tSDFile_handle[i]) {
|
if (!tSDFile_handle[i]) {
|
||||||
tSDFile_handle[i] = *((sdfat::File*)handle);
|
tSDFile_handle[i] = *((File*)handle);
|
||||||
// filename
|
// filename
|
||||||
char tmp[255];
|
char tmp[255];
|
||||||
tSDFile_handle[i].getName(tmp, 254);
|
tSDFile_handle[i].getName(tmp, 254);
|
||||||
@ -456,14 +464,17 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode,
|
|||||||
// todo need also to add short filename
|
// todo need also to add short filename
|
||||||
const char* ESP_SDFile::shortname() const {
|
const char* ESP_SDFile::shortname() const {
|
||||||
static char sname[13];
|
static char sname[13];
|
||||||
sdfat::File ftmp = SD.open(_filename.c_str());
|
File ftmp = SD.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
ftmp.getSFN(sname);
|
ftmp.getSFN(sname, 12);
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
|
if (strlen(sname) == 0) {
|
||||||
|
return _name.c_str();
|
||||||
|
}
|
||||||
return sname;
|
return sname;
|
||||||
} else {
|
} else {
|
||||||
return _name.c_str();
|
return _name.c_str();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void ESP_SDFile::close() {
|
void ESP_SDFile::close() {
|
||||||
@ -473,14 +484,14 @@ void ESP_SDFile::close() {
|
|||||||
// reopen if mode = write
|
// reopen if mode = write
|
||||||
// udate size + date
|
// udate size + date
|
||||||
if (_iswritemode && !_isdir) {
|
if (_iswritemode && !_isdir) {
|
||||||
sdfat::File ftmp = SD.open(_filename.c_str());
|
File ftmp = SD.open(_filename.c_str());
|
||||||
if (ftmp) {
|
if (ftmp) {
|
||||||
_size = ftmp.size();
|
_size = ftmp.size();
|
||||||
_lastwrite = getDateTimeFile(ftmp);
|
_lastwrite = getDateTimeFile(ftmp);
|
||||||
ftmp.close();
|
ftmp.close();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
tSDFile_handle[_index] = sdfat::File();
|
tSDFile_handle[_index] = File();
|
||||||
// esp3d_log("Closing File at index %d",_index);
|
// esp3d_log("Closing File at index %d",_index);
|
||||||
_index = -1;
|
_index = -1;
|
||||||
}
|
}
|
||||||
@ -491,7 +502,7 @@ ESP_SDFile ESP_SDFile::openNextFile() {
|
|||||||
esp3d_log("openNextFile failed");
|
esp3d_log("openNextFile failed");
|
||||||
return ESP_SDFile();
|
return ESP_SDFile();
|
||||||
}
|
}
|
||||||
sdfat::File tmp = tSDFile_handle[_index].openNextFile();
|
File tmp = tSDFile_handle[_index].openNextFile();
|
||||||
if (tmp) {
|
if (tmp) {
|
||||||
char tmps[255];
|
char tmps[255];
|
||||||
tmp.getName(tmps, 254);
|
tmp.getName(tmps, 254);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user