Skip to content

Commit

Permalink
Fix audio files not working on radio.
Browse files Browse the repository at this point in the history
Cleanup compiler warnings.
  • Loading branch information
philmoz committed Oct 30, 2023
1 parent aae31b9 commit aad3312
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 8 deletions.
3 changes: 1 addition & 2 deletions radio/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -319,7 +319,7 @@ void referenceModelAudioFiles()
sdAvailableSwitchAudioFiles.reset();
sdAvailableLogicalSwitchAudioFiles.reset();

getModelAudioPath(path);
getModelAudioPath(path, false);

FRESULT res = f_opendir(&dir, path); /* Open the directory */
if (res == FR_OK) {
Expand All @@ -328,7 +328,6 @@ void referenceModelAudioFiles()
if (res != FR_OK || fno.fname[0] == 0)
break; /* Break on error or end of dir */
uint8_t len = strlen(fno.fname);
bool found = false;

// Eliminates directories / non wav files
if (fno.fattrib & AM_DIR) continue;
Expand Down
11 changes: 6 additions & 5 deletions radio/src/model_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@

static const char* const _suffixes[] = {"-off", "-on"};

char* getModelAudioPath(char* path)
char* getModelAudioPath(char* path, bool trailingSlash)
{
strcpy(path, SOUNDS_PATH "/");
strncpy(path + SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2);
Expand All @@ -36,7 +36,8 @@ char* getModelAudioPath(char* path)
buf = strcat_currentmodelname(path + sizeof(SOUNDS_PATH), 0);
}

*buf++ = '/';
if (trailingSlash)
*buf++ = '/';
*buf = '\0';
return buf;
}
Expand Down Expand Up @@ -99,7 +100,7 @@ bool matchModeAudioFile(const char* filename, int& index, int& event)
auto fm_name_len = strnlen(fm_name, LEN_FLIGHT_MODE_NAME);
if (strncasecmp(c, fm_name, fm_name_len) != 0) continue;
c += fm_name_len;
for (int e = 0; e < DIM(_suffixes); e++) {
for (size_t e = 0; e < DIM(_suffixes); e++) {
auto suffix_len = strlen(_suffixes[e]);
if (strncasecmp(c, _suffixes[e], suffix_len) != 0) continue;
c += suffix_len;
Expand All @@ -121,7 +122,7 @@ bool matchSwitchAudioFile(const char* filename, int& sw_pos)
auto sw_name_len = strlen(sw_name);
if (strncasecmp(c, sw_name, sw_name_len) != 0) continue;
c += sw_name_len;
for (int pos = 0; pos < DIM(_sw_positions); pos++) {
for (size_t pos = 0; pos < DIM(_sw_positions); pos++) {
auto pos_len = strlen(_sw_positions[pos]);
if (strncasecmp(c, _sw_positions[pos], pos_len) != 0) continue;
c += pos_len;
Expand Down Expand Up @@ -167,7 +168,7 @@ bool matchLogicalSwitchAudioFile(const char* filename, int& index, int& event)
}
if (*c != '-' || lsw < 1) return false;

for (int e = 0; e < DIM(_suffixes); e++) {
for (size_t e = 0; e < DIM(_suffixes); e++) {
auto* s = c;
auto suffix_len = strlen(_suffixes[e]);
if (strncasecmp(s, _suffixes[e], suffix_len) != 0) continue;
Expand Down
2 changes: 1 addition & 1 deletion radio/src/model_audio.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@

#include "opentx_types.h"

char* getModelAudioPath(char* path);
char* getModelAudioPath(char* path, bool trailingSlash = true);

void getFlightmodeAudioFile(char* path, int index, unsigned int event);
bool getSwitchAudioFile(char* path, swsrc_t index);
Expand Down

0 comments on commit aad3312

Please sign in to comment.