rtc: add settings entry for RTC sync with GPS
Added settings menu entry to make RTC synchronization with GPS persistent across reboots. When the synchronization is enabled the RTC will be updated on the first valid RMC sentence received. Signed-off-by: Silvano Seva <silseva@fastwebnet.it>
This commit is contained in:
parent
b3b057699b
commit
c95f9ab6b6
|
|
@ -63,6 +63,7 @@ typedef struct
|
|||
bool m17_can_rx; // Check M17 CAN on RX
|
||||
char m17_dest[10]; // M17 destination
|
||||
bool showBatteryIcon; // Battery display true: icon, false: percentage
|
||||
bool gpsSetTime; // Use GPS to ajust RTC time
|
||||
}
|
||||
__attribute__((packed)) settings_t;
|
||||
|
||||
|
|
@ -89,6 +90,7 @@ static const settings_t default_settings =
|
|||
false, // Check M17 CAN on RX
|
||||
"", // Empty M17 destination
|
||||
false, // Display battery icon
|
||||
false, // Update RTC with GPS
|
||||
};
|
||||
|
||||
#endif /* SETTINGS_H */
|
||||
|
|
|
|||
|
|
@ -29,6 +29,23 @@
|
|||
|
||||
static bool gpsEnabled = false;
|
||||
|
||||
#ifdef CONFIG_RTC
|
||||
static bool rtcSyncDone = false;
|
||||
static void syncRtc(datetime_t timestamp)
|
||||
{
|
||||
if(state.settings.gpsSetTime == false) {
|
||||
rtcSyncDone = false;
|
||||
return;
|
||||
}
|
||||
|
||||
if(rtcSyncDone)
|
||||
return;
|
||||
|
||||
platform_setTime(timestamp);
|
||||
rtcSyncDone = true;
|
||||
}
|
||||
#endif
|
||||
|
||||
void gps_task(const struct gpsDevice *dev)
|
||||
{
|
||||
char sentence[2*MINMEA_MAX_LENGTH];
|
||||
|
|
@ -81,6 +98,10 @@ void gps_task(const struct gpsDevice *dev)
|
|||
gps_data.timestamp.month = frame.date.month;
|
||||
gps_data.timestamp.year = frame.date.year;
|
||||
gps_data.speed = KNOTS2KMH(minmea_toint(&frame.speed));
|
||||
#ifdef CONFIG_RTC
|
||||
if(frame.valid)
|
||||
syncRtc(gps_data.timestamp);
|
||||
#endif
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
|
@ -171,20 +192,4 @@ void gps_task(const struct gpsDevice *dev)
|
|||
pthread_mutex_lock(&state_mutex);
|
||||
state.gps_data = gps_data;
|
||||
pthread_mutex_unlock(&state_mutex);
|
||||
|
||||
// Synchronize RTC with GPS UTC clock, only when fix is done
|
||||
#ifdef CONFIG_RTC
|
||||
if(state.gps_set_time)
|
||||
{
|
||||
if((sId == MINMEA_SENTENCE_RMC) && (gps_data.fix_quality > 0))
|
||||
{
|
||||
platform_setTime(gps_data.timestamp);
|
||||
|
||||
// Done, clear the flag
|
||||
pthread_mutex_lock(&state_mutex);
|
||||
state.gps_set_time = false;
|
||||
pthread_mutex_unlock(&state_mutex);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2156,10 +2156,10 @@ void ui_updateFSM(bool *sync_rtx)
|
|||
state.settings.gps_enabled);
|
||||
break;
|
||||
case G_SET_TIME:
|
||||
state.gps_set_time = !state.gps_set_time;
|
||||
state.settings.gpsSetTime = !state.settings.gpsSetTime;
|
||||
vp_announceSettingsOnOffToggle(¤tLanguage->gpsSetTime,
|
||||
queueFlags,
|
||||
state.gps_set_time);
|
||||
state.settings.gpsSetTime);
|
||||
break;
|
||||
case G_TIMEZONE:
|
||||
if(msg.keys & KEY_LEFT || msg.keys & KEY_DOWN ||
|
||||
|
|
|
|||
|
|
@ -316,7 +316,7 @@ int _ui_getSettingsGPSValueName(char *buf, uint8_t max_len, uint8_t index)
|
|||
currentLanguage->off);
|
||||
break;
|
||||
case G_SET_TIME:
|
||||
sniprintf(buf, max_len, "%s", (last_state.gps_set_time) ?
|
||||
sniprintf(buf, max_len, "%s", (last_state.settings.gpsSetTime) ?
|
||||
currentLanguage->on :
|
||||
currentLanguage->off);
|
||||
break;
|
||||
|
|
|
|||
Loading…
Reference in New Issue