From cad026f9025ea6dc66c4e43d360f6f41d8832668 Mon Sep 17 00:00:00 2001 From: Silvano Seva Date: Wed, 31 Aug 2022 12:37:34 +0200 Subject: [PATCH] Renamed vp_clearCurrPrompt() to vp_flush(), added a vp_stop() function allowing to stop an in-progress voice prompt but without flushing the data buffer --- openrtx/include/core/voicePrompts.h | 11 ++++++++--- openrtx/src/core/voicePromptUtils.c | 20 ++++++++++---------- openrtx/src/core/voicePrompts.c | 14 ++++++++++---- openrtx/src/ui/ui.c | 4 ++-- openrtx/src/ui/ui_menu.c | 2 +- tests/unit/voice_prompts.c | 2 +- 6 files changed, 32 insertions(+), 21 deletions(-) diff --git a/openrtx/include/core/voicePrompts.h b/openrtx/include/core/voicePrompts.h index 55e5a644..e9bea718 100644 --- a/openrtx/include/core/voicePrompts.h +++ b/openrtx/include/core/voicePrompts.h @@ -238,10 +238,15 @@ void vp_init(); void vp_terminate(); /** - * Clear the currently in-progress prompt, to be called before building a new - * voice prompt sequence. + * Stop an in-progress prompt and rewind data pointers to the beginning keeping + * prompt data intact. This allows to replay the prompt. */ -void vp_clearCurrPrompt(); +void vp_stop(); + +/** + * Stop an in-progress prompt, if present, and clear the prompt data buffer. + */ +void vp_flush(); /** * Append an individual prompt item to the prompt queue. diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index cd8fbc05..85d06622 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -34,7 +34,7 @@ static void clearCurrPromptIfNeeded(const vpQueueFlags_t flags) { if (flags & vpqInit) - vp_clearCurrPrompt(); + vp_flush(); } static void playIfNeeded(const vpQueueFlags_t flags) @@ -73,7 +73,7 @@ static void removeUnnecessaryZerosFromVoicePrompts(char* str) void vp_announceVFO() { - vp_clearCurrPrompt(); + vp_flush(); vp_queuePrompt(PROMPT_VFO); vp_play(); } @@ -204,7 +204,7 @@ void vp_announceChannelSummary(const channel_t* channel, if (channel == NULL) return; - vp_clearCurrPrompt(); + vp_flush(); vpQueueFlags_t localFlags = vpqAddSeparatingSilence; @@ -275,7 +275,7 @@ void vp_announceInputChar(const char ch) char buf[2] = "\0"; buf[0] = ch; - vp_clearCurrPrompt(); + vp_flush(); uint8_t flags = vpAnnounceCaps | vpAnnounceSpace @@ -301,7 +301,7 @@ void vp_announceInputReceiveOrTransmit(const bool tx, const vpQueueFlags_t flags void vp_replayLastPrompt() { if (vp_isPlaying()) - vp_terminate(); + vp_stop(); else vp_play(); } @@ -533,7 +533,7 @@ void vp_announceGPSInfo() if (!state.settings.gps_enabled) return; - vp_clearCurrPrompt(); + vp_flush(); vpQueueFlags_t flags = vpqIncludeDescriptions | vpqAddSeparatingSilence; @@ -626,7 +626,7 @@ void vp_announceGPSInfo() void vp_announceAboutScreen() { - vp_clearCurrPrompt(); + vp_flush(); vp_queueStringTableEntry(¤tLanguage->openRTX); @@ -641,7 +641,7 @@ void vp_announceAboutScreen() void vp_announceBackupScreen() { - vp_clearCurrPrompt(); + vp_flush(); vp_queueStringTableEntry(¤tLanguage->flashBackup); @@ -655,7 +655,7 @@ void vp_announceBackupScreen() void vp_announceRestoreScreen() { - vp_clearCurrPrompt(); + vp_flush(); vp_queueStringTableEntry(¤tLanguage->flashRestore); @@ -670,7 +670,7 @@ void vp_announceRestoreScreen() #ifdef RTC_PRESENT void vp_announceSettingsTimeDate() { - vp_clearCurrPrompt(); + vp_flush(); vp_queueStringTableEntry(¤tLanguage->timeAndDate); diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index 0bad5925..4f64a3d1 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -305,22 +305,28 @@ void vp_terminate() #endif } -void vp_clearCurrPrompt() +void vp_stop() { voicePromptActive = false; - vpCurrentSequence.length = 0; vpCurrentSequence.pos = 0; vpCurrentSequence.c2DataIndex = 0; vpCurrentSequence.c2DataLength = 0; } +void vp_flush() +{ + // Stop the prompt and reset the codec data length + vp_stop(); + vpCurrentSequence.length = 0; +} + void vp_queuePrompt(const uint16_t prompt) { if (state.settings.vpLevel < vpLow) return; if (voicePromptActive) - vp_clearCurrPrompt(); + vp_flush(); if (vpCurrentSequence.length < VP_SEQUENCE_BUF_SIZE) { @@ -335,7 +341,7 @@ void vp_queueString(const char* string, vpFlags_t flags) return; if (voicePromptActive) - vp_clearCurrPrompt(); + vp_flush(); if (state.settings.vpPhoneticSpell) flags |= vpAnnouncePhoneticRendering; diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 3ebd5c87..4ccc0172 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -587,7 +587,7 @@ static int _ui_fsm_loadChannel(int16_t channel_index, bool *sync_rtx) static void _ui_fsm_confirmVFOInput(bool *sync_rtx) { - vp_clearCurrPrompt(); + vp_flush(); // Switch to TX input if(ui_state.input_set == SET_RX) { @@ -637,7 +637,7 @@ static void _ui_fsm_insertVFONumber(kbd_msg_t msg, bool *sync_rtx) // Advance input position ui_state.input_position += 1; // clear any prompts in progress. - vp_clearCurrPrompt(); + vp_flush(); // Save pressed number to calculate frequency and show in GUI ui_state.input_number = input_getPressedNumber(msg); // queue the digit just pressed. diff --git a/openrtx/src/ui/ui_menu.c b/openrtx/src/ui/ui_menu.c index 9deee74c..e5d93322 100644 --- a/openrtx/src/ui/ui_menu.c +++ b/openrtx/src/ui/ui_menu.c @@ -104,7 +104,7 @@ static void announceMenuItemIfNeeded(char* name, char* value) bool voicePromptWasPlaying = vp_isPlaying(); // Stop any prompt in progress and/or clear the buffer. - vp_clearCurrPrompt(); + vp_flush(); // If no value is supplied, or, no prompt is in progress, announce the name. if ((voicePromptWasPlaying == false) || (value == NULL) || (*value == '\0')) diff --git a/tests/unit/voice_prompts.c b/tests/unit/voice_prompts.c index b28be722..dd4f2c33 100644 --- a/tests/unit/voice_prompts.c +++ b/tests/unit/voice_prompts.c @@ -35,7 +35,7 @@ int main() vpQueueFlags_t flags = vp_getVoiceLevelQueueFlags(); vp_init(); - vp_clearCurrPrompt(); + vp_flush(); vp_queueStringTableEntry(¤tLanguage->allChannels); vp_play(); while(true)