From 87b57766483c4efcd65c931789d4edf87522a8b8 Mon Sep 17 00:00:00 2001 From: jpirnay Date: Mon, 20 Apr 2026 09:07:56 +0200 Subject: [PATCH] Wire clock to fil date times --- lib/hal/HalStorage.cpp | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/lib/hal/HalStorage.cpp b/lib/hal/HalStorage.cpp index a565b355..0b4bc5fa 100644 --- a/lib/hal/HalStorage.cpp +++ b/lib/hal/HalStorage.cpp @@ -2,11 +2,13 @@ #include "HalStorage.h" #include // need to be included before SdFat.h for compatibility with FS.h's File class +#include #include #include #include #include +#include #include #define SDCard SDCardManager::getInstance() @@ -20,7 +22,18 @@ HalStorage::HalStorage() { // begin() and ready() are only called from setup, no need to acquire mutex for them -bool HalStorage::begin() { return SDCard.begin(); } +bool HalStorage::begin() { + if (!SDCard.begin()) return false; + FsDateTime::setCallback([](uint16_t* date, uint16_t* time) { + if (!HalClock::isSynced()) return; + const time_t t = HalClock::now(); + const struct tm* tm = localtime(&t); + if (!tm) return; + *date = FS_DATE(tm->tm_year + 1900, tm->tm_mon + 1, tm->tm_mday); + *time = FS_TIME(tm->tm_hour, tm->tm_min, tm->tm_sec); + }); + return true; +} bool HalStorage::ready() const { return SDCard.ready(); }