diff --git a/radio/src/audio.cpp b/radio/src/audio.cpp index 0553fcfa1dc..2616e9f53eb 100644 --- a/radio/src/audio.cpp +++ b/radio/src/audio.cpp @@ -19,14 +19,14 @@ * GNU General Public License for more details. */ -#include "opentx.h" #include +#include "opentx.h" #include "strhelpers.h" #include "switches.h" #if defined(LIBOPENUI) - #include "libopenui.h" +#include "libopenui.h" #endif #include "model_audio.h" @@ -313,7 +313,7 @@ void referenceModelAudioFiles() { DIR dir; FILINFO fno; - char path[AUDIO_FILENAME_MAXLEN+1]; + char path[AUDIO_FILENAME_MAXLEN + 1]; sdAvailableFlightmodeAudioFiles.reset(); sdAvailableSwitchAudioFiles.reset(); @@ -321,11 +321,12 @@ void referenceModelAudioFiles() getModelAudioPath(path); - FRESULT res = f_opendir(&dir, path); /* Open the directory */ + FRESULT res = f_opendir(&dir, path); /* Open the directory */ if (res == FR_OK) { for (;;) { - res = f_readdir(&dir, &fno); /* Read a directory item */ - if (res != FR_OK || fno.fname[0] == 0) break; /* Break on error or end of dir */ + res = f_readdir(&dir, &fno); /* Read a directory item */ + 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; @@ -333,14 +334,15 @@ void referenceModelAudioFiles() if (fno.fattrib & AM_DIR) continue; if (len < sizeof(SOUNDS_EXT)) continue; - char* ext = fno.fname + len - (sizeof(SOUNDS_EXT) - 1); + char *ext = fno.fname + len - (sizeof(SOUNDS_EXT) - 1); if (strcasecmp(ext, SOUNDS_EXT)) continue; TRACE("referenceModelAudioFiles(): using file: %s", fno.fname); int idx, event; if (matchModeAudioFile(fno.fname, idx, event)) { - sdAvailableFlightmodeAudioFiles.setBit(INDEX_PHASE_AUDIO_FILE(idx, event)); + sdAvailableFlightmodeAudioFiles.setBit( + INDEX_PHASE_AUDIO_FILE(idx, event)); continue; } diff --git a/radio/src/model_audio.cpp b/radio/src/model_audio.cpp index 1fab9694834..851003a9783 100644 --- a/radio/src/model_audio.cpp +++ b/radio/src/model_audio.cpp @@ -24,13 +24,13 @@ #include "opentx.h" #include "switches.h" -static const char * const _suffixes[] = { "-off", "-on" }; +static const char* const _suffixes[] = {"-off", "-on"}; char* getModelAudioPath(char* path) { strcpy(path, SOUNDS_PATH "/"); strncpy(path + SOUNDS_PATH_LNG_OFS, currentLanguagePack->id, 2); - char *buf = strcat_currentmodelname(path + sizeof(SOUNDS_PATH), ' '); + char* buf = strcat_currentmodelname(path + sizeof(SOUNDS_PATH), ' '); if (!isFileAvailable(path)) { buf = strcat_currentmodelname(path + sizeof(SOUNDS_PATH), 0); @@ -49,9 +49,7 @@ void getFlightmodeAudioFile(char* path, int index, unsigned int event) strAppend(tmp, SOUNDS_EXT); } -static const char * const _sw_positions[] = { - "-up", "-mid", "-down" -}; +static const char* const _sw_positions[] = {"-up", "-mid", "-down"}; bool getSwitchAudioFile(char* path, swsrc_t index) { @@ -63,9 +61,9 @@ bool getSwitchAudioFile(char* path, swsrc_t index) if (!sw_name) return false; str = strAppend(str, sw_name); str = strAppend(str, _sw_positions[swinfo.rem]); - } - else { - div_t swinfo = div((int)(index - SWSRC_FIRST_MULTIPOS_SWITCH), XPOTS_MULTIPOS_COUNT); + } else { + div_t swinfo = + div((int)(index - SWSRC_FIRST_MULTIPOS_SWITCH), XPOTS_MULTIPOS_COUNT); *str++ = 'S'; *str++ = '1' + swinfo.quot; *str++ = '1' + swinfo.rem; @@ -75,17 +73,16 @@ bool getSwitchAudioFile(char* path, swsrc_t index) return true; } -void getLogicalSwitchAudioFile(char * filename, int index, unsigned int event) +void getLogicalSwitchAudioFile(char* filename, int index, unsigned int event) { - char * str = getModelAudioPath(filename); + char* str = getModelAudioPath(filename); *str++ = 'L'; if (index >= 9) { div_t qr = div(index + 1, 10); *str++ = '0' + qr.quot; *str++ = '0' + qr.rem; - } - else { + } else { *str++ = '1' + index; } @@ -97,8 +94,8 @@ void getLogicalSwitchAudioFile(char * filename, int index, unsigned int event) bool matchModeAudioFile(const char* filename, int& index, int& event) { for (int i = 0; i < MAX_FLIGHT_MODES; i++) { - auto *c = filename; - auto *fm_name = g_model.flightModeData[i].name; + auto* c = filename; + auto* fm_name = g_model.flightModeData[i].name; 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; @@ -119,7 +116,7 @@ bool matchSwitchAudioFile(const char* filename, int& sw_pos) { // Switches Audio Files -[up|mid|down].wav for (int i = 0; i < switchGetMaxSwitches(); i++) { - auto *c = filename; + auto* c = filename; auto sw_name = switchGetName(i); auto sw_name_len = strlen(sw_name); if (strncasecmp(c, sw_name, sw_name_len) != 0) continue; @@ -145,7 +142,7 @@ bool matchSwitchAudioFile(const char* filename, int& sw_pos) uint8_t pos = uint8_t(*c++ - '1'); if (pos >= XPOTS_MULTIPOS_COUNT) return false; if (*c != '.') return false; - + for (int i = 0; i < MAX_POTS; i++) { if (i != xpot) continue; if (!IS_POT_MULTIPOS(i)) continue; diff --git a/radio/src/tests/model_audio.cpp b/radio/src/tests/model_audio.cpp index c504f995d04..3254e092215 100644 --- a/radio/src/tests/model_audio.cpp +++ b/radio/src/tests/model_audio.cpp @@ -19,9 +19,10 @@ * GNU General Public License for more details. */ -#include "gtests.h" #include "model_audio.h" +#include "gtests.h" + TEST(ModelAudio, flightModes) { strncpy(g_model.flightModeData[0].name, "One", LEN_FLIGHT_MODE_NAME); @@ -99,4 +100,3 @@ TEST(ModelAudio, logicalSwitches) EXPECT_FALSE(matchLogicalSwitchAudioFile("l24", idx, event)); EXPECT_FALSE(matchLogicalSwitchAudioFile("l24-o.wav", idx, event)); } -