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
@@ -43,7 +43,7 @@ uint8_t g_moduleIdx;
|
||||
uint8_t getSwitchWarningsCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
|
||||
for (int i = 0; i < switchGetMaxAllSwitches(); ++i) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
++count;
|
||||
}
|
||||
@@ -79,6 +79,20 @@ enum MenuModelSetupItems {
|
||||
ITEM_MODEL_SETUP_SW4,
|
||||
ITEM_MODEL_SETUP_SW5,
|
||||
ITEM_MODEL_SETUP_SW6,
|
||||
ITEM_MODEL_SETUP_SW7,
|
||||
ITEM_MODEL_SETUP_SW8,
|
||||
ITEM_MODEL_SETUP_SW9,
|
||||
ITEM_MODEL_SETUP_SW10,
|
||||
ITEM_MODEL_SETUP_SW11,
|
||||
ITEM_MODEL_SETUP_SW12,
|
||||
ITEM_MODEL_SETUP_SW13,
|
||||
ITEM_MODEL_SETUP_SW14,
|
||||
ITEM_MODEL_SETUP_SW15,
|
||||
ITEM_MODEL_SETUP_SW16,
|
||||
ITEM_MODEL_SETUP_SW17,
|
||||
ITEM_MODEL_SETUP_SW18,
|
||||
ITEM_MODEL_SETUP_SW19,
|
||||
ITEM_MODEL_SETUP_SW20,
|
||||
ITEM_MODEL_SETUP_GROUP1_LABEL,
|
||||
ITEM_MODEL_SETUP_GROUP1_ALWAYS_ON,
|
||||
ITEM_MODEL_SETUP_GROUP1_START,
|
||||
@@ -88,6 +102,9 @@ enum MenuModelSetupItems {
|
||||
ITEM_MODEL_SETUP_GROUP3_LABEL,
|
||||
ITEM_MODEL_SETUP_GROUP3_ALWAYS_ON,
|
||||
ITEM_MODEL_SETUP_GROUP3_START,
|
||||
ITEM_MODEL_SETUP_GROUP4_LABEL,
|
||||
ITEM_MODEL_SETUP_GROUP4_ALWAYS_ON,
|
||||
ITEM_MODEL_SETUP_GROUP4_START,
|
||||
#endif
|
||||
ITEM_MODEL_SETUP_EXTENDED_LIMITS,
|
||||
ITEM_MODEL_SETUP_EXTENDED_TRIMS,
|
||||
@@ -107,6 +124,7 @@ enum MenuModelSetupItems {
|
||||
ITEM_MODEL_SETUP_SWITCHES_WARNING1,
|
||||
#if defined(PCBTARANIS)
|
||||
ITEM_MODEL_SETUP_SWITCHES_WARNING2,
|
||||
ITEM_MODEL_SETUP_SWITCHES_WARNING3,
|
||||
ITEM_MODEL_SETUP_POTS_WARNING,
|
||||
#endif
|
||||
ITEM_MODEL_SETUP_BEEP_CENTER,
|
||||
@@ -259,6 +277,7 @@ static uint8_t FS_ROW(uint8_t value) { return expandState.functionSwitches ? val
|
||||
uint8_t G1_ROW(int8_t value) { return (firstSwitchInGroup(1) >= 0) ? value : HIDDEN_ROW; }
|
||||
uint8_t G2_ROW(int8_t value) { return (firstSwitchInGroup(2) >= 0) ? value : HIDDEN_ROW; }
|
||||
uint8_t G3_ROW(int8_t value) { return (firstSwitchInGroup(3) >= 0) ? value : HIDDEN_ROW; }
|
||||
uint8_t G4_ROW(int8_t value) { return (firstSwitchInGroup(4) >= 0) ? value : HIDDEN_ROW; }
|
||||
#endif
|
||||
|
||||
static uint8_t VIEWOPT_ROW(uint8_t value) { return expandState.viewOpt ? value : HIDDEN_ROW; }
|
||||
@@ -304,17 +323,18 @@ static uint8_t VIEWOPT_ROW(uint8_t value) { return expandState.viewOpt ? value :
|
||||
#define CURRENT_RECEIVER_EDITED(k) (k - ITEM_MODEL_SETUP_EXTERNAL_MODULE_PXX2_RECEIVER_1)
|
||||
#endif
|
||||
|
||||
#define MAX_SWITCH_PER_LINE (getSwitchWarningsCount() > 5 ? 4 : 5)
|
||||
#define MAX_SWITCH_PER_LINE 5
|
||||
#if defined(PCBXLITE)
|
||||
// X-Lite needs an additional column for full line selection (<])
|
||||
#define SW_WARN_ROWS \
|
||||
PREFLIGHT_ROW(uint8_t(NAVIGATION_LINE_BY_LINE|getSwitchWarningsCount())), \
|
||||
PREFLIGHT_ROW(uint8_t(getSwitchWarningsCount() > 4 ? TITLE_ROW : HIDDEN_ROW))
|
||||
PREFLIGHT_ROW(uint8_t(getSwitchWarningsCount() > MAX_SWITCH_PER_LINE ? TITLE_ROW : HIDDEN_ROW))
|
||||
#else
|
||||
// Handle special case when there is only one switch that can trigger a warning (MT12)
|
||||
#define SW_WARN_ROWS \
|
||||
PREFLIGHT_ROW(uint8_t(NAVIGATION_LINE_BY_LINE|((getSwitchWarningsCount() == 1) ? 1 : getSwitchWarningsCount()-1))), \
|
||||
PREFLIGHT_ROW(uint8_t(getSwitchWarningsCount() > MAX_SWITCH_PER_LINE ? TITLE_ROW : HIDDEN_ROW))
|
||||
PREFLIGHT_ROW(uint8_t(getSwitchWarningsCount() > MAX_SWITCH_PER_LINE ? TITLE_ROW : HIDDEN_ROW)), \
|
||||
PREFLIGHT_ROW(uint8_t(getSwitchWarningsCount() > (MAX_SWITCH_PER_LINE * 2) ? TITLE_ROW : HIDDEN_ROW))
|
||||
#endif
|
||||
|
||||
inline uint8_t MODULE_TYPE_ROWS(int moduleIdx)
|
||||
@@ -356,22 +376,23 @@ inline uint8_t TIMER_ROW(uint8_t timer, uint8_t value)
|
||||
#define EXTRA_MODULE_ROWS
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define FUNCTION_SWITCHES_ROWS 0, \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(0), \
|
||||
FS_ROW(G1_ROW(LABEL())), \
|
||||
FS_ROW(G1_ROW(0)), \
|
||||
FS_ROW(G1_ROW(0)), \
|
||||
FS_ROW(G2_ROW(LABEL())), \
|
||||
FS_ROW(G2_ROW(0)), \
|
||||
FS_ROW(G2_ROW(0)), \
|
||||
FS_ROW(G3_ROW(LABEL())), \
|
||||
FS_ROW(G3_ROW(0)), \
|
||||
FS_ROW(G3_ROW(0)),
|
||||
#define FUNCTION_SWITCHES_ROWS 0, \
|
||||
FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), \
|
||||
FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), \
|
||||
FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), \
|
||||
FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), FS_ROW(0), \
|
||||
FS_ROW(G1_ROW(LABEL())), \
|
||||
FS_ROW(G1_ROW(0)), \
|
||||
FS_ROW(G1_ROW(0)), \
|
||||
FS_ROW(G2_ROW(LABEL())), \
|
||||
FS_ROW(G2_ROW(0)), \
|
||||
FS_ROW(G2_ROW(0)), \
|
||||
FS_ROW(G3_ROW(LABEL())), \
|
||||
FS_ROW(G3_ROW(0)), \
|
||||
FS_ROW(G3_ROW(0)), \
|
||||
FS_ROW(G4_ROW(LABEL())), \
|
||||
FS_ROW(G4_ROW(0)), \
|
||||
FS_ROW(G4_ROW(0)),
|
||||
#else
|
||||
#define FUNCTION_SWITCHES_ROWS
|
||||
#endif
|
||||
@@ -561,10 +582,6 @@ inline uint8_t USB_JOYSTICK_APPLYROW()
|
||||
#define USB_JOYSTICK_ROWS
|
||||
#endif
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
static const char* _fct_sw_start[] = { STR_CHAR_DOWN, STR_CHAR_UP, "=" };
|
||||
#endif
|
||||
|
||||
uint8_t viewOptChoice(coord_t y, const char* title, uint8_t value, uint8_t attr, event_t event)
|
||||
{
|
||||
lcdDrawText(INDENT_WIDTH-1, y, title);
|
||||
@@ -572,93 +589,99 @@ uint8_t viewOptChoice(coord_t y, const char* title, uint8_t value, uint8_t attr,
|
||||
}
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
static int cfsIndex;
|
||||
const char* _fct_sw_start[] = { STR_CHAR_UP, STR_CHAR_DOWN, "=" };
|
||||
static int swIndex;
|
||||
static uint8_t cfsGroup;
|
||||
|
||||
bool checkCFSTypeAvailable(int val)
|
||||
{
|
||||
int group = FSWITCH_GROUP(cfsIndex);
|
||||
if (group > 0 && IS_FSWITCH_GROUP_ON(group) && val == SWITCH_TOGGLE)
|
||||
if (val == SWITCH_3POS) return false;
|
||||
int group = g_model.cfsGroup(swIndex);
|
||||
if (group > 0 && g_model.cfsGroupAlwaysOn(group) && val == SWITCH_TOGGLE)
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkCFSGroupAvailable(int group)
|
||||
static bool checkCFSGroupAvailable(int group)
|
||||
{
|
||||
if (FSWITCH_CONFIG(cfsIndex) == SWITCH_TOGGLE && group && IS_FSWITCH_GROUP_ON(group))
|
||||
if (g_model.cfsType(swIndex) == SWITCH_TOGGLE && group && g_model.cfsGroupAlwaysOn(group))
|
||||
return false;
|
||||
return true;
|
||||
}
|
||||
|
||||
bool checkCFSSwitchAvailable(int sw)
|
||||
static bool checkCFSSwitchAvailable(int sw)
|
||||
{
|
||||
return (sw == 0) || (sw == NUM_FUNCTIONS_SWITCHES + 1) || (FSWITCH_GROUP(sw - 1) == cfsGroup);
|
||||
return (sw == -1) || (sw == switchGetMaxSwitches()) || (switchIsCustomSwitch(sw) && (g_model.cfsGroup(sw) == cfsGroup));
|
||||
}
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
bool checkCFSColorAvailable(int col)
|
||||
static bool checkCFSColorAvailable(int col)
|
||||
{
|
||||
return col > 0;
|
||||
}
|
||||
#endif
|
||||
|
||||
enum CFSFields {
|
||||
CFS_FIELD_NAME,
|
||||
CFS_FIELD_TYPE,
|
||||
CFS_FIELD_NAME,
|
||||
CFS_FIELD_GROUP,
|
||||
CFS_FIELD_START,
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
CFS_FIELD_COLOR_LABEL,
|
||||
CFS_FIELD_ON_COLOR,
|
||||
CFS_FIELD_ON_LUA_OVERRIDE,
|
||||
CFS_FIELD_OFF_COLOR,
|
||||
CFS_FIELD_OFF_LUA_OVERRIDE,
|
||||
#endif
|
||||
CFS_FIELD_COUNT
|
||||
};
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags attr, event_t event)
|
||||
void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags attr, event_t event)
|
||||
{
|
||||
uint8_t selectedColor = getRGBColorIndex(color.getColor());
|
||||
selectedColor = editChoice(30, y, title, \
|
||||
STR_FS_COLOR_LIST, selectedColor, 0, DIM(colorTable), menuHorizontalPosition == 0 ? attr : 0, event, INDENT_WIDTH, checkCFSColorAvailable);
|
||||
if (attr && menuHorizontalPosition == 0 && checkIncDec_Ret) {
|
||||
color.setColor(colorTable[selectedColor - 1]);
|
||||
storageDirty(EE_MODEL);
|
||||
storageDirty((isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
}
|
||||
|
||||
lcdDrawNumber(LCD_W - 6 * FW, y, color.r, (menuHorizontalPosition == 1 ? attr : 0) | RIGHT);
|
||||
if (attr && menuHorizontalPosition == 1)
|
||||
color.r = checkIncDecModel(event, color.r, 0, 255);
|
||||
color.r = checkIncDec(event, color.r, 0, 255, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
|
||||
lcdDrawNumber(LCD_W - 3 * FW, y, color.g, (menuHorizontalPosition == 2 ? attr : 0) | RIGHT);
|
||||
if (attr && menuHorizontalPosition == 2)
|
||||
color.g = checkIncDecModel(event, color.g, 0, 255);
|
||||
color.g = checkIncDec(event, color.g, 0, 255, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
|
||||
lcdDrawNumber(LCD_W, y, color.b, (menuHorizontalPosition == 3 ? attr : 0) | RIGHT);
|
||||
if (attr && menuHorizontalPosition == 3)
|
||||
color.b = checkIncDecModel(event, color.b, 0, 255);
|
||||
color.b = checkIncDec(event, color.b, 0, 255, (isModelMenuDisplayed()) ? EE_MODEL : EE_GENERAL);
|
||||
}
|
||||
#endif
|
||||
|
||||
void menuModelCFSOne(event_t event)
|
||||
static void menuModelCFSOne(event_t event)
|
||||
{
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetName(cfsIndex + switchGetMaxSwitches());
|
||||
s += switchGetDefaultName(swIndex);
|
||||
|
||||
int config = FSWITCH_CONFIG(cfsIndex);
|
||||
uint8_t group = FSWITCH_GROUP(cfsIndex);
|
||||
int startPos = FSWITCH_STARTUP(cfsIndex);
|
||||
int config = g_model.cfsType(swIndex);
|
||||
uint8_t group = g_model.cfsGroup(swIndex);
|
||||
int startPos = g_model.cfsStart(swIndex);
|
||||
|
||||
SUBMENU(s.c_str(), CFS_FIELD_COUNT,
|
||||
{
|
||||
0,
|
||||
0,
|
||||
(uint8_t)((config != SWITCH_NONE) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_TOGGLE && group == 0) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_TOGGLE && config != SWITCH_GLOBAL && group == 0) ? 0 : HIDDEN_ROW),
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
LABEL(),
|
||||
3,
|
||||
3,
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? LABEL() : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 3 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 3 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
#endif
|
||||
});
|
||||
|
||||
@@ -677,40 +700,42 @@ void menuModelCFSOne(event_t event)
|
||||
LcdFlags attr = (sub == i ? (editMode > 0 ? BLINK | INVERS : INVERS) : 0);
|
||||
|
||||
switch(i) {
|
||||
case CFS_FIELD_TYPE:
|
||||
config = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_SWITCH_TYPE, STR_SWTYPES, config, SWITCH_NONE, SWITCH_GLOBAL, attr, event, 0, checkCFSTypeAvailable);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_model.cfsSetType(swIndex, (SwitchConfig)config);
|
||||
if (config == SWITCH_NONE) {
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
fsLedRGB(switchGetCustomSwitchIdx(swIndex), 0);
|
||||
#endif
|
||||
} else if (config == SWITCH_TOGGLE) {
|
||||
g_model.cfsSetStart(swIndex, FS_START_PREVIOUS); // Toggle switches do not have startup position
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CFS_FIELD_NAME:
|
||||
editSingleName(MODEL_SETUP_2ND_COLUMN, y, STR_NAME, g_model.switchNames[cfsIndex],
|
||||
editSingleName(MODEL_SETUP_2ND_COLUMN, y, STR_NAME, g_model.cfsName(swIndex),
|
||||
LEN_SWITCH_NAME, event, (attr != 0),
|
||||
editMode);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_TYPE:
|
||||
config = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_SWITCH_TYPE, STR_SWTYPES, config, SWITCH_NONE, SWITCH_2POS, attr, event, 0, checkCFSTypeAvailable);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
FSWITCH_SET_CONFIG(cfsIndex, config);
|
||||
if (config == SWITCH_TOGGLE) {
|
||||
FSWITCH_SET_STARTUP(cfsIndex, FS_START_PREVIOUS); // Toggle switches do not have startup position
|
||||
}
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
break;
|
||||
|
||||
case CFS_FIELD_GROUP:
|
||||
group = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_SWITCH_GROUP, STR_FSGROUPS, group, 0, 3, attr, event, 0, checkCFSGroupAvailable);
|
||||
group = editChoice(MODEL_SETUP_2ND_COLUMN, y, STR_SWITCH_GROUP, STR_FSGROUPS, group, 0, NUM_FUNCTIONS_GROUPS, attr, event, 0, checkCFSGroupAvailable);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
int oldGroup = FSWITCH_GROUP(cfsIndex);
|
||||
int oldGroup = g_model.cfsGroup(swIndex);
|
||||
if (groupHasSwitchOn(group))
|
||||
setFSLogicalState(cfsIndex, 0);
|
||||
FSWITCH_SET_GROUP(cfsIndex, group);
|
||||
setFSLogicalState(swIndex, 0);
|
||||
g_model.cfsSetGroup(swIndex, group);
|
||||
if (group > 0) {
|
||||
FSWITCH_SET_STARTUP(cfsIndex, groupDefaultSwitch(group) == -1 ? FS_START_PREVIOUS : FS_START_OFF);
|
||||
if (config == SWITCH_TOGGLE && IS_FSWITCH_GROUP_ON(group))
|
||||
FSWITCH_SET_CONFIG(cfsIndex, SWITCH_2POS);
|
||||
setGroupSwitchState(group, cfsIndex);
|
||||
g_model.cfsSetStart(swIndex, groupDefaultSwitch(group) == -1 ? FS_START_PREVIOUS : FS_START_OFF);
|
||||
if (config == SWITCH_TOGGLE && g_model.cfsGroupAlwaysOn(group))
|
||||
g_model.cfsSetType(swIndex, SWITCH_2POS);
|
||||
setGroupSwitchState(group);
|
||||
} else {
|
||||
FSWITCH_SET_STARTUP(cfsIndex, FS_START_PREVIOUS);
|
||||
g_model.cfsSetStart(swIndex, FS_START_PREVIOUS);
|
||||
}
|
||||
setGroupSwitchState(oldGroup);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -718,9 +743,8 @@ void menuModelCFSOne(event_t event)
|
||||
lcdDrawText(0, y, STR_SWITCH_STARTUP);
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN, y, _fct_sw_start[startPos], attr ? (s_editMode ? INVERS + BLINK : INVERS) : 0);
|
||||
if (attr) {
|
||||
startPos = checkIncDec(event, startPos, FS_START_ON, FS_START_PREVIOUS, EE_MODEL);
|
||||
FSWITCH_SET_STARTUP(cfsIndex, startPos);
|
||||
storageDirty(EE_MODEL);
|
||||
startPos = checkIncDec(event, startPos, FS_START_OFF, FS_START_PREVIOUS, EE_MODEL);
|
||||
g_model.cfsSetStart(swIndex, (fsStartPositionType)startPos);
|
||||
}
|
||||
break;
|
||||
|
||||
@@ -733,11 +757,19 @@ void menuModelCFSOne(event_t event)
|
||||
break;
|
||||
|
||||
case CFS_FIELD_ON_COLOR:
|
||||
menuCFSColor(y, g_model.functionSwitchLedONColor[cfsIndex], STR_OFFON[1], attr, event);
|
||||
menuCFSColor(y, g_model.cfsOnColor(swIndex), STR_OFFON[1], attr, event);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_ON_LUA_OVERRIDE:
|
||||
g_model.cfsSetOnColorLuaOverride(swIndex, editCheckBox(g_model.cfsOnColorLuaOverride(swIndex), LCD_W - 2 * FW, y, STR_LUA_OVERRIDE, attr, event, INDENT_WIDTH));
|
||||
break;
|
||||
|
||||
case CFS_FIELD_OFF_COLOR:
|
||||
menuCFSColor(y, g_model.functionSwitchLedOFFColor[cfsIndex], STR_OFFON[0], attr, event);
|
||||
menuCFSColor(y, g_model.cfsOffColor(swIndex), STR_OFFON[0], attr, event);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_OFF_LUA_OVERRIDE:
|
||||
g_model.cfsSetOffColorLuaOverride(swIndex, editCheckBox(g_model.cfsOffColorLuaOverride(swIndex), LCD_W - 2 * FW, y, STR_LUA_OVERRIDE, attr, event, INDENT_WIDTH));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
@@ -812,6 +844,15 @@ void menuModelSetup(event_t event)
|
||||
USB_JOYSTICK_ROWS
|
||||
});
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
int swCnt = switchGetMaxSwitches();
|
||||
uint8_t* p = (uint8_t*)mstate_tab;
|
||||
for (int i = 0; i < MAX_SWITCHES; i += 1) {
|
||||
if (i >= swCnt || !switchIsCustomSwitch(i))
|
||||
p[i + ITEM_MODEL_SETUP_SW1] = HIDDEN_ROW;
|
||||
}
|
||||
#endif
|
||||
|
||||
MENU_CHECK(menuTabModel, MENU_MODEL_SETUP, HEADER_LINE + ITEM_MODEL_SETUP_LINES_COUNT);
|
||||
title(STR_MENU_MODEL_SETUP);
|
||||
|
||||
@@ -988,33 +1029,48 @@ void menuModelSetup(event_t event)
|
||||
case ITEM_MODEL_SETUP_SW4:
|
||||
case ITEM_MODEL_SETUP_SW5:
|
||||
case ITEM_MODEL_SETUP_SW6:
|
||||
case ITEM_MODEL_SETUP_SW7:
|
||||
case ITEM_MODEL_SETUP_SW8:
|
||||
case ITEM_MODEL_SETUP_SW9:
|
||||
case ITEM_MODEL_SETUP_SW10:
|
||||
case ITEM_MODEL_SETUP_SW11:
|
||||
case ITEM_MODEL_SETUP_SW12:
|
||||
case ITEM_MODEL_SETUP_SW13:
|
||||
case ITEM_MODEL_SETUP_SW14:
|
||||
case ITEM_MODEL_SETUP_SW15:
|
||||
case ITEM_MODEL_SETUP_SW16:
|
||||
case ITEM_MODEL_SETUP_SW17:
|
||||
case ITEM_MODEL_SETUP_SW18:
|
||||
case ITEM_MODEL_SETUP_SW19:
|
||||
case ITEM_MODEL_SETUP_SW20:
|
||||
{
|
||||
int index = (k - ITEM_MODEL_SETUP_SW1);
|
||||
|
||||
lcdDrawSizedText(INDENT_WIDTH, y, STR_CHAR_SWITCH, 2, attr);
|
||||
lcdDrawText(lcdNextPos, y, switchGetName(index+switchGetMaxSwitches()), attr);
|
||||
lcdDrawText(lcdNextPos, y, switchGetDefaultName(index), attr);
|
||||
|
||||
if (attr && event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
cfsIndex = index;
|
||||
swIndex = index;
|
||||
pushMenu(menuModelCFSOne);
|
||||
}
|
||||
|
||||
if (ZEXIST(g_model.switchNames[index])) {
|
||||
char s[LEN_SWITCH_NAME + 1];
|
||||
strAppend(s, g_model.switchNames[index], LEN_SWITCH_NAME);
|
||||
lcdDrawText(35, y, s);
|
||||
} else {
|
||||
lcdDrawMMM(35, y, 0);
|
||||
}
|
||||
|
||||
int config = FSWITCH_CONFIG(index);
|
||||
int config = g_model.cfsType(index);
|
||||
lcdDrawText(30 + 5 * FW, y, STR_SWTYPES[config]);
|
||||
|
||||
if (config != SWITCH_NONE) {
|
||||
uint8_t group = FSWITCH_GROUP(index);
|
||||
if (config != SWITCH_NONE && config != SWITCH_GLOBAL) {
|
||||
if (g_model.cfsName(index)[0]) {
|
||||
char s[LEN_SWITCH_NAME + 1];
|
||||
strAppend(s, g_model.cfsName(index), LEN_SWITCH_NAME);
|
||||
lcdDrawText(35, y, s);
|
||||
} else {
|
||||
lcdDrawMMM(35, y, 0);
|
||||
}
|
||||
|
||||
uint8_t group = g_model.cfsGroup(index);
|
||||
lcdDrawText(30 + 13 * FW, y, STR_FSGROUPS[group]);
|
||||
|
||||
if (config != SWITCH_TOGGLE && group == 0) {
|
||||
int startPos = FSWITCH_STARTUP(index);
|
||||
int startPos = g_model.cfsStart(index);
|
||||
lcdDrawText(30 + 15 * FW, y, _fct_sw_start[startPos]);
|
||||
}
|
||||
}
|
||||
@@ -1024,6 +1080,7 @@ void menuModelSetup(event_t event)
|
||||
case ITEM_MODEL_SETUP_GROUP1_LABEL:
|
||||
case ITEM_MODEL_SETUP_GROUP2_LABEL:
|
||||
case ITEM_MODEL_SETUP_GROUP3_LABEL:
|
||||
case ITEM_MODEL_SETUP_GROUP4_LABEL:
|
||||
{
|
||||
int group = (k - ITEM_MODEL_SETUP_GROUP1_LABEL) / 3 + 1;
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_GROUP);
|
||||
@@ -1034,13 +1091,14 @@ void menuModelSetup(event_t event)
|
||||
case ITEM_MODEL_SETUP_GROUP1_ALWAYS_ON:
|
||||
case ITEM_MODEL_SETUP_GROUP2_ALWAYS_ON:
|
||||
case ITEM_MODEL_SETUP_GROUP3_ALWAYS_ON:
|
||||
case ITEM_MODEL_SETUP_GROUP4_ALWAYS_ON:
|
||||
{
|
||||
uint8_t group = (k - ITEM_MODEL_SETUP_GROUP1_ALWAYS_ON) / 3 + 1;
|
||||
lcdDrawText(INDENT_WIDTH * 2, y, STR_GROUP_ALWAYS_ON);
|
||||
int groupAlwaysOn = IS_FSWITCH_GROUP_ON(group);
|
||||
int groupAlwaysOn = g_model.cfsGroupAlwaysOn(group);
|
||||
groupAlwaysOn = editCheckBox(groupAlwaysOn, MODEL_SETUP_2ND_COLUMN, y, nullptr, attr, event);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
SET_FSWITCH_GROUP_ON(group, groupAlwaysOn);
|
||||
g_model.cfsSetGroupAlwaysOn(group, groupAlwaysOn);
|
||||
setGroupSwitchState(group);
|
||||
}
|
||||
}
|
||||
@@ -1049,20 +1107,27 @@ void menuModelSetup(event_t event)
|
||||
case ITEM_MODEL_SETUP_GROUP1_START:
|
||||
case ITEM_MODEL_SETUP_GROUP2_START:
|
||||
case ITEM_MODEL_SETUP_GROUP3_START:
|
||||
case ITEM_MODEL_SETUP_GROUP4_START:
|
||||
{
|
||||
uint8_t group = (k - ITEM_MODEL_SETUP_GROUP1_START) / 3 + 1;
|
||||
lcdDrawText(INDENT_WIDTH * 2, y, STR_START);
|
||||
int sw = groupDefaultSwitch(group) + 1;
|
||||
int sw = groupDefaultSwitch(group);
|
||||
cfsGroup = group;
|
||||
sw = editChoice(MODEL_SETUP_2ND_COLUMN + 1, y, nullptr, STR_FSSWITCHES, sw, 0, IS_FSWITCH_GROUP_ON(group) ? NUM_FUNCTIONS_SWITCHES : NUM_FUNCTIONS_SWITCHES + 1, attr, event, 0, checkCFSSwitchAvailable);
|
||||
if (sw == -1)
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN + 1, y, "=", attr);
|
||||
else if (sw == switchGetMaxSwitches())
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN + 1, y, STR_OFF, attr);
|
||||
else
|
||||
lcdDrawText(MODEL_SETUP_2ND_COLUMN + 1, y, switchGetDefaultName(sw), attr);
|
||||
sw = checkIncDec(event, sw, -1, switchGetMaxSwitches() - (g_model.cfsGroupAlwaysOn(group) ? 1 : 0), EE_MODEL, checkCFSSwitchAvailable);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
for (int i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
if (FSWITCH_GROUP(i) == group) {
|
||||
FSWITCH_SET_STARTUP(i, sw ? FS_START_OFF : FS_START_PREVIOUS);
|
||||
for (int i = 0; i < switchGetMaxSwitches(); i += 1) {
|
||||
if (switchIsCustomSwitch(i) && g_model.cfsGroup(i) == group) {
|
||||
g_model.cfsSetStart(i, (sw >= 0) ? FS_START_OFF : FS_START_PREVIOUS);
|
||||
}
|
||||
}
|
||||
if (sw > 0 && sw <= NUM_FUNCTIONS_SWITCHES) {
|
||||
FSWITCH_SET_STARTUP(sw - 1, FS_START_ON);
|
||||
if (sw >= 0 && sw < switchGetMaxSwitches()) {
|
||||
g_model.cfsSetStart(sw, FS_START_ON);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1162,6 +1227,7 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
|
||||
case ITEM_MODEL_SETUP_SWITCHES_WARNING2:
|
||||
case ITEM_MODEL_SETUP_SWITCHES_WARNING3:
|
||||
if (i==0) {
|
||||
if (IS_PREVIOUS_EVENT(event))
|
||||
menuVerticalOffset--;
|
||||
@@ -1186,8 +1252,6 @@ void menuModelSetup(event_t event)
|
||||
break;
|
||||
}
|
||||
|
||||
swarnstate_t states = g_model.switchWarning;
|
||||
|
||||
lcdDrawTextIndented(y, STR_SWITCHWARNING);
|
||||
#if defined(PCBXLITE)
|
||||
lcdDrawText(LCD_W, y, "<]", RIGHT);
|
||||
@@ -1213,17 +1277,15 @@ void menuModelSetup(event_t event)
|
||||
}
|
||||
|
||||
int current = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); i++) {
|
||||
for (int i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
div_t qr = div(current, MAX_SWITCH_PER_LINE);
|
||||
if (event == EVT_KEY_BREAK(KEY_ENTER) && attr &&
|
||||
l_posHorz == current && old_posHorz >= 0) {
|
||||
uint8_t curr_state = (states & 0x07);
|
||||
// remove old setting
|
||||
g_model.switchWarning &= ~(0x07 << (3 * i));
|
||||
uint8_t curr_state = g_model.getSwitchWarning(i);
|
||||
// add the new one (if switch UP and 2POS, jump directly to DOWN)
|
||||
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
|
||||
g_model.switchWarning |= (curr_state & 0x03) << (3 * i);
|
||||
g_model.setSwitchWarning(i, curr_state);
|
||||
storageDirty(EE_MODEL);
|
||||
#if defined(PCBXLITE)
|
||||
s_editMode = 0;
|
||||
@@ -1235,10 +1297,9 @@ void menuModelSetup(event_t event)
|
||||
y + FH * qr.quot, switchGetLetter(i),
|
||||
attr && (menuHorizontalPosition == current) ? INVERS : 0);
|
||||
lcdDrawText(lcdNextPos, y + FH * qr.quot,
|
||||
getSwitchWarnSymbol(states & 0x03));
|
||||
getSwitchWarnSymbol(g_model.getSwitchWarning(i)));
|
||||
++current;
|
||||
}
|
||||
states >>= 3;
|
||||
}
|
||||
if (attr && ((menuHorizontalPosition < 0) ||
|
||||
menuHorizontalPosition >= switchWarningsCount)) {
|
||||
|
||||
@@ -257,13 +257,13 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
|
||||
lcdDrawText(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, STR_CHANS, attr);
|
||||
else
|
||||
drawSource(MODEL_SPECIAL_FUNC_3RD_COLUMN, y, MIXSRC_FIRST_STICK + param - 1, attr);
|
||||
if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_CH_INDEX(cfn), maxParam);
|
||||
}
|
||||
#if defined(GVARS)
|
||||
else if (func == FUNC_ADJUST_GVAR) {
|
||||
maxParam = MAX_GVARS - 1;
|
||||
drawStringWithIndex(lcdNextPos + 2, y, STR_GV, CFN_GVAR_INDEX(cfn)+1, attr);
|
||||
if (active) CFN_GVAR_INDEX(cfn) = checkIncDec(event, CFN_GVAR_INDEX(cfn), 0, maxParam, eeFlags);
|
||||
break;
|
||||
}
|
||||
#endif // GVARS
|
||||
else if (func == FUNC_SET_TIMER) {
|
||||
@@ -276,18 +276,17 @@ void menuSpecialFunctions(event_t event, CustomFunctionData * functions, CustomF
|
||||
if (attr)
|
||||
repeatLastCursorHorMove(event);
|
||||
}
|
||||
break;
|
||||
}
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
else if (func == FUNC_PUSH_CUST_SWITCH) {
|
||||
maxParam = NUM_FUNCTIONS_SWITCHES - 1;
|
||||
drawStringWithIndex(lcdNextPos +5, y, "SW", CFN_CS_INDEX(cfn) + 1, attr);
|
||||
uint8_t sw = switchGetSwitchFromCustomIdx(CFN_CS_INDEX(cfn));
|
||||
lcdDrawText(lcdNextPos + 5, y, switchGetDefaultName(sw), attr);
|
||||
if (active) CFN_CS_INDEX(cfn) = switchGetCustomSwitchIdx(checkIncDec(event, sw, 0, switchGetMaxSwitches() - 1, eeFlags, switchIsCustomSwitch));
|
||||
}
|
||||
#endif
|
||||
else if (attr) {
|
||||
repeatLastCursorHorMove(event);
|
||||
}
|
||||
if (active) CHECK_INCDEC_MODELVAR_ZERO(event, CFN_CH_INDEX(cfn), maxParam);
|
||||
break;
|
||||
}
|
||||
|
||||
|
||||
@@ -65,21 +65,41 @@ void menuRadioDiagFS(event_t event)
|
||||
constexpr coord_t FS_3RD_COLUMN = 100;
|
||||
#endif
|
||||
SIMPLE_SUBMENU(STR_MENU_FSWITCH, 1);
|
||||
|
||||
lcdDrawText(FS_1ST_COLUMN, MENU_HEADER_HEIGHT + 1, "Phys");
|
||||
lcdDrawText(FS_2ND_COLUMN, MENU_HEADER_HEIGHT + 1, "Log");
|
||||
lcdDrawText(FS_3RD_COLUMN, MENU_HEADER_HEIGHT + 1, "Led");
|
||||
|
||||
for(uint8_t i=0; i < NUM_FUNCTIONS_SWITCHES; i++) {
|
||||
coord_t y = 2*FH + i*FH + 1;
|
||||
lcdDrawTextIndented(y, STR_CHAR_SWITCH);
|
||||
lcdDrawText(lcdNextPos, y, switchGetName(i+switchGetMaxSwitches()), 0);
|
||||
lcdDrawText(FS_1ST_COLUMN + 7, y, getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP);
|
||||
lcdDrawText(FS_2ND_COLUMN + 5, y, getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP);
|
||||
static uint8_t nxtSw = 0;
|
||||
static uint8_t ofst = 0;
|
||||
|
||||
if (event == EVT_ENTRY)
|
||||
ofst = 0;
|
||||
|
||||
for(uint8_t i=ofst, r=0; i < switchGetMaxSwitches(); i++) {
|
||||
if (switchIsCustomSwitch(i)) {
|
||||
if (r < 6) {
|
||||
uint8_t sw = switchGetCustomSwitchIdx(i);
|
||||
coord_t y = 2*FH + r*FH + 1;
|
||||
lcdDrawTextIndented(y, STR_CHAR_SWITCH);
|
||||
lcdDrawText(lcdNextPos, y, switchGetDefaultName(i));
|
||||
lcdDrawText(FS_1ST_COLUMN + 7, y, getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP);
|
||||
lcdDrawText(FS_2ND_COLUMN + 5, y, g_model.cfsState(i) ? STR_CHAR_DOWN : STR_CHAR_UP);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
lcdDrawText(FS_3RD_COLUMN, y, STR_FS_COLOR_LIST[getRGBColorIndex(fsGetLedRGB(i))], 0);
|
||||
lcdDrawText(FS_3RD_COLUMN, y, STR_FS_COLOR_LIST[getRGBColorIndex(rgbGetLedColor(sw))], 0);
|
||||
#else
|
||||
lcdDrawText(FS_3RD_COLUMN, y, STR_OFFON[fsLedState(i)]);
|
||||
lcdDrawText(FS_3RD_COLUMN, y, STR_OFFON[fsLedState(sw)]);
|
||||
#endif
|
||||
r += 1;
|
||||
} else {
|
||||
nxtSw = i;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (nxtSw > 6 && event == EVT_KEY_BREAK(KEY_PAGEDN)) {
|
||||
if (ofst == 0) ofst = nxtSw; else ofst = 0;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
@@ -93,6 +113,8 @@ void menuRadioDiagKeys(event_t event)
|
||||
lcdDrawText(14*FW, 1, STR_VTRIM, INVERS);
|
||||
trim_yo = MENU_HEADER_HEIGHT + 1;
|
||||
}
|
||||
uint8_t sw_y = MENU_HEADER_HEIGHT + 1;
|
||||
uint8_t sw_x = 8 * FW - 9;
|
||||
|
||||
for (uint8_t i = 0; i < 16; i++) {
|
||||
coord_t y;
|
||||
@@ -131,13 +153,18 @@ void menuRadioDiagKeys(event_t event)
|
||||
}
|
||||
}
|
||||
|
||||
if (i < switchGetMaxSwitches()) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
y = (i > 4) ? FH * (i - 4) + 1 : MENU_HEADER_HEIGHT + FH * i + 1;
|
||||
if (i < switchGetMaxAllSwitches()) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsCustomSwitch(i)) {
|
||||
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
|
||||
getvalue_t sw =
|
||||
((val < 0) ? 3 * i + 1 : ((val == 0) ? 3 * i + 2 : 3 * i + 3));
|
||||
drawSwitch(i > 4 ? 11 * FW - 5 : 8 * FW - 9, y, sw, 0, false);
|
||||
drawSwitch(sw_x, sw_y, sw, 0, false);
|
||||
if (i == 5) {
|
||||
sw_x = 11 * FW - 5;
|
||||
sw_y = MENU_HEADER_HEIGHT + 1;
|
||||
} else {
|
||||
sw_y += FH;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -351,7 +351,7 @@ void drawSmallSwitch(coord_t x, coord_t y, int width, unsigned int index)
|
||||
}
|
||||
}
|
||||
|
||||
lcdDrawChar(width == 5 ? x + 1 : x, y, 'A' + index, SMLSIZE);
|
||||
lcdDrawChar(width == 5 ? x + 1 : x, y, switchGetDefaultName(index)[1], SMLSIZE);
|
||||
y += 7;
|
||||
|
||||
if (val <= 0) {
|
||||
@@ -520,14 +520,25 @@ void menuMainView(event_t event)
|
||||
// -> 2 columns: one for each side
|
||||
// -> 4 slots on each side
|
||||
uint8_t maxSwitch = 0;
|
||||
uint8_t leftMaxRow = 0;
|
||||
uint8_t rightMaxRow = 0;
|
||||
for (uint8_t n = 0; n < switchGetMaxSwitches(); n += 1)
|
||||
if (SWITCH_EXISTS(n) && !switchIsFlex(n))
|
||||
if (SWITCH_EXISTS(n) && !switchIsFlex(n) && !switchIsCustomSwitch(n)) {
|
||||
auto switch_display = switchGetDisplayPosition(n);
|
||||
if (switch_display.col) {
|
||||
if (switch_display.row > rightMaxRow)
|
||||
rightMaxRow = switch_display.row;
|
||||
} else {
|
||||
if (switch_display.row > leftMaxRow)
|
||||
leftMaxRow = switch_display.row;
|
||||
}
|
||||
maxSwitch = n + 1;
|
||||
}
|
||||
|
||||
for (int i = 0; i < maxSwitch; ++i) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsFlex(i)) {
|
||||
auto switch_display = switchGetDisplayPosition(i);
|
||||
if (maxSwitch < 7) {
|
||||
if (leftMaxRow < 3 && rightMaxRow < 3) {
|
||||
for (int i = 0; i < maxSwitch; ++i) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsFlex(i) && !switchIsCustomSwitch(i)) {
|
||||
auto switch_display = switchGetDisplayPosition(i);
|
||||
coord_t x = switch_display.col == 0 ? 3 * FW + 3 : 18 * FW + 1;
|
||||
coord_t y = 33 + switch_display.row * FH;
|
||||
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
|
||||
@@ -537,9 +548,14 @@ void menuMainView(event_t event)
|
||||
: ((val == 0) ? 3 * i + 2 : 3 * i + 3));
|
||||
drawSwitch(x, y, sw, CENTERED, false);
|
||||
}
|
||||
else {
|
||||
}
|
||||
}
|
||||
else {
|
||||
for (int i = 0; i < maxSwitch; ++i) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsFlex(i) && !switchIsCustomSwitch(i)) {
|
||||
auto switch_display = switchGetDisplayPosition(i);
|
||||
coord_t x = (switch_display.col == 0 ? 8 : 96) + switch_display.row * 5;
|
||||
if (maxSwitch < 9) x += (switch_display.col == 0 ? 2 : 3);
|
||||
if (maxSwitch < 9) x += 3;
|
||||
drawSmallSwitch(x, 5 * FH + 1, 4, i);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -41,7 +41,7 @@ uint8_t g_moduleIdx;
|
||||
uint8_t getSwitchWarningsCount()
|
||||
{
|
||||
uint8_t count = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); ++i) {
|
||||
for (int i = 0; i < switchGetMaxAllSwitches(); ++i) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
++count;
|
||||
}
|
||||
@@ -870,7 +870,6 @@ void menuModelSetup(event_t event)
|
||||
}
|
||||
#endif
|
||||
lcdDrawTextIndented(y, STR_SWITCHWARNING);
|
||||
swarnstate_t states = g_model.switchWarning;
|
||||
|
||||
if (attr) {
|
||||
s_editMode = 0;
|
||||
@@ -888,17 +887,15 @@ void menuModelSetup(event_t event)
|
||||
LcdFlags line = attr;
|
||||
|
||||
int current = 0;
|
||||
for (int i = 0; i < switchGetMaxSwitches(); i++) {
|
||||
for (int i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
div_t qr = div(current, 8);
|
||||
if (event == EVT_KEY_BREAK(KEY_ENTER) && line &&
|
||||
l_posHorz == current) {
|
||||
uint8_t curr_state = (states & 0x07);
|
||||
// remove old setting
|
||||
g_model.switchWarning &= ~(0x07 << (3 * i));
|
||||
uint8_t curr_state = g_model.getSwitchWarning(i);
|
||||
// add the new one (if switch UP and 2POS, jump directly to DOWN)
|
||||
curr_state += (curr_state != 1 || IS_CONFIG_3POS(i) ? 1 : 2);
|
||||
g_model.switchWarning |= (curr_state & 0x03) << (3 * i);
|
||||
g_model.setSwitchWarning(i, curr_state);
|
||||
storageDirty(EE_MODEL);
|
||||
}
|
||||
lcdDrawChar(
|
||||
@@ -906,10 +903,9 @@ void menuModelSetup(event_t event)
|
||||
y + FH * qr.quot, 'A' + i,
|
||||
line && (menuHorizontalPosition == current) ? INVERS : 0);
|
||||
lcdDrawText(lcdNextPos, y + FH * qr.quot,
|
||||
getSwitchWarnSymbol(states & 0x03));
|
||||
getSwitchWarnSymbol(g_model.getSwitchWarning(i)));
|
||||
++current;
|
||||
}
|
||||
states >>= 3;
|
||||
}
|
||||
if (attr && menuHorizontalPosition < 0) {
|
||||
#if defined(PCBX9E)
|
||||
|
||||
@@ -123,6 +123,7 @@ endif()
|
||||
|
||||
if(FUNCTION_SWITCHES)
|
||||
add_gui_src(model/function_switches.cpp)
|
||||
add_gui_src(radio/radio_cfs.cpp)
|
||||
add_gui_src(radio/radio_diagcustswitches.cpp)
|
||||
endif()
|
||||
|
||||
|
||||
@@ -59,15 +59,14 @@ void SwitchWarnDialog::checkEvents()
|
||||
FullScreenDialog::checkEvents();
|
||||
|
||||
std::string warn_txt;
|
||||
swarnstate_t states = g_model.switchWarning;
|
||||
for (int i = 0; i < MAX_SWITCHES; ++i) {
|
||||
for (int i = 0; i < switchGetMaxAllSwitches(); ++i) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
swarnstate_t mask = ((swarnstate_t)0x07 << (i * 3));
|
||||
if (states & mask) {
|
||||
if ((switches_states & mask) != (states & mask)) {
|
||||
swarnstate_t state = (states >> (i * 3)) & 0x07;
|
||||
uint8_t warnState = g_model.getSwitchWarning(i);
|
||||
if (warnState) {
|
||||
swarnstate_t swState = g_model.getSwitchStateForWarning(i);
|
||||
if (warnState != swState) {
|
||||
warn_txt +=
|
||||
getSwitchPositionName(SWSRC_FIRST_SWITCH + i * 3 + state - 1);
|
||||
getSwitchPositionName(SWSRC_FIRST_SWITCH + i * 3 + warnState - 1);
|
||||
warn_txt += " ";
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,15 +24,16 @@
|
||||
#include "function_switches.h"
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "hal/rgbleds.h"
|
||||
#include "strhelpers.h"
|
||||
#include "switches.h"
|
||||
#include "color_picker.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_MODEL)
|
||||
|
||||
static const char* _fct_sw_start[] = {STR_CHAR_DOWN, STR_CHAR_UP, STR_LAST};
|
||||
const char* _fct_sw_start[] = {STR_CHAR_UP, STR_CHAR_DOWN, STR_LAST};
|
||||
|
||||
const std::string edgetx_fs_manual_url =
|
||||
const char* edgetx_fs_manual_url =
|
||||
"https://edgetx.gitbook.io/edgetx-user-manual/b-and-w-radios/model-select/"
|
||||
"setup#function-switches";
|
||||
|
||||
@@ -45,65 +46,70 @@ class FunctionSwitch : public Window
|
||||
padAll(PAD_TINY);
|
||||
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetName(switchIndex + switchGetMaxSwitches());
|
||||
s += switchGetDefaultName(switchIndex);
|
||||
|
||||
new StaticText(this, {PAD_LARGE, PAD_MEDIUM, SW_W, EdgeTxStyles::STD_FONT_HEIGHT}, s);
|
||||
|
||||
new ModelTextEdit(this, {NM_X, 0, NM_W, 0},
|
||||
g_model.switchNames[switchIndex], LEN_SWITCH_NAME);
|
||||
g_model.cfsName(switchIndex), LEN_SWITCH_NAME);
|
||||
|
||||
typeChoice = new Choice(
|
||||
this, {TP_X, 0, TP_W, 0}, STR_SWTYPES, SWITCH_NONE, SWITCH_2POS,
|
||||
[=]() { return FSWITCH_CONFIG(switchIndex); },
|
||||
this, {TP_X, 0, TP_W, 0}, STR_SWTYPES, SWITCH_NONE, SWITCH_GLOBAL,
|
||||
[=]() { return g_model.cfsType(switchIndex); },
|
||||
[=](int val) {
|
||||
FSWITCH_SET_CONFIG(switchIndex, val);
|
||||
if (val == SWITCH_TOGGLE) {
|
||||
FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS);
|
||||
g_model.cfsSetType(switchIndex, (SwitchConfig)val);
|
||||
if (val == SWITCH_NONE) {
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
fsLedRGB(switchGetCustomSwitchIdx(switchIndex), 0);
|
||||
#endif
|
||||
} else if (val == SWITCH_TOGGLE) {
|
||||
g_model.cfsSetStart(switchIndex, FS_START_PREVIOUS);
|
||||
setFSLogicalState(switchIndex, 0);
|
||||
startChoice->setValue(startChoice->getIntValue());
|
||||
}
|
||||
SET_DIRTY();
|
||||
});
|
||||
typeChoice->setAvailableHandler([=](int typ) -> bool {
|
||||
int group = FSWITCH_GROUP(switchIndex);
|
||||
if (group > 0 && IS_FSWITCH_GROUP_ON(group) && typ == SWITCH_TOGGLE)
|
||||
if (typ == SWITCH_3POS) return false;
|
||||
int group = g_model.cfsGroup(switchIndex);
|
||||
if (group > 0 && g_model.cfsGroupAlwaysOn(group) && typ == SWITCH_TOGGLE)
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
groupChoice = new Choice(
|
||||
this, {GR_X, 0, GR_W, 0}, STR_FUNCTION_SWITCH_GROUPS, 0, 3,
|
||||
[=]() { return FSWITCH_GROUP(switchIndex); },
|
||||
[=]() { return g_model.cfsGroup(switchIndex); },
|
||||
[=](int group) {
|
||||
int oldGroup = FSWITCH_GROUP(switchIndex);
|
||||
int oldGroup = g_model.cfsGroup(switchIndex);
|
||||
if (groupHasSwitchOn(group)) setFSLogicalState(switchIndex, 0);
|
||||
FSWITCH_SET_GROUP(switchIndex, group);
|
||||
g_model.cfsSetGroup(switchIndex, group);
|
||||
if (group > 0) {
|
||||
FSWITCH_SET_STARTUP(switchIndex, groupDefaultSwitch(group) == -1
|
||||
g_model.cfsSetStart(switchIndex, groupDefaultSwitch(group) == -1
|
||||
? FS_START_PREVIOUS
|
||||
: FS_START_OFF);
|
||||
if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE &&
|
||||
IS_FSWITCH_GROUP_ON(group))
|
||||
FSWITCH_SET_CONFIG(switchIndex, SWITCH_2POS);
|
||||
setGroupSwitchState(group, switchIndex);
|
||||
if (g_model.cfsType(switchIndex) == SWITCH_TOGGLE &&
|
||||
g_model.cfsGroupAlwaysOn(group))
|
||||
g_model.cfsSetType(switchIndex, SWITCH_2POS);
|
||||
setGroupSwitchState(group);
|
||||
} else {
|
||||
FSWITCH_SET_STARTUP(switchIndex, FS_START_PREVIOUS);
|
||||
g_model.cfsSetStart(switchIndex, FS_START_PREVIOUS);
|
||||
}
|
||||
setGroupSwitchState(oldGroup);
|
||||
SET_DIRTY();
|
||||
});
|
||||
groupChoice->setAvailableHandler([=](int group) -> bool {
|
||||
if (FSWITCH_CONFIG(switchIndex) == SWITCH_TOGGLE && group &&
|
||||
IS_FSWITCH_GROUP_ON(group))
|
||||
if (g_model.cfsType(switchIndex) == SWITCH_TOGGLE && group &&
|
||||
g_model.cfsGroupAlwaysOn(group))
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
startChoice = new Choice(
|
||||
this, {ST_X, 0, ST_W, 0}, _fct_sw_start, 0, 2,
|
||||
[=]() { return FSWITCH_STARTUP(switchIndex); },
|
||||
[=]() { return g_model.cfsStart(switchIndex); },
|
||||
[=](int val) {
|
||||
FSWITCH_SET_STARTUP(switchIndex, val);
|
||||
g_model.cfsSetStart(switchIndex, (fsStartPositionType)val);
|
||||
SET_DIRTY();
|
||||
});
|
||||
|
||||
@@ -113,23 +119,23 @@ class FunctionSwitch : public Window
|
||||
new StaticText(this, rect_t{C2_X - C2_W - PAD_TINY, C2_Y + PAD_SMALL, C2_W, 0}, STR_ON_ONE_SWITCHES[0], COLOR_THEME_PRIMARY1_INDEX, FONT(XS) | RIGHT);
|
||||
#endif
|
||||
|
||||
offValue = g_model.functionSwitchLedOFFColor[switchIndex];
|
||||
onValue = g_model.functionSwitchLedONColor[switchIndex];
|
||||
offValue = g_model.cfsOffColor(switchIndex);
|
||||
onValue = g_model.cfsOnColor(switchIndex);
|
||||
|
||||
offColor = new ColorPicker(
|
||||
this, {C1_X, C1_Y, C1_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_model.functionSwitchLedOFFColor[switchIndex].getColor() | RGB888_FLAG;
|
||||
return g_model.cfsOffColor(switchIndex).getColor() | RGB888_FLAG;
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_model.functionSwitchLedOFFColor[switchIndex] = offValue;
|
||||
g_model.functionSwitchLedONColor[switchIndex] = onValue;
|
||||
g_model.cfsOffColor(switchIndex) = offValue;
|
||||
g_model.cfsOnColor(switchIndex) = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_model.functionSwitchLedOFFColor[switchIndex].setColor(newValue);
|
||||
g_model.cfsOffColor(switchIndex).setColor(newValue);
|
||||
|
||||
offValue = g_model.functionSwitchLedOFFColor[switchIndex];
|
||||
offValue = g_model.cfsOffColor(switchIndex);
|
||||
SET_DIRTY();
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, ETX_RGB888);
|
||||
@@ -137,20 +143,29 @@ class FunctionSwitch : public Window
|
||||
onColor = new ColorPicker(
|
||||
this, {C2_X, C2_Y, C2_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_model.functionSwitchLedONColor[switchIndex].getColor() | RGB888_FLAG;
|
||||
return g_model.cfsOnColor(switchIndex).getColor() | RGB888_FLAG;
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_model.functionSwitchLedOFFColor[switchIndex] = offValue;
|
||||
g_model.functionSwitchLedONColor[switchIndex] = onValue;
|
||||
g_model.cfsOffColor(switchIndex) = offValue;
|
||||
g_model.cfsOnColor(switchIndex) = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_model.functionSwitchLedONColor[switchIndex].setColor(newValue);
|
||||
g_model.cfsOnColor(switchIndex).setColor(newValue);
|
||||
|
||||
onValue = g_model.functionSwitchLedONColor[switchIndex];
|
||||
onValue = g_model.cfsOnColor(switchIndex);
|
||||
SET_DIRTY();
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, ETX_RGB888);
|
||||
|
||||
overrideLabel = new StaticText(this, {GR_X, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_LARGE, GR_W + ST_W - PAD_LARGE, 0},
|
||||
STR_LUA_OVERRIDE, COLOR_THEME_PRIMARY1_INDEX, FONT(XS) | RIGHT);
|
||||
offOverride = new ToggleSwitch(this, {C1_X - PAD_MEDIUM * 2, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE, 0, 0},
|
||||
[=]() { return g_model.cfsOffColorLuaOverride(switchIndex); },
|
||||
[=](bool v) { g_model.cfsSetOffColorLuaOverride(switchIndex, v); });
|
||||
onOverride = new ToggleSwitch(this, {C2_X, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE, 0, 0},
|
||||
[=]() { return g_model.cfsOnColorLuaOverride(switchIndex); },
|
||||
[=](bool v) { g_model.cfsSetOnColorLuaOverride(switchIndex, v); });
|
||||
#endif //FUNCTION_SWITCHES_RGB_LEDS
|
||||
|
||||
setState();
|
||||
@@ -167,7 +182,7 @@ class FunctionSwitch : public Window
|
||||
static constexpr coord_t ST_X = GR_X + GR_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(ST_W, 60)
|
||||
#if NARROW_LAYOUT
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT * 2 + PAD_OUTLINE * 3;
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT * 3 + PAD_OUTLINE * 4;
|
||||
static constexpr coord_t C1_X = TP_X;
|
||||
static constexpr coord_t C1_Y = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE;
|
||||
static LAYOUT_VAL_SCALED(C1_W, 40)
|
||||
@@ -175,7 +190,7 @@ class FunctionSwitch : public Window
|
||||
static constexpr coord_t C2_Y = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE;
|
||||
static LAYOUT_VAL_SCALED(C2_W, 40)
|
||||
#else
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE * 2;
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT * 2 + PAD_OUTLINE * 3;
|
||||
static constexpr coord_t C1_X = ST_X + ST_W + PAD_SMALL;
|
||||
static constexpr coord_t C1_Y = 0;
|
||||
static LAYOUT_VAL_SCALED(C1_W, 40)
|
||||
@@ -206,6 +221,9 @@ class FunctionSwitch : public Window
|
||||
ColorPicker* onColor = nullptr;
|
||||
RGBLedColor offValue;
|
||||
RGBLedColor onValue;
|
||||
StaticText* overrideLabel = nullptr;
|
||||
ToggleSwitch* onOverride = nullptr;
|
||||
ToggleSwitch* offOverride = nullptr;
|
||||
#endif
|
||||
int lastType = -1;
|
||||
|
||||
@@ -214,29 +232,37 @@ class FunctionSwitch : public Window
|
||||
{
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
if (getFSLogicalState(switchIndex)) {
|
||||
g_model.functionSwitchLedONColor[switchIndex].setColor(newValue);
|
||||
if (g_model.cfsState(switchIndex)) {
|
||||
g_model.cfsOnColor(switchIndex).setColor(newValue);
|
||||
} else {
|
||||
g_model.functionSwitchLedOFFColor[switchIndex].setColor(newValue);
|
||||
g_model.cfsOffColor(switchIndex).setColor(newValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setState()
|
||||
{
|
||||
startChoice->show(FSWITCH_CONFIG(switchIndex) == SWITCH_2POS && FSWITCH_GROUP(switchIndex) == 0);
|
||||
groupChoice->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
uint8_t typ = g_model.cfsType(switchIndex);
|
||||
startChoice->show(typ == SWITCH_2POS && g_model.cfsGroup(switchIndex) == 0);
|
||||
groupChoice->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
offColor->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
onColor->show(FSWITCH_CONFIG(switchIndex) != SWITCH_NONE);
|
||||
offColor->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
onColor->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
overrideLabel->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
onOverride->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
offOverride->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
if (typ != SWITCH_NONE && typ != SWITCH_GLOBAL)
|
||||
setHeight(ROW_H);
|
||||
else
|
||||
setHeight(ROW_H - EdgeTxStyles::UI_ELEMENT_HEIGHT - PAD_OUTLINE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
setState();
|
||||
if (lastType != (int)FSWITCH_CONFIG(switchIndex)) {
|
||||
lastType = FSWITCH_CONFIG(switchIndex);
|
||||
if (lastType != (int)g_model.cfsType(switchIndex)) {
|
||||
lastType = g_model.cfsType(switchIndex);
|
||||
typeChoice->setValue(lastType);
|
||||
}
|
||||
Window::checkEvents();
|
||||
@@ -256,38 +282,43 @@ class SwitchGroup : public Window
|
||||
|
||||
auto btn = new TextButton(
|
||||
this, {AO_X, 0, AO_W, 0}, STR_GROUP_ALWAYS_ON, [=]() -> int8_t {
|
||||
int groupAlwaysOn = IS_FSWITCH_GROUP_ON(groupIndex);
|
||||
int groupAlwaysOn = g_model.cfsGroupAlwaysOn(groupIndex);
|
||||
groupAlwaysOn ^= 1;
|
||||
SET_FSWITCH_GROUP_ON(groupIndex, groupAlwaysOn);
|
||||
g_model.cfsSetGroupAlwaysOn(groupIndex, groupAlwaysOn);
|
||||
setGroupSwitchState(groupIndex);
|
||||
startChoice->setValue(startChoice->getIntValue());
|
||||
SET_DIRTY();
|
||||
return groupAlwaysOn;
|
||||
});
|
||||
btn->check(IS_FSWITCH_GROUP_ON(groupIndex));
|
||||
btn->check(g_model.cfsGroupAlwaysOn(groupIndex));
|
||||
|
||||
new StaticText(this, {SL_X, PAD_MEDIUM, SL_W, EdgeTxStyles::STD_FONT_HEIGHT}, STR_SWITCH_STARTUP);
|
||||
|
||||
startChoice = new Choice(
|
||||
this, {ST_X, 0, ST_W, 0}, STR_FSSWITCHES, 0,
|
||||
NUM_FUNCTIONS_SWITCHES + 1,
|
||||
this, {ST_X, 0, ST_W, 0}, 0, switchGetMaxSwitches() + 1,
|
||||
[=]() { return groupDefaultSwitch(groupIndex) + 1; },
|
||||
[=](int sw) {
|
||||
for (int i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
if (FSWITCH_GROUP(i) == groupIndex) {
|
||||
FSWITCH_SET_STARTUP(i, sw ? FS_START_OFF : FS_START_PREVIOUS);
|
||||
for (int i = 0; i < switchGetMaxSwitches(); i += 1) {
|
||||
if (switchIsCustomSwitch(i) && g_model.cfsGroup(i) == groupIndex) {
|
||||
g_model.cfsSetStart(i, (sw > 0) ? FS_START_OFF : FS_START_PREVIOUS);
|
||||
}
|
||||
}
|
||||
if (sw > 0 && sw <= NUM_FUNCTIONS_SWITCHES) {
|
||||
FSWITCH_SET_STARTUP(sw - 1, FS_START_ON);
|
||||
if (sw > 0 && sw <= switchGetMaxSwitches()) {
|
||||
g_model.cfsSetStart(sw - 1, FS_START_ON);
|
||||
}
|
||||
SET_DIRTY();
|
||||
});
|
||||
startChoice->setTextHandler([=](int sw) -> std::string {
|
||||
if (sw == 0)
|
||||
return "=";
|
||||
if (sw == switchGetMaxSwitches() + 1)
|
||||
return STR_OFF;
|
||||
return switchGetDefaultName(sw - 1);
|
||||
});
|
||||
startChoice->setAvailableHandler([=](int sw) -> bool {
|
||||
return (sw == 0) ||
|
||||
(sw == NUM_FUNCTIONS_SWITCHES + 1 &&
|
||||
!IS_FSWITCH_GROUP_ON(groupIndex)) ||
|
||||
(FSWITCH_GROUP(sw - 1) == groupIndex);
|
||||
(sw == switchGetMaxSwitches() + 1 && !g_model.cfsGroupAlwaysOn(groupIndex)) ||
|
||||
(switchIsCustomSwitch(sw - 1) && g_model.cfsGroup(sw - 1) == groupIndex);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -331,8 +362,9 @@ ModelFunctionSwitches::ModelFunctionSwitches() : Page(ICON_MODEL_SETUP)
|
||||
new StaticText(box, rect_t{FunctionSwitch::C2_X + PAD_OUTLINE, 0, FunctionSwitch::C2_W, 0}, STR_ON_ONE_SWITCHES[0], COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
new FunctionSwitch(body, i);
|
||||
for (uint8_t i = 0; i < switchGetMaxSwitches(); i += 1) {
|
||||
if (switchIsCustomSwitch(i))
|
||||
new FunctionSwitch(body, i);
|
||||
}
|
||||
|
||||
for (uint8_t i = 1; i <= 3; i += 1) {
|
||||
@@ -349,8 +381,7 @@ ModelFunctionSwitches::ModelFunctionSwitches() : Page(ICON_MODEL_SETUP)
|
||||
auto qr = lv_qrcode_create(box->getLvObj(), 150,
|
||||
makeLvColor(COLOR_THEME_SECONDARY1),
|
||||
makeLvColor(COLOR_THEME_SECONDARY3));
|
||||
lv_qrcode_update(qr, edgetx_fs_manual_url.c_str(),
|
||||
edgetx_fs_manual_url.length());
|
||||
lv_qrcode_update(qr, edgetx_fs_manual_url, strlen(edgetx_fs_manual_url));
|
||||
lv_obj_set_pos(qr, (LCD_W - 150) / 2, EdgeTxStyles::STD_FONT_HEIGHT);
|
||||
#endif
|
||||
|
||||
|
||||
@@ -38,7 +38,7 @@ class SwitchWarnMatrix : public ButtonMatrix
|
||||
{
|
||||
// Setup button layout & texts
|
||||
uint8_t btn_cnt = 0;
|
||||
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
|
||||
for (uint8_t i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
sw_idx[btn_cnt] = i;
|
||||
btn_cnt++;
|
||||
@@ -66,17 +66,16 @@ class SwitchWarnMatrix : public ButtonMatrix
|
||||
return;
|
||||
}
|
||||
|
||||
if (btn_id >= MAX_SWITCHES) return;
|
||||
if (btn_id >= switchGetMaxAllSwitches()) return;
|
||||
auto sw = sw_idx[btn_id];
|
||||
|
||||
swarnstate_t newstate = bfGet(g_model.switchWarning, 3 * sw, 3);
|
||||
if (newstate == 1 && SWITCH_CONFIG(sw) != SWITCH_3POS)
|
||||
uint8_t newstate = g_model.getSwitchWarning(sw);
|
||||
if (newstate == 1 && g_model.getSwitchType(sw) != SWITCH_3POS)
|
||||
newstate = 3;
|
||||
else
|
||||
newstate = (newstate + 1) % 4;
|
||||
newstate = (newstate + 1) & 3;
|
||||
|
||||
g_model.switchWarning =
|
||||
bfSet(g_model.switchWarning, newstate, 3 * sw, 3);
|
||||
g_model.setSwitchWarning(sw, newstate);
|
||||
SET_DIRTY();
|
||||
|
||||
setTextAndState(btn_id);
|
||||
@@ -84,15 +83,15 @@ class SwitchWarnMatrix : public ButtonMatrix
|
||||
|
||||
bool isActive(uint8_t btn_id) override
|
||||
{
|
||||
if (btn_id >= MAX_SWITCHES) return false;
|
||||
return bfGet(g_model.switchWarning, 3 * sw_idx[btn_id], 3) != 0;
|
||||
if (btn_id >= switchGetMaxAllSwitches()) return false;
|
||||
return g_model.getSwitchWarning(sw_idx[btn_id]) != 0;
|
||||
}
|
||||
|
||||
void setTextAndState(uint8_t btn_id)
|
||||
{
|
||||
swsrc_t index = sw_idx[btn_id];
|
||||
auto warn_pos = g_model.switchWarning >> (3 * index) & 0x07;
|
||||
std::string s = std::string(switchGetName(index)) +
|
||||
auto warn_pos = g_model.getSwitchWarning(index);
|
||||
std::string s = std::string(switchGetDefaultName(index)) +
|
||||
std::string(getSwitchWarnSymbol(warn_pos));
|
||||
setText(btn_id, s.c_str());
|
||||
setChecked(btn_id);
|
||||
@@ -109,7 +108,7 @@ class SwitchWarnMatrix : public ButtonMatrix
|
||||
void setAllState()
|
||||
{
|
||||
uint8_t btn_id = 0;
|
||||
for (uint8_t i = 0; i < MAX_SWITCHES; i++) {
|
||||
for (uint8_t i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_WARNING_ALLOWED(i)) {
|
||||
setTextAndState(btn_id);
|
||||
btn_id++;
|
||||
|
||||
@@ -220,7 +220,7 @@ void FunctionLineButton::refresh()
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
case FUNC_PUSH_CUST_SWITCH:
|
||||
sprintf(s + strlen(s), "%s%d", STR_SWITCH, CFN_CS_INDEX(cfn) + 1);
|
||||
strAppend(s + strlen(s), switchGetDefaultName(switchGetSwitchFromCustomIdx(CFN_CS_INDEX(cfn))));
|
||||
break;
|
||||
#endif
|
||||
|
||||
@@ -505,10 +505,15 @@ void FunctionEditPage::updateSpecialFunctionOneWindow()
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
case FUNC_PUSH_CUST_SWITCH: {
|
||||
new StaticText(line, rect_t{}, STR_SWITCH);
|
||||
auto choice = new Choice(line, rect_t{}, 0, NUM_FUNCTIONS_SWITCHES - 1, GET_SET_DEFAULT(CFN_CS_INDEX(cfn)), STR_SWITCH);
|
||||
auto choice = new Choice(line, rect_t{}, 0, switchGetMaxSwitches() - 1,
|
||||
[=]() { return switchGetSwitchFromCustomIdx(CFN_CS_INDEX(cfn)); },
|
||||
[=](int n) { CFN_CS_INDEX(cfn) = switchGetCustomSwitchIdx(n); },
|
||||
STR_SWITCH);
|
||||
choice->setTextHandler([=](int n) {
|
||||
return std::string(STR_SWITCH) + std::to_string(n + 1);
|
||||
return std::string(switchGetDefaultName(n));
|
||||
});
|
||||
choice->setAvailableHandler(switchIsCustomSwitch);
|
||||
|
||||
line = specialFunctionOneWindow->newLine(grid);
|
||||
|
||||
auto edit = addNumberEdit(line, STR_INTERVAL, cfn, PUSH_CS_DURATION_MIN,
|
||||
|
||||
@@ -171,7 +171,7 @@ class SwitchDynamicLabel : public StaticText
|
||||
|
||||
std::string label()
|
||||
{
|
||||
std::string str(switchGetCanonicalName(index));
|
||||
std::string str(switchGetDefaultName(index));
|
||||
return str + getSwitchPositionSymbol(lastpos);
|
||||
}
|
||||
|
||||
@@ -206,7 +206,7 @@ class HWSwitch
|
||||
HWSwitch(Window* parent, int swnum, coord_t y)
|
||||
{
|
||||
new SwitchDynamicLabel(parent, swnum, PAD_TINY, y + PAD_SMALL, HWSwitches::SW_CTRL_W);
|
||||
new HWInputEdit(parent, (char*)switchGetCustomName(swnum), LEN_SWITCH_NAME,
|
||||
new HWInputEdit(parent, g_eeGeneral.getSwitchCustomName(swnum), LEN_SWITCH_NAME,
|
||||
HWSwitches::SW_CTRL_W + PAD_SMALL, y);
|
||||
|
||||
coord_t x = HWSwitches::SW_CTRL_W * 2 + PAD_SMALL * 2;
|
||||
@@ -233,12 +233,9 @@ class HWSwitch
|
||||
sw_cfg = new Choice(
|
||||
parent, {x, y, HWSwitches::SW_CTRL_W, 0},
|
||||
STR_SWTYPES, SWITCH_NONE, switchGetMaxType(swnum),
|
||||
[=]() -> int { return SWITCH_CONFIG(swnum); },
|
||||
[=]() -> int { return g_eeGeneral.switchType(swnum); },
|
||||
[=](int newValue) {
|
||||
swconfig_t mask = (swconfig_t)SWITCH_CONFIG_MASK(swnum);
|
||||
g_eeGeneral.switchConfig =
|
||||
(g_eeGeneral.switchConfig & ~mask) |
|
||||
((swconfig_t(newValue) & SW_CFG_MASK) << (SW_CFG_BITS * swnum));
|
||||
g_eeGeneral.switchSetType(swnum, (SwitchConfig)newValue);
|
||||
SET_DIRTY();
|
||||
});
|
||||
|
||||
@@ -266,9 +263,10 @@ HWSwitches::HWSwitches(Window* parent) :
|
||||
{
|
||||
padAll(PAD_TINY);
|
||||
|
||||
auto max_switches = switchGetMaxSwitches();
|
||||
auto max_switches = switchGetMaxAllSwitches();
|
||||
for (int i = 0; i < max_switches; i++) {
|
||||
new HWSwitch(this, i, i * HWSwitch::SW_CTRL_H + PAD_OUTLINE);
|
||||
if (!switchIsCustomSwitch(i))
|
||||
new HWSwitch(this, i, i * HWSwitch::SW_CTRL_H + PAD_OUTLINE);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,318 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
|
||||
#include "radio_cfs.h"
|
||||
|
||||
#include "edgetx.h"
|
||||
#include "hal/rgbleds.h"
|
||||
#include "strhelpers.h"
|
||||
#include "switches.h"
|
||||
#include "color_picker.h"
|
||||
|
||||
#define SET_DIRTY() storageDirty(EE_GENERAL)
|
||||
|
||||
static const lv_coord_t cfs_line_col_dsc1[] = {LV_GRID_CONTENT,
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static const lv_coord_t cfs_line_col_dsc2[] = {
|
||||
LV_GRID_FR(13), LV_GRID_FR(11), LV_GRID_FR(11),
|
||||
LV_GRID_FR(12), LV_GRID_FR(10), LV_GRID_FR(7), LV_GRID_FR(7),
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
#else
|
||||
static const lv_coord_t cfs_line_col_dsc2[] = {
|
||||
LV_GRID_FR(10), LV_GRID_FR(10), LV_GRID_FR(10),
|
||||
LV_GRID_FR(12), LV_GRID_FR(8), LV_GRID_TEMPLATE_LAST};
|
||||
#endif
|
||||
|
||||
static const lv_coord_t cfs_line_row_dsc[] = {LV_GRID_CONTENT,
|
||||
LV_GRID_TEMPLATE_LAST};
|
||||
|
||||
extern const char* _fct_sw_start[];
|
||||
extern const char* edgetx_fs_manual_url;
|
||||
|
||||
class RadioFunctionSwitch : public Window
|
||||
{
|
||||
public:
|
||||
RadioFunctionSwitch(Window* parent, uint8_t sw) :
|
||||
Window(parent, {0, 0, LCD_W - PAD_SMALL * 2, ROW_H}), switchIndex(sw)
|
||||
{
|
||||
padAll(PAD_TINY);
|
||||
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetDefaultName(switchIndex);
|
||||
|
||||
new StaticText(this, {PAD_LARGE, PAD_MEDIUM, SW_W, EdgeTxStyles::STD_FONT_HEIGHT}, s);
|
||||
|
||||
new ModelTextEdit(this, {NM_X, 0, NM_W, 0},
|
||||
g_eeGeneral.switchName(switchIndex), LEN_SWITCH_NAME);
|
||||
|
||||
typeChoice = new Choice(
|
||||
this, {TP_X, 0, TP_W, 0}, STR_SWTYPES, SWITCH_NONE, SWITCH_GLOBAL,
|
||||
[=]() { return g_eeGeneral.switchType(switchIndex); },
|
||||
[=](int val) {
|
||||
g_eeGeneral.switchSetType(switchIndex, (SwitchConfig)val);
|
||||
if (val == SWITCH_NONE) {
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
if (g_model.getSwitchType(switchIndex) == SWITCH_NONE)
|
||||
fsLedRGB(switchGetCustomSwitchIdx(switchIndex), 0);
|
||||
#endif
|
||||
} else if (val == SWITCH_TOGGLE) {
|
||||
g_eeGeneral.switchSetStart(switchIndex, FS_START_PREVIOUS);
|
||||
setFSLogicalState(switchIndex, 0);
|
||||
startChoice->setValue(startChoice->getIntValue());
|
||||
}
|
||||
SET_DIRTY();
|
||||
});
|
||||
typeChoice->setAvailableHandler([=](int typ) -> bool {
|
||||
if (typ == SWITCH_3POS || typ == SWITCH_GLOBAL) return false;
|
||||
int group = g_eeGeneral.switchGroup(switchIndex);
|
||||
if (group > 0 && g_model.cfsGroupAlwaysOn(group) && typ == SWITCH_TOGGLE)
|
||||
return false;
|
||||
return true;
|
||||
});
|
||||
|
||||
startChoice = new Choice(
|
||||
this, {ST_X, 0, ST_W, 0}, _fct_sw_start, 0, 2,
|
||||
[=]() { return g_eeGeneral.switchStart(switchIndex); },
|
||||
[=](int val) {
|
||||
g_eeGeneral.switchSetStart(switchIndex, (fsStartPositionType)val);
|
||||
SET_DIRTY();
|
||||
});
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
#if NARROW_LAYOUT
|
||||
new StaticText(this, rect_t{C1_X - C1_W - PAD_TINY, C1_Y + PAD_SMALL, C1_W, 0}, STR_OFF, COLOR_THEME_PRIMARY1_INDEX, FONT(XS) | RIGHT);
|
||||
new StaticText(this, rect_t{C2_X - C2_W - PAD_TINY, C2_Y + PAD_SMALL, C2_W, 0}, STR_ON_ONE_SWITCHES[0], COLOR_THEME_PRIMARY1_INDEX, FONT(XS) | RIGHT);
|
||||
#endif
|
||||
|
||||
offValue = g_eeGeneral.switchOffColor(switchIndex);
|
||||
onValue = g_eeGeneral.switchOnColor(switchIndex);
|
||||
|
||||
offColor = new ColorPicker(
|
||||
this, {C1_X, 0, C1_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_eeGeneral.switchOffColor(switchIndex).getColor() | RGB888_FLAG;
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_eeGeneral.switchOffColor(switchIndex) = offValue;
|
||||
g_eeGeneral.switchOnColor(switchIndex) = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_eeGeneral.switchOffColor(switchIndex).setColor(newValue);
|
||||
|
||||
offValue = g_eeGeneral.switchOffColor(switchIndex);
|
||||
SET_DIRTY();
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, ETX_RGB888);
|
||||
|
||||
onColor = new ColorPicker(
|
||||
this, {C2_X, 0, C2_W, 0},
|
||||
[=]() -> int { // getValue
|
||||
return g_eeGeneral.switchOnColor(switchIndex).getColor() | RGB888_FLAG;
|
||||
},
|
||||
[=](int newValue) { // setValue
|
||||
g_eeGeneral.switchOffColor(switchIndex) = offValue;
|
||||
g_eeGeneral.switchOnColor(switchIndex) = onValue;
|
||||
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
g_eeGeneral.switchOnColor(switchIndex).setColor(newValue);
|
||||
|
||||
onValue = g_eeGeneral.switchOnColor(switchIndex);
|
||||
SET_DIRTY();
|
||||
},
|
||||
[=](int newValue) { previewColor(newValue); }, ETX_RGB888);
|
||||
|
||||
overrideLabel = new StaticText(this, {GR_X, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_LARGE, GR_W + ST_W - PAD_LARGE, 0},
|
||||
STR_LUA_OVERRIDE, COLOR_THEME_PRIMARY1_INDEX, FONT(XS) | RIGHT);
|
||||
offOverride = new ToggleSwitch(this, {C1_X - PAD_MEDIUM * 2, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE, 0, 0},
|
||||
[=]() { return g_model.cfsOffColorLuaOverride(switchIndex); },
|
||||
[=](bool v) { g_model.cfsSetOffColorLuaOverride(switchIndex, v); });
|
||||
onOverride = new ToggleSwitch(this, {C2_X, C1_Y + EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE, 0, 0},
|
||||
[=]() { return g_model.cfsOnColorLuaOverride(switchIndex); },
|
||||
[=](bool v) { g_model.cfsSetOnColorLuaOverride(switchIndex, v); });
|
||||
#endif //FUNCTION_SWITCHES_RGB_LEDS
|
||||
|
||||
setState();
|
||||
}
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
static LAYOUT_VAL_SCALED(SW_W, 70)
|
||||
static constexpr coord_t NM_X = SW_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(NM_W, 60)
|
||||
static constexpr coord_t TP_X = NM_X + NM_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(TP_W, 78)
|
||||
static constexpr coord_t GR_X = TP_X + TP_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(GR_W, 84)
|
||||
static constexpr coord_t ST_X = GR_X + GR_W + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(ST_W, 60)
|
||||
#if NARROW_LAYOUT
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT * 3 + PAD_OUTLINE * 4;
|
||||
static constexpr coord_t C1_X = TP_X;
|
||||
static constexpr coord_t C1_Y = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE;
|
||||
static LAYOUT_VAL_SCALED(C1_W, 40)
|
||||
static constexpr coord_t C2_X = GR_X;
|
||||
static constexpr coord_t C2_Y = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE;
|
||||
static LAYOUT_VAL_SCALED(C2_W, 40)
|
||||
#else
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT * 2 + PAD_OUTLINE * 3;
|
||||
static constexpr coord_t C1_X = ST_X + ST_W + PAD_SMALL;
|
||||
static constexpr coord_t C1_Y = 0;
|
||||
static LAYOUT_VAL_SCALED(C1_W, 40)
|
||||
static constexpr coord_t C2_X = C1_X + C1_W + PAD_SMALL;
|
||||
static constexpr coord_t C2_Y = 0;
|
||||
static LAYOUT_VAL_SCALED(C2_W, 40)
|
||||
#endif
|
||||
#else
|
||||
static constexpr coord_t ROW_H = EdgeTxStyles::UI_ELEMENT_HEIGHT + PAD_OUTLINE * 2;
|
||||
static constexpr coord_t SW_W = (LCD_W - PAD_SMALL * 2 - PAD_TINY * 4) / 5;
|
||||
static constexpr coord_t NM_X = SW_W + PAD_TINY;
|
||||
static LAYOUT_VAL_SCALED(NM_W, 80)
|
||||
static constexpr coord_t TP_X = NM_X + SW_W + PAD_TINY;
|
||||
static LAYOUT_VAL_SCALED(TP_W, 86)
|
||||
static constexpr coord_t GR_X = TP_X + SW_W + PAD_TINY;
|
||||
static LAYOUT_VAL_SCALED(GR_W, 94)
|
||||
static constexpr coord_t ST_X = GR_X + SW_W + PAD_LARGE * 2 + PAD_SMALL;
|
||||
static LAYOUT_VAL_SCALED(ST_W, 70)
|
||||
#endif
|
||||
|
||||
protected:
|
||||
uint8_t switchIndex;
|
||||
Choice* typeChoice = nullptr;
|
||||
Choice* startChoice = nullptr;
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
ColorPicker* offColor = nullptr;
|
||||
ColorPicker* onColor = nullptr;
|
||||
RGBLedColor offValue;
|
||||
RGBLedColor onValue;
|
||||
StaticText* overrideLabel = nullptr;
|
||||
ToggleSwitch* onOverride = nullptr;
|
||||
ToggleSwitch* offOverride = nullptr;
|
||||
#endif
|
||||
int lastType = -1;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
void previewColor(int newValue)
|
||||
{
|
||||
// Convert color index to RGB
|
||||
newValue = color32ToRGB(newValue);
|
||||
if (g_model.cfsState(switchIndex)) {
|
||||
g_eeGeneral.switchOnColor(switchIndex).setColor(newValue);
|
||||
} else {
|
||||
g_eeGeneral.switchOffColor(switchIndex).setColor(newValue);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
void setState()
|
||||
{
|
||||
uint8_t typ = g_eeGeneral.switchType(switchIndex);
|
||||
startChoice->show(typ == SWITCH_2POS && g_eeGeneral.switchGroup(switchIndex) == 0);
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
offColor->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
onColor->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
overrideLabel->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
onOverride->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
offOverride->show(typ != SWITCH_NONE && typ != SWITCH_GLOBAL);
|
||||
if (typ != SWITCH_NONE && typ != SWITCH_GLOBAL)
|
||||
setHeight(ROW_H);
|
||||
else
|
||||
setHeight(ROW_H - EdgeTxStyles::UI_ELEMENT_HEIGHT - PAD_OUTLINE);
|
||||
#endif
|
||||
}
|
||||
|
||||
void checkEvents() override
|
||||
{
|
||||
setState();
|
||||
if (lastType != (int)g_eeGeneral.switchType(switchIndex)) {
|
||||
lastType = g_eeGeneral.switchType(switchIndex);
|
||||
typeChoice->setValue(lastType);
|
||||
}
|
||||
Window::checkEvents();
|
||||
}
|
||||
};
|
||||
|
||||
RadioFunctionSwitches::RadioFunctionSwitches() : Page(ICON_RADIO_HARDWARE)
|
||||
{
|
||||
header->setTitle(STR_HARDWARE);
|
||||
header->setTitle2(STR_MENU_FSWITCH);
|
||||
|
||||
body->padAll(PAD_TINY);
|
||||
body->setFlexLayout(LV_FLEX_FLOW_COLUMN, PAD_ZERO);
|
||||
|
||||
FlexGridLayout grid1(cfs_line_col_dsc1, cfs_line_row_dsc, PAD_TINY);
|
||||
FlexGridLayout grid2(cfs_line_col_dsc2, cfs_line_row_dsc, PAD_TINY);
|
||||
|
||||
auto line = body->newLine(grid2);
|
||||
new StaticText(line, rect_t{}, STR_SWITCHES);
|
||||
new StaticText(line, rect_t{}, STR_NAME, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
new StaticText(line, rect_t{}, STR_SWITCH_TYPE,
|
||||
COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
grid2.nextColumn();
|
||||
// new StaticText(line, rect_t{}, STR_GROUP, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
startupHeader = new StaticText(line, rect_t{}, STR_SWITCH_STARTUP,
|
||||
COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
new StaticText(line, rect_t{}, STR_OFF, COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
new StaticText(line, rect_t{}, STR_ON_ONE_SWITCHES[0], COLOR_THEME_PRIMARY1_INDEX, FONT(XS));
|
||||
#endif
|
||||
|
||||
for (uint8_t i = 0; i < switchGetMaxSwitches(); i += 1) {
|
||||
if (switchIsCustomSwitch(i))
|
||||
new RadioFunctionSwitch(body, i);
|
||||
}
|
||||
|
||||
setState();
|
||||
|
||||
line = body->newLine(grid1);
|
||||
|
||||
new StaticText(line, rect_t{}, STR_MORE_INFO);
|
||||
|
||||
line = body->newLine(grid1);
|
||||
line->padBottom(PAD_LARGE);
|
||||
line->padLeft((width() - 150) / 2);
|
||||
|
||||
auto qr = lv_qrcode_create(line->getLvObj(), 150,
|
||||
makeLvColor(COLOR_THEME_SECONDARY1),
|
||||
makeLvColor(COLOR_THEME_SECONDARY3));
|
||||
lv_qrcode_update(qr, edgetx_fs_manual_url, strlen(edgetx_fs_manual_url));
|
||||
}
|
||||
|
||||
void RadioFunctionSwitches::setState()
|
||||
{
|
||||
// int cnt = 0;
|
||||
// for (int i = 1; i <= 3; i += 1) {
|
||||
// cnt += getSwitchCountInFSGroup(i);
|
||||
// }
|
||||
// startupHeader->show(cnt != NUM_FUNCTIONS_SWITCHES);
|
||||
}
|
||||
|
||||
void RadioFunctionSwitches::checkEvents()
|
||||
{
|
||||
setState();
|
||||
Page::checkEvents();
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,42 @@
|
||||
/*
|
||||
* Copyright (C) EdgeTX
|
||||
*
|
||||
* Based on code named
|
||||
* opentx - https://github.com/opentx/opentx
|
||||
* th9x - http://code.google.com/p/th9x
|
||||
* er9x - http://code.google.com/p/er9x
|
||||
* gruvin9x - http://code.google.com/p/gruvin9x
|
||||
*
|
||||
* License GPLv2: http://www.gnu.org/licenses/gpl-2.0.html
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License version 2 as
|
||||
* published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
|
||||
#include "page.h"
|
||||
|
||||
class RadioFunctionSwitches : public Page
|
||||
{
|
||||
public:
|
||||
RadioFunctionSwitches();
|
||||
|
||||
protected:
|
||||
BitmapBuffer* qrcode = nullptr;
|
||||
StaticText* startupHeader = nullptr;
|
||||
|
||||
void setState();
|
||||
void checkEvents() override;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
@@ -65,36 +65,40 @@ class RadioCustSwitchesDiagsWindow : public Window
|
||||
"Log");
|
||||
new StaticText(this, {FS_3RD_COLUMN, PAD_SMALL, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
"Led");
|
||||
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
coord_t y = (i + 2) * EdgeTxStyles::STD_FONT_HEIGHT;
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetName(i + switchGetMaxSwitches());
|
||||
new StaticText(this, {PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, s);
|
||||
new DynamicText(
|
||||
this, {FS_1ST_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() {
|
||||
return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP;
|
||||
});
|
||||
new DynamicText(
|
||||
this, {FS_2ND_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() { return getFSLogicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; });
|
||||
|
||||
for (uint8_t i = 0, r = 0; i < switchGetMaxSwitches(); i += 1) {
|
||||
if (switchIsCustomSwitch(i)) {
|
||||
coord_t y = (r + 2) * EdgeTxStyles::STD_FONT_HEIGHT;
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetDefaultName(i);
|
||||
new StaticText(this, {PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT}, s);
|
||||
new DynamicText(
|
||||
this, {FS_1ST_COLUMN + PAD_LARGE, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() {
|
||||
return getFSPhysicalState(i) ? STR_CHAR_DOWN : STR_CHAR_UP;
|
||||
});
|
||||
new DynamicText(
|
||||
this, {FS_2ND_COLUMN + 10, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() { return g_model.cfsState(i) ? STR_CHAR_DOWN : STR_CHAR_UP; });
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
colorBox[i] = new ColorSwatch(this, {FS_3RD_COLUMN, y, FS_COLOR_WIDTH,
|
||||
FS_COLOR_HEIGHT}, getLedColor(i));
|
||||
colorBox[r] = new ColorSwatch(this, {FS_3RD_COLUMN, y, FS_COLOR_WIDTH,
|
||||
FS_COLOR_HEIGHT}, getLedColor(r));
|
||||
#else
|
||||
new DynamicText(this,
|
||||
{FS_3RD_COLUMN, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() { return STR_OFFON[getFSLedState(i)]; });
|
||||
new DynamicText(this,
|
||||
{FS_3RD_COLUMN, y, FS_LBL_WIDTH, LV_SIZE_CONTENT},
|
||||
[=]() { return STR_OFFON[getFSLedState(i)]; });
|
||||
#endif
|
||||
r += 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
void checkEvents() override {
|
||||
Window::checkEvents();
|
||||
for (uint8_t i = 0; i < NUM_FUNCTIONS_SWITCHES; i += 1) {
|
||||
colorBox[i]->setColor(getLedColor(i));
|
||||
if (colorBox[i])
|
||||
colorBox[i]->setColor(getLedColor(i));
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
@@ -125,14 +125,14 @@ class RadioKeyDiagsWindow : public Window
|
||||
|
||||
void addSwitches(Window *form)
|
||||
{
|
||||
switchValues = new lv_obj_t *[switchGetMaxSwitches()];
|
||||
switchValues = new lv_obj_t *[switchGetMaxAllSwitches()];
|
||||
lv_obj_t *obj = form->getLvObj();
|
||||
uint8_t i;
|
||||
uint8_t row = 0;
|
||||
|
||||
// SWITCHES
|
||||
for (i = 0; i < switchGetMaxSwitches(); i++) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
for (i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsCustomSwitch(i)) {
|
||||
auto lbl = lv_label_create(obj);
|
||||
lv_label_set_text(lbl, "");
|
||||
lv_obj_set_pos(lbl, 0, row * EdgeTxStyles::STD_FONT_HEIGHT);
|
||||
@@ -197,8 +197,8 @@ class RadioKeyDiagsWindow : public Window
|
||||
{
|
||||
uint8_t i;
|
||||
|
||||
for (i = 0; i < switchGetMaxSwitches(); i++) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
for (i = 0; i < switchGetMaxAllSwitches(); i++) {
|
||||
if (SWITCH_EXISTS(i) && !switchIsCustomSwitch(i)) {
|
||||
getvalue_t val = getValue(MIXSRC_FIRST_SWITCH + i);
|
||||
getvalue_t sw =
|
||||
((val < 0) ? 3 * i + 1 : ((val == 0) ? 3 * i + 2 : 3 * i + 3));
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
#include "radio_setup.h"
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#include "radio_cfs.h"
|
||||
#include "radio_diagcustswitches.h"
|
||||
#endif
|
||||
|
||||
@@ -191,6 +192,9 @@ void RadioHardwarePage::build(Window* window)
|
||||
{STR_STICKS, []() { new HWInputDialog<HWSticks>(STR_STICKS); }},
|
||||
{STR_POTS, []() { new HWInputDialog<HWPots>(STR_POTS, HWPots::POTS_WINDOW_WIDTH); }},
|
||||
{STR_SWITCHES, []() { new HWInputDialog<HWSwitches>(STR_SWITCHES, HWSwitches::SW_WINDOW_WIDTH); }},
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
{STR_FUNCTION_SWITCHES, []() { new RadioFunctionSwitches(); }},
|
||||
#endif
|
||||
});
|
||||
|
||||
// Debugs
|
||||
|
||||
@@ -32,7 +32,11 @@ class RadioHardwarePage : public PageTab
|
||||
|
||||
void build(Window* window) override;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
static LAYOUT_SIZE(BTN_COLS, 2, 2)
|
||||
#else
|
||||
static LAYOUT_SIZE(BTN_COLS, 4, 3)
|
||||
#endif
|
||||
static LAYOUT_SIZE(FS_BTN_COLS, 2, 2)
|
||||
|
||||
protected:
|
||||
|
||||
@@ -24,6 +24,7 @@
|
||||
#include "hal/adc_driver.h"
|
||||
#include "hal/switch_driver.h"
|
||||
#include "hal/module_port.h"
|
||||
#include "hal/rgbleds.h"
|
||||
|
||||
#include "analogs.h"
|
||||
#include "switches.h"
|
||||
@@ -62,6 +63,11 @@ enum {
|
||||
ITEM_RADIO_HARDWARE_LABEL_SWITCHES,
|
||||
ITEM_RADIO_HARDWARE_SWITCH,
|
||||
ITEM_RADIO_HARDWARE_SWITCH_END = ITEM_RADIO_HARDWARE_SWITCH + MAX_SWITCHES - 1,
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
ITEM_RADIO_HARDWARE_LABEL_CFS,
|
||||
ITEM_RADIO_HARDWARE_CFS,
|
||||
ITEM_RADIO_HARDWARE_CFS_END = ITEM_RADIO_HARDWARE_CFS + MAX_SWITCHES - 1,
|
||||
#endif
|
||||
CASE_BATTGRAPH(ITEM_RADIO_HARDWARE_BATT_RANGE)
|
||||
ITEM_RADIO_HARDWARE_BATTERY_CALIB,
|
||||
ITEM_RADIO_HARDWARE_RTC_BATTERY,
|
||||
@@ -114,6 +120,130 @@ static void onHardwareAntennaSwitchConfirm(const char * result)
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
#define RADIO_SETUP_2ND_COLUMN (LCD_W-11*FW)
|
||||
extern char* _fct_sw_start[];
|
||||
static int swIndex;
|
||||
|
||||
extern bool checkCFSTypeAvailable(int val);
|
||||
|
||||
enum CFSFields {
|
||||
CFS_FIELD_TYPE,
|
||||
CFS_FIELD_NAME,
|
||||
CFS_FIELD_START,
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
CFS_FIELD_COLOR_LABEL,
|
||||
CFS_FIELD_ON_COLOR,
|
||||
CFS_FIELD_ON_LUA_OVERRIDE,
|
||||
CFS_FIELD_OFF_COLOR,
|
||||
CFS_FIELD_OFF_LUA_OVERRIDE,
|
||||
#endif
|
||||
CFS_FIELD_COUNT
|
||||
};
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
extern void menuCFSColor(coord_t y, RGBLedColor& color, const char* title, LcdFlags attr, event_t event);
|
||||
#endif
|
||||
|
||||
static void menuRadioCFSOne(event_t event)
|
||||
{
|
||||
std::string s(STR_CHAR_SWITCH);
|
||||
s += switchGetDefaultName(swIndex);
|
||||
|
||||
int config = g_eeGeneral.switchType(swIndex);
|
||||
uint8_t group = g_eeGeneral.switchGroup(swIndex);
|
||||
int startPos = g_eeGeneral.switchStart(swIndex);
|
||||
|
||||
SUBMENU(s.c_str(), CFS_FIELD_COUNT,
|
||||
{
|
||||
0,
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_TOGGLE && config != SWITCH_GLOBAL && group == 0) ? 0 : HIDDEN_ROW),
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? LABEL() : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 3 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 3 : HIDDEN_ROW),
|
||||
(uint8_t)((config != SWITCH_NONE && config != SWITCH_GLOBAL) ? 0 : HIDDEN_ROW),
|
||||
#endif
|
||||
});
|
||||
|
||||
int8_t sub = menuVerticalPosition;
|
||||
int8_t editMode = s_editMode;
|
||||
|
||||
coord_t y = MENU_HEADER_HEIGHT + 1;
|
||||
|
||||
for (int k = 0; k < NUM_BODY_LINES; k += 1) {
|
||||
int i = k + menuVerticalOffset;
|
||||
for (int j = 0; j <= i; j += 1) {
|
||||
if (j < (int)DIM(mstate_tab) && mstate_tab[j] == HIDDEN_ROW) {
|
||||
i += 1;
|
||||
}
|
||||
}
|
||||
LcdFlags attr = (sub == i ? (editMode > 0 ? BLINK | INVERS : INVERS) : 0);
|
||||
|
||||
switch(i) {
|
||||
case CFS_FIELD_TYPE:
|
||||
config = editChoice(RADIO_SETUP_2ND_COLUMN, y, STR_SWITCH_TYPE, STR_SWTYPES, config, SWITCH_NONE, SWITCH_3POS, attr, event, 0, checkCFSTypeAvailable);
|
||||
if (attr && checkIncDec_Ret) {
|
||||
g_eeGeneral.switchSetType(swIndex, (SwitchConfig)config);
|
||||
if (config == SWITCH_NONE) {
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
if (g_model.getSwitchType(swIndex) == SWITCH_NONE)
|
||||
fsLedRGB(switchGetCustomSwitchIdx(swIndex), 0);
|
||||
#endif
|
||||
} else if (config == SWITCH_TOGGLE) {
|
||||
g_eeGeneral.switchSetStart(swIndex, FS_START_PREVIOUS); // Toggle switches do not have startup position
|
||||
}
|
||||
}
|
||||
break;
|
||||
|
||||
case CFS_FIELD_NAME:
|
||||
editSingleName(RADIO_SETUP_2ND_COLUMN, y, STR_NAME, g_eeGeneral.switchName(swIndex),
|
||||
LEN_SWITCH_NAME, event, (attr != 0),
|
||||
editMode);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_START:
|
||||
lcdDrawText(0, y, STR_SWITCH_STARTUP);
|
||||
lcdDrawText(RADIO_SETUP_2ND_COLUMN, y, _fct_sw_start[startPos], attr ? (s_editMode ? INVERS + BLINK : INVERS) : 0);
|
||||
if (attr) {
|
||||
startPos = checkIncDec(event, startPos, FS_START_OFF, FS_START_PREVIOUS, EE_MODEL);
|
||||
g_eeGeneral.switchSetStart(swIndex, (fsStartPositionType)startPos);
|
||||
}
|
||||
break;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES_RGB_LEDS)
|
||||
case CFS_FIELD_COLOR_LABEL:
|
||||
lcdDrawText(0, y, STR_BLCOLOR);
|
||||
lcdDrawText(LCD_W - 6 * FW, y, "R", RIGHT | SMLSIZE);
|
||||
lcdDrawText(LCD_W - 3 * FW, y, "G", RIGHT | SMLSIZE);
|
||||
lcdDrawText(LCD_W, y, "B", RIGHT | SMLSIZE);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_ON_COLOR:
|
||||
menuCFSColor(y, g_eeGeneral.switchOnColor(swIndex), STR_OFFON[1], attr, event);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_ON_LUA_OVERRIDE:
|
||||
g_eeGeneral.cfsSetOnColorLuaOverride(swIndex, editCheckBox(g_eeGeneral.cfsOnColorLuaOverride(swIndex), LCD_W - 2 * FW, y, STR_LUA_OVERRIDE, attr, event, INDENT_WIDTH));
|
||||
break;
|
||||
|
||||
case CFS_FIELD_OFF_COLOR:
|
||||
menuCFSColor(y, g_eeGeneral.switchOffColor(swIndex), STR_OFFON[0], attr, event);
|
||||
break;
|
||||
|
||||
case CFS_FIELD_OFF_LUA_OVERRIDE:
|
||||
g_eeGeneral.cfsSetOffColorLuaOverride(swIndex, editCheckBox(g_eeGeneral.cfsOffColorLuaOverride(swIndex), LCD_W - 2 * FW, y, STR_LUA_OVERRIDE, attr, event, INDENT_WIDTH));
|
||||
break;
|
||||
#endif
|
||||
}
|
||||
|
||||
y += FH;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
static uint8_t _dispSerialPort(uint8_t port_nr)
|
||||
{
|
||||
auto port = serialGetPort(port_nr);
|
||||
@@ -147,11 +277,25 @@ static void _init_menu_tab_array(uint8_t* tab, size_t len)
|
||||
tab[i] = idx < max_pots ? (IS_POT_MULTIPOS(idx) ? 1 : 2) : HIDDEN_ROW;
|
||||
}
|
||||
|
||||
auto max_switches = switchGetMaxSwitches();
|
||||
int max_switches = switchGetMaxAllSwitches();
|
||||
for (int i = ITEM_RADIO_HARDWARE_SWITCH; i <= ITEM_RADIO_HARDWARE_SWITCH_END; i++) {
|
||||
uint8_t idx = i - ITEM_RADIO_HARDWARE_SWITCH;
|
||||
tab[i] = switchIsFlex(idx) ? 2 : idx < max_switches ? 1 : HIDDEN_ROW;
|
||||
if (idx < max_switches && !switchIsCustomSwitch(idx)) {
|
||||
tab[i] = switchIsFlex(idx) ? 2 : 1;
|
||||
} else {
|
||||
tab[i] = HIDDEN_ROW;
|
||||
}
|
||||
}
|
||||
#if defined (FUNCTION_SWITCHES)
|
||||
for (int i = ITEM_RADIO_HARDWARE_CFS; i <= ITEM_RADIO_HARDWARE_CFS_END; i++) {
|
||||
uint8_t idx = i - ITEM_RADIO_HARDWARE_CFS;
|
||||
if (idx < max_switches && switchIsCustomSwitch(idx)) {
|
||||
tab[i] = 0;
|
||||
} else {
|
||||
tab[i] = HIDDEN_ROW;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
#if defined(BATTGRAPH)
|
||||
tab[ITEM_RADIO_HARDWARE_BATT_RANGE] = 1;
|
||||
@@ -280,6 +424,12 @@ void menuRadioHardware(event_t event)
|
||||
lcdDrawTextAlignedLeft(y, STR_SWITCHES);
|
||||
break;
|
||||
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
case ITEM_RADIO_HARDWARE_LABEL_CFS:
|
||||
lcdDrawTextAlignedLeft(y, STR_FUNCTION_SWITCHES);
|
||||
break;
|
||||
#endif
|
||||
|
||||
#if defined(BATTGRAPH)
|
||||
case ITEM_RADIO_HARDWARE_BATT_RANGE:
|
||||
lcdDrawTextAlignedLeft(y, STR_BATTERY_RANGE);
|
||||
@@ -530,15 +680,14 @@ void menuRadioHardware(event_t event)
|
||||
setPotInversion(idx, 0);
|
||||
storageDirty(EE_GENERAL);
|
||||
}
|
||||
}
|
||||
else if (k <= ITEM_RADIO_HARDWARE_SWITCH_END) {
|
||||
} else if (k <= ITEM_RADIO_HARDWARE_SWITCH_END) {
|
||||
// Switches
|
||||
int index = k - ITEM_RADIO_HARDWARE_SWITCH;
|
||||
int config = SWITCH_CONFIG(index);
|
||||
int config = g_eeGeneral.switchType(index);
|
||||
|
||||
LcdFlags flags = menuHorizontalPosition < 0 ? attr : 0;
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_CHAR_SWITCH, flags);
|
||||
lcdDrawText(lcdNextPos, y, switchGetName(index), flags);
|
||||
lcdDrawText(lcdNextPos, y, switchGetDefaultName(index), flags);
|
||||
|
||||
if (switchIsFlex(index)) {
|
||||
// flexSwitch source
|
||||
@@ -550,10 +699,10 @@ void menuRadioHardware(event_t event)
|
||||
|
||||
//Name
|
||||
flags = menuHorizontalPosition == 1 ? attr : 0;
|
||||
if (switchHasCustomName(index) ||
|
||||
if (g_eeGeneral.switchHasCustomName(index) ||
|
||||
(attr && s_editMode > 0 && menuHorizontalPosition == 1)) {
|
||||
editName(HW_SETTINGS_COLUMN2, y,
|
||||
(char*)switchGetCustomName(index), LEN_SWITCH_NAME,
|
||||
g_eeGeneral.getSwitchCustomName(index), LEN_SWITCH_NAME,
|
||||
event, flags, 0, old_editMode);
|
||||
} else {
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN2, y, flags);
|
||||
@@ -565,19 +714,14 @@ void menuRadioHardware(event_t event)
|
||||
SWITCH_NONE, switchGetMaxType(index), flags, event);
|
||||
|
||||
if (attr && checkIncDec_Ret) {
|
||||
swconfig_t mask = SWITCH_CONFIG_MASK(index);
|
||||
g_eeGeneral.switchConfig =
|
||||
(g_eeGeneral.switchConfig & ~mask) |
|
||||
((swconfig_t(config) & SW_CFG_MASK) << (SW_CFG_BITS * index));
|
||||
storageDirty(EE_GENERAL);
|
||||
g_eeGeneral.switchSetType(index, (SwitchConfig)config);
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
flags = menuHorizontalPosition == 0 ? attr : 0;
|
||||
if (switchHasCustomName(index) ||
|
||||
if (g_eeGeneral.switchHasCustomName(index) ||
|
||||
(attr && s_editMode > 0 && menuHorizontalPosition == 0)) {
|
||||
editName(HW_SETTINGS_COLUMN1, y,
|
||||
(char*)switchGetCustomName(index), LEN_SWITCH_NAME,
|
||||
g_eeGeneral.getSwitchCustomName(index), LEN_SWITCH_NAME,
|
||||
event, flags, 0, old_editMode);
|
||||
} else {
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN1, y, flags);
|
||||
@@ -589,13 +733,43 @@ void menuRadioHardware(event_t event)
|
||||
SWITCH_NONE, switchGetMaxType(index), flags, event);
|
||||
|
||||
if (attr && checkIncDec_Ret) {
|
||||
swconfig_t mask = SWITCH_CONFIG_MASK(index);
|
||||
g_eeGeneral.switchConfig =
|
||||
(g_eeGeneral.switchConfig & ~mask) |
|
||||
((swconfig_t(config) & SW_CFG_MASK) << (SW_CFG_BITS * index));
|
||||
storageDirty(EE_GENERAL);
|
||||
g_eeGeneral.switchSetType(index, (SwitchConfig)config);
|
||||
}
|
||||
}
|
||||
#if defined(FUNCTION_SWITCHES)
|
||||
} else if (k <= ITEM_RADIO_HARDWARE_CFS_END) {
|
||||
// Customisable Switches
|
||||
int index = k - ITEM_RADIO_HARDWARE_CFS;
|
||||
int config = g_eeGeneral.switchType(index);
|
||||
|
||||
lcdDrawText(INDENT_WIDTH, y, STR_CHAR_SWITCH, attr);
|
||||
lcdDrawText(lcdNextPos, y, switchGetDefaultName(index), attr);
|
||||
|
||||
lcdDrawText(HW_SETTINGS_COLUMN2, y, STR_SWTYPES[config]);
|
||||
|
||||
if (attr && event == EVT_KEY_BREAK(KEY_ENTER)) {
|
||||
swIndex = index;
|
||||
pushMenu(menuRadioCFSOne);
|
||||
}
|
||||
|
||||
if (config != SWITCH_NONE) {
|
||||
if (g_eeGeneral.switchName(index)[0]) {
|
||||
char s[LEN_SWITCH_NAME + 1];
|
||||
strAppend(s, g_eeGeneral.switchName(index), LEN_SWITCH_NAME);
|
||||
lcdDrawText(HW_SETTINGS_COLUMN1, y, s);
|
||||
} else {
|
||||
lcdDrawMMM(HW_SETTINGS_COLUMN1, y, 0);
|
||||
}
|
||||
|
||||
uint8_t group = g_eeGeneral.switchGroup(index);
|
||||
// lcdDrawText(30 + 13 * FW, y, STR_FSGROUPS[group]);
|
||||
|
||||
if (config != SWITCH_TOGGLE && group == 0) {
|
||||
int startPos = g_eeGeneral.switchStart(index);
|
||||
lcdDrawText(30 + 15 * FW, y, _fct_sw_start[startPos]);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
} else if (k <= ITEM_RADIO_HARDWARE_SERIAL_PORT_END) {
|
||||
auto port_nr = k - ITEM_RADIO_HARDWARE_SERIAL_PORT;
|
||||
auto port = serialGetPort(port_nr);
|
||||
|
||||
@@ -362,7 +362,7 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
||||
|
||||
if (swtch >= SWSRC_FIRST_SWITCH && swtch <= SWSRC_LAST_SWITCH) {
|
||||
div_t swinfo = switchInfo(swtch);
|
||||
if (swinfo.quot >= switchGetMaxSwitches() + switchGetMaxFctSwitches()) {
|
||||
if (swinfo.quot >= switchGetMaxAllSwitches()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -370,7 +370,7 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (IS_SWITCH_FS(swinfo.quot) && context == GeneralCustomFunctionsContext) {
|
||||
if (switchIsCustomSwitch(swinfo.quot) && context == GeneralCustomFunctionsContext) {
|
||||
return false; // FS are defined at model level, and cannot be in global functions
|
||||
}
|
||||
|
||||
@@ -439,7 +439,7 @@ static bool isSwitchSwitchAvailable(int swtch, bool invert) {
|
||||
// Check normal switch
|
||||
if (swtch < MAX_SWITCHES * 3) {
|
||||
div_t swinfo = switchInfo(swtch + SWSRC_FIRST_SWITCH);
|
||||
if (swinfo.quot >= switchGetMaxSwitches() + switchGetMaxFctSwitches()) {
|
||||
if (swinfo.quot >= switchGetMaxAllSwitches()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -670,12 +670,9 @@ bool isAssignableFunctionAvailable(int function, bool modelFunctions)
|
||||
case FUNC_DISABLE_AUDIO_AMP:
|
||||
return false;
|
||||
#endif
|
||||
#if !defined(LED_STRIP_GPIO)
|
||||
#if !defined(LED_STRIP_LENGTH)
|
||||
case FUNC_RGB_LED:
|
||||
return false;
|
||||
#elif defined(RGB_LED_OFFSET)
|
||||
case FUNC_RGB_LED:
|
||||
return (LED_STRIP_LENGTH > RGB_LED_OFFSET);
|
||||
#endif
|
||||
#if !defined(DEBUG)
|
||||
case FUNC_TEST:
|
||||
|
||||
Reference in New Issue
Block a user