8000 Add fileCreation/getCreation create-time accessors by earlephilhower · Pull Request #7000 · esp8266/Arduino · GitHub
[go: up one dir, main page]

Skip to content

Add fileCreation/getCreation create-time accessors #7000

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 12 commits into from
Feb 22, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Enable SdFat's sateTime callback for timestamping
SdFat requries the dateTimeCallback call (global for everything) to
update dates and times on created files.

Because the callback signature doesn't have space for us to provide
any parameters, we cannot get the the File, Dir, or FS object's
dateTimeCB member.  Instead, just go with `time(null)` as the callback
function which is right in all but the most esoteric cases.
  • Loading branch information
earlephilhower committed Jan 19, 2020
commit 76a0a1d24cecd232c823dd949dbe7968b2dadcb9
12 changes: 12 additions & 0 deletions libraries/SDFS/src/SDFS.h
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,7 @@ class SDFSImpl : public FSImpl
format();
_mounted = _fs.begin(_cfg._csPin, _cfg._spiSettings);
}
sdfat::SdFile::dateTimeCallback(dateTimeCB);
return _mounted;
}

Expand Down Expand Up @@ -204,6 +205,17 @@ class SDFSImpl : public FSImpl
return mktime(&tiempo);
}

// Because SdFat has a single, global setting for this we can only use a
// static member of our class to return the time/date. However, since
// this is static, we can't see the time callback variable. Punt for now,
// using time(NULL) as the best we can do.
static void dateTimeCB(uint16_t *dosYear, uint16_t *dosTime) {
time_t now = time(nullptr);
struct tm *tiempo = localtime(&now);
*dosYear = ((tiempo->tm_year - 1980) << 9) | (tiempo->tm_mon << 5) | tiempo->tm_mday;
*dosTime = (tiempo->tm_hour << 11) | (tiempo->tm_min << 5) | tiempo->tm_sec;
}

protected:
friend class SDFileImpl;
friend class SDFSDirImpl;
Expand Down
0