diff --git a/openrtx/include/core/voicePromptUtils.h b/openrtx/include/core/voicePromptUtils.h index b7469678..6fd0bce2 100644 --- a/openrtx/include/core/voicePromptUtils.h +++ b/openrtx/include/core/voicePromptUtils.h @@ -217,5 +217,6 @@ void vp_announceDisplayTimer(); * */ vpQueueFlags_t vp_getVoiceLevelQueueFlags(); +void vp_playMenuBeepIfNeeded(bool firstItem); #endif // VOICE_PROMPT_UTILS_H diff --git a/openrtx/include/core/voicePrompts.h b/openrtx/include/core/voicePrompts.h index 3e6c34a8..32d5385e 100644 --- a/openrtx/include/core/voicePrompts.h +++ b/openrtx/include/core/voicePrompts.h @@ -300,4 +300,8 @@ bool vp_isPlaying(); */ bool vp_sequenceNotEmpty(); +/** + * play a beep at a given frequency for a given duration. + */ +void vp_beep(uint16_t freq, uint16_t duration); #endif diff --git a/openrtx/src/core/voicePromptUtils.c b/openrtx/src/core/voicePromptUtils.c index c009ba7f..f82699d4 100644 --- a/openrtx/src/core/voicePromptUtils.c +++ b/openrtx/src/core/voicePromptUtils.c @@ -878,3 +878,13 @@ vpQueueFlags_t vp_getVoiceLevelQueueFlags() return flags; } +void vp_playMenuBeepIfNeeded(bool firstItem) +{ + if (state.settings.vpLevel < vpBeep) + return; + if (firstItem) + vp_beep(500, 250); + else + vp_beep(1000, 250); +} + diff --git a/openrtx/src/core/voicePrompts.c b/openrtx/src/core/voicePrompts.c index c8b5f7ae..1b968688 100644 --- a/openrtx/src/core/voicePrompts.c +++ b/openrtx/src/core/voicePrompts.c @@ -31,6 +31,7 @@ static const uint32_t VOICE_PROMPTS_DATA_MAGIC = 0x5056; //'VP' static const uint32_t VOICE_PROMPTS_DATA_VERSION = 0x1000; // v1000 OpenRTX +static uint16_t currentBeepDuration=0; #define VOICE_PROMPTS_TOC_SIZE 350 #define CODEC2_HEADER_SIZE 7 @@ -311,6 +312,9 @@ void vp_stop() vpCurrentSequence.pos = 0; vpCurrentSequence.c2DataIndex = 0; vpCurrentSequence.c2DataLength = 0; + // If any beep is playing, immediately stop it. + if (currentBeepDuration > 0) + platform_beepStop(); } void vp_flush() @@ -456,6 +460,16 @@ void vp_play() audio_enableAmp(); } +void BeepTick() +{ + if (currentBeepDuration > 0) + { + currentBeepDuration--; + if (currentBeepDuration==0) + platform_beepStop(); + } +} + void vp_tick() { if (voicePromptActive == false) @@ -502,6 +516,7 @@ void vp_tick() vpCurrentSequence.c2DataIndex = 0; vpCurrentSequence.c2DataLength = 0; } + BeepTick(); } bool vp_isPlaying() @@ -513,3 +528,22 @@ bool vp_sequenceNotEmpty() { return (vpCurrentSequence.length > 0); } + +void vp_beep(uint16_t freq, uint16_t duration) +{ + if (state.settings.vpLevel < vpBeep) + return; + + // Do not play a new one if one is playing. + if (currentBeepDuration) + return ; + // avoid extra long beeps! + if (duration > 2000) + duration=2000; + + currentBeepDuration=duration; + + platform_beepStart(freq); + // See BeepTick for termination. +} + diff --git a/openrtx/src/ui/ui.c b/openrtx/src/ui/ui.c index 47a53903..2635efae 100644 --- a/openrtx/src/ui/ui.c +++ b/openrtx/src/ui/ui.c @@ -279,13 +279,13 @@ static void ReleaseFunctionLatchIfNeeded() return; functionLatchTimer = 0; - // Play beep for function latch release. + vp_beep(200, 500); } static void SetFunctionLatchTimer() { functionLatchTimer= getTick() + FUNCTION_LATCH_TIMEOUT; - // Play beep for set function latch. + vp_beep(800, 500); } static bool FunctionKeyIsLatched() @@ -980,6 +980,7 @@ static void _ui_menuUp(uint8_t menu_entries) ui_state.menu_selected -= 1; else ui_state.menu_selected = menu_entries - 1; + vp_playMenuBeepIfNeeded(ui_state.menu_selected==0); } static void _ui_menuDown(uint8_t menu_entries) @@ -988,6 +989,7 @@ static void _ui_menuDown(uint8_t menu_entries) ui_state.menu_selected += 1; else ui_state.menu_selected = 0; + vp_playMenuBeepIfNeeded(ui_state.menu_selected==0); } static void _ui_menuBack(uint8_t prev_state) @@ -1002,6 +1004,7 @@ static void _ui_menuBack(uint8_t prev_state) state.ui_screen = prev_state; // Reset menu selection ui_state.menu_selected = 0; + vp_playMenuBeepIfNeeded(true); } }