From 5829df6dd327115b929fc842f3cf92ab90be72b8 Mon Sep 17 00:00:00 2001 From: vk7js <58905135+vk7js@users.noreply.github.com> Date: Tue, 13 Sep 2022 15:40:12 +1000 Subject: [PATCH] Now read speed, altitude and direction changes on the GPS screen automatically with a forced minimum of 10 seconds between readings to avoid a bit of hysterisis . Can still get full summary on long hold f1. --- openrtx/include/core/voicePromptUtils.h | 2 +- openrtx/include/core/voicePrompts.h | 16 ++ openrtx/src/core/voicePromptUtils.c | 197 ++++++++++++++---------- openrtx/src/ui/ui.c | 48 +++++- 4 files changed, 176 insertions(+), 87 deletions(-) diff --git a/openrtx/include/core/voicePromptUtils.h b/openrtx/include/core/voicePromptUtils.h index 2534d592..9d6999b2 100644 --- a/openrtx/include/core/voicePromptUtils.h +++ b/openrtx/include/core/voicePromptUtils.h @@ -155,7 +155,7 @@ void vp_announceM17Info(const channel_t* channel, const vpQueueFlags_t flags); * */ #ifdef GPS_PRESENT -void vp_announceGPSInfo(); +void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags); #endif /** diff --git a/openrtx/include/core/voicePrompts.h b/openrtx/include/core/voicePrompts.h index dc9fb483..ba95b733 100644 --- a/openrtx/include/core/voicePrompts.h +++ b/openrtx/include/core/voicePrompts.h @@ -242,6 +242,22 @@ typedef enum } vpSummaryInfoFlags_t; +typedef enum +{ + vpGPSNone=0, + vpGPSIntro=0x01, + vpGPSFixQuality = 0x02, + vpGPSFixType = 0x04, + vpGPSLatitude = 0x08, + vpGPSLongitude = 0x10, + vpGPSSpeed = 0x20, + vpGPSAltitude = 0x40, + vpGPSDirection = 0x80, + vpGPSSatCount = 0x100, + vpGPSAll = 0xff, +} +vpGPSInfoFlags_t; + typedef struct { uint16_t freq; diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index 2ce1a07e..8ce39aa4 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -527,104 +527,131 @@ void vp_announceM17Info(const channel_t* channel, const vpQueueFlags_t flags) } #ifdef GPS_PRESENT -void vp_announceGPSInfo() +void vp_announceGPSInfo(vpGPSInfoFlags_t gpsInfoFlags) { vp_flush(); vpQueueFlags_t flags = vpqIncludeDescriptions | vpqAddSeparatingSilence; - - vp_queueStringTableEntry(¤tLanguage->gps); - if (!state.settings.gps_enabled) + + if (gpsInfoFlags & vpGPSIntro) { - vp_queueStringTableEntry(¤tLanguage->off); - vp_play(); - - return; - } - - switch (state.gps_data.fix_quality) - { - case 0: - vp_queueStringTableEntry(¤tLanguage->noFix); + vp_queueStringTableEntry(¤tLanguage->gps); + if (!state.settings.gps_enabled) + { + vp_queueStringTableEntry(¤tLanguage->off); vp_play(); + return; - case 1: - vp_queueString("SPS", vpAnnounceCommonSymbols); - break; - - case 2: - vp_queueString("DGPS", vpAnnounceCommonSymbols); - break; - - case 3: - vp_queueString("PPS", vpAnnounceCommonSymbols); - break; - - case 6: - vp_queueStringTableEntry(¤tLanguage->fixLost); - break; - - default: - vp_queueStringTableEntry(¤tLanguage->error); - - vp_play(); - - return; + } } - - addSilenceIfNeeded(flags); - - switch (state.gps_data.fix_type) + + if (gpsInfoFlags & vpGPSFixQuality) { - case 2: - vp_queueString("2D", vpAnnounceCommonSymbols); - break; + switch (state.gps_data.fix_quality) + { + case 0: + vp_queueStringTableEntry(¤tLanguage->noFix); + vp_play(); + return; + case 1: + vp_queueString("SPS", vpAnnounceCommonSymbols); + break; - case 3: - vp_queueString("3D", vpAnnounceCommonSymbols); - break; + case 2: + vp_queueString("DGPS", vpAnnounceCommonSymbols); + break; + + case 3: + vp_queueString("PPS", vpAnnounceCommonSymbols); + break; + + case 6: + vp_queueStringTableEntry(¤tLanguage->fixLost); + break; + + default: + vp_queueStringTableEntry(¤tLanguage->error); + + vp_play(); + + return; + } + + addSilenceIfNeeded(flags); + } + if (gpsInfoFlags & vpGPSFixType) + { + switch (state.gps_data.fix_type) + { + case 2: + vp_queueString("2D", vpAnnounceCommonSymbols); + break; + + case 3: + vp_queueString("3D", vpAnnounceCommonSymbols); + break; + } + + addSilenceIfNeeded(flags); } - - addSilenceIfNeeded(flags); - - // lat/long + char buffer[16] = "\0"; - snprintf(buffer, 16, "%8.6f", state.gps_data.latitude); - removeUnnecessaryZerosFromVoicePrompts(buffer); - vp_queuePrompt(PROMPT_LATITUDE); - vp_queueString(buffer, vpAnnounceCommonSymbols); - vp_queuePrompt(PROMPT_NORTH); + + if (gpsInfoFlags & vpGPSLatitude) + { + // lat/long + snprintf(buffer, 16, "%8.6f", state.gps_data.latitude); + removeUnnecessaryZerosFromVoicePrompts(buffer); + vp_queuePrompt(PROMPT_LATITUDE); + vp_queueString(buffer, vpAnnounceCommonSymbols); + vp_queuePrompt(PROMPT_NORTH); + } + + if (gpsInfoFlags & vpGPSLongitude) + { + float longitude = state.gps_data.longitude; + voicePrompt_t direction = (longitude < 0) ? PROMPT_WEST : PROMPT_EAST; + longitude = (longitude < 0) ? -longitude : longitude; + snprintf(buffer, 16, "%8.6f", longitude); + removeUnnecessaryZerosFromVoicePrompts(buffer); - float longitude = state.gps_data.longitude; - voicePrompt_t direction = (longitude < 0) ? PROMPT_WEST : PROMPT_EAST; - longitude = (longitude < 0) ? -longitude : longitude; - snprintf(buffer, 16, "%8.6f", longitude); - removeUnnecessaryZerosFromVoicePrompts(buffer); - - vp_queuePrompt(PROMPT_LONGITUDE); - vp_queueString(buffer, vpAnnounceCommonSymbols); - vp_queuePrompt(direction); - addSilenceIfNeeded(flags); - - // speed/altitude: - snprintf(buffer, 16, "%4.1fkm/h", state.gps_data.speed); - vp_queuePrompt(PROMPT_SPEED); - vp_queueString(buffer, vpAnnounceCommonSymbols); - vp_queuePrompt(PROMPT_ALTITUDE); - - snprintf(buffer, 16, "%4.1fm", state.gps_data.altitude); - vp_queueString(buffer, vpAnnounceCommonSymbols); - addSilenceIfNeeded(flags); - - snprintf(buffer, 16, "%3.1f", state.gps_data.tmg_true); - vp_queuePrompt(PROMPT_COMPASS); - vp_queueString(buffer, vpAnnounceCommonSymbols); - vp_queuePrompt(PROMPT_DEGREES); - addSilenceIfNeeded(flags); - - vp_queuePrompt(PROMPT_SATELLITES); - vp_queueInteger(state.gps_data.satellites_in_view); + vp_queuePrompt(PROMPT_LONGITUDE); + vp_queueString(buffer, vpAnnounceCommonSymbols); + vp_queuePrompt(direction); + addSilenceIfNeeded(flags); + } + + if (gpsInfoFlags & vpGPSSpeed) + { + // speed/altitude: + snprintf(buffer, 16, "%4.1fkm/h", state.gps_data.speed); + vp_queuePrompt(PROMPT_SPEED); + vp_queueString(buffer, vpAnnounceCommonSymbols); + } + + if (gpsInfoFlags & vpGPSAltitude) + { + vp_queuePrompt(PROMPT_ALTITUDE); + snprintf(buffer, 16, "%4.1fm", state.gps_data.altitude); + vp_queueString(buffer, vpAnnounceCommonSymbols); + addSilenceIfNeeded(flags); + } + + if (gpsInfoFlags & vpGPSDirection) + { + snprintf(buffer, 16, "%3.1f", state.gps_data.tmg_true); + vp_queuePrompt(PROMPT_COMPASS); + vp_queueString(buffer, vpAnnounceCommonSymbols); + vp_queuePrompt(PROMPT_DEGREES); + addSilenceIfNeeded(flags); + } + + if (gpsInfoFlags & vpGPSSatCount) + { + vp_queuePrompt(PROMPT_SATELLITES); + vp_queueInteger(state.gps_data.satellites_in_view); + } vp_play(); } #endif // GPS_PRESENT @@ -769,7 +796,7 @@ void vp_announceScreen(uint8_t ui_screen) break; #ifdef GPS_PRESENT case MENU_GPS: - vp_announceGPSInfo(); + vp_announceGPSInfo(vpGPSAll); break; #endif // GPS_PRESENT case MENU_BACKUP: diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index bed61eba..51edd00f 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -1132,6 +1132,42 @@ void ui_saveState() last_state = state; } +#ifdef GPS_PRESENT +static float priorGPSSpeed = 0; +static float priorGPSAltitude = 0; +static float priorGPSDirection = 0; +static uint32_t vpGPSLastUpdate = 0; + +static vpGPSInfoFlags_t GetGPSDirectionOrSpeedChanged() +{ + uint32_t now = getTick(); + if (now - vpGPSLastUpdate < 10000) + return vpGPSNone; + vpGPSLastUpdate=now; + + if (!state.settings.gps_enabled) + return vpGPSNone; + if (state.gps_data.fix_quality == 0 || state.gps_data.fix_quality >= 6) + return vpGPSNone; + + vpGPSInfoFlags_t whatChanged= vpGPSNone; + if (state.gps_data.speed != priorGPSSpeed) + whatChanged |= vpGPSSpeed; + + if (state.gps_data.altitude != priorGPSAltitude) + whatChanged |= vpGPSAltitude; + + if (state.gps_data.tmg_true != priorGPSDirection) + whatChanged |= vpGPSDirection; + + priorGPSSpeed = state.gps_data.speed; + priorGPSAltitude = state.gps_data.altitude; + priorGPSDirection = state.gps_data.tmg_true; + + return whatChanged; +} +#endif // GPS_PRESENT + void ui_updateFSM(bool *sync_rtx) { // Check for events @@ -1591,7 +1627,7 @@ void ui_updateFSM(bool *sync_rtx) if ((msg.keys & KEY_F1) && (state.settings.vpLevel > vpBeep)) {// quick press repeat vp, long press summary. if (msg.long_press) - vp_announceGPSInfo(); + vp_announceGPSInfo(vpGPSAll); else vp_replayLastPrompt(); f1Handled = true; @@ -1980,6 +2016,16 @@ void ui_updateFSM(bool *sync_rtx) else if(event.type == EVENT_STATUS) { ReleaseFunctionLatchIfNeeded(); +#ifdef GPS_PRESENT + if ((state.ui_screen == MENU_GPS) && + (!txOngoing && !rtx_rxSquelchOpen()) && + (state.settings.vpLevel > vpLow)) + {// automatically read speed and direction changes only! + vpGPSInfoFlags_t whatChanged = GetGPSDirectionOrSpeedChanged(); + if (whatChanged != vpGPSNone) + vp_announceGPSInfo(whatChanged); + } +#endif // GPS_PRESENT if (txOngoing || rtx_rxSquelchOpen()) {