Auto Switch function (only in Flight Phases now)

This commit is contained in:
bsongis
2012-05-06 21:41:41 +00:00
parent 809e45c1e2
commit 597d201b30
5 changed files with 44 additions and 12 deletions
+8
View File
@@ -47,6 +47,10 @@ TEMPLATES = YES
# POTS (POT1, POT2, POT3), # POTS (POT1, POT2, POT3),
NAVIGATION = NO NAVIGATION = NO
# Switches autmatic selection
# Values = YES, NO
AUTOSWITCH = YES
# AUDIO Mods # AUDIO Mods
# Values = YES, NO # Values = YES, NO
AUDIO = NO AUDIO = NO
@@ -226,6 +230,10 @@ ifeq ($(NAVIGATION), POTS)
CPPDEFS += -DNAVIGATION_POT1 -DNAVIGATION_POT2 -DNAVIGATION_POT3 CPPDEFS += -DNAVIGATION_POT1 -DNAVIGATION_POT2 -DNAVIGATION_POT3
endif endif
ifeq ($(AUTOSWITCH), YES)
CPPDEFS += -DAUTOSWITCH
endif
ifeq ($(SPLASH), YES) ifeq ($(SPLASH), YES)
CPPDEFS += -DSPLASH CPPDEFS += -DSPLASH
endif endif
+11 -4
View File
@@ -98,14 +98,21 @@ int16_t checkIncDec(uint8_t event, int16_t val, int16_t i_min, int16_t i_max, ui
newval -= p1valdiff; newval -= p1valdiff;
#endif #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; newval = i_max;
killEvents(event); killEvents(event);
AUDIO_WARNING2(); AUDIO_WARNING2();
} }
if(newval < i_min) if (newval < i_min) {
{
newval = i_min; newval = i_min;
killEvents(event); killEvents(event);
AUDIO_WARNING2(); AUDIO_WARNING2();
+8
View File
@@ -101,6 +101,7 @@ extern int8_t s_editMode; // global editmode
#define EE_GENERAL 0x01 #define EE_GENERAL 0x01
#define EE_MODEL 0x02 #define EE_MODEL 0x02
#define NO_INCDEC_MARKS 0x04 #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); 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 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); int8_t checkIncDecGen(uint8_t event, int8_t i_val, int8_t i_min, int8_t i_max);
@@ -108,6 +109,13 @@ 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) var = checkIncDecModel(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) \ #define CHECK_INCDEC_GENVAR(event, var, min, max) \
var = checkIncDecGen(event,var,min,max) var = checkIncDecGen(event,var,min,max)
+1 -1
View File
@@ -780,7 +780,7 @@ void menuProcPhaseOne(uint8_t event)
case 1: case 1:
lcd_putsLeft( y, STR_SWITCH); lcd_putsLeft( y, STR_SWITCH);
putsSwitches(10*FW, y, phase->swtch, attr); 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; break;
case 2: case 2:
lcd_putsLeft( y, STR_TRIMS); lcd_putsLeft( y, STR_TRIMS);
+9
View File
@@ -594,9 +594,12 @@ bool getSwitch(int8_t swtch, bool nc)
return __getSwitch(swtch); return __getSwitch(swtch);
} }
#if defined(AUTOSWITCH)
int8_t getMovedSwitch() int8_t getMovedSwitch()
{ {
static uint8_t switches_states = 0; static uint8_t switches_states = 0;
static uint16_t s_last_time = 0;
int8_t result = 0; int8_t result = 0;
for (uint8_t i=MAX_PSWITCH; i>0; i--) { 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; return result;
} }
#endif
#ifdef FLIGHT_PHASES #ifdef FLIGHT_PHASES
uint8_t getFlightPhase() uint8_t getFlightPhase()