sync clock with RDS time

Tested with my SansaClip+. I don't think this will need extra battery
but let me know if I am wrong.

Change-Id: I287dae134113e0f8a138af68f5087b8ea45b0f4c
This commit is contained in:
Wolfram Sang 2021-11-25 22:18:44 +01:00
parent 5b8873bf33
commit 95dfc489b5
9 changed files with 64 additions and 2 deletions

View file

@ -25,6 +25,8 @@
#include <kernel.h>
#include "rds.h"
#include "time.h"
#include "timefuncs.h"
#include "settings.h"
#include "string-extra.h"
#define TIMED_OUT(tick) \
@ -225,6 +227,18 @@ void rds_sync(void)
}
}
void rds_set_time(time_t time)
{
ct_data = time;
#ifdef CONFIG_RTC
if (ct_data && global_settings.sync_rds_time) {
struct tm *tm = gmtime(&ct_data);
set_time(tm);
}
#endif
}
#if (CONFIG_RDS & RDS_CFG_PROCESS)
/* handles a group 0 packet, returns true if a new message was received */
static void handle_group0(const uint16_t data[4])
@ -367,7 +381,7 @@ static void handle_group4a(const uint16_t data[4])
seconds += hour * 3600;
seconds += minute * 60;
seconds += ((offset_sig == 0) ? offset_abs : -offset_abs) * 1800;
ct_data = seconds;
rds_set_time(seconds);
}
}
@ -428,7 +442,7 @@ void rds_push_info(enum rds_info_id info_id, uintptr_t data, size_t size)
SET_TIMEOUT(rt_copy_tmo, TEXT_TIMEOUT);
break;
case RDS_INFO_CT:
ct_data = (time_t)data;
rds_set_time((time_t)data);
break;
default:;