Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(sim): flight mode name incorrect in the simulator window title bar #5854

Merged
merged 2 commits into from
Feb 2, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Fix flight mode name in simulator title bar. Cleanup unused code.
philmoz committed Jan 30, 2025

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature. The key has expired.
commit 206c33d1e0fc6d613929575890390659302a8d98
24 changes: 0 additions & 24 deletions radio/src/edgetx.h
Original file line number Diff line number Diff line change
@@ -794,30 +794,6 @@ union ReusableBuffer

extern ReusableBuffer reusableBuffer;

uint8_t zlen(const char *str, uint8_t size);
bool zexist(const char *str, uint8_t size);
char * strcat_zchar(char *dest, const char *name, uint8_t size, const char spaceSym = 0, const char *defaultName=nullptr, uint8_t defaultNameSize=0, uint8_t defaultIdx=0);
#define strcatFlightmodeName(dest, idx) strcat_zchar(dest, g_model.flightModeData[idx].name, LEN_FLIGHT_MODE_NAME, 0, STR_FM, PSIZE(TR_FM), idx+1)

#if !defined(STORAGE_MODELSLIST)

#define strcat_modelname(dest, idx, spaceSym) \
strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, spaceSym, STR_MODEL, \
PSIZE(TR_MODEL), idx + 1)

#define strcat_currentmodelname(dest, spaceSym) \
strcat_modelname(dest, g_eeGeneral.currModel, spaceSym)

#else

#define strcat_currentmodelname(dest, spaceSym) \
strcat_zchar(dest, g_model.header.name, LEN_MODEL_NAME, spaceSym)

#endif

#define ZLEN(s) zlen(s, sizeof(s))
#define ZEXIST(s) zexist(s, sizeof(s))

// Stick tolerance varies between transmitters, Higher is better
#define STICK_TOLERANCE 64

52 changes: 0 additions & 52 deletions radio/src/strhelpers.cpp
Original file line number Diff line number Diff line change
@@ -48,62 +48,10 @@ const char* sanitizeForFilename(const char* name, int len)
return _static_str_buffer;
}

char hex2zchar(uint8_t hex) { return (hex >= 10 ? hex - 9 : 27 + hex); }

char hex2char(uint8_t hex) { return (hex >= 10 ? hex - 10 + 'A' : hex + '0'); }

char zchar2char(int8_t idx)
{
if (idx == 0) return ' ';
if (idx < 0) {
if (idx > -27) return 'a' - idx - 1;
idx = -idx;
}
if (idx < 27) return 'A' + idx - 1;
if (idx < 37) return '0' + idx - 27;
if (idx <= 40) return *(s_charTab + idx - 37);
#if LEN_SPECIAL_CHARS > 0
if (idx <= (LEN_STD_CHARS + LEN_SPECIAL_CHARS)) return 'z' + 5 + idx - 40;
#endif
return ' ';
}

char char2lower(char c) { return (c >= 'A' && c <= 'Z') ? c + 32 : c; }

int8_t char2zchar(char c)
{
if (c == '_') return 37;
#if LEN_SPECIAL_CHARS > 0
if ((int8_t)c < 0 && c + 128 <= LEN_SPECIAL_CHARS) return 41 + (c + 128);
#endif
if (c >= 'a') return 'a' - c - 1;
if (c >= 'A') return c - 'A' + 1;
if (c >= '0') return c - '0' + 27;
if (c == '-') return 38;
if (c == '.') return 39;
if (c == ',') return 40;
return 0;
}

void str2zchar(char *dest, const char *src, int size)
{
memset(dest, 0, size);
for (int c = 0; c < size && src[c]; c++) {
dest[c] = char2zchar(src[c]);
}
}

int zchar2str(char *dest, const char *src, int size)
{
for (int c = 0; c < size; c++) {
dest[c] = zchar2char(src[c]);
}
do {
dest[size--] = '\0';
} while (size >= 0 && dest[size] == ' ');
return size + 1;
}

int strnlen(const char *src, int max_size)
{
for (int i = 0; i < max_size; i++) {
30 changes: 25 additions & 5 deletions radio/src/strhelpers.h
Original file line number Diff line number Diff line change
@@ -56,15 +56,35 @@ typedef union {
TimerDisplayOptions displayOptions;
} TimerOptions;

uint8_t zlen(const char *str, uint8_t size);
bool zexist(const char *str, uint8_t size);
char * strcat_zchar(char *dest, const char *name, uint8_t size, const char spaceSym = 0, const char *defaultName=nullptr, uint8_t defaultNameSize=0, uint8_t defaultIdx=0);

#define strcatFlightmodeName(dest, idx) strcat_zchar(dest, g_model.flightModeData[idx].name, LEN_FLIGHT_MODE_NAME, 0, STR_FM, PSIZE(TR_FM), idx+1)

#if !defined(STORAGE_MODELSLIST)

#define strcat_modelname(dest, idx, spaceSym) \
strcat_zchar(dest, modelHeaders[idx].name, LEN_MODEL_NAME, spaceSym, STR_MODEL, \
PSIZE(TR_MODEL), idx + 1)

#define strcat_currentmodelname(dest, spaceSym) \
strcat_modelname(dest, g_eeGeneral.currModel, spaceSym)

#else

#define strcat_currentmodelname(dest, spaceSym) \
strcat_zchar(dest, g_model.header.name, LEN_MODEL_NAME, spaceSym)

#endif

#define ZLEN(s) zlen(s, sizeof(s))
#define ZEXIST(s) zexist(s, sizeof(s))

const char* sanitizeForFilename(const char* name, int len);

char hex2zchar(uint8_t hex);
char hex2char(uint8_t hex);
char zchar2char(int8_t idx);
char char2lower(char c);
int8_t char2zchar(char c);
void str2zchar(char *dest, const char *src, int size);
int zchar2str(char *dest, const char *src, int size);
int strnlen(const char *src, int max_size);
unsigned int effectiveLen(const char *str, unsigned int size);

4 changes: 2 additions & 2 deletions radio/src/targets/simu/opentxsimulator.cpp
Original file line number Diff line number Diff line change
@@ -876,8 +876,8 @@ uint8_t OpenTxSimulator::getStickMode()

const char * OpenTxSimulator::getPhaseName(unsigned int phase)
{
static char buff[sizeof(g_model.flightModeData[0].name)+1];
zchar2str(buff, g_model.flightModeData[phase].name, sizeof(g_model.flightModeData[0].name));
static char buff[LEN_FLIGHT_MODE_NAME+1];
strAppend(buff, g_model.flightModeData[phase].name, LEN_FLIGHT_MODE_NAME);
return buff;
}