Tried to add the time call back function so that files created on the sd card get a correct time and date, not working sadly, the sd card lib might be at fault here

This commit is contained in:
anschrammh 2020-02-02 20:54:10 +01:00
parent 45f22dea3e
commit fe8b51d3a8
2 changed files with 32 additions and 0 deletions

View File

@ -1,5 +1,10 @@
#include "SAB.h"
//Initializing the static pointer to the RtcManager
//Ugly, but I don't know how to do it an other way
//This static member is used to declare the callback necessary to set the file system's time
RtcManager *SAB::_rtcManagerP = NULL;
SAB::SAB() : _sdCardManager(_boardConfig.getSPI_SDCard_cs(), _boardConfig.getSPISpeed()),
_display(_boardConfig.getScreenWidth(),_boardConfig.getScreenHeight(), &Wire),
_screenManager(_display, &_sdCardManager),
@ -23,8 +28,16 @@ _error(0)
//We initialize the pins for the I2C communication
Wire.begin(_boardConfig.getI2C_sda(), _boardConfig.getI2C_scl());
if(!_rtc.begin()) _error |= RTC_BEGIN_ERR;
else
{
SAB::_rtcManagerP = &_rtcManager;
}
if(!_display.begin(SSD1306_SWITCHCAPVCC, _boardConfig.getI2C_screenAddress())){ _error |= DISP_BEGIN_ERR; }
if(!_sdCardManager.mountSD()){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(8000000); Serial.print(" CS PIN : "); Serial.println(_boardConfig.getSPI_SDCard_cs());}
else
{
_sdCardManager.setTimeCallback(&(SAB::myTimeCallback));
}
_screenManager.init();
_connectivityManager = new ConnectivityManager(_sdCardManager);
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
@ -55,8 +68,16 @@ _error(0)
//We initialize the pins for the I2C communication
Wire.begin(_boardConfig.getI2C_sda(), _boardConfig.getI2C_scl());
if(!_rtc.begin()) _error |= RTC_BEGIN_ERR;
else
{
SAB::_rtcManagerP = &_rtcManager;
}
if(!_display.begin(SSD1306_SWITCHCAPVCC, _boardConfig.getI2C_screenAddress())) _error |= DISP_BEGIN_ERR;
if(!_sdCardManager.mountSD()){ _error |= SDCARD_INIT_ERR; Serial.print("Failed to init SDCard : SPI_SPEED : "); Serial.print(8000000); Serial.print(" CS PIN : "); Serial.println(_boardConfig.getSPI_SDCard_cs());}
else
{
_sdCardManager.setTimeCallback(&(SAB::myTimeCallback));
}
_screenManager.init();
_connectivityManager = new ConnectivityManager(_sdCardManager);
if(!_pcf.begin()){_error |= IO_INIT_ERR;}
@ -69,6 +90,14 @@ void SAB::initGPIO()
pinMode(GPIO_0, INPUT);
}
time_t SAB::myTimeCallback()
{
if(SAB::_rtcManagerP != NULL)
return SAB::_rtcManagerP->getDateTime().unixtime();
else
return 0;
}
ScreenManager& SAB::getScreenManager()
{
return _screenManager;

View File

@ -47,12 +47,15 @@ class SAB
unsigned char getError() const;
private:
void initGPIO();
static time_t myTimeCallback();
const BoardConfig _boardConfig;
Adafruit_SSD1306 _display;
ScreenManager _screenManager;
RTC_DS3231 _rtc;
RtcManager _rtcManager;
static RtcManager *_rtcManagerP;
SDCardManager _sdCardManager;
ConnectivityManager *_connectivityManager;
//WEBServerManager _webServerManager;