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

@ -105,6 +105,10 @@ radio_remote
#endif
#endif
#if defined(HAVE_RDS_CAP)
rds
#endif
#if defined(HAVE_RECORDING)
recording
#if defined(HAVE_LINE_IN)

View file

@ -16229,3 +16229,20 @@
*: "Prefer Image File"
</voice>
</phrase>
<phrase>
id: LANG_FM_SYNC_RDS_TIME
desc: in radio screen and Settings
user: core
<source>
*: none
rds: "Sync RDS Time"
</source>
<dest>
*: none
rds: "Sync RDS Time"
</dest>
<voice>
*: none
rds: "Sync RDS Time"
</voice>
</phrase>

View file

@ -87,6 +87,9 @@ MENUITEM_FUNCTION(presetclear_item, 0, ID2P(LANG_FM_PRESET_CLEAR),
MENUITEM_SETTING(set_region, &global_settings.fm_region, NULL);
MENUITEM_SETTING(force_mono, &global_settings.fm_force_mono, NULL);
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
MENUITEM_SETTING(sync_rds_time, &global_settings.sync_rds_time, NULL);
#endif
#ifndef FM_MODE
extern int radio_mode;
@ -146,6 +149,9 @@ MAKE_MENU(radio_settings_menu, ID2P(LANG_FM_MENU), NULL,
#endif
#ifdef FM_RECORDING_SETTINGS
&recsettings_item,
#endif
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
&sync_rds_time,
#endif
&scan_presets_item);

View file

@ -242,6 +242,9 @@ static int time_menu_callback(int action,
return action;
}
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
MENUITEM_SETTING(sync_rds_time, &global_settings.sync_rds_time, NULL);
#endif
MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), time_menu_callback, Icon_NOICON,
&time_set,
@ -250,6 +253,9 @@ MAKE_MENU(time_menu, ID2P(LANG_TIME_MENU), time_menu_callback, Icon_NOICON,
#if defined(HAVE_RECORDING) || CONFIG_TUNER
&alarm_wake_up_screen,
#endif
#endif
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
&sync_rds_time,
#endif
&timeformat);

View file

@ -458,6 +458,9 @@ struct user_settings
unsigned char rfms_file[MAX_FILENAME+1]; /* last remote-fms */
#endif
#endif /* CONFIG_TUNER */
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
bool sync_rds_time; /* use RDS time to set the clock */
#endif
/* misc options */
#ifndef HAVE_WHEEL_ACCELERATION

View file

@ -1096,6 +1096,9 @@ const struct settings_list settings[] = {
false, "force fm mono", toggle_mono_mode),
SYSTEM_SETTING(NVRAM(4), last_frequency, 0),
#endif
#if defined(HAVE_RDS_CAP) && defined(CONFIG_RTC)
OFFON_SETTING(0, sync_rds_time, LANG_FM_SYNC_RDS_TIME, false, "sync_rds_time", NULL),
#endif
#if BATTERY_TYPES_COUNT > 1
CHOICE_SETTING(0, battery_type, LANG_BATTERY_TYPE, 0, "battery type",

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:;

View file

@ -370,6 +370,10 @@
force fm mono
& off, on & N/A\\
}%
\opt{rds}{
sync RDS time
& off, on & N/A\\
}%
\bottomrule
\end{longtable}

View file

@ -21,4 +21,9 @@ if voice support is enabled.
}%\opt{recording,radio}
}%\opt{alarm}
\item[Time Format:] Choose 12 or 24 hour clock.
\opt{rds}{
\item[Sync RDS time:]
If this option is enabled, your clock will be kept in sync with the time provided
by Radio Data System (RDS) if the currently selected station provides it.
}%\opt{rds}
\end{description}