Auto Switch function (only in Flight Phases now)
This commit is contained in:
@@ -47,6 +47,10 @@ TEMPLATES = YES
|
||||
# POTS (POT1, POT2, POT3),
|
||||
NAVIGATION = NO
|
||||
|
||||
# Switches autmatic selection
|
||||
# Values = YES, NO
|
||||
AUTOSWITCH = YES
|
||||
|
||||
# AUDIO Mods
|
||||
# Values = YES, NO
|
||||
AUDIO = NO
|
||||
@@ -226,6 +230,10 @@ ifeq ($(NAVIGATION), POTS)
|
||||
CPPDEFS += -DNAVIGATION_POT1 -DNAVIGATION_POT2 -DNAVIGATION_POT3
|
||||
endif
|
||||
|
||||
ifeq ($(AUTOSWITCH), YES)
|
||||
CPPDEFS += -DAUTOSWITCH
|
||||
endif
|
||||
|
||||
ifeq ($(SPLASH), YES)
|
||||
CPPDEFS += -DSPLASH
|
||||
endif
|
||||
|
||||
+16
-9
@@ -66,28 +66,28 @@ int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, ui
|
||||
int16_t newval = val;
|
||||
uint8_t kpl=KEY_RIGHT, kmi=KEY_LEFT, kother = -1;
|
||||
|
||||
if(event & _MSK_KEY_DBL){
|
||||
if (event & _MSK_KEY_DBL) {
|
||||
uint8_t hlp=kpl;
|
||||
kpl=kmi;
|
||||
kmi=hlp;
|
||||
event=EVT_KEY_FIRST(EVT_KEY_MASK & event);
|
||||
}
|
||||
if(event==EVT_KEY_FIRST(kpl) || event== EVT_KEY_REPT(kpl) || (s_editMode>0 && (event==EVT_KEY_FIRST(KEY_UP) || event== EVT_KEY_REPT(KEY_UP))) ) {
|
||||
if (event==EVT_KEY_FIRST(kpl) || event== EVT_KEY_REPT(kpl) || (s_editMode>0 && (event==EVT_KEY_FIRST(KEY_UP) || event== EVT_KEY_REPT(KEY_UP))) ) {
|
||||
newval++;
|
||||
AUDIO_KEYPAD_UP();
|
||||
kother=kmi;
|
||||
}
|
||||
else if(event==EVT_KEY_FIRST(kmi) || event== EVT_KEY_REPT(kmi) || (s_editMode>0 && (event==EVT_KEY_FIRST(KEY_DOWN) || event== EVT_KEY_REPT(KEY_DOWN))) ) {
|
||||
else if (event==EVT_KEY_FIRST(kmi) || event== EVT_KEY_REPT(kmi) || (s_editMode>0 && (event==EVT_KEY_FIRST(KEY_DOWN) || event== EVT_KEY_REPT(KEY_DOWN))) ) {
|
||||
newval--;
|
||||
AUDIO_KEYPAD_DOWN();
|
||||
kother=kpl;
|
||||
}
|
||||
if((kother != (uint8_t)-1) && keyState((EnumKeys)kother)){
|
||||
if ((kother != (uint8_t)-1) && keyState((EnumKeys)kother)) {
|
||||
newval=-val;
|
||||
killEvents(kmi);
|
||||
killEvents(kpl);
|
||||
}
|
||||
if(i_min==0 && i_max==1 && event==EVT_KEY_FIRST(KEY_MENU)) {
|
||||
if (i_min==0 && i_max==1 && event==EVT_KEY_FIRST(KEY_MENU)) {
|
||||
s_editMode = 0;
|
||||
newval=!val;
|
||||
killEvents(event);
|
||||
@@ -98,14 +98,21 @@ int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, ui
|
||||
newval -= p1valdiff;
|
||||
#endif
|
||||
|
||||
if(newval > i_max)
|
||||
{
|
||||
#if defined(AUTOSWITCH)
|
||||
if (i_flags & INCDEC_SWITCH) {
|
||||
uint8_t swtch = getMovedSwitch();
|
||||
if (swtch) {
|
||||
newval = (val == swtch ? -swtch : swtch);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
if (newval > i_max) {
|
||||
newval = i_max;
|
||||
killEvents(event);
|
||||
AUDIO_WARNING2();
|
||||
}
|
||||
if(newval < i_min)
|
||||
{
|
||||
if (newval < i_min) {
|
||||
newval = i_min;
|
||||
killEvents(event);
|
||||
AUDIO_WARNING2();
|
||||
|
||||
+10
-2
@@ -101,14 +101,22 @@ extern int8_t s_editMode; // global editmode
|
||||
#define EE_GENERAL 0x01
|
||||
#define EE_MODEL 0x02
|
||||
#define NO_INCDEC_MARKS 0x04
|
||||
#define INCDEC_SWITCH 0x08
|
||||
int16_t checkIncDec(uint8_t event, int16_t i_pval, int16_t i_min, int16_t i_max, uint8_t i_flags);
|
||||
int8_t checkIncDecModel(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
|
||||
int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
|
||||
|
||||
#define CHECK_INCDEC_MODELVAR( event, var, min, max) \
|
||||
#define CHECK_INCDEC_MODELVAR(event, var, min, max) \
|
||||
var = checkIncDecModel(event,var,min,max)
|
||||
|
||||
#define CHECK_INCDEC_GENVAR( event, var, min, max) \
|
||||
#if defined(AUTOSWITCH)
|
||||
#define CHECK_INCDEC_MODELSWITCH(event, var, min, max) \
|
||||
var = checkIncDec(event,var,min,max,EE_MODEL|INCDEC_SWITCH)
|
||||
#else
|
||||
#define CHECK_INCDEC_MODELSWITCH CHECK_INCDEC_MODELVAR
|
||||
#endif
|
||||
|
||||
#define CHECK_INCDEC_GENVAR(event, var, min, max) \
|
||||
var = checkIncDecGen(event,var,min,max)
|
||||
|
||||
#if defined(ROTARY_ENCODERS)
|
||||
|
||||
+1
-1
@@ -780,7 +780,7 @@ void menuProcPhaseOne(uint8_t event)
|
||||
case 1:
|
||||
lcd_putsLeft( y, STR_SWITCH);
|
||||
putsSwitches(10*FW, y, phase->swtch, attr);
|
||||
if(attr) CHECK_INCDEC_MODELVAR(event, phase->swtch, -MAX_DRSWITCH, MAX_DRSWITCH);
|
||||
if (attr) CHECK_INCDEC_MODELSWITCH(event, phase->swtch, -MAX_DRSWITCH, MAX_DRSWITCH);
|
||||
break;
|
||||
case 2:
|
||||
lcd_putsLeft( y, STR_TRIMS);
|
||||
|
||||
@@ -594,9 +594,12 @@ bool getSwitch(int8_t swtch, bool nc)
|
||||
return __getSwitch(swtch);
|
||||
}
|
||||
|
||||
#if defined(AUTOSWITCH)
|
||||
int8_t getMovedSwitch()
|
||||
{
|
||||
static uint8_t switches_states = 0;
|
||||
static uint16_t s_last_time = 0;
|
||||
|
||||
int8_t result = 0;
|
||||
|
||||
for (uint8_t i=MAX_PSWITCH; i>0; i--) {
|
||||
@@ -623,8 +626,14 @@ int8_t getMovedSwitch()
|
||||
}
|
||||
}
|
||||
|
||||
if (get_tmr10ms() - s_last_time > 10)
|
||||
result = 0;
|
||||
|
||||
s_last_time = get_tmr10ms();
|
||||
|
||||
return result;
|
||||
}
|
||||
#endif
|
||||
|
||||
#ifdef FLIGHT_PHASES
|
||||
uint8_t getFlightPhase()
|
||||
|
||||
Reference in New Issue
Block a user