Added vpQueueFrequency to speak frequency with proper handling of decimal place and addition of MHz.

This commit is contained in:
vk7js 2022-05-06 21:59:06 +10:00 committed by Silvano Seva
parent 88619dc682
commit af76afb521
2 changed files with 31 additions and 0 deletions

View File

@ -168,6 +168,8 @@ void vpAppendPrompt(uint16_t prompt);// Append an individual prompt item. This c
void vpQueueString(char *promptString, VoicePromptFlags_T flags);
void vpQueueInteger(int32_t value); // Append a signed integer
void vpQueueStringTableEntry(const char * const *);//Append a text string from the current language e.g. currentLanguage->off
void vpQueueFrequency(freq_t freq, bool includeMHz);
void vpPlay(void);// Starts prompt playback
extern bool vpIsPlaying(void);
bool vpHasDataToPlay(void);

View File

@ -316,3 +316,32 @@ bool vpHasDataToPlay(void)
return (vpCurrentSequence.Length > 0);
}
static void removeUnnecessaryZerosFromVoicePrompts(char *str)
{
const int NUM_DECIMAL_PLACES = 1;
int len = strlen(str);
for(int i = len; i > 2; i--)
{
if ((str[i - 1] != '0') || (str[i - (NUM_DECIMAL_PLACES + 1)] == '.'))
{
str[i] = 0;
return;
}
}
}
void vpQueueFrequency(freq_t freq, bool includeMHz)
{
char buffer[10];
snprintf(buffer, 10, "%d.%05d", (freq / 1000000), ((freq%1000000)/10));
removeUnnecessaryZerosFromVoicePrompts(buffer);
vpQueueString(buffer);
if (includeMHz)
{
vpQueuePrompt(PROMPT_MEGAHERTZ);
}
}