Skip to content

Commit

Permalink
chore: Formatting
Browse files Browse the repository at this point in the history
  • Loading branch information
pfeerick committed Oct 18, 2023
1 parent 27612b4 commit 578060b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 26 deletions.
18 changes: 10 additions & 8 deletions radio/src/audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,14 +19,14 @@
* GNU General Public License for more details.
*/

#include "opentx.h"
#include <math.h>

#include "opentx.h"
#include "strhelpers.h"
#include "switches.h"

#if defined(LIBOPENUI)
#include "libopenui.h"
#include "libopenui.h"
#endif

#include "model_audio.h"
Expand Down Expand Up @@ -313,34 +313,36 @@ void referenceModelAudioFiles()
{
DIR dir;
FILINFO fno;
char path[AUDIO_FILENAME_MAXLEN+1];
char path[AUDIO_FILENAME_MAXLEN + 1];

sdAvailableFlightmodeAudioFiles.reset();
sdAvailableSwitchAudioFiles.reset();
sdAvailableLogicalSwitchAudioFiles.reset();

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;

// Eliminates directories / non wav files
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;
}

Expand Down
29 changes: 13 additions & 16 deletions radio/src/model_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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)
{
Expand All @@ -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;
Expand All @@ -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;
}

Expand All @@ -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;
Expand All @@ -119,7 +116,7 @@ bool matchSwitchAudioFile(const char* filename, int& sw_pos)
{
// Switches Audio Files <switchname>-[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;
Expand All @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions radio/src/tests/model_audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -99,4 +100,3 @@ TEST(ModelAudio, logicalSwitches)
EXPECT_FALSE(matchLogicalSwitchAudioFile("l24", idx, event));
EXPECT_FALSE(matchLogicalSwitchAudioFile("l24-o.wav", idx, event));
}

0 comments on commit 578060b

Please sign in to comment.