Skip to content

Commit

Permalink
Workaround for settings being retained when restarting the simulator.
Browse files Browse the repository at this point in the history
  • Loading branch information
philmoz committed Feb 22, 2025
1 parent 088c8e2 commit 33ec0ea
Show file tree
Hide file tree
Showing 21 changed files with 115 additions and 61 deletions.
11 changes: 4 additions & 7 deletions radio/src/analogs.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,28 +20,25 @@
*/

#include "analogs.h"
#include "dataconstants.h"
#include "edgetx_helpers.h"
#include "edgetx.h"

#include "hal/adc_driver.h"

static char _custom_names[MAX_ANALOG_INPUTS][LEN_ANA_NAME + 1] = { 0 };

void analogSetCustomLabel(uint8_t type, uint8_t idx, const char* str, size_t len)
{
if (idx >= adcGetMaxInputs(type)) return;
idx += adcGetInputOffset(type);

strncpy(_custom_names[idx], str, min<size_t>(LEN_ANA_NAME, len));
_custom_names[idx][LEN_ANA_NAME] = '\0';
strncpy(g_eeGeneral.analogNames[idx], str, min<size_t>(LEN_ANA_NAME, len));
g_eeGeneral.analogNames[idx][LEN_ANA_NAME] = '\0';
}

const char* analogGetCustomLabel(uint8_t type, uint8_t idx)
{
if (idx >= adcGetMaxInputs(type)) return "";
idx += adcGetInputOffset(type);

return _custom_names[idx];
return g_eeGeneral.analogNames[idx];
}

bool analogHasCustomLabel(uint8_t type, uint8_t idx)
Expand Down
6 changes: 3 additions & 3 deletions radio/src/datastructs.h
Original file line number Diff line number Diff line change
Expand Up @@ -83,11 +83,11 @@ static inline void check_struct()
#endif

#if defined(PCBXLITES)
CHKSIZE(RadioData, 872);
CHKSIZE(RadioData, 1008);
#elif defined(COLORLCD)
CHKSIZE(RadioData, 966);
CHKSIZE(RadioData, 1134);
#else
CHKSIZE(RadioData, 870);
CHKSIZE(RadioData, 1006);
#endif

#if defined(RADIO_TPRO) || defined(RADIO_TPROV2) || defined(RADIO_BUMBLEBEE)
Expand Down
3 changes: 3 additions & 0 deletions radio/src/datastructs_private.h
Original file line number Diff line number Diff line change
Expand Up @@ -1026,6 +1026,9 @@ PACK(struct RadioData {

NOBACKUP(uint8_t pwrOffIfInactive);

NOBACKUP(char switchNames[MAX_SWITCHES][LEN_SWITCH_NAME + 1] SKIP);
NOBACKUP(char analogNames[MAX_ANALOG_INPUTS][LEN_ANA_NAME + 1] SKIP);

NOBACKUP(uint8_t getBrightness() const
{
#if defined(OLED_SCREEN)
Expand Down
1 change: 1 addition & 0 deletions radio/src/edgetx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1104,6 +1104,7 @@ void edgeTxClose(uint8_t shutdown)
#if defined(HAPTIC)
hapticOff();
#endif
mixerTaskExit();
}

logsClose();
Expand Down
7 changes: 7 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_128x64.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -363,6 +368,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "invertLCD", 1 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_f16.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -389,6 +394,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 704 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -692,11 +699,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
7 changes: 7 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_gx12.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -364,6 +369,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "invertLCD", 1 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_nb4p.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -380,6 +385,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 704 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -683,11 +690,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_nv14_family.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -279,6 +279,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -387,6 +392,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 704 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -690,11 +697,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_t15.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -389,6 +394,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 704 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -692,11 +699,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
7 changes: 7 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_t20.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -364,6 +369,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "invertLCD", 1 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down
7 changes: 7 additions & 0 deletions radio/src/storage/yaml/yaml_datastructs_tpro.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -263,6 +263,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -364,6 +369,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "invertLCD", 1 ),
YAML_PADDING( 3 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_x10.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -280,6 +280,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -388,6 +393,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 6 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 704 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -691,11 +698,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_x9d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -362,6 +367,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 4 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -664,11 +671,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
12 changes: 7 additions & 5 deletions radio/src/storage/yaml/yaml_datastructs_x9dp2019.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,11 @@ static const struct YamlNode struct_CustomFunctionData[] = {
YAML_PADDING( 7 ),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "manuallyEdited", 1 ),
YAML_SIGNED( "timezoneMinutes", 3 ),
Expand Down Expand Up @@ -362,6 +367,8 @@ static const struct YamlNode struct_RadioData[] = {
YAML_UNSIGNED( "disablePwrOnOffHaptic", 1 ),
YAML_PADDING( 4 ),
YAML_UNSIGNED( "pwrOffIfInactive", 8 ),
YAML_PADDING( 640 ),
YAML_PADDING( 448 ),
YAML_END
};
static const struct YamlNode struct_unsigned_8[] = {
Expand Down Expand Up @@ -664,11 +671,6 @@ static const struct YamlNode struct_ScriptData[] = {
YAML_ARRAY("inputs", 16, 6, union_ScriptDataInput, NULL),
YAML_END
};
static const struct YamlNode struct_string_32[] = {
YAML_IDX,
YAML_STRING("val", 4),
YAML_END
};
static const struct YamlNode union_anonymous_14_elmts[] = {
YAML_UNSIGNED( "id", 16 ),
YAML_UNSIGNED( "persistentValue", 16 ),
Expand Down
Loading

0 comments on commit 33ec0ea

Please sign in to comment.