diff --git a/doc/Extended-audio.txt b/doc/Extended-audio.txt index 16f05c3d29..2bd9dce487 100644 --- a/doc/Extended-audio.txt +++ b/doc/Extended-audio.txt @@ -2,9 +2,6 @@ A. Voice Feedback on the following are supported. For additional details, refer - Changing Switch Positions. - Turning of Auxiliary Knobs. Different voice files can be specified for turning up & turning down of knobs. - - Trim buttons as virtual switches. - Different voice files can be specified for the same trim button when used as - Momentary or Toggle switch. B. Following options have been added to media/sound.ini file. 1) Specify a different playback device for each alert message. diff --git a/src/config/model.c b/src/config/model.c index 625ecbf59e..dd69a2e4f5 100644 --- a/src/config/model.c +++ b/src/config/model.c @@ -19,6 +19,7 @@ #include "tx.h" #include "music.h" #include "extended_audio.h" +#include "voice.h" #include #include @@ -1076,7 +1077,8 @@ int assign_int(void* ptr, const struct struct_map *map, int map_size) if (MATCH_SECTION(SECTION_VOICE)) { u16 val = atoi(value); - if(val>MAX_VOICEMAP_ENTRIES-1 || voice_map[val].duration == 0 || val < CUSTOM_ALARM_ID) { + CONFIG_VoiceParse(val); + if (current_voice_mapping.duration == 0 || val < CUSTOM_ALARM_ID) { printf("%s: Music %s not found in voice.ini or below ID %d\n", section, value, CUSTOM_ALARM_ID); return 0; } @@ -1106,6 +1108,8 @@ int assign_int(void* ptr, const struct struct_map *map, int map_size) for (int i = 0; i < NUM_TIMERS; i++) { if (MATCH_KEY(VOICE_TIMER[i])) { m->voice.timer[i].music = val; + CONFIG_VoiceParse(MUSIC_ALARM1+i); + m->timer[i].duration = current_voice_mapping.duration; return 1; } } @@ -1494,6 +1498,12 @@ static void clear_model(u8 full) } Model.ppmin_centerpw = 1500; Model.ppmin_deltapw = 400; +#if HAS_EXTENDED_AUDIO + for (int i = 0; i < NUM_TIMERS; i++) { + CONFIG_VoiceParse(MUSIC_ALARM1 + i); + Model.timer[i].duration = current_voice_mapping.duration; + } +#endif } u8 CONFIG_ReadModel(u8 model_num) { diff --git a/src/config/tx.c b/src/config/tx.c index d4cbfe7850..fbb4bdf50c 100644 --- a/src/config/tx.c +++ b/src/config/tx.c @@ -338,6 +338,7 @@ void CONFIG_LoadTx() #if HAS_EXTENDED_AUDIO Transmitter.audio_player = AUDIO_NONE; Transmitter.audio_vol = 10; + Transmitter.voice_ini_entries = VOICE_INI_EMPTY; #endif #if HAS_AUDIO_UART Transmitter.audio_uart = 0; @@ -349,7 +350,7 @@ void CONFIG_LoadTx() CONFIG_LoadHardware(); CONFIG_IniParse("tx.ini", ini_handler, (void *)&Transmitter); crc32 = Crc(&Transmitter, sizeof(Transmitter)); -#if HAS_EXTENDED_AUDIO +#if HAS_MUSIC_CONFIG CONFIG_VoiceParse(MAX_VOICEMAP_ENTRIES); #endif return; diff --git a/src/config/tx.h b/src/config/tx.h index 121d808b8f..b028ef0054 100644 --- a/src/config/tx.h +++ b/src/config/tx.h @@ -64,6 +64,7 @@ struct Transmitter { #if HAS_EXTENDED_AUDIO enum AudioPlayers audio_player; u8 audio_vol; + s16 voice_ini_entries; #endif #if HAS_AUDIO_UART u8 audio_uart; diff --git a/src/config/voice.c b/src/config/voice.c index 4371bc45bf..3ce3dbc946 100644 --- a/src/config/voice.c +++ b/src/config/voice.c @@ -32,7 +32,7 @@ const char SECTION_VOICE_CUSTOM[] = "custom"; static int ini_handler(void* user, const char* section, const char* name, const char* value) { - // ini_handler returns a requested mp3 label passed at *user to tempstring + (void) section; u16 req_id = *((long*)user); u16 id = atoi(name); const char* ptr = value; @@ -47,32 +47,24 @@ static int ini_handler(void* user, const char* section, const char* name, const duration = atoi(ptr + 1); } -#if HAS_MUSIC_CONFIG if ( k && (req_id != MAX_VOICEMAP_ENTRIES) && (req_id == id) ) { - strlcpy(tempstring, value, k+1); - tempstring[MAX_VOICE_LABEL] = '\0'; // limit label length + current_voice_mapping.duration = duration; + if (HAS_MUSIC_CONFIG) + strlcpy(tempstring, value, k+1); // return a requested mp3 label passed at *user to tempstring return 1; } -#endif - if ( req_id == MAX_VOICEMAP_ENTRIES ) { - if (MATCH_SECTION(SECTION_VOICE_GLOBAL)) { - for (int i = 0; i < CUSTOM_ALARM_ID; i++) { - snprintf(tempstring, 4, "%d", i); - if (MATCH_KEY(tempstring)) { - voice_map[i].duration = duration; - voice_map[i].id = i; - return 1; - } + if (HAS_MUSIC_CONFIG) { + if ( req_id == MAX_VOICEMAP_ENTRIES ) { + if (MATCH_SECTION(SECTION_VOICE_GLOBAL)) { + Transmitter.voice_ini_entries = VOICE_INI_GLOBAL_ONLY; } + if (MATCH_SECTION(SECTION_VOICE_CUSTOM)) { + // Initial count of custom voicemap entries + Transmitter.voice_ini_entries++; + return 1; + } + return 0; } - if (MATCH_SECTION(SECTION_VOICE_CUSTOM)) { - voice_map[voice_map_entries].duration = duration; - voice_map[voice_map_entries].id = id; - voice_map_entries++; - return 1; - } - printf("Unknown entry in voice.ini: %s\n", value); - return 0; } return 1; // voice label ignored } @@ -95,16 +87,16 @@ const char* CONFIG_VoiceParse(unsigned id) char filename[] = "media/voice.ini"; #endif if (id == MAX_VOICEMAP_ENTRIES) { // initial parse of voice.ini - voice_map_entries = CUSTOM_ALARM_ID; // Reserve space in map for global alerts - if (CONFIG_IniParse(filename, ini_handler, &id)) { - printf("Failed to parse voice.ini\n"); - Transmitter.audio_player = AUDIO_NONE; // disable external voice output + if (CONFIG_IniParse(filename, ini_handler, &id)) tempstring[0] = '\0'; + if (Transmitter.voice_ini_entries == VOICE_INI_EMPTY) { + printf("Failed to parse voice.ini\n"); + Transmitter.audio_player = AUDIO_NONE; // disable external voice when no global voices are found in voice.ini } } - if ( (id < MAX_VOICEMAP_ENTRIES) && (id >= CUSTOM_ALARM_ID) ) { + if ( (id < MAX_VOICEMAP_ENTRIES) ) { if (CONFIG_IniParse(filename, ini_handler, &id)) { - // ini handler will return tempstring with label of id + // ini handler will return tempstring with label of id and fill current_voice_mapping } } return tempstring; diff --git a/src/config/voice.h b/src/config/voice.h index abd6db56df..6497754945 100644 --- a/src/config/voice.h +++ b/src/config/voice.h @@ -1 +1,6 @@ -const char* CONFIG_VoiceParse(); +#ifndef _VOICE_H_ +#define _VOICE_H_ + +const char* CONFIG_VoiceParse(unsigned id); + +#endif diff --git a/src/extended_audio.c b/src/extended_audio.c index bb9cd1e406..aeba2428ce 100644 --- a/src/extended_audio.c +++ b/src/extended_audio.c @@ -17,6 +17,7 @@ #include "music.h" #include "config/tx.h" #include "config/model.h" +#include "config/voice.h" #include "extended_audio.h" #include "stdlib.h" @@ -25,9 +26,8 @@ #endif // EMULATOR #if HAS_EXTENDED_AUDIO -u16 voice_map_entries; -struct VoiceMap voice_map[MAX_VOICEMAP_ENTRIES]; -u16 audio_queue[AUDIO_QUEUE_LENGTH]; +struct QueueEntry current_voice_mapping; +struct QueueEntry audio_queue[AUDIO_QUEUE_LENGTH]; u8 next_audio; u8 num_audio; u32 audio_queue_time; @@ -75,8 +75,7 @@ void AUDIO_Init() { #ifndef EMULATOR // Send a block of len bytes to the Audio device. -void -AUDIO_Send(u8 *data, int len) { +static void AUDIO_Send(u8 *data, int len) { void AUDIO_send_char(char c); for (u16 iter = 0; iter < len; iter += 1) { AUDIO_send_char(data[iter]); @@ -84,19 +83,18 @@ AUDIO_Send(u8 *data, int len) { } // Send a string to the Audio device. -void -AUDIO_Print(char *string) { +static void AUDIO_Print(char *string) { AUDIO_Send((u8 *)string, strlen(string)); } #endif // EMULATOR -void u16ToArray(u16 value, u8 *array){ +static void u16ToArray(u16 value, u8 *array) { *array = (u8)(value>>8); *(array+1) = (u8)value; } // generate Checksum for DFPlyer commands -u16 AUDIO_CalculateChecksum(u8 *buffer) { +static u16 AUDIO_CalculateChecksum(u8 *buffer) { u16 sum = 0; for (int i=1; i < 7; i += 1) sum += buffer[i]; @@ -104,22 +102,21 @@ u16 AUDIO_CalculateChecksum(u8 *buffer) { } // Generate a string to play. -int AUDIO_Play(u16 music) { - +static int AUDIO_Play(u16 id) { // If we are just playing beeps.... - if (music == MUSIC_KEY_PRESSING || music == MUSIC_MAXLEN) { + if (id == MUSIC_KEY_PRESSING || id == MUSIC_MAXLEN) { printf("Voice: beep only\n"); return 0; } - printf("Voice: Playing mp3 #%d\n", voice_map[music].id); + printf("Voice: Playing mp3 #%d\n", id); #ifdef EMULATOR // On emulators call mpg123 to play mp3s char cmd[70]; u16 vol_val = Transmitter.audio_vol * 32786/10; #ifdef _WIN32 - sprintf(cmd, "start /B ..\\..\\mpg123 -f %d -q ..\\..\\mp3\\%04d*.mp3 > nul 2>&1", vol_val, voice_map[music].id); + snprintf(cmd, sizeof(cmd), "start /B ..\\..\\mpg123 -f %d -q ..\\..\\mp3\\%04d*.mp3 > nul 2>&1", vol_val, id); #else - sprintf(cmd, "mpg123 -f %d -q ../../mp3/%04d*.mp3 > /dev/null 2>&1 &", vol_val, voice_map[music].id); + snprintf(cmd, sizeof(cmd), "mpg123 -f %d -q ../../mp3/%04d*.mp3 > /dev/null 2>&1 &", vol_val, id); #endif // _WIN32 system(cmd); return 1; @@ -132,14 +129,14 @@ int AUDIO_Play(u16 music) { case AUDIO_NONE: return 0; // Play beeps... case AUDIO_AUDIOFX: { char buffer[5]; - snprintf(buffer, sizeof(buffer), "#%d\n", voice_map[music].id); + snprintf(buffer, sizeof(buffer), "#%d\n", id); AUDIO_Print(buffer); break; } case AUDIO_DF_PLAYER: // Fill in track number and checksum player_buffer[3] = 0x12; - u16ToArray(voice_map[music].id, player_buffer+5); + u16ToArray(id, player_buffer+5); u16ToArray(AUDIO_CalculateChecksum(player_buffer), player_buffer+7); AUDIO_Send(player_buffer, sizeof(player_buffer)); break; @@ -188,32 +185,35 @@ void AUDIO_SetVolume() { } #endif } +static void AUDIO_ResetQueue() { + num_audio = 0; + next_audio = 0; + printf("Voice: Resetting queue.\n"); +} void AUDIO_CheckQueue() { u32 t = CLOCK_getms(); if (next_audio < num_audio) { if (t > audio_queue_time) { - AUDIO_Play(audio_queue[next_audio]); - audio_queue_time = CLOCK_getms() + voice_map[audio_queue[next_audio]].duration; + AUDIO_Play(audio_queue[next_audio].id); + audio_queue_time = CLOCK_getms() + audio_queue[next_audio].duration; next_audio++; } } else if (num_audio && t > audio_queue_time) { - printf("Voice: Queue finished, resetting.\n"); - num_audio = 0; - next_audio = 0; + printf("Voice: Queue finished.\n"); + AUDIO_ResetQueue(); AUDIO_SetVolume(); } } -int AUDIO_VoiceAvailable() { +static int AUDIO_VoiceAvailable() { #if defined BUILDTYPE_DEV #if HAS_AUDIO_UART if (!Transmitter.audio_uart) #endif { printf("Voice: Dev mode enabled, cannot set volume\n"); - num_audio = 0; // Reset queue when audio not available - next_audio = 0; + AUDIO_ResetQueue(); return 0; } #endif // BUILDTYPE_DEV @@ -224,15 +224,13 @@ int AUDIO_VoiceAvailable() { if ( PPMin_Mode() || Model.protocol == PROTOCOL_PPM ) { // don't send play command when using PPM port #endif printf("Voice: PPM port in use\n"); - num_audio = 0; // Reset queue when audio not available - next_audio = 0; + AUDIO_ResetQueue(); return 0; } #endif // _DEVO12_TARGET_H_ if ( (Transmitter.audio_player == AUDIO_NONE) || (Transmitter.audio_player == AUDIO_DISABLED) || !Transmitter.audio_vol ) { - num_audio = 0; // Reset queue when audio not available - next_audio = 0; + AUDIO_ResetQueue(); return 0; } @@ -240,16 +238,19 @@ int AUDIO_VoiceAvailable() { } int AUDIO_AddQueue(u16 music) { - if (num_audio == AUDIO_QUEUE_LENGTH) { - printf("Voice: Queue full, cannot add new mp3 #%d\n",music); + if (!AUDIO_VoiceAvailable() || num_audio == AUDIO_QUEUE_LENGTH) { + printf("Voice: queue full or voice not available, cannot add new mp3 #%d\n", music); return 0; } - if (!voice_map[music].duration) { + CONFIG_VoiceParse(music); + if (!current_voice_mapping.duration) { printf("Voice: mp3 length is zero\n"); return 0; } - - audio_queue[num_audio++] = music; + audio_queue[num_audio].duration = current_voice_mapping.duration; + audio_queue[num_audio].id = music; + printf("Voice: added ID %d with duration %d to queue position %d.\n", music, current_voice_mapping.duration, num_audio); + num_audio++; return 1; } diff --git a/src/extended_audio.h b/src/extended_audio.h index ae9cd65f5c..f3e4343cab 100644 --- a/src/extended_audio.h +++ b/src/extended_audio.h @@ -6,13 +6,12 @@ #define AUDIO_QUEUE_LENGTH 20 // arbitraty chosen, do we need more? void AUDIO_Init(); -int AUDIO_Play(u16 music); void AUDIO_SetVolume(); void AUDIO_CheckQueue(); int AUDIO_AddQueue(u16 music); -int AUDIO_VoiceAvailable(); -extern u16 audio_queue[AUDIO_QUEUE_LENGTH]; +extern struct QueueEntry audio_queue[AUDIO_QUEUE_LENGTH]; +extern struct QueueEntry current_voice_mapping; extern u8 next_audio; extern u8 num_audio; extern u32 audio_queue_time; diff --git a/src/main.c b/src/main.c index 12f960b89f..c69cc297fd 100644 --- a/src/main.c +++ b/src/main.c @@ -232,15 +232,12 @@ void EventLoop() } if(Transmitter.music_shutdown) { #if HAS_EXTENDED_AUDIO - if(AUDIO_VoiceAvailable()) { MUSIC_Play(MUSIC_SHUTDOWN); while (CLOCK_getms() < audio_queue_time) { // Wait for voice to finished CLOCK_ResetWatchdog(); } - } else { #else - { // We wait ~1sec for shutdown buzzer music finished unsigned int time; MUSIC_Play(MUSIC_SHUTDOWN); @@ -250,8 +247,6 @@ void EventLoop() } #endif } - } - PWR_Shutdown(); } #endif diff --git a/src/mixer.c b/src/mixer.c index 47554e57a7..f63fa0bc2c 100644 --- a/src/mixer.c +++ b/src/mixer.c @@ -319,6 +319,9 @@ void MIXER_ApplyMixer(struct Mixer *mixer, volatile s32 *raw, s32 *orig_value) //4th: multiplex result s32 scaled_value = raw[mixer->dest + NUM_INPUTS + 1]; +#if HAS_EXTENDED_AUDIO + u16 diff_value = abs(value-scaled_value); +#endif switch(MIXER_MUX(mixer)) { case MUX_REPLACE: break; @@ -360,12 +363,12 @@ void MIXER_ApplyMixer(struct Mixer *mixer, volatile s32 *raw, s32 *orig_value) #if HAS_EXTENDED_AUDIO case MUX_BEEP: if (orig_value) { - if (abs(value - scaled_value) > 100) + if (diff_value > 100) MIXER_SET_BEEP_LOCK(mixer, 0); if (! MIXER_BEEP_LOCK(mixer)) { if ((value > *orig_value && value < scaled_value) || (value < *orig_value && value > scaled_value) || - (abs(value - scaled_value) <= 10)) { + (diff_value <= 10)) { MIXER_SET_BEEP_LOCK(mixer, 1); MUSIC_Play(MUSIC_MAXLEN); } @@ -375,12 +378,12 @@ void MIXER_ApplyMixer(struct Mixer *mixer, volatile s32 *raw, s32 *orig_value) break; case MUX_VOICE: if (orig_value) { - if (abs(value - scaled_value) > 100) + if (diff_value > 100) MIXER_SET_VOICE_LOCK(mixer, 0); if (! MIXER_VOICE_LOCK(mixer)) { if ((value > *orig_value && value < scaled_value) || (value < *orig_value && value > scaled_value) || - (abs(value - scaled_value) <= 10)) { + (diff_value <= 10)) { MIXER_SET_VOICE_LOCK(mixer, 1); if (Model.voice.mixer[mixer->dest].music) MUSIC_Play(Model.voice.mixer[mixer->dest].music); @@ -721,25 +724,6 @@ void MIXER_InitMixer(struct Mixer *mixer, unsigned ch) mixer->curve.points[i] = 0; } -#if HAS_EXTENDED_AUDIO -static void _trim_music_play(int trim_idx, int is_neg, int on_state) -{ - int button_idx; - - if (is_neg) - button_idx = Model.trims[trim_idx].neg - 1; - else - button_idx = Model.trims[trim_idx].pos - 1; - if (on_state) { - if (Model.voice.buttons[button_idx].on) - MUSIC_Play(Model.voice.buttons[button_idx].on); - } else { - if (Model.voice.buttons[button_idx].off) - MUSIC_Play(Model.voice.buttons[button_idx].off); - } -} -#endif - static void _trim_as_switch(unsigned flags, int i, int is_neg) { s8 *value = MIXER_GetTrim(i); @@ -747,40 +731,22 @@ static void _trim_as_switch(unsigned flags, int i, int is_neg) //Momentarty if (flags & BUTTON_PRESS) { *value = 100; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, 1); -#endif } else if (flags & BUTTON_RELEASE) { *value = -100; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, 0); -#endif } } else if (Model.trims[i].step == TRIM_3POS) { if (flags & BUTTON_PRESS) { *value = is_neg ? -100 : 100; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, 1); -#endif } else if (flags & BUTTON_RELEASE) { *value = 0; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, 0); -#endif } } else if (flags & BUTTON_PRESS) { if (Model.trims[i].step == TRIM_ONOFF) { //On/Off *value = is_neg ? -100 : 100; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, 1); -#endif } else { //Toggle *value = *value == -100 ? 100 : -100; -#if HAS_EXTENDED_AUDIO - _trim_music_play(i, is_neg, *value == -100 ? 0 : 1); -#endif } } } diff --git a/src/music.c b/src/music.c index 841f53dbc4..db7087bf42 100644 --- a/src/music.c +++ b/src/music.c @@ -213,7 +213,6 @@ void MUSIC_Play(u16 music) #if HAS_EXTENDED_AUDIO // Play audio for switch if ( music > MUSIC_TOTAL ) { - if (AUDIO_VoiceAvailable()) AUDIO_AddQueue(music); return; } @@ -229,7 +228,7 @@ void MUSIC_Play(u16 music) #if HAS_EXTENDED_AUDIO if ( !(playback_device == AUDDEV_BUZZER) ) { - if ( AUDIO_VoiceAvailable() && AUDIO_AddQueue(music) ) { + if (AUDIO_AddQueue(music)) { if ((playback_device == AUDDEV_EXTAUDIO) || (playback_device == AUDDEV_UNDEF)) { Volume = 0; return; @@ -251,12 +250,6 @@ u16 MUSIC_GetTelemetryAlarm(enum Music music) { return music; } -u16 MUSIC_GetTimerAlarm(enum Music music) { - if ( Model.voice.timer[music - MUSIC_ALARM1].music > 0 ) - return Model.voice.timer[music - MUSIC_ALARM1].music; - return music; -} - void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec) { u32 i; @@ -273,9 +266,8 @@ void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec) } } - if ( !AUDIO_VoiceAvailable() || !AUDIO_AddQueue(music)) { - if (music < MUSIC_TOTAL) - MUSIC_Play(music); + if ( !AUDIO_AddQueue(music) && (music < MUSIC_TOTAL) ) { + MUSIC_Play(music); return; } @@ -283,15 +275,15 @@ void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec) if (unit == VOICE_UNIT_TIME) { if (value >= 3600) { i = value / 3600; + value %= 3600; AUDIO_AddQueue(i + MUSIC_TOTAL); AUDIO_AddQueue(VOICE_UNIT_HOURS + VOICE_UNIT_OFFSET); - value %= 3600; } if (value >= 60) { i = value / 60; + value %= 60; AUDIO_AddQueue(i + MUSIC_TOTAL); AUDIO_AddQueue(VOICE_UNIT_MINUTES + VOICE_UNIT_OFFSET); - value %= 60; } if (value > 0) { AUDIO_AddQueue(value + MUSIC_TOTAL); @@ -303,7 +295,7 @@ void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec) // Add minus sign for negative number if (value < 0) { AUDIO_AddQueue(VOICE_UNIT_MINUS + VOICE_UNIT_OFFSET); - value *= -1; + value = -value; } //Add precision digits @@ -316,32 +308,32 @@ void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec) digits[digit_count++] = VOICE_DEC_SEP; } - // Special case value == 0 and not playing TIME - if (value == 0 && unit != VOICE_UNIT_TIME) + // Special case value == 0 + if (value == 0) digits[digit_count++] = 0; // Get single digits from remaining value while (value > 0) { - if(value > 999) { + if (value > 999) { thousands = value / 1000; value %= 1000; } - if(value > 100) { + if (value > 100) { digits[digit_count++] = value % 100; value /= 100; digits[digit_count++] = value + 99; - if (thousands){ - digits[digit_count++] = 109; // MP3 for "thousands" - digits[digit_count++] = thousands; + if (thousands) { + digits[digit_count++] = 109; // MP3 for "thousands" + digits[digit_count++] = thousands; } break; } - if(value < 101 && value > 0) { + if (value < 101 && value > 0) { digits[digit_count++] = value; break; } else { - if (thousands){ - digits[digit_count++] = 109; // MP3 for "thousands" + if (thousands) { + digits[digit_count++] = 109; // MP3 for "thousands" digits[digit_count++] = thousands; } } diff --git a/src/music.h b/src/music.h index 59d78b480f..c5960911b0 100644 --- a/src/music.h +++ b/src/music.h @@ -29,7 +29,7 @@ enum Music { }; #if HAS_EXTENDED_AUDIO -#define MAX_VOICEMAP_ENTRIES 400 // arbitraty chosen +#define MAX_VOICEMAP_ENTRIES 999 // arbitraty chosen #ifdef _DEVO12_TARGET_H_ // Check for Devo12 screen #define MAX_VOICE_LABEL 35 // limit label length due to limited screen width #else @@ -85,10 +85,9 @@ enum { VOICE_UNIT_TOTAL }; -struct ButtonVoice { - u16 on; // Music to be played when button is On - u16 off; - u16 music; // Music to be played when button is Off +enum { + VOICE_INI_EMPTY = -1, + VOICE_INI_GLOBAL_ONLY = 0, }; struct CustomVoice { @@ -100,23 +99,17 @@ struct Voice { struct CustomVoice telemetry[TELEM_NUM_ALARMS]; //Telemetry Alarm array to point to music file number struct CustomVoice timer[NUM_TIMERS]; //Timer Alarm array to point to music file number struct CustomVoice mixer[NUM_OUT_CHANNELS + NUM_VIRT_CHANNELS]; - struct ButtonVoice buttons[NUM_TX_BUTTONS]; //Button array to point to music file number #if NUM_AUX_KNOBS struct CustomVoice aux[NUM_AUX_KNOBS * 2]; //two per knob for up and down #endif }; -extern u16 voice_map_entries; - -struct VoiceMap { +struct QueueEntry { u16 id; u16 duration; }; -extern struct VoiceMap voice_map[MAX_VOICEMAP_ENTRIES]; - u16 MUSIC_GetTelemetryAlarm(enum Music music); -u16 MUSIC_GetTimerAlarm(enum Music music); void MUSIC_PlayValue(u16 music, s32 value, u8 unit, u8 prec); #endif //HAS_EXTENDED_AUDIO diff --git a/src/pages/128x64x1/voiceconfig_page.c b/src/pages/128x64x1/voiceconfig_page.c index 6792f0f112..9fd9c9a5f8 100644 --- a/src/pages/128x64x1/voiceconfig_page.c +++ b/src/pages/128x64x1/voiceconfig_page.c @@ -56,7 +56,7 @@ void PAGE_VoiceconfigInit(int page) { (void)page; PAGE_SetModal(0); - if ( !AUDIO_VoiceAvailable() ) { + if ( !AUDIO_AddQueue(MUSIC_KEY_PRESSING) ) { // MUSIC_KEY_PRESSING is empty by default GUI_CreateLabelBox(&gui->msg, MSG_X, MSG_Y, 0, 0, &LABEL_FONT, GUI_Localize, NULL, _tr_noop("External voice\ncurrently not\navailable")); return; diff --git a/src/pages/320x240x16/voiceconfig_page.c b/src/pages/320x240x16/voiceconfig_page.c index d7eac68c9c..6a3be008c0 100644 --- a/src/pages/320x240x16/voiceconfig_page.c +++ b/src/pages/320x240x16/voiceconfig_page.c @@ -46,7 +46,7 @@ void PAGE_VoiceconfigInit(int page) PAGE_SetModal(0); PAGE_ShowHeader(PAGE_GetName(PAGEID_VOICECFG)); - if ( !AUDIO_VoiceAvailable() ) { + if ( !AUDIO_AddQueue(MUSIC_KEY_PRESSING) ) { // MUSIC_KEY_PRESSING is empty by default GUI_CreateLabelBox(&gui->msg, 20, 80, 280, 100, &NARROW_FONT, GUI_Localize, NULL, _tr_noop("External voice\ncurrently not\navailable")); return; diff --git a/src/pages/common/_voiceconfig_page.c b/src/pages/common/_voiceconfig_page.c index 15916fe8e3..5afe1681e1 100644 --- a/src/pages/common/_voiceconfig_page.c +++ b/src/pages/common/_voiceconfig_page.c @@ -29,14 +29,10 @@ static struct voiceconfig_obj * const gui = &gui_objs.u.voiceconfig; static u16 current_selected = 0; - - static u8 voiceconfig_getsrctype (u8 idx) { if (idx < NUM_SWITCHES) return VOICE_SRC_SWITCH; -/* if (idx < NUM_INPUTS - INP_HAS_CALIBRATION + NUM_TX_BUTTONS) - return VOICE_SRC_BUTTON;*/ #if NUM_AUX_KNOBS if (idx < NUM_SWITCHES + NUM_AUX_KNOBS * 2) return VOICE_SRC_AUX; @@ -48,6 +44,24 @@ static u8 voiceconfig_getsrctype (u8 idx) return VOICE_SRC_MIXER; } +static struct CustomVoice *voiceconfig_setsrcptr(u8 idx) { + switch (voiceconfig_getsrctype(idx)) { + case VOICE_SRC_SWITCH: + return &Model.voice.switches[idx - VOICE_SRC_SWITCH]; +#if NUM_AUX_KNOBS + case VOICE_SRC_AUX: + return &Model.voice.aux[idx - VOICE_SRC_AUX]; +#endif + case VOICE_SRC_TIMER: + return &Model.voice.timer[idx - VOICE_SRC_TIMER]; + case VOICE_SRC_TELEMETRY: + return &Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY]; + case VOICE_SRC_MIXER: + return &Model.voice.mixer[idx - VOICE_SRC_MIXER]; + } + return NULL; +} + const char *voiceconfig_str_cb(guiObject_t *obj, const void *data) { (void)obj; @@ -90,61 +104,24 @@ static void voice_test_cb(guiObject_t *obj, void *data) { (void) obj; u8 idx = (long)data; - switch(voiceconfig_getsrctype(idx)) { - case VOICE_SRC_SWITCH: - if (Model.voice.switches[idx - VOICE_SRC_SWITCH].music) - MUSIC_Play(Model.voice.switches[idx - VOICE_SRC_SWITCH].music); - break; -#if NUM_AUX_KNOBS - case VOICE_SRC_AUX: - if (Model.voice.aux[idx - VOICE_SRC_AUX].music) - MUSIC_Play(Model.voice.aux[idx - VOICE_SRC_AUX].music); - break; -#endif - case VOICE_SRC_TIMER: - if (Model.voice.timer[idx - VOICE_SRC_TIMER].music) - MUSIC_Play(Model.voice.timer[idx - VOICE_SRC_TIMER].music); - break; - case VOICE_SRC_TELEMETRY: - if (Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY].music) - MUSIC_Play(Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY].music); - break; - case VOICE_SRC_MIXER: - if (Model.voice.mixer[idx - VOICE_SRC_MIXER].music) - MUSIC_Play(Model.voice.mixer[idx - VOICE_SRC_MIXER].music); - break; - } + struct CustomVoice *vpt; + vpt = voiceconfig_setsrcptr(idx); + if (vpt == NULL) + return; + MUSIC_Play(vpt->music); } static const char *voicelbl_cb(guiObject_t *obj, const void *data) { (void) obj; int idx = (long)data; - switch (voiceconfig_getsrctype(idx)) { - case VOICE_SRC_SWITCH: - if (Model.voice.switches[idx - VOICE_SRC_SWITCH].music) - return CONFIG_VoiceParse(voice_map[Model.voice.switches[idx - VOICE_SRC_SWITCH].music].id); - break; -#if NUM_AUX_KNOBS - case VOICE_SRC_AUX: - if(Model.voice.aux[idx - VOICE_SRC_AUX].music) - return CONFIG_VoiceParse(voice_map[Model.voice.aux[idx - VOICE_SRC_AUX].music].id); - break; -#endif - case VOICE_SRC_TIMER: - if (Model.voice.timer[idx - VOICE_SRC_TIMER].music) - return CONFIG_VoiceParse(voice_map[Model.voice.timer[idx - VOICE_SRC_TIMER].music].id); - break; - case VOICE_SRC_TELEMETRY: - if (Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY].music) - return CONFIG_VoiceParse(voice_map[Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY].music].id); - break; - case VOICE_SRC_MIXER: - if (Model.voice.mixer[idx - VOICE_SRC_MIXER].music) - return CONFIG_VoiceParse(voice_map[Model.voice.mixer[idx - VOICE_SRC_MIXER].music].id); - break; + struct CustomVoice *vpt; + vpt = voiceconfig_setsrcptr(idx); + if (!vpt->music) { + tempstring[0] = '\0'; + return tempstring; } - return strcpy(tempstring, ""); + return CONFIG_VoiceParse(vpt->music); } static const char *voiceid_cb(guiObject_t *obj, int dir, void *data) @@ -153,39 +130,29 @@ static const char *voiceid_cb(guiObject_t *obj, int dir, void *data) int idx = (long)data; int cur_row = idx - GUI_ScrollableCurrentRow(&gui->scrollable); struct CustomVoice *vpt; - vpt = NULL; + vpt = voiceconfig_setsrcptr(idx); - switch (voiceconfig_getsrctype(idx)) { - case VOICE_SRC_SWITCH: - vpt = &Model.voice.switches[idx - VOICE_SRC_SWITCH]; - break; -#if NUM_AUX_KNOBS - case VOICE_SRC_AUX: - vpt = &Model.voice.aux[idx - VOICE_SRC_AUX]; - break; -#endif - case VOICE_SRC_TIMER: - vpt = &Model.voice.timer[idx - VOICE_SRC_TIMER]; - break; - case VOICE_SRC_TELEMETRY: - vpt = &Model.voice.telemetry[idx - VOICE_SRC_TELEMETRY]; - break; - case VOICE_SRC_MIXER: - vpt = &Model.voice.mixer[idx - VOICE_SRC_MIXER]; - break; - } - if (dir == -1 && vpt->music == CUSTOM_ALARM_ID) // set to none below 1 + if (dir == -1 && vpt->music == CUSTOM_ALARM_ID) // set to none below 1 vpt->music = 0; - if (dir == 1 && vpt->music == 0) // set to CUSTOM_ALARM_ID when currently none + if (dir == 1 && vpt->music == 0) // set to CUSTOM_ALARM_ID when currently none vpt->music = CUSTOM_ALARM_ID - 1; GUI_TextSelectEnablePress((guiTextSelect_t *)obj, vpt->music); if (vpt->music == 0) { GUI_Redraw(&gui->voicelbl[cur_row]); + if (voiceconfig_getsrctype(idx) == VOICE_SRC_TIMER) { // Setting duration to global alarm value for timers + CONFIG_VoiceParse(idx - VOICE_SRC_TIMER + MUSIC_ALARM1); + Model.timer[idx - VOICE_SRC_TIMER].duration = current_voice_mapping.duration; + } return strcpy(tempstring, _tr("None")); } - vpt->music = GUI_TextSelectHelper(vpt->music - CUSTOM_ALARM_ID + 1, //Relabling so voice in menu starts with 1 - 1, voice_map_entries - CUSTOM_ALARM_ID, dir, 1, 10, NULL) + CUSTOM_ALARM_ID - 1; + vpt->music = GUI_TextSelectHelper(vpt->music - CUSTOM_ALARM_ID + 1, // Relabling so voice in menu starts with 1 + 1, Transmitter.voice_ini_entries, dir, 1, 10, NULL) + CUSTOM_ALARM_ID - 1; + + if (voiceconfig_getsrctype(idx) == VOICE_SRC_TIMER) { // Setting duration for custom timer alarms + CONFIG_VoiceParse(vpt->music); + Model.timer[idx - VOICE_SRC_TIMER].duration = current_voice_mapping.duration; + } snprintf(tempstring, 5, "%d", vpt->music - CUSTOM_ALARM_ID + 1); GUI_Redraw(&gui->voicelbl[cur_row]); return tempstring; diff --git a/src/telemetry.c b/src/telemetry.c index d040c68c45..d026178324 100644 --- a/src/telemetry.c +++ b/src/telemetry.c @@ -380,121 +380,118 @@ void TELEMETRY_Alarm() #if HAS_EXTENDED_AUDIO u16 telem_music = MUSIC_GetTelemetryAlarm(MUSIC_TELEMALARM1 + telem_idx); s32 telem_value = TELEMETRY_GetValue(alarm->src); - if (TELEMETRY_Type() == TELEM_DEVO) { - switch (alarm->src) { - case TELEM_DEVO_VOLT1: - case TELEM_DEVO_VOLT2: - case TELEM_DEVO_VOLT3: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_VOLT,1); break; - case TELEM_DEVO_RPM1: - case TELEM_DEVO_RPM2: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_RPM,0); break; - default: MUSIC_PlayValue(telem_music, telem_value-20,VOICE_UNIT_TEMP,0); break; - } - } - if (TELEMETRY_Type() == TELEM_DSM) { - switch (alarm->src) { + unsigned telem_unit = VOICE_UNIT_NONE; + unsigned telem_prec = 0; + switch (TELEMETRY_Type()) { + case TELEM_DEVO: + switch (alarm->src) { + case TELEM_DEVO_VOLT1: + case TELEM_DEVO_VOLT2: + case TELEM_DEVO_VOLT3: telem_unit = VOICE_UNIT_VOLT; telem_prec = 1; break; + case TELEM_DEVO_RPM1: + case TELEM_DEVO_RPM2: telem_unit = VOICE_UNIT_RPM; break; + default: telem_value -= 20; telem_unit = VOICE_UNIT_TEMP; break; + } + break; + case TELEM_DSM: + switch (alarm->src) { #if HAS_EXTENDED_TELEMETRY - case TELEM_DSM_JETCAT_RPM: - case TELEM_DSM_ESC_RPM: + case TELEM_DSM_JETCAT_RPM: + case TELEM_DSM_ESC_RPM: #endif - case TELEM_DSM_FLOG_RPM1: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_RPM,0); break; + case TELEM_DSM_FLOG_RPM1: telem_unit = VOICE_UNIT_RPM; break; #if HAS_EXTENDED_TELEMETRY - case TELEM_DSM_PBOX_VOLT1: - case TELEM_DSM_PBOX_VOLT2: - case TELEM_DSM_JETCAT_PACKVOLT: - case TELEM_DSM_JETCAT_PUMPVOLT: - case TELEM_DSM_RXPCAP_VOLT: - case TELEM_DSM_ESC_VOLT1: - case TELEM_DSM_ESC_VOLT2: + case TELEM_DSM_PBOX_VOLT1: + case TELEM_DSM_PBOX_VOLT2: + case TELEM_DSM_JETCAT_PACKVOLT: + case TELEM_DSM_JETCAT_PUMPVOLT: + case TELEM_DSM_RXPCAP_VOLT: + case TELEM_DSM_ESC_VOLT1: + case TELEM_DSM_ESC_VOLT2: #endif - case TELEM_DSM_FLOG_VOLT1: - case TELEM_DSM_FLOG_VOLT2: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_VOLT,2); break; + case TELEM_DSM_FLOG_VOLT1: + case TELEM_DSM_FLOG_VOLT2: telem_unit = VOICE_UNIT_VOLT; telem_prec = 2; break; #if HAS_EXTENDED_TELEMETRY - case TELEM_DSM_JETCAT_TEMPEGT: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_TEMP,0); break; - case TELEM_DSM_ESC_TEMP1: - case TELEM_DSM_ESC_TEMP2: + case TELEM_DSM_JETCAT_TEMPEGT: telem_unit = VOICE_UNIT_TEMP; break; + case TELEM_DSM_ESC_TEMP1: + case TELEM_DSM_ESC_TEMP2: #endif - case TELEM_DSM_FLOG_TEMP1: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_TEMP,1); break; + case TELEM_DSM_FLOG_TEMP1: telem_unit = VOICE_UNIT_TEMP; telem_prec = 1; break; #if HAS_EXTENDED_TELEMETRY - case TELEM_DSM_RXPCAP_AMPS: - case TELEM_DSM_ESC_AMPS1: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_AMPS,2); break; - case TELEM_DSM_FPCAP_AMPS: - case TELEM_DSM_ESC_AMPS2: + case TELEM_DSM_RXPCAP_AMPS: + case TELEM_DSM_ESC_AMPS1: telem_unit = VOICE_UNIT_AMPS; telem_prec = 2; break; + case TELEM_DSM_FPCAP_AMPS: + case TELEM_DSM_ESC_AMPS2: #endif - case TELEM_DSM_AMPS1: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_AMPS,1); break; - case TELEM_DSM_ALTITUDE: - case TELEM_DSM_ALTITUDE_MAX: - case TELEM_DSM_VARIO_CLIMBRATE1: - case TELEM_DSM_VARIO_CLIMBRATE2: - case TELEM_DSM_VARIO_CLIMBRATE3: - case TELEM_DSM_VARIO_CLIMBRATE4: - case TELEM_DSM_VARIO_CLIMBRATE5: - case TELEM_DSM_VARIO_CLIMBRATE6: - case TELEM_DSM_VARIO_ALTITUDE: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_ALTITUDE,1); break; - - case TELEM_DSM_GFORCE_X: - case TELEM_DSM_GFORCE_Y: - case TELEM_DSM_GFORCE_Z: - case TELEM_DSM_GFORCE_XMAX: - case TELEM_DSM_GFORCE_YMAX: - case TELEM_DSM_GFORCE_ZMAX: - case TELEM_DSM_GFORCE_ZMIN: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_GFORCE,2); break; + case TELEM_DSM_AMPS1: telem_unit = VOICE_UNIT_AMPS; telem_prec = 1; break; + case TELEM_DSM_ALTITUDE: + case TELEM_DSM_ALTITUDE_MAX: + case TELEM_DSM_VARIO_CLIMBRATE1: + case TELEM_DSM_VARIO_CLIMBRATE2: + case TELEM_DSM_VARIO_CLIMBRATE3: + case TELEM_DSM_VARIO_CLIMBRATE4: + case TELEM_DSM_VARIO_CLIMBRATE5: + case TELEM_DSM_VARIO_CLIMBRATE6: + case TELEM_DSM_VARIO_ALTITUDE: telem_unit = VOICE_UNIT_ALTITUDE; telem_prec = 1; break; + + case TELEM_DSM_GFORCE_X: + case TELEM_DSM_GFORCE_Y: + case TELEM_DSM_GFORCE_Z: + case TELEM_DSM_GFORCE_XMAX: + case TELEM_DSM_GFORCE_YMAX: + case TELEM_DSM_GFORCE_ZMAX: + case TELEM_DSM_GFORCE_ZMIN: telem_unit = VOICE_UNIT_GFORCE; telem_prec = 2; break; #if HAS_EXTENDED_TELEMETRY - case TELEM_DSM_FLOG_RSSI_DBM: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_DB,0); break; + case TELEM_DSM_FLOG_RSSI_DBM: telem_unit = VOICE_UNIT_DB; break; #endif - default: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_NONE,0); - } - } - - if (TELEMETRY_Type() == TELEM_FRSKY) { - switch (alarm->src) { + } + break; + case TELEM_FRSKY: + switch (alarm->src) { #if HAS_EXTENDED_TELEMETRY - case TELEM_FRSKY_VOLT3: - case TELEM_FRSKY_VOLTA: - case TELEM_FRSKY_MIN_CELL: - case TELEM_FRSKY_ALL_CELL: - case TELEM_FRSKY_CELL1: - case TELEM_FRSKY_CELL2: - case TELEM_FRSKY_CELL3: - case TELEM_FRSKY_CELL4: - case TELEM_FRSKY_CELL5: - case TELEM_FRSKY_CELL6: + case TELEM_FRSKY_VOLT3: + case TELEM_FRSKY_VOLTA: + case TELEM_FRSKY_MIN_CELL: + case TELEM_FRSKY_ALL_CELL: + case TELEM_FRSKY_CELL1: + case TELEM_FRSKY_CELL2: + case TELEM_FRSKY_CELL3: + case TELEM_FRSKY_CELL4: + case TELEM_FRSKY_CELL5: + case TELEM_FRSKY_CELL6: #endif - case TELEM_FRSKY_VOLT1: - case TELEM_FRSKY_VOLT2: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_VOLT,2); break; + case TELEM_FRSKY_VOLT1: + case TELEM_FRSKY_VOLT2: telem_unit = VOICE_UNIT_VOLT; telem_prec = 2; break; #if HAS_EXTENDED_TELEMETRY - case TELEM_FRSKY_TEMP1: - case TELEM_FRSKY_TEMP2: MUSIC_PlayValue(telem_music, telem_value-20,VOICE_UNIT_TEMP,0); break; - case TELEM_FRSKY_RPM: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_RPM,0); break; - case TELEM_FRSKY_CURRENT: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_AMPS,2); break; - case TELEM_FRSKY_ALTITUDE: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_ALTITUDE,2); break; + case TELEM_FRSKY_TEMP1: + case TELEM_FRSKY_TEMP2: telem_value -= 20; telem_unit = VOICE_UNIT_TEMP; break; + case TELEM_FRSKY_RPM: telem_unit = VOICE_UNIT_RPM; break; + case TELEM_FRSKY_CURRENT: telem_unit = VOICE_UNIT_AMPS; telem_prec = 2; break; + case TELEM_FRSKY_ALTITUDE: telem_unit = VOICE_UNIT_ALTITUDE; telem_prec = 2; break; #endif - case TELEM_FRSKY_LRSSI: - case TELEM_FRSKY_RSSI: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_DB,0); break; - default: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_NONE,0); - } - } - + case TELEM_FRSKY_LRSSI: + case TELEM_FRSKY_RSSI: telem_unit = VOICE_UNIT_DB; break; + } + break; #if HAS_EXTENDED_TELEMETRY - if (TELEMETRY_Type() == TELEM_CRSF) { - switch (alarm->src) { - case TELEM_CRSF_BATT_VOLTAGE: - MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_VOLT,2); break; - case TELEM_CRSF_BATT_CURRENT: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_AMPS,2); break; - case TELEM_CRSF_GPS_ALTITUDE: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_ALTITUDE,2); break; - case TELEM_CRSF_TX_SNR: - case TELEM_CRSF_TX_RSSI: - case TELEM_CRSF_RX_SNR: - case TELEM_CRSF_RX_RSSI1: - case TELEM_CRSF_RX_RSSI2: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_DB,0); break; - default: MUSIC_PlayValue(telem_music, telem_value,VOICE_UNIT_NONE,0); - } - } + case TELEM_CRSF: + switch (alarm->src) { + case TELEM_CRSF_BATT_VOLTAGE: telem_unit = VOICE_UNIT_VOLT; telem_prec = 2; break; + case TELEM_CRSF_BATT_CURRENT: telem_unit = VOICE_UNIT_AMPS; telem_prec = 2; break; + case TELEM_CRSF_GPS_ALTITUDE: telem_unit = VOICE_UNIT_ALTITUDE; telem_prec = 2; break; + case TELEM_CRSF_TX_SNR: + case TELEM_CRSF_TX_RSSI: + case TELEM_CRSF_RX_SNR: + case TELEM_CRSF_RX_RSSI1: + case TELEM_CRSF_RX_RSSI2: telem_unit = VOICE_UNIT_DB; break; + } + break; #endif //HAS_EXTENDED_TELEMETRY - + } + MUSIC_PlayValue(telem_music, telem_value, telem_unit, telem_prec); #else MUSIC_Play(MUSIC_TELEMALARM1 + telem_idx); #endif //HAS_EXTENDED_AUDIO - } } diff --git a/src/tests/320x240x16/Voice_config.png b/src/tests/320x240x16/Voice_config.png deleted file mode 100644 index 25dd1e5fbf..0000000000 Binary files a/src/tests/320x240x16/Voice_config.png and /dev/null differ diff --git a/src/timer.c b/src/timer.c index b18f6fe116..71c4bf95be 100644 --- a/src/timer.c +++ b/src/timer.c @@ -141,6 +141,7 @@ void TIMER_Update() unsigned i; unsigned chan_val = 0; u32 t = CLOCK_getms(); + if (PROTOCOL_WaitingForSafe()) return; if( Transmitter.power_alarm > 0 ) @@ -173,6 +174,11 @@ void TIMER_Update() } } if (timer_state[i]) { +#if HAS_EXTENDED_AUDIO + unsigned timer_music = MUSIC_ALARM1 + i; + if (Model.voice.timer[i].music) + timer_music = Model.voice.timer[i].music; +#endif s32 delta = t - last_time[i]; s32 warn_time; if (Model.timer[i].type == TIMER_STOPWATCH_PROP || Model.timer[i].type == TIMER_COUNTDOWN_PROP) { @@ -195,10 +201,10 @@ void TIMER_Update() if (timer_val[i] >= 600000) warn_time += 300000; // 5-minute alerts above 10 minutes } - warn_time -= voice_map[MUSIC_ALARM1 + i].duration; + warn_time -= Model.timer[i].duration; if (timer_val[i] > warn_time && (timer_val[i] - delta) <= warn_time) - MUSIC_PlayValue(MUSIC_GetTimerAlarm(MUSIC_ALARM1 + i), - (timer_val[i]+voice_map[MUSIC_GetTimerAlarm(MUSIC_ALARM1 + i)].duration)/1000, VOICE_UNIT_TIME, 0); + MUSIC_PlayValue(timer_music, + (timer_val[i]+Model.timer[i].duration)/1000, VOICE_UNIT_TIME, 0); #endif } else { // start to beep for each prealert_interval at the last prealert_time(seconds) @@ -209,12 +215,11 @@ void TIMER_Update() warn_time = ((timer_val[i] / Transmitter.countdown_timer_settings.prealert_interval) * Transmitter.countdown_timer_settings.prealert_interval); #if HAS_EXTENDED_AUDIO - warn_time += voice_map[MUSIC_TIMER_WARNING].duration + 1000; + warn_time += 2000; // Play voice prealerts earlier to optimize timing #endif if (timer_val[i] > warn_time && (timer_val[i] - delta) <= warn_time) { #if HAS_EXTENDED_AUDIO - MUSIC_PlayValue(MUSIC_TIMER_WARNING, - (timer_val[i]-voice_map[MUSIC_TIMER_WARNING].duration-1000)/1000,VOICE_UNIT_TIME,0); + MUSIC_PlayValue(MUSIC_TIMER_WARNING, (timer_val[i]-2000)/1000, VOICE_UNIT_TIME, 0); #else MUSIC_Play(MUSIC_TIMER_WARNING); #endif @@ -225,12 +230,12 @@ void TIMER_Update() warn_time = ((timer_val[i] - Transmitter.countdown_timer_settings.timeup_interval) / Transmitter.countdown_timer_settings.timeup_interval) * Transmitter.countdown_timer_settings.timeup_interval; #if HAS_EXTENDED_AUDIO - warn_time += voice_map[MUSIC_ALARM1 + i].duration; + warn_time += Model.timer[i].duration; #endif if (timer_val[i] > warn_time && (timer_val[i] - delta) <= warn_time) { #if HAS_EXTENDED_AUDIO - MUSIC_PlayValue(MUSIC_GetTimerAlarm(MUSIC_ALARM1 + i), - (timer_val[i]-voice_map[MUSIC_GetTimerAlarm(MUSIC_ALARM1 + i)].duration)/-1000+1,VOICE_UNIT_TIME,0); + MUSIC_PlayValue(timer_music, + (timer_val[i]-Model.timer[i].duration)/-1000+1, VOICE_UNIT_TIME, 0); #else MUSIC_Play(MUSIC_ALARM1 + i + 2); #endif @@ -238,7 +243,7 @@ void TIMER_Update() } if (timer_val[i] >= 0 && timer_val[i] < delta) { #if HAS_EXTENDED_AUDIO - MUSIC_Play(MUSIC_GetTimerAlarm(MUSIC_ALARM1 + i)); + MUSIC_Play(timer_music); #else MUSIC_Play(MUSIC_ALARM1+i); #endif diff --git a/src/timer.h b/src/timer.h index 78c1b1b620..bed80a492e 100644 --- a/src/timer.h +++ b/src/timer.h @@ -24,8 +24,9 @@ struct Timer { u8 resetsrc; u16 timer; u32 val; + u16 duration; // only needed for voice, but we're padding anyways enum TimerType type; - u8 padding_1[3]; //Needed to ensure structure is word aligned + u8 padding_1[1]; // Needed to ensure structure is word aligned }; struct CountDownTimerSettings {