Remove C time API glue from driver

This commit is contained in:
BlackMark 2020-05-15 10:20:56 +02:00
parent 9303fbf5b5
commit 04af54e7c8
2 changed files with 0 additions and 136 deletions

View File

@ -1,107 +0,0 @@
#include "systime.h"
//////////////////////////////////////////////////////////////////////////
// DST magic by Edgar Bonet
int SysTime::euDST( const time_t *pTime, int32_t *pZ )
{
static_cast<void>( pZ );
uint32_t t = *pTime;
if( static_cast<uint8_t>( t >> 24 ) >= 194 )
t -= 3029443200U;
t = ( t + 655513200 ) / 604800 * 28;
if( static_cast<uint16_t>( t % 1461 ) < 856 )
return ONE_HOUR;
return 0;
}
//////////////////////////////////////////////////////////////////////////
bool SysTime::init()
{
twi_init_master();
rtc_init();
if( !rtc_is_ds3231() )
return false;
set_zone( 1 * ONE_HOUR );
set_dst( euDST );
syncSysTime();
return true;
}
//////////////////////////////////////////////////////////////////////////
void SysTime::syncSysTime()
{
tm sTime = getTime();
set_system_time( mk_gmtime( &sTime ) );
}
//////////////////////////////////////////////////////////////////////////
bool SysTime::checkSync()
{
time_t timeNow = time( nullptr );
tm *ptmUTC = gmtime( &timeNow );
rtc_tm *ptmRtcTime = rtc_get_time();
if( ptmUTC->tm_sec != ptmRtcTime->sec || ptmUTC->tm_min != ptmRtcTime->min || ptmUTC->tm_hour != ptmRtcTime->hour )
return false;
if( ptmUTC->tm_mday != ptmRtcTime->mday || ( ptmUTC->tm_mon + 1 ) != ptmRtcTime->mon || ( ptmUTC->tm_year + 1900 ) != ptmRtcTime->year )
return false;
return true;
}
//////////////////////////////////////////////////////////////////////////
void SysTime::tick()
{
system_tick();
}
//////////////////////////////////////////////////////////////////////////
tm SysTime::getTime()
{
tm sTime;
rtc_tm *ptmTime = rtc_get_time();
sTime.tm_sec = ptmTime->sec;
sTime.tm_min = ptmTime->min;
sTime.tm_hour = ptmTime->hour;
sTime.tm_mday = ptmTime->mday;
sTime.tm_mon = ptmTime->mon - 1;
sTime.tm_year = ptmTime->year - 1900;
sTime.tm_isdst = 0;
time_t timeUTC = mk_gmtime( &sTime );
sTime = *( gmtime( &timeUTC ) );
return sTime;
}
//////////////////////////////////////////////////////////////////////////
void SysTime::setTime( const tm &sTime )
{
rtc_tm *pRtcTime = rtc_get_time();
pRtcTime->sec = sTime.tm_sec;
pRtcTime->min = sTime.tm_min;
pRtcTime->hour = sTime.tm_hour;
pRtcTime->mday = sTime.tm_mday;
pRtcTime->mon = sTime.tm_mon + 1;
pRtcTime->year = sTime.tm_year + 1900;
pRtcTime->wday = sTime.tm_wday + 1;
pRtcTime->am = ( sTime.tm_hour < 12 ) ? true : false;
pRtcTime->twelveHour = ( sTime.tm_hour == 0 ) ? 12 : ( ( sTime.tm_hour > 12 ) ? ( sTime.tm_hour - 12 ) : sTime.tm_hour );
rtc_set_time( pRtcTime );
syncSysTime();
}

View File

@ -1,29 +0,0 @@
/*
* Copyright (c) by BlackMark 2017
* Date 17/12/2016
* Version 1.0
*/
#ifndef SYSTIME_H
#define SYSTIME_H
#include <time.h>
#include "twi.h"
#include "rtc.h"
class SysTime
{
private:
static int euDST( const time_t *pTime, int32_t *pZ );
public:
static bool init();
static void syncSysTime();
static bool checkSync();
static void tick();
static tm getTime();
static void setTime( const tm &sTime );
};
#endif