1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-24 00:35:18 +03:00

merged changes from Issue020_ThrottleWarning

based on current next branch, includes all changes from old
ThrottleWarning branch.

Solves issue 020: Throttle warning if P1-P3 is selected as Thr source.
Adds Turnigy TransmitterFix option
code savings:
120 bytes without Transmitter fix
4 bytes but 1 more data if Transmitter Fix is activated.

Added make option TURNIGY_TRANSMITTER_FIX for this purpose
TURNIGY_TRANSMITTER_FIX = NO   is default
set to YES for new Turnigy9x transmitter which transmits even no pulses
are generated.
This commit is contained in:
openfsguruh 2014-02-10 20:51:25 +01:00
parent 1a6832c83a
commit da23a624dc
3 changed files with 188 additions and 39 deletions

View file

@ -67,6 +67,14 @@ EXT = STD
# Values = YES, NO, CHOICE # Values = YES, NO, CHOICE
FAI = NO FAI = NO
# the latests deliveries for Turnigy 9x transmitters (since 2 years now, 2014) do not stop sending if no pulses are generated.
# This fact totally breaks the nice throttle and switch warning concept, because even we prevent sending pulses the
# transmitter modul ignores this, and continous to send the last value or 0 at beginning. And 0 means in the middle of throttle -> 50%.
# To cope with this situation, we need a new concept how to handle throttle and switch warnings.
# if you have a 0 value (50% ) for throttle, while throttle warning is active, you should activate this switch
# Values = YES, NO
TURNIGY_TRANSMITTER_FIX = NO
# Enable heli menu # Enable heli menu
# Values = YES, NO # Values = YES, NO
HELI = NO HELI = NO
@ -671,6 +679,10 @@ ifeq ($(PCB), TARANIS)
CPPSRC += protocols/hubsan.cpp CPPSRC += protocols/hubsan.cpp
CPPSRC += targets/taranis/a7105_driver.cpp CPPSRC += targets/taranis/a7105_driver.cpp
endif endif
ifeq ($(TURNIGY_TRANSMITTER_FIX), YES)
$(error TURNIGY_TRANSMITTER_FIX is not yet implemented for Taranis. If this is actually needed, getSwitch() needs to be modified)
endif
endif endif
CC = $(TRGT)gcc CC = $(TRGT)gcc
@ -743,6 +755,10 @@ ifeq ($(NAVIGATION), ROTENC)
CPPDEFS += -DROTARY_ENCODER_NAVIGATION CPPDEFS += -DROTARY_ENCODER_NAVIGATION
endif endif
ifeq ($(TURNIGY_TRANSMITTER_FIX), YES)
CPPDEFS += -DINPUT_WARNINGS_GENERATE_SIM_DATA
endif
ifeq ($(AUTOSWITCH), YES) ifeq ($(AUTOSWITCH), YES)
CPPDEFS += -DAUTOSWITCH CPPDEFS += -DAUTOSWITCH
endif endif

View file

@ -51,6 +51,9 @@ int24_t act [MAX_MIXERS] = {0};
SwOn swOn [MAX_MIXERS]; // TODO better name later... SwOn swOn [MAX_MIXERS]; // TODO better name later...
uint8_t mixWarning; uint8_t mixWarning;
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
uint8_t checkWarningState;
#endif
#if defined(CPUARM) #if defined(CPUARM)
#define MENUS_STACK_SIZE 2000 #define MENUS_STACK_SIZE 2000
@ -1246,9 +1249,11 @@ getvalue_t getValue(uint8_t i)
else if (i==MIXSRC_SG) return (switchState(SW_SG0) ? -1024 : (switchState(SW_SG1) ? 0 : 1024)); else if (i==MIXSRC_SG) return (switchState(SW_SG0) ? -1024 : (switchState(SW_SG1) ? 0 : 1024));
else if (i==MIXSRC_SH) return (switchState(SW_SH0) ? -1024 : 1024); else if (i==MIXSRC_SH) return (switchState(SW_SH0) ? -1024 : 1024);
#else #else
else if (i==MIXSRC_3POS) return (switchState(SW_ID0) ? -1024 : (switchState(SW_ID1) ? 0 : 1024)); else if (i==MIXSRC_3POS) return (getSwitch(SW_ID0-SW_BASE+1) ? -1024 : (getSwitch(SW_ID1-SW_BASE+1) ? 0 : 1024));
// don't use switchState directly to give getSwitch possibility to hack values if needed for switch warning
#if defined(EXTRA_3POS) #if defined(EXTRA_3POS)
else if (i==MIXSRC_3POS2) return (switchState(SW_ID3) ? -1024 : (switchState(SW_ID4) ? 0 : 1024)); else if (i==MIXSRC_3POS2) return (getSwitch(SW_ID3-SW_BASE+1) ? -1024 : (getSwitch(SW_ID4-SW_BASE+1) ? 0 : 1024));
// don't use switchState directly to give getSwitch possibility to hack values if needed for switch warning
#endif #endif
#endif #endif
@ -1380,6 +1385,10 @@ void getSwitchesPosition()
int16_t csLastValue[NUM_CSW]; int16_t csLastValue[NUM_CSW];
#define CS_LAST_VALUE_INIT -32768 #define CS_LAST_VALUE_INIT -32768
// param swtch may be (negativ sign ignored)
// 0 --> no source
// 1 .. 9 (or max switches) --> returns switch value including 3pos
// others internal switches etc.
bool getSwitch(int8_t swtch) bool getSwitch(int8_t swtch)
{ {
bool result; bool result;
@ -1394,6 +1403,19 @@ bool getSwitch(int8_t swtch)
} }
else if (cs_idx <= SWSRC_LAST_SWITCH) { else if (cs_idx <= SWSRC_LAST_SWITCH) {
result = SWITCH_POSITION(cs_idx-SWSRC_FIRST_SWITCH); result = SWITCH_POSITION(cs_idx-SWSRC_FIRST_SWITCH);
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
if (checkWarningState<e_InWarnFinished) {
// if throttle or switch warning is currently active, ignore actual stick position and use wanted values
if (cs_idx<=3) {
if (!(g_model.nSwToWarn&1)) { // ID1 to ID3 is just one bit in nSwToWarn
result=(cs_idx)==((g_model.switchWarningStates&3)+1); // overwrite result with desired value
}
} else if (!(g_model.nSwToWarn&(1<<(cs_idx-3)) )) {
// current switch should not be ignored for warning
result=g_model.switchWarningStates&(1<<(cs_idx-2)); // overwrite result with desired value
}
}
#endif
} }
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
else if (cs_idx <= SWSRC_P26) { else if (cs_idx <= SWSRC_P26) {
@ -1618,6 +1640,30 @@ int8_t getMovedSwitch()
} }
} }
#else #else
// saves about 50 bytes flash
// return delivers 1 to 3 for ID1 to ID3
// 4..8 for all other switches if changed to true
// -4..-8 for all other switches if changed to false
// 9 for Trainer switch if changed to true; Change to false is ignored
swstate_t mask=0x80;
for (uint8_t i=NUM_PSWITCH; i>1; i--) {
bool prev;
// mask= (1<<(i-2));
prev=(switches_states & mask);
// don't use getSwitch here to always get the proper value, even getSwitch manipulates
// bool next = getSwitch(i);
bool next = switchState((EnumKeys)(SW_BASE+i-1));
if (prev!=next) {
if (((i<NUM_PSWITCH) && (i>3)) || next==true)
result = next ? i : -i;
if ((i<=3) && (result==0)) result=1;
switches_states ^= mask;
}
mask>>=1;
} //endfor
/*
for (uint8_t i=NUM_PSWITCH; i>0; i--) { for (uint8_t i=NUM_PSWITCH; i>0; i--) {
bool prev; bool prev;
swstate_t mask = 0; swstate_t mask = 0;
@ -1628,7 +1674,9 @@ int8_t getMovedSwitch()
mask = (1<<(i-2)); mask = (1<<(i-2));
prev = (switches_states & mask); prev = (switches_states & mask);
} }
bool next = getSwitch(i); // don't use getSwitch here to always get the proper value, because getSwitch manipulates
// bool next = getSwitch(i);
bool next = switchState((EnumKeys)(SW_BASE+i-1));
if (prev != next) { if (prev != next) {
if (i!=NUM_PSWITCH || next==true) if (i!=NUM_PSWITCH || next==true)
result = next ? i : -i; result = next ? i : -i;
@ -1638,7 +1686,7 @@ int8_t getMovedSwitch()
switches_states = (switches_states & 0xFC) | (i-1); switches_states = (switches_states & 0xFC) | (i-1);
} }
} }
} } //endfor */
#endif #endif
if ((tmr10ms_t)(get_tmr10ms() - s_move_last_time) > 10) if ((tmr10ms_t)(get_tmr10ms() - s_move_last_time) > 10)
@ -2228,14 +2276,35 @@ void doSplash()
#define doSplash() #define doSplash()
#endif #endif
// #define INPUT_WARNINGS_GENERATE_SIM_DATA
// the latests deliveries from 9x transmitters (since 2 years now, 2014) do not stop sending if no pulses are generated.
// This fact totally breaks the nice throttle and switch warning concept, because even we prevent sending pulses the
// transmitter modul ignores this, and continous to send the last value or 0 at beginning. And 0 means in the middle of throttle -> 50%.
// To cope with this situation, we need a new concept how to handle throttle and switch warnings.
// My solution is, not to stop pulses at all. In warning situation the input of the appropriate channels are ignored and
// replaced with a value which wouldn't generate the warning, e.g. for throttle -100%
// Because this new concept is also compatible with the better (older) transmitter we can enable it by default and let the user choose if
// he want's the old handling or new one.
#if defined(PCBTARANIS) && defined(INPUT_WARNINGS_GENERATE_SIM_DATA)
// #error "INPUT_WARNINGS_GENERATE_SIM_DATA is not yet implemented for Taranis build."
// according current transmitters, this shouldn't be necessary as well
// but if wanted the switch simulation part needs to be simulated the same way as for stock
#endif
void checkAll() void checkAll()
{ {
#if !defined(PCBSKY9X) #if !defined(PCBSKY9X)
checkLowEEPROM(); checkLowEEPROM();
#endif #endif
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
checkWarningState=e_InWarnBegin;
#else
checkTHR(); checkTHR();
checkSwitches(); checkSwitches();
#endif
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
if (modelHasNotes() && g_model.displayText) { if (modelHasNotes() && g_model.displayText) {
@ -2249,6 +2318,16 @@ void checkAll()
clearKeyEvents(); clearKeyEvents();
} }
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
void checkInMix()
{
if (checkWarningState>=e_InWarnFinished) return; // no more checks
if (checkWarningState<e_InWarnStartSwitchWarn) checkTHR();
else checkSwitches();
}
#endif
#if !defined(PCBSKY9X) #if !defined(PCBSKY9X)
void checkLowEEPROM() void checkLowEEPROM()
{ {
@ -2261,41 +2340,55 @@ void checkLowEEPROM()
void checkTHR() void checkTHR()
{ {
if (g_model.disableThrottleWarning) return; uint8_t thrchn = ((g_model.thrTraceSrc==0)||(g_model.thrTraceSrc>NUM_POTS)) ?
THR_STICK : g_model.thrTraceSrc+NUM_STICKS-1;
// throttle channel is either the stick according stick mode (already handled in evalInputs)
// or P1 to P3;
// in case an output channel is choosen as throttle source (thrTraceSrc>NUM_POTS) we assume the throttle stick is the input
// no other information avaialbe at the moment, and good enough to my option (otherwise too much exceptions...)
uint8_t thrchn = (2-(stickMode&1)); //stickMode=0123 -> thr=2121 #ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
int16_t v = calibratedStick[thrchn];
#ifdef SIMU if ((v<=(THRCHK_DEADBAND-1024)) || g_model.disableThrottleWarning) {
int16_t lowLim = THRCHK_DEADBAND - 1024 ; checkWarningState=e_InWarnStartSwitchWarn;
// checkWarningState=e_InWarnFinished;
} else {
calibratedStick[thrchn]=-1024;
#if !defined(PCBTARANIS)
rawAnas[thrchn]=anas[thrchn]=calibratedStick[thrchn];
#endif
if (checkWarningState<e_InWarnThrottleWarnActive) {
// warning message is not yet visible
MESSAGE(STR_THROTTLEWARN, STR_THROTTLENOTIDLE, STR_PRESSANYKEYTOSKIP, AU_THROTTLE_ALERT);
checkWarningState=e_InWarnThrottleWarnActive;
} else if (pwrCheck()==e_power_off || keyDown()) {
// key pressed -> disable warning
checkWarningState=e_InWarnStartSwitchWarn;
// checkWarningState=e_InWarnFinished;
}
}
#else #else
getADC(); // if thr is down - do not display warning at all if (g_model.disableThrottleWarning) return;
CalibData * calib = &g_eeGeneral.calib[thrchn]; evalInputs(e_perout_mode_notrainer); // let do evalInputs do the job
int16_t lowLim = calib->mid; int16_t v = calibratedStick[thrchn];
lowLim = (g_model.throttleReversed ? - lowLim - calib->spanPos : lowLim - calib->spanNeg); if (v<=(THRCHK_DEADBAND-1024)) return; // prevent warning if throttle input OK
lowLim += THRCHK_DEADBAND; // first - display warning; also deletes inputs if any have been before
#endif MESSAGE(STR_THROTTLEWARN, STR_THROTTLENOTIDLE, STR_PRESSANYKEYTOSKIP, AU_THROTTLE_ALERT);
int16_t v = thrAnaIn(thrchn);
while (1) {
if (v<=lowLim) return;
// first - display warning
MESSAGE(STR_THROTTLEWARN, STR_THROTTLENOTIDLE, STR_PRESSANYKEYTOSKIP, AU_THROTTLE_ALERT);
while (1)
{
SIMU_SLEEP(1); SIMU_SLEEP(1);
getADC(); getADC();
int16_t v = thrAnaIn(thrchn); evalInputs(e_perout_mode_notrainer); // let do evalInputs do the job
v = calibratedStick[thrchn];
if (pwrCheck()==e_power_off || keyDown() || v<=lowLim) if (pwrCheck()==e_power_off || keyDown() || v<=(THRCHK_DEADBAND-1024))
break; break;
checkBacklight(); checkBacklight();
wdt_reset(); wdt_reset();
} }//endwhile
#endif
} }
void checkAlarm() // added by Gohst void checkAlarm() // added by Gohst
@ -2306,21 +2399,28 @@ void checkAlarm() // added by Gohst
void checkSwitches() void checkSwitches()
{ {
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
static swstate_t last_bad_switches = 0xff;
#else
swstate_t last_bad_switches = 0xff; swstate_t last_bad_switches = 0xff;
#endif
swstate_t states = g_model.switchWarningStates; swstate_t states = g_model.switchWarningStates;
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
uint8_t bad_pots = 0, last_bad_pots = 0xff; uint8_t bad_pots = 0, last_bad_pots = 0xff;
#endif #endif
#ifndef INPUT_WARNINGS_GENERATE_SIM_DATA
while (1) { while (1) {
#if defined(TELEMETRY_MOD_14051) || defined(PCBTARANIS) #if defined(TELEMETRY_MOD_14051) || defined(PCBTARANIS)
getADC(); getADC();
#endif #endif
#endif //INPUT_WARNINGS_GENERATE_SIM_DATA
getMovedSwitch(); getMovedSwitch();
uint8_t warn = false; bool warn = false;
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
for (uint8_t i=0; i<NUM_SWITCHES-1; i++) { for (uint8_t i=0; i<NUM_SWITCHES-1; i++) {
if (!(g_model.nSwToWarn & (1<<i))) { if (!(g_model.nSwToWarn & (1<<i))) {
@ -2352,7 +2452,15 @@ void checkSwitches()
} }
#endif #endif
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
if (!warn) {
checkWarningState=e_InWarnFinished;
last_bad_switches = 0xff;
return;
}
#else
if(!warn) return; if(!warn) return;
#endif
// first - display warning // first - display warning
#if defined(PCBTARANIS) #if defined(PCBTARANIS)
@ -2408,6 +2516,14 @@ void checkSwitches()
last_bad_switches = switches_states; last_bad_switches = switches_states;
} }
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
// checkWarningState=e_InWarnSwitchWarnActive; not needed, because redraw is prevented with last switch compare
if (pwrCheck()==e_power_off || keyDown()) {
checkWarningState=e_InWarnFinished;
last_bad_switches = 0xff;
// return; // Usb on or power off
}
#else
if (pwrCheck()==e_power_off || keyDown()) return; // Usb on or power off if (pwrCheck()==e_power_off || keyDown()) return; // Usb on or power off
checkBacklight(); checkBacklight();
@ -2416,6 +2532,7 @@ void checkSwitches()
SIMU_SLEEP(1); SIMU_SLEEP(1);
} }
#endif
} }
void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG) void alert(const pm_char * t, const pm_char *s MESSAGE_SOUND_ARG)
@ -2637,12 +2754,6 @@ uint16_t BandGap = 2040 ;
uint16_t BandGap ; uint16_t BandGap ;
#endif #endif
int16_t thrAnaIn(uint8_t chan)
{
int16_t v = anaIn(chan);
return (g_model.throttleReversed) ? -v : v;
}
#if !defined(SIMU) #if !defined(SIMU)
uint16_t anaIn(uint8_t chan) uint16_t anaIn(uint8_t chan)
{ {
@ -3502,6 +3613,10 @@ void perOut(uint8_t mode, uint8_t tick10ms)
{ {
evalInputs(mode); evalInputs(mode);
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
checkInMix();
#endif
#if defined(HELI) #if defined(HELI)
if (g_model.swashR.value) { if (g_model.swashR.value) {
uint32_t v = ((int32_t)anas[ELE_STICK]*anas[ELE_STICK] + (int32_t)anas[AIL_STICK]*anas[AIL_STICK]); uint32_t v = ((int32_t)anas[ELE_STICK]*anas[ELE_STICK] + (int32_t)anas[AIL_STICK]*anas[AIL_STICK]);
@ -4482,6 +4597,10 @@ void perMain()
} }
#endif #endif
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
if (checkWarningState<e_InWarnFinished) return; // don't do menu's until throttle and switch warnings are handled
#endif
if (!usbPlugged()) { if (!usbPlugged()) {
// TODO merge these 2 branches // TODO merge these 2 branches
#if defined(PCBSKY9X) #if defined(PCBSKY9X)

View file

@ -803,6 +803,20 @@ enum PerOutMode {
e_perout_mode_noinput = e_perout_mode_notrainer+e_perout_mode_notrims+e_perout_mode_nosticks e_perout_mode_noinput = e_perout_mode_notrainer+e_perout_mode_notrims+e_perout_mode_nosticks
}; };
#ifdef INPUT_WARNINGS_GENERATE_SIM_DATA
extern uint8_t checkWarningState;
enum InputWarningStates {
e_InWarnBegin = 0,
e_InWarnThrottleWarnActive = 1,
e_InWarnStartSwitchWarn = 2,
// e_InWarnSwitchWarnActive = 3, currently not needed
e_InWarnFinished = 3,
};
#endif
// Fiddle to force compiler to use a pointer // Fiddle to force compiler to use a pointer
#if defined(CPUARM) || defined(SIMU) #if defined(CPUARM) || defined(SIMU)
#define FORCE_INDIRECT(ptr) #define FORCE_INDIRECT(ptr)
@ -1211,8 +1225,8 @@ int applyCurve(int x, int8_t idx);
void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS_INC); void applyExpos(int16_t *anas, uint8_t mode APPLY_EXPOS_EXTRA_PARAMS_INC);
int16_t applyLimits(uint8_t channel, int32_t value); int16_t applyLimits(uint8_t channel, int32_t value);
void evalInputs(uint8_t mode);
uint16_t anaIn(uint8_t chan); uint16_t anaIn(uint8_t chan);
int16_t thrAnaIn(uint8_t chan);
extern int16_t calibratedStick[NUM_STICKS+NUM_POTS]; extern int16_t calibratedStick[NUM_STICKS+NUM_POTS];
#define FLASH_DURATION 20 /*200ms*/ #define FLASH_DURATION 20 /*200ms*/