[Taranis] Switches selection menu

This commit is contained in:
bsongis
2015-06-16 18:10:16 +02:00
parent 0283096ac7
commit 07444b002c
16 changed files with 117 additions and 34 deletions
+9 -4
View File
@@ -183,6 +183,12 @@ enum SwitchContext
MixesContext
};
bool isLogicalSwitchAvailable(int index)
{
LogicalSwitchData * lsw = lswAddress(index);
return (lsw->func != LS_FUNC_NONE);
}
bool isSwitchAvailable(int swtch, SwitchContext context)
{
uint32_t index = switchInfo(abs(swtch)).quot;
@@ -219,8 +225,7 @@ bool isSwitchAvailable(int swtch, SwitchContext context)
return false;
}
else if (context != LogicalSwitchesContext) {
LogicalSwitchData * cs = lswAddress(swtch-SWSRC_FIRST_LOGICAL_SWITCH);
return (cs->func != LS_FUNC_NONE);
return isLogicalSwitchAvailable(swtch - SWSRC_FIRST_LOGICAL_SWITCH);
}
}
@@ -344,9 +349,9 @@ bool modelHasNotes()
return isFileAvailable(filename);
}
int getFirstAvailableSource(int min, int max, bool (*func)(int))
int getFirstAvailable(int min, int max, bool (*func)(int))
{
int retval = MIXSRC_NONE;
int retval = 0;
for (int i = min; i <= max; i++) {
if ((*func)(i)) {
retval = i;
+2 -1
View File
@@ -196,12 +196,13 @@ int8_t checkIncDecMovedSwitch(int8_t val);
bool isThrottleSourceAvailable(int source);
bool isLogicalSwitchFunctionAvailable(int function);
bool isAssignableFunctionAvailable(int function);
bool isLogicalSwitchAvailable(int index);
bool isSwitchAvailableInLogicalSwitches(int swtch);
bool isSwitchAvailableInCustomFunctions(int swtch);
bool isSwitchAvailableInMixes(int swtch);
bool isSwitchAvailableInTimers(int swtch);
bool isModuleAvailable(int module);
int getFirstAvailableSource(int min, int max, bool (*func)(int));
int getFirstAvailable(int min, int max, bool (*func)(int));
#define AUTOSWITCH_ENTER_LONG() (attr && event==EVT_KEY_LONG(KEY_ENTER))
#define CHECK_INCDEC_SWITCH(event, var, min, max, flags, available) \
var = checkIncDec(event, var, min, max, (flags)|INCDEC_SWITCH, available)
+66 -29
View File
@@ -42,7 +42,7 @@ horzpos_t m_posHorz;
int8_t s_editMode;
uint8_t s_noHi;
uint8_t calibrationState;
int s_source = MIXSRC_NONE;
int checkIncDecSelection = 0;
#if defined(AUTOSWITCH)
int8_t checkIncDecMovedSwitch(int8_t val)
@@ -71,44 +71,57 @@ INIT_STOPS(stops100, 3, -100, 0, 100)
INIT_STOPS(stops1000, 3, -1000, 0, 1000)
INIT_STOPS(stopsSwitch, 15, SWSRC_FIRST, CATEGORY_END(-SWSRC_FIRST_LOGICAL_SWITCH), CATEGORY_END(-SWSRC_FIRST_TRIM), CATEGORY_END(-SWSRC_LAST_SWITCH+1), 0, CATEGORY_END(SWSRC_LAST_SWITCH), CATEGORY_END(SWSRC_FIRST_TRIM-1), CATEGORY_END(SWSRC_FIRST_LOGICAL_SWITCH-1), SWSRC_LAST)
void onLongEnterPress(const char *result)
void onSourceLongEnterPress(const char *result)
{
if (result == STR_MENU_INPUTS)
s_source = getFirstAvailableSource(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable)+1;
checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable)+1;
#if defined(LUA_MODEL_SCRIPTS)
else if (result == STR_MENU_LUA)
s_source = getFirstAvailableSource(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable);
checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable);
#endif
else if (result == STR_MENU_STICKS)
s_source = MIXSRC_FIRST_STICK;
checkIncDecSelection = MIXSRC_FIRST_STICK;
else if (result == STR_MENU_POTS)
s_source = MIXSRC_FIRST_POT;
checkIncDecSelection = MIXSRC_FIRST_POT;
else if (result == STR_MENU_MAX)
s_source = MIXSRC_MAX;
checkIncDecSelection = MIXSRC_MAX;
else if (result == STR_MENU_HELI)
s_source = MIXSRC_FIRST_HELI;
checkIncDecSelection = MIXSRC_FIRST_HELI;
else if (result == STR_MENU_TRIMS)
s_source = MIXSRC_FIRST_TRIM;
checkIncDecSelection = MIXSRC_FIRST_TRIM;
else if (result == STR_MENU_SWITCHES)
s_source = MIXSRC_FIRST_SWITCH;
checkIncDecSelection = MIXSRC_FIRST_SWITCH;
else if (result == STR_MENU_TRAINER)
s_source = MIXSRC_FIRST_TRAINER;
checkIncDecSelection = MIXSRC_FIRST_TRAINER;
else if (result == STR_MENU_CHANNELS)
s_source = getFirstAvailableSource(MIXSRC_FIRST_CH, MIXSRC_LAST_CH, isSourceAvailable);
checkIncDecSelection = getFirstAvailable(MIXSRC_FIRST_CH, MIXSRC_LAST_CH, isSourceAvailable);
else if (result == STR_MENU_GVARS)
s_source = MIXSRC_FIRST_GVAR;
checkIncDecSelection = MIXSRC_FIRST_GVAR;
else if (result == STR_MENU_TELEMETRY) {
for (int i = 0; i < MAX_SENSORS; i++) {
TelemetrySensor * sensor = & g_model.telemetrySensors[i];
if (sensor->isAvailable()) {
s_source = MIXSRC_FIRST_TELEM + 3*i;
checkIncDecSelection = MIXSRC_FIRST_TELEM + 3*i;
break;
}
}
}
}
void onSwitchLongEnterPress(const char *result)
{
if (result == STR_MENU_SWITCHES)
checkIncDecSelection = SWSRC_FIRST_SWITCH;
else if (result == STR_MENU_TRIMS)
checkIncDecSelection = SWSRC_FIRST_TRIM;
else if (result == STR_MENU_LOGICAL_SWITCHES)
checkIncDecSelection = SWSRC_FIRST_LOGICAL_SWITCH + getFirstAvailable(0, NUM_LOGICAL_SWITCH, isLogicalSwitchAvailable);
else if (result == STR_MENU_OTHER)
checkIncDecSelection = SWSRC_ON;
else if (result == STR_MENU_INVERT)
checkIncDecSelection = SWSRC_INVERT;
}
#define DBLKEYS_PRESSED_RGT_LFT(in) ((in & ((2<<KEY_PLUS) + (2<<KEY_MINUS))) == ((2<<KEY_PLUS) + (2<<KEY_MINUS)))
#define DBLKEYS_PRESSED_UP_DWN(in) ((in & ((2<<KEY_MENU) + (2<<KEY_PAGE))) == ((2<<KEY_MENU) + (2<<KEY_PAGE)))
#define DBLKEYS_PRESSED_RGT_UP(in) ((in & ((2<<KEY_ENTER) + (2<<KEY_MINUS))) == ((2<<KEY_ENTER) + (2<<KEY_MINUS)))
@@ -255,16 +268,18 @@ int checkIncDec(unsigned int event, int val, int i_min, int i_max, unsigned int
if (i_flags & INCDEC_SOURCE) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
s_source = MIXSRC_NONE;
checkIncDecSelection = MIXSRC_NONE;
if (i_min <= MIXSRC_FIRST_INPUT && i_max >= MIXSRC_FIRST_INPUT) {
if (getFirstAvailableSource(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE)
if (getFirstAvailable(MIXSRC_FIRST_INPUT, MIXSRC_LAST_INPUT, isInputAvailable) != MIXSRC_NONE) {
MENU_ADD_ITEM(STR_MENU_INPUTS);
}
}
#if defined(LUA_MODEL_SCRIPTS)
if (i_min <= MIXSRC_FIRST_LUA && i_max >= MIXSRC_FIRST_LUA) {
if (getFirstAvailableSource(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE)
if (getFirstAvailable(MIXSRC_FIRST_LUA, MIXSRC_LAST_LUA, isSourceAvailable) != MIXSRC_NONE) {
MENU_ADD_ITEM(STR_MENU_LUA);
}
}
#endif
if (i_min <= MIXSRC_FIRST_STICK && i_max >= MIXSRC_FIRST_STICK) MENU_ADD_ITEM(STR_MENU_STICKS);
@@ -277,28 +292,50 @@ int checkIncDec(unsigned int event, int val, int i_min, int i_max, unsigned int
if (i_min <= MIXSRC_FIRST_SWITCH && i_max >= MIXSRC_FIRST_SWITCH) MENU_ADD_ITEM(STR_MENU_SWITCHES);
if (i_min <= MIXSRC_FIRST_TRAINER && i_max >= MIXSRC_FIRST_TRAINER) MENU_ADD_ITEM(STR_MENU_TRAINER);
if (i_min <= MIXSRC_FIRST_CH && i_max >= MIXSRC_FIRST_CH) MENU_ADD_ITEM(STR_MENU_CHANNELS);
if (i_min <= MIXSRC_FIRST_GVAR && i_max >= MIXSRC_FIRST_GVAR && isValueAvailable(MIXSRC_FIRST_GVAR))
if (i_min <= MIXSRC_FIRST_GVAR && i_max >= MIXSRC_FIRST_GVAR && isValueAvailable(MIXSRC_FIRST_GVAR)) {
MENU_ADD_ITEM(STR_MENU_GVARS);
}
if (i_min <= MIXSRC_FIRST_TELEM && i_max >= MIXSRC_FIRST_TELEM) {
bool available = false;
for (int i = 0; i < MAX_SENSORS; i++) {
TelemetrySensor * sensor = & g_model.telemetrySensors[i];
if (sensor->isAvailable()) {
available = true;
MENU_ADD_ITEM(STR_MENU_TELEMETRY);
break;
}
}
if (available)
MENU_ADD_ITEM(STR_MENU_TELEMETRY);
}
menuHandler = onLongEnterPress;
menuHandler = onSourceLongEnterPress;
}
if (s_source != MIXSRC_NONE) {
newval = s_source;
if (s_source != MIXSRC_MAX)
s_editMode = 1;
s_source = MIXSRC_NONE;
if (checkIncDecSelection != 0) {
newval = checkIncDecSelection;
if (checkIncDecSelection != MIXSRC_MAX)
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
}
}
else if (i_flags & INCDEC_SWITCH) {
if (event == EVT_KEY_LONG(KEY_ENTER)) {
killEvents(event);
checkIncDecSelection = SWSRC_NONE;
if (i_min <= SWSRC_FIRST_SWITCH && i_max >= SWSRC_LAST_SWITCH) MENU_ADD_ITEM(STR_MENU_SWITCHES);
if (i_min <= SWSRC_FIRST_TRIM && i_max >= SWSRC_LAST_TRIM) MENU_ADD_ITEM(STR_MENU_TRIMS);
if (i_min <= SWSRC_FIRST_LOGICAL_SWITCH && i_max >= SWSRC_LAST_LOGICAL_SWITCH) {
for (int i = 0; i < NUM_LOGICAL_SWITCH; i++) {
if (isLogicalSwitchAvailable(i)) {
MENU_ADD_ITEM(STR_MENU_LOGICAL_SWITCHES);
break;
}
}
}
if (isValueAvailable && isValueAvailable(SWSRC_ON)) MENU_ADD_ITEM(STR_MENU_OTHER);
if (isValueAvailable && isValueAvailable(-newval)) MENU_ADD_ITEM(STR_MENU_INVERT);
menuHandler = onSwitchLongEnterPress;
}
if (checkIncDecSelection != 0) {
newval = (checkIncDecSelection == SWSRC_INVERT ? -newval : checkIncDecSelection);
s_editMode = EDIT_MODIFY_FIELD;
checkIncDecSelection = 0;
}
}
return newval;
+4
View File
@@ -1761,6 +1761,10 @@ enum SwitchSources {
#endif
SWSRC_FIRST_IN_LOGICAL_SWITCHES = -SWSRC_LAST_IN_LOGICAL_SWITCHES,
SWSRC_FIRST_IN_MIXES = -SWSRC_LAST_IN_MIXES,
#if defined(CPUARM)
SWSRC_INVERT = SWSRC_COUNT+1,
#endif
};
enum MixSources {
+3
View File
@@ -606,10 +606,13 @@ const pm_char STR_BLCOLOR[] PROGMEM = TR_BLCOLOR;
const pm_char STR_MENU_HELI[] PROGMEM = TR_MENU_HELI;
const pm_char STR_MENU_TRIMS[] PROGMEM = TR_MENU_TRIMS;
const pm_char STR_MENU_SWITCHES[] PROGMEM = TR_MENU_SWITCHES;
const pm_char STR_MENU_LOGICAL_SWITCHES[] PROGMEM = TR_MENU_LOGICAL_SWITCHES;
const pm_char STR_MENU_TRAINER[] PROGMEM = TR_MENU_TRAINER;
const pm_char STR_MENU_CHANNELS[] PROGMEM = TR_MENU_CHANNELS;
const pm_char STR_MENU_GVARS[] PROGMEM = TR_MENU_GVARS;
const pm_char STR_MENU_TELEMETRY[] PROGMEM = TR_MENU_TELEMETRY;
const pm_char STR_MENU_OTHER[] PROGMEM = TR_MENU_OTHER;
const pm_char STR_MENU_INVERT[] PROGMEM = TR_MENU_INVERT;
#endif
#if MENUS_LOCK == 1
+3
View File
@@ -822,10 +822,13 @@ extern const pm_char STR_BLCOLOR[];
extern const pm_char STR_MENU_HELI[];
extern const pm_char STR_MENU_TRIMS[];
extern const pm_char STR_MENU_SWITCHES[];
extern const pm_char STR_MENU_LOGICAL_SWITCHES[];
extern const pm_char STR_MENU_TRAINER[];
extern const pm_char STR_MENU_CHANNELS[];
extern const pm_char STR_MENU_GVARS[];
extern const pm_char STR_MENU_TELEMETRY[];
extern const pm_char STR_MENU_OTHER[];
extern const pm_char STR_MENU_INVERT[];
#endif
#if MENUS_LOCK == 1
+3
View File
@@ -1087,10 +1087,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1091,10 +1091,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1086,10 +1086,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1035,10 +1035,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1035,10 +1035,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1078,10 +1078,13 @@
#define TR_MENU_HELI "\316Cyclique"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Inters"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Ecolage"
#define TR_MENU_CHANNELS "\320Canaux"
#define TR_MENU_GVARS "\311Vars. glob."
#define TR_MENU_TELEMETRY "\321Télémesure"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1035,10 +1035,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1090,10 +1090,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trymy"
#define TR_MENU_SWITCHES "\312Przełczn"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trener "
#define TR_MENU_CHANNELS "\320Kanały "
#define TR_MENU_GVARS "\311ZmGlo"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1035,10 +1035,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"
+3
View File
@@ -1035,10 +1035,13 @@
#define TR_MENU_HELI "\316Cyclic"
#define TR_MENU_TRIMS "\313Trims"
#define TR_MENU_SWITCHES "\312Switches"
#define TR_MENU_LOGICAL_SWITCHES "\312Logical Switches"
#define TR_MENU_TRAINER "\317Trainer"
#define TR_MENU_CHANNELS "\320Channels"
#define TR_MENU_GVARS "\311GVars"
#define TR_MENU_TELEMETRY "\321Telemetry"
#define TR_MENU_OTHER "Other"
#define TR_MENU_INVERT "Invert"
#define ZSTR_RSSI "RSSI"
#define ZSTR_SWR "SWR"