From c37b90ea058a48fd0ebf988c4e29f1caed9abe25 Mon Sep 17 00:00:00 2001 From: Luc Date: Mon, 21 Oct 2019 17:50:18 +0200 Subject: [PATCH] Add time in sd file Add create command to filesystem Clean SD filesystem code --- docs/Commands.txt | 4 +- esp3d/src/core/espcmd/ESP730.cpp | 14 +++- esp3d/src/core/espcmd/ESP740.cpp | 7 +- esp3d/src/core/espcmd/ESP750.cpp | 14 +++- esp3d/src/include/version.h | 2 +- .../src/modules/filesystem/esp_filesystem.cpp | 4 +- esp3d/src/modules/filesystem/esp_sd.cpp | 6 +- esp3d/src/modules/filesystem/esp_sd.h | 1 - .../modules/filesystem/sd/sd_native_esp32.cpp | 14 ++-- .../filesystem/sd/sd_native_esp8266.cpp | 75 ++++++++++++++---- .../modules/filesystem/sd/sd_sdfat_esp32.cpp | 76 +++++++++++++++---- .../src/modules/filesystem/sd/sdio_esp32.cpp | 14 ++-- esp3d/src/modules/time/time_server.cpp | 18 ++++- esp3d/src/modules/time/time_server.h | 3 +- 14 files changed, 191 insertions(+), 61 deletions(-) diff --git a/docs/Commands.txt b/docs/Commands.txt index cde10b94..44394c22 100644 --- a/docs/Commands.txt +++ b/docs/Commands.txt @@ -191,14 +191,14 @@ Get will give type and settings only, not the protected T1/T2 [ESP720] pwd= * Action on ESP Filesystem -rmdir / remove / mkdir / exists +rmdir / remove / mkdir / exists / create [ESP730]= pwd= * List SD Filesystem [ESP740] pwd= * Action on SD Filesystem -rmdir / remove / mkdir / exists +rmdir / remove / mkdir / exists / create [ESP750]= pwd= * FW Informations diff --git a/esp3d/src/core/espcmd/ESP730.cpp b/esp3d/src/core/espcmd/ESP730.cpp index ddf3480c..dddd8a95 100644 --- a/esp3d/src/core/espcmd/ESP730.cpp +++ b/esp3d/src/core/espcmd/ESP730.cpp @@ -25,7 +25,7 @@ #include "../../modules/authentication/authentication_service.h" #include "../../modules/filesystem/esp_filesystem.h" // Action on ESP Filesystem -//rmdir / remove / mkdir / exists +//rmdir / remove / mkdir / exists / create //[ESP730]= pwd= bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) { @@ -79,6 +79,18 @@ bool Commands::ESP730(const char* cmd_params, level_authenticate_type auth_type, } return response; } + parameter = get_param (cmd_params, "create="); + if (parameter.length() != 0) { + ESP_File f = ESP_FileSystem::open(parameter.c_str(), ESP_SD_FILE_WRITE); + if (f.isOpen()) { + f.close(); + output->printMSG ("ok"); + } else { + output->printERROR ("failed!"); + response = false; + } + return response; + } output->printERROR ("Incorrect command!"); return false; } diff --git a/esp3d/src/core/espcmd/ESP740.cpp b/esp3d/src/core/espcmd/ESP740.cpp index 965ebbb1..c2fe58eb 100644 --- a/esp3d/src/core/espcmd/ESP740.cpp +++ b/esp3d/src/core/espcmd/ESP740.cpp @@ -24,6 +24,9 @@ #include "../settings_esp3d.h" #include "../../modules/authentication/authentication_service.h" #include "../../modules/filesystem/esp_sd.h" +#ifdef SD_TIMESTAMP_FEATURE +#include "../../modules/time/time_server.h" +#endif //SD_TIMESTAMP_FEATURE //List SD Filesystem //[ESP740] pwd= bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) @@ -86,9 +89,7 @@ bool Commands::ESP740(const char* cmd_params, level_authenticate_type auth_type, output->print(ESP_SD::formatBytes(sub.size()).c_str()); output->print(" \t"); #ifdef SD_TIMESTAMP_FEATURE - time_t t = sub.getLastWrite(); - struct tm * tmstruct = localtime(&t); - output->printf("%d-%02d-%02d %02d:%02d:%02d",(tmstruct->tm_year)+1900,( tmstruct->tm_mon)+1, tmstruct->tm_mday,tmstruct->tm_hour, tmstruct->tm_min, tmstruct->tm_sec); + output->print(timeserver.current_time(sub.getLastWrite())); output->print(" \t"); #endif //SD_TIMESTAMP_FEATURE output->printLN(""); diff --git a/esp3d/src/core/espcmd/ESP750.cpp b/esp3d/src/core/espcmd/ESP750.cpp index 92e8849b..c0fa10e2 100644 --- a/esp3d/src/core/espcmd/ESP750.cpp +++ b/esp3d/src/core/espcmd/ESP750.cpp @@ -25,7 +25,7 @@ #include "../../modules/authentication/authentication_service.h" #include "../../modules/filesystem/esp_sd.h" // Action on SD Filesystem -//rmdir / remove / mkdir / exists +//rmdir / remove / mkdir / exists /create //[ESP750]= pwd= bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, ESP3DOutput * output) { @@ -90,6 +90,18 @@ bool Commands::ESP750(const char* cmd_params, level_authenticate_type auth_type, } return response; } + parameter = get_param (cmd_params, "create="); + if (parameter.length() != 0) { + ESP_SDFile f = ESP_SD::open(parameter.c_str(), ESP_SD_FILE_WRITE); + if (f.isOpen()) { + f.close(); + output->printMSG ("ok"); + } else { + output->printERROR ("failed!"); + response = false; + } + return response; + } output->printERROR ("Incorrect command!"); return false; } diff --git a/esp3d/src/include/version.h b/esp3d/src/include/version.h index 3cfb5371..60c4d3de 100644 --- a/esp3d/src/include/version.h +++ b/esp3d/src/include/version.h @@ -22,7 +22,7 @@ #define _VERSION_ESP3D_H //version and sources location -#define FW_VERSION "3.0.0.a22" +#define FW_VERSION "3.0.0.a23" #define REPOSITORY "https://github.com/luc-github/ESP3D" #endif //_VERSION_ESP3D_H diff --git a/esp3d/src/modules/filesystem/esp_filesystem.cpp b/esp3d/src/modules/filesystem/esp_filesystem.cpp index 2331fa8a..3d5c43ca 100644 --- a/esp3d/src/modules/filesystem/esp_filesystem.cpp +++ b/esp3d/src/modules/filesystem/esp_filesystem.cpp @@ -98,7 +98,7 @@ ESP_File::ESP_File(const char * name, const char * filename, bool isdir, size_t _filename = filename; _name = name; #ifdef FILESYSTEM_TIMESTAMP_FEATURE - memset (&_lastwrite,0,sizeof(time_t)); + _lastwrite = 0; #endif //FILESYSTEM_TIMESTAMP_FEATURE _iswritemode = false; _size = size; @@ -211,7 +211,7 @@ ESP_File& ESP_File::operator=(const ESP_File & other) _iswritemode = other._iswritemode; _dirlist = other._dirlist; #ifdef FILESYSTEM_TIMESTAMP_FEATURE - memcpy(&_lastwrite, &(other._lastwrite), sizeof (time_t)); + _lastwrite = other._lastwrite; #endif //FILESYSTEM_TIMESTAMP_FEATURE return *this; } diff --git a/esp3d/src/modules/filesystem/esp_sd.cpp b/esp3d/src/modules/filesystem/esp_sd.cpp index 90418ca0..700f7298 100644 --- a/esp3d/src/modules/filesystem/esp_sd.cpp +++ b/esp3d/src/modules/filesystem/esp_sd.cpp @@ -85,12 +85,11 @@ ESP_SDFile::ESP_SDFile(const char * name, const char * filename, bool isdir, siz { _isdir = isdir; _dirlist = ""; - _isfakedir = isdir; _index = -1; _filename = filename; _name = name; #ifdef SD_TIMESTAMP_FEATURE - memset (&_lastwrite,0,sizeof(time_t)); + _lastwrite = 0; #endif //SD_TIMESTAMP_FEATURE _iswritemode = false; _size = size; @@ -195,7 +194,6 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other) { //log_esp3d("Copy %s", other._filename.c_str()); _isdir = other._isdir; - _isfakedir = other._isfakedir; _index = other._index; _filename = other._filename; _name = other._name; @@ -203,7 +201,7 @@ ESP_SDFile& ESP_SDFile::operator=(const ESP_SDFile & other) _iswritemode = other._iswritemode; _dirlist = other._dirlist; #ifdef SD_TIMESTAMP_FEATURE - memcpy(&_lastwrite, &(other._lastwrite), sizeof (time_t)); + _lastwrite = other._lastwrite; #endif //SD_TIMESTAMP_FEATURE return *this; } diff --git a/esp3d/src/modules/filesystem/esp_sd.h b/esp3d/src/modules/filesystem/esp_sd.h index 8134c062..ff8fc50d 100644 --- a/esp3d/src/modules/filesystem/esp_sd.h +++ b/esp3d/src/modules/filesystem/esp_sd.h @@ -60,7 +60,6 @@ public: private: String _dirlist; bool _isdir; - bool _isfakedir; bool _iswritemode; int8_t _index; String _filename; diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp index 028525c4..404ed798 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp32.cpp @@ -207,13 +207,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * { _isdir = isdir; _dirlist = ""; - _isfakedir = false; _index = -1; _filename = ""; _name = ""; -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE memset (&_lastwrite,0,sizeof(time_t)); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE _iswritemode = iswritemode; _size = 0; if (!handle) { @@ -228,7 +227,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * _filename = path; if (_name.endsWith("/")) { _name.remove( _name.length() - 1,1); - _isfakedir = true; _isdir = true; } if (_name[0] == '/') { @@ -241,9 +239,9 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * //size _size = tSDFile_handle[i].size(); //time -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE _lastwrite = tSDFile_handle[i].getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE _index = i; //log_esp3d("Opening File at index %d",_index); set = true; @@ -262,9 +260,9 @@ void ESP_SDFile::close() File ftmp = SD.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE _lastwrite = ftmp.getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE ftmp.close(); } } diff --git a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp index 956f466a..055535d2 100644 --- a/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_native_esp8266.cpp @@ -29,9 +29,47 @@ sd_native_esp8266.cpp - ESP3D sd support class extern sdfat::File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; using namespace sdfat; - SdFat SD; +#ifdef SD_TIMESTAMP_FEATURE +void dateTime (uint16_t* date, uint16_t* dtime) +{ + struct tm tmstruct; + time_t now; + time (&now); + localtime_r (&now, &tmstruct); + *date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday); + *dtime = FAT_TIME (tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); +} + +time_t getDateTimeFile(File & filehandle) +{ + time_t dt = 0; + struct tm timefile; + memset((void *)&timefile, 0, sizeof(tm)); + dir_t d; + 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; + if (mktime(&timefile) != -1) { + dt = mktime(&timefile); + } else { + log_esp3d("mktime failed"); + } + } else { + log_esp3d("stat file failed"); + } + return dt; +} + + +#endif //SD_TIMESTAMP_FEATURE + uint8_t ESP_SD::getState(bool refresh) { #if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1 @@ -70,6 +108,10 @@ bool ESP_SD::begin() if (_spi_speed_divider <= 0) { _spi_speed_divider = 1; } +#ifdef SD_TIMESTAMP_FEATURE + //set callback to get time on files on SD + SdFile::dateTimeCallback (dateTime); +#endif //SD_TIMESTAMP_FEATURE if (getState(true) == ESP_SDCARD_IDLE) { freeBytes(); } @@ -108,6 +150,7 @@ uint64_t ESP_SD::freeBytes() bool ESP_SD::format() { //not available yet + //SDFat has a feature for this return false; } @@ -222,13 +265,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * { _isdir = isdir; _dirlist = ""; - _isfakedir = false; _index = -1; _filename = ""; _name = ""; -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE memset (&_lastwrite,0,sizeof(time_t)); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE _iswritemode = iswritemode; _size = 0; if (!handle) { @@ -246,7 +288,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * _name = tmp; if (_name.endsWith("/")) { _name.remove( _name.length() - 1,1); - _isfakedir = true; _isdir = true; } if (_name[0] == '/') { @@ -259,9 +300,15 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * //size _size = tSDFile_handle[i].size(); //time -#ifdef FILESYSTEM_TIMESTAMP_FEATURE - _lastwrite = tSDFile_handle[i].getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE + if (!_isdir) { + _lastwrite = getDateTimeFile(tSDFile_handle[i]); + + } else { + //no need date time for directory + _lastwrite = 0; + } +#endif //SD_TIMESTAMP_FEATURE _index = i; //log_esp3d("Opening File at index %d",_index); set = true; @@ -277,7 +324,9 @@ const char* ESP_SDFile::shortname() const ftmp.getSFN(sname); ftmp.close(); return sname; - } else return _name.c_str(); + } else { + return _name.c_str(); + } } void ESP_SDFile::close() @@ -291,9 +340,9 @@ void ESP_SDFile::close() sdfat::File ftmp = SD.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); -#ifdef FILESYSTEM_TIMESTAMP_FEATURE - _lastwrite = ftmp.getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE + _lastwrite = getDateTimeFile(ftmp); +#endif //SD_TIMESTAMP_FEATURE ftmp.close(); } } @@ -328,7 +377,7 @@ ESP_SDFile ESP_SDFile::openNextFile() const char * ESP_SD::FilesystemName() { - return "SD native"; + return "SDFat"; } #endif //SD_DEVICE == ESP_SD_NATIVE diff --git a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp index 7645742f..da3f9cd5 100644 --- a/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sd_sdfat_esp32.cpp @@ -30,6 +30,45 @@ extern File tSDFile_handle[ESP_MAX_SD_OPENHANDLE]; #define FREQMZ 40 SdFat SD; +#ifdef SD_TIMESTAMP_FEATURE +void dateTime (uint16_t* date, uint16_t* dtime) +{ + struct tm tmstruct; + time_t now; + time (&now); + localtime_r (&now, &tmstruct); + *date = FAT_DATE ( (tmstruct.tm_year) + 1900, ( tmstruct.tm_mon) + 1, tmstruct.tm_mday); + *dtime = FAT_TIME (tmstruct.tm_hour, tmstruct.tm_min, tmstruct.tm_sec); +} + +time_t getDateTimeFile(File & filehandle) +{ + time_t dt = 0; + struct tm timefile; + memset((void *)&timefile, 0, sizeof(tm)); + dir_t d; + 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; + if (mktime(&timefile) != -1) { + dt = mktime(&timefile); + } else { + log_esp3d("mktime failed"); + } + } else { + log_esp3d("stat file failed"); + } + return dt; +} + + +#endif //SD_TIMESTAMP_FEATURE + uint8_t ESP_SD::getState(bool refresh) { #if defined(ESP_SD_DETECT_PIN) && ESP_SD_DETECT_PIN != -1 @@ -68,6 +107,10 @@ bool ESP_SD::begin() if (_spi_speed_divider <= 0) { _spi_speed_divider = 1; } +#ifdef SD_TIMESTAMP_FEATURE + //set callback to get time on files on SD + SdFile::dateTimeCallback (dateTime); +#endif //SD_TIMESTAMP_FEATURE if (getState(true) == ESP_SDCARD_IDLE) { freeBytes(); } @@ -106,6 +149,7 @@ uint64_t ESP_SD::freeBytes() bool ESP_SD::format() { //not available yet + //SDFat has a feature for this return false; } @@ -220,13 +264,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * { _isdir = isdir; _dirlist = ""; - _isfakedir = false; _index = -1; _filename = ""; _name = ""; -#ifdef FILESYSTEM_TIMESTAMP_FEATURE - memset (&_lastwrite,0,sizeof(time_t)); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE + _lastwrite = 0 ; +#endif //SD_TIMESTAMP_FEATURE _iswritemode = iswritemode; _size = 0; if (!handle) { @@ -244,7 +287,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * _name = tmp; if (_name.endsWith("/")) { _name.remove( _name.length() - 1,1); - _isfakedir = true; _isdir = true; } if (_name[0] == '/') { @@ -257,9 +299,15 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * //size _size = tSDFile_handle[i].size(); //time -#ifdef FILESYSTEM_TIMESTAMP_FEATURE - _lastwrite = tSDFile_handle[i].getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE + if (!_isdir) { + _lastwrite = getDateTimeFile(tSDFile_handle[i]); + + } else { + //no need date time for directory + _lastwrite = 0; + } +#endif //SD_TIMESTAMP_FEATURE _index = i; //log_esp3d("Opening File at index %d",_index); set = true; @@ -275,7 +323,9 @@ const char* ESP_SDFile::shortname() const ftmp.getSFN(sname); ftmp.close(); return sname; - } else return _name.c_str(); + } else { + return _name.c_str(); + } } void ESP_SDFile::close() @@ -289,9 +339,9 @@ void ESP_SDFile::close() File ftmp = SD.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); -#ifdef FILESYSTEM_TIMESTAMP_FEATURE - _lastwrite = ftmp.getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE + _lastwrite = getDateTimeFile(ftmp); +#endif //SD_TIMESTAMP_FEATURE ftmp.close(); } } @@ -326,7 +376,7 @@ ESP_SDFile ESP_SDFile::openNextFile() const char * ESP_SD::FilesystemName() { - return "SDfat"; + return "SDFat"; } #endif //SD_DEVICE == ESP_SD_NATIVE diff --git a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp index cbbdd7ff..70f572ea 100644 --- a/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp +++ b/esp3d/src/modules/filesystem/sd/sdio_esp32.cpp @@ -196,13 +196,12 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * { _isdir = isdir; _dirlist = ""; - _isfakedir = false; _index = -1; _filename = ""; _name = ""; -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE memset (&_lastwrite,0,sizeof(time_t)); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE _iswritemode = iswritemode; _size = 0; if (!handle) { @@ -217,7 +216,6 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * _filename = path; if (_name.endsWith("/")) { _name.remove( _name.length() - 1,1); - _isfakedir = true; _isdir = true; } if (_name[0] == '/') { @@ -230,9 +228,9 @@ ESP_SDFile::ESP_SDFile(void* handle, bool isdir, bool iswritemode, const char * //size _size = tSDFile_handle[i].size(); //time -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE _lastwrite = tSDFile_handle[i].getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE _index = i; //log_esp3d("Opening File at index %d",_index); set = true; @@ -251,9 +249,9 @@ void ESP_SDFile::close() File ftmp = SD_MMC.open(_filename.c_str()); if (ftmp) { _size = ftmp.size(); -#ifdef FILESYSTEM_TIMESTAMP_FEATURE +#ifdef SD_TIMESTAMP_FEATURE _lastwrite = ftmp.getLastWrite(); -#endif //FILESYSTEM_TIMESTAMP_FEATURE +#endif //SD_TIMESTAMP_FEATURE ftmp.close(); } } diff --git a/esp3d/src/modules/time/time_server.cpp b/esp3d/src/modules/time/time_server.cpp index 4df6de16..de3d5e1f 100644 --- a/esp3d/src/modules/time/time_server.cpp +++ b/esp3d/src/modules/time/time_server.cpp @@ -114,14 +114,26 @@ bool TimeServer::begin() return _started; } -const char * TimeServer::current_time() +const char * TimeServer::current_time(time_t t) { static String stmp; struct tm tmstruct; time_t now; stmp = ""; - time(&now); - localtime_r(&now, &tmstruct); + //get current time + if (t == 0) { + time(&now); + localtime_r(&now, &tmstruct); + } else { + /* struct tm * tmstructtmp = localtime(&t); + tmstruct.tm_year = tmstructtmp->tm_year; + tmstruct.tm_mon = tmstructtmp->tm_mon; + tmstruct.tm_mday = tmstructtmp->tm_mday; + tmstruct.tm_hour = tmstructtmp->tm_hour; + tmstruct.tm_min = tmstructtmp->tm_min; + tmstruct.tm_sec = tmstructtmp->tm_sec;*/ + localtime_r(&t, &tmstruct); + } stmp = String((tmstruct.tm_year)+1900) + "-"; if (((tmstruct.tm_mon)+1) < 10) { stmp +="0"; diff --git a/esp3d/src/modules/time/time_server.h b/esp3d/src/modules/time/time_server.h index f5b23eec..b03d7412 100644 --- a/esp3d/src/modules/time/time_server.h +++ b/esp3d/src/modules/time/time_server.h @@ -23,6 +23,7 @@ #ifndef _TIME_SERVER_H #define _TIME_SERVER_H +#include class TimeServer { @@ -32,7 +33,7 @@ public: bool begin(); void end(); void handle(); - const char * current_time(); + const char * current_time(time_t t = 0); bool setTime(const char* stime); bool started(); bool is_internet_time(bool readfromsettings = false);