feat(radio): refactor of switch handling to better support customisable switches (#6095)
Co-authored-by: philmoz <phil.a.mitchell@gmail.com> Co-authored-by: 3djc <3djc@gh.com> Co-authored-by: elecpower <elecpower@users.noreply.github.com>
This commit is contained in:
co-authored by
philmoz
3djc
elecpower
parent
28833f42e6
commit
0c8c39b134
+125
-11
@@ -32,6 +32,7 @@
|
||||
#include "usb_joystick.h"
|
||||
#include "input_mapping.h"
|
||||
#include "debug.h"
|
||||
#include "bitfield.h"
|
||||
|
||||
#if defined(PCBTARANIS)
|
||||
#define N_TARANIS_FIELD(x)
|
||||
@@ -643,21 +644,54 @@ struct RGBLedColor {
|
||||
}
|
||||
};
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
PACK(struct customSwitch {
|
||||
CUST_IDX(sw, cfs_idx_read, cfs_idx_write);
|
||||
NOBACKUP(char name[LEN_SWITCH_NAME]);
|
||||
uint8_t type:3 ENUM(SwitchConfig);
|
||||
#if NUM_FUNCTIONS_GROUPS > 3
|
||||
uint8_t group:3;
|
||||
#else
|
||||
uint8_t group:2;
|
||||
#endif
|
||||
uint8_t start:2 ENUM(fsStartPositionType);
|
||||
uint8_t state:1;
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
NOBACKUP(uint8_t onColorLuaOverride:1 ENUM(booleanEnum));
|
||||
NOBACKUP(uint8_t offColorLuaOverride:1 ENUM(booleanEnum));
|
||||
#if NUM_FUNCTIONS_GROUPS > 3
|
||||
NOBACKUP(uint8_t spare:5) SKIP;
|
||||
#else
|
||||
NOBACKUP(uint8_t spare:6) SKIP;
|
||||
#endif
|
||||
NOBACKUP(RGBLedColor onColor) FUNC(isAlwaysActive);
|
||||
NOBACKUP(RGBLedColor offColor) FUNC(isAlwaysActive);
|
||||
#else
|
||||
#if NUM_FUNCTIONS_GROUPS > 3
|
||||
NOBACKUP(uint8_t spare:7) SKIP;
|
||||
#endif
|
||||
#endif
|
||||
});
|
||||
#endif
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
#define FUNCTION_SWITCHS_RGB_LEDS_FIELDS \
|
||||
RGBLedColor functionSwitchLedONColor[NUM_FUNCTIONS_SWITCHES]; \
|
||||
RGBLedColor functionSwitchLedOFFColor[NUM_FUNCTIONS_SWITCHES];
|
||||
CUST_ARRAY(functionSwitchLedONColor, struct_cfsOnColorConfig, NUM_FUNCTIONS_SWITCHES, nullptr); \
|
||||
CUST_ARRAY(functionSwitchLedOFFColor, struct_cfsOffColorConfig, NUM_FUNCTIONS_SWITCHES, nullptr);
|
||||
#else
|
||||
#define FUNCTION_SWITCHS_RGB_LEDS_FIELDS
|
||||
#endif
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define FUNCTION_SWITCHS_FIELDS \
|
||||
uint16_t functionSwitchConfig; \
|
||||
uint16_t functionSwitchGroup; \
|
||||
uint16_t functionSwitchStartConfig; \
|
||||
uint8_t functionSwitchLogicalState; \
|
||||
char switchNames[NUM_FUNCTIONS_SWITCHES][LEN_SWITCH_NAME]; \
|
||||
FUNCTION_SWITCHS_RGB_LEDS_FIELDS
|
||||
CUST_ATTR(functionSwitchConfig, r_functionSwitchConfig, nullptr); \
|
||||
CUST_ATTR(functionSwitchGroup, r_functionSwitchGroup, nullptr); \
|
||||
CUST_ATTR(functionSwitchStartConfig, r_functionSwitchStartConfig, nullptr); \
|
||||
CUST_ATTR(functionSwitchLogicalState, r_functionSwitchLogicalState, nullptr); \
|
||||
CUST_ARRAY(switchNames, struct_cfsNameConfig, NUM_FUNCTIONS_SWITCHES, nullptr); \
|
||||
FUNCTION_SWITCHS_RGB_LEDS_FIELDS \
|
||||
customSwitch customSwitches[NUM_FUNCTIONS_SWITCHES] FUNC(isAlwaysActive) NO_IDX; \
|
||||
uint8_t cfsGroupOn ARRAY(1, struct_cfsGroupOn, cfsGroupIsActive); \
|
||||
NOBACKUP(uint8_t sfPushState) SKIP;
|
||||
#else
|
||||
#define FUNCTION_SWITCHS_FIELDS
|
||||
#endif
|
||||
@@ -744,7 +778,7 @@ PACK(struct ModelData {
|
||||
|
||||
NOBACKUP(uint8_t thrTraceSrc CUST(r_thrSrc,w_thrSrc));
|
||||
CUST_ATTR(switchWarningState, r_swtchWarn, nullptr);
|
||||
NOBACKUP(swarnstate_t switchWarning ARRAY(3, struct_swtchWarn, nullptr));
|
||||
NOBACKUP(swarnstate_t switchWarning ARRAY(2, struct_swtchWarn, nullptr));
|
||||
|
||||
GVarData gvars[MAX_GVARS];
|
||||
|
||||
@@ -828,6 +862,47 @@ PACK(struct ModelData {
|
||||
uint8_t modelSFDisabled:2 ENUM(ModelOverridableEnable);
|
||||
uint8_t modelCustomScriptsDisabled:2 ENUM(ModelOverridableEnable);
|
||||
uint8_t modelTelemetryDisabled:2 ENUM(ModelOverridableEnable);
|
||||
|
||||
SwitchConfig getSwitchType(uint8_t n);
|
||||
void setSwitchType(uint8_t n, SwitchConfig v);
|
||||
char* getSwitchCustomName(uint8_t n);
|
||||
bool switchHasCustomName(uint8_t n);
|
||||
|
||||
uint8_t getSwitchStateForWarning(uint8_t n);
|
||||
NOBACKUP(uint8_t getSwitchWarning(uint8_t n) { return bfGet<swarnstate_t>(switchWarning, n * 2, 2); })
|
||||
NOBACKUP(void setSwitchWarning(uint8_t n, uint8_t v) { switchWarning = bfSet<swarnstate_t>(switchWarning, v, n * 2, 2); })
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
uint8_t getSwitchGroup(uint8_t n);
|
||||
fsStartPositionType getSwitchStart(uint8_t n);
|
||||
void setSwitchStart(uint8_t n, fsStartPositionType v);
|
||||
SwitchConfig cfsType(uint8_t n);
|
||||
void cfsSetType(uint8_t n, SwitchConfig v);
|
||||
char* cfsName(uint8_t n);
|
||||
uint8_t cfsGroup(uint8_t n);
|
||||
void cfsSetGroup(uint8_t n, uint8_t v);
|
||||
fsStartPositionType cfsStart(uint8_t n);
|
||||
void cfsSetStart(uint8_t n, fsStartPositionType v);
|
||||
bool cfsState(uint8_t n);
|
||||
void cfsSetState(uint8_t n, bool v);
|
||||
bool cfsSFState(uint8_t n);
|
||||
void cfsSetSFState(uint8_t n, bool v);
|
||||
void cfsResetSFState();
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
RGBLedColor& getSwitchOnColor(uint8_t n);
|
||||
RGBLedColor& getSwitchOffColor(uint8_t n);
|
||||
bool getSwitchOnColorLuaOverride(uint8_t n);
|
||||
bool getSwitchOffColorLuaOverride(uint8_t n);
|
||||
RGBLedColor& cfsOnColor(uint8_t n);
|
||||
RGBLedColor& cfsOffColor(uint8_t n);
|
||||
bool cfsOnColorLuaOverride(uint8_t n);
|
||||
bool cfsOffColorLuaOverride(uint8_t n);
|
||||
void cfsSetOnColorLuaOverride(uint8_t n, bool v);
|
||||
void cfsSetOffColorLuaOverride(uint8_t n, bool v);
|
||||
#endif
|
||||
bool cfsGroupAlwaysOn(uint8_t n) { return bfGet<uint8_t>(cfsGroupOn, n, 1); }
|
||||
void cfsSetGroupAlwaysOn(uint8_t n, bool v) { cfsGroupOn = bfSet<uint8_t>(cfsGroupOn, v, n, 1); }
|
||||
#endif
|
||||
});
|
||||
|
||||
/*
|
||||
@@ -877,6 +952,26 @@ PACK(struct TrainerData {
|
||||
#define BUZZER_FIELD int8_t spare2:2 SKIP
|
||||
#endif
|
||||
|
||||
PACK(struct switchDef {
|
||||
CUST_IDX(sw, sw_idx_read, sw_idx_write);
|
||||
NOBACKUP(char name[LEN_SWITCH_NAME]);
|
||||
uint8_t type:3 ENUM(SwitchConfig);
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
uint8_t start:2 ENUM(fsStartPositionType) FUNC(switch_is_cfs);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
NOBACKUP(uint8_t onColorLuaOverride:1 ENUM(booleanEnum)) FUNC(switch_is_cfs);
|
||||
NOBACKUP(uint8_t offColorLuaOverride:1 ENUM(booleanEnum)) FUNC(switch_is_cfs);
|
||||
NOBACKUP(uint8_t spare:1) SKIP;
|
||||
NOBACKUP(RGBLedColor onColor) FUNC(switch_is_cfs);
|
||||
NOBACKUP(RGBLedColor offColor) FUNC(switch_is_cfs);
|
||||
#else
|
||||
NOBACKUP(uint8_t spare:3) SKIP;
|
||||
#endif
|
||||
#else
|
||||
NOBACKUP(uint8_t spare:5) SKIP;
|
||||
#endif
|
||||
});
|
||||
|
||||
PACK(struct RadioData {
|
||||
|
||||
// Real attributes
|
||||
@@ -967,7 +1062,7 @@ PACK(struct RadioData {
|
||||
CUST_ARRAY(slidersConfig, struct_sliderConfig, MAX_POTS, nullptr);
|
||||
uint8_t stickInvert SKIP;
|
||||
potconfig_t potsConfig ARRAY(4,struct_potConfig,nullptr);
|
||||
swconfig_t switchConfig ARRAY(2,struct_switchConfig,nullptr);
|
||||
switchDef switchConfig[MAX_SWITCHES] FUNC(switchIsActive) NO_IDX; \
|
||||
CUST_ARRAY(flexSwitches, struct_flexSwitch, MAX_FLEX_SWITCHES, flex_sw_valid);
|
||||
|
||||
EXTRA_GENERAL_FIELDS
|
||||
@@ -1035,6 +1130,25 @@ PACK(struct RadioData {
|
||||
return backlightBright;
|
||||
#endif
|
||||
});
|
||||
|
||||
char* getSwitchCustomName(uint8_t n);
|
||||
bool switchHasCustomName(uint8_t n);
|
||||
SwitchConfig switchType(uint8_t n);
|
||||
void switchSetType(uint8_t n, SwitchConfig v);
|
||||
char* switchName(uint8_t n);
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
uint8_t switchGroup(uint8_t n) { return 0; }
|
||||
fsStartPositionType switchStart(uint8_t n);
|
||||
void switchSetStart(uint8_t n, fsStartPositionType v);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
RGBLedColor& switchOnColor(uint8_t n);
|
||||
RGBLedColor& switchOffColor(uint8_t n);
|
||||
bool cfsOnColorLuaOverride(uint8_t n);
|
||||
bool cfsOffColorLuaOverride(uint8_t n);
|
||||
void cfsSetOnColorLuaOverride(uint8_t n, bool v);
|
||||
void cfsSetOffColorLuaOverride(uint8_t n, bool v);
|
||||
#endif
|
||||
#endif
|
||||
});
|
||||
|
||||
#undef SWITCHES_WARNING_DATA
|
||||
|
||||
Reference in New Issue
Block a user