mirror of
https://github.com/opentx/opentx.git
synced 2025-07-13 11:29:51 +03:00
Merge pull request #8232 from opentx/3djc/autoswitch-multipos
Support multipos in autosource/autoswitch
This commit is contained in:
commit
b01e948157
8 changed files with 35 additions and 13 deletions
|
@ -136,7 +136,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla
|
|||
#if defined(AUTOSWITCH)
|
||||
else {
|
||||
uint8_t swtch = abs(getMovedSwitch());
|
||||
if (swtch) {
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -137,7 +137,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla
|
|||
#if defined(AUTOSWITCH)
|
||||
else {
|
||||
unsigned int swtch = abs(getMovedSwitch());
|
||||
if (swtch) {
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla
|
|||
#if defined(AUTOSWITCH)
|
||||
else {
|
||||
unsigned int swtch = abs(getMovedSwitch());
|
||||
if (swtch) {
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -173,7 +173,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla
|
|||
#if defined(AUTOSWITCH)
|
||||
else {
|
||||
unsigned int swtch = abs(getMovedSwitch());
|
||||
if (swtch) {
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,7 +166,7 @@ int checkIncDec(event_t event, int val, int i_min, int i_max, unsigned int i_fla
|
|||
#if defined(AUTOSWITCH)
|
||||
else {
|
||||
uint8_t swtch = abs(getMovedSwitch());
|
||||
if (swtch) {
|
||||
if (swtch && !IS_SWITCH_MULTIPOS(swtch)) {
|
||||
newval = switchToMix(swtch);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -557,6 +557,8 @@ bool isInputRecursive(int index)
|
|||
}
|
||||
|
||||
#if defined(AUTOSOURCE)
|
||||
constexpr int MULTIPOS_STEP_SIZE = (2 * RESX) / XPOTS_MULTIPOS_COUNT;
|
||||
|
||||
int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS)
|
||||
{
|
||||
int8_t result = 0;
|
||||
|
@ -565,7 +567,7 @@ int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS)
|
|||
static int16_t inputsStates[MAX_INPUTS];
|
||||
if (min <= MIXSRC_FIRST_INPUT) {
|
||||
for (uint8_t i=0; i<MAX_INPUTS; i++) {
|
||||
if (abs(anas[i] - inputsStates[i]) > 512) {
|
||||
if (abs(anas[i] - inputsStates[i]) > MULTIPOS_STEP_SIZE) {
|
||||
if (!isInputRecursive(i)) {
|
||||
result = MIXSRC_FIRST_INPUT+i;
|
||||
break;
|
||||
|
@ -577,7 +579,7 @@ int8_t getMovedSource(GET_MOVED_SOURCE_PARAMS)
|
|||
static int16_t sourcesStates[NUM_STICKS+NUM_POTS+NUM_SLIDERS+NUM_MOUSE_ANALOGS];
|
||||
if (result == 0) {
|
||||
for (uint8_t i=0; i<NUM_STICKS+NUM_POTS+NUM_SLIDERS; i++) {
|
||||
if (abs(calibratedAnalogs[i] - sourcesStates[i]) > 512) {
|
||||
if (abs(calibratedAnalogs[i] - sourcesStates[i]) > MULTIPOS_STEP_SIZE) {
|
||||
result = MIXSRC_Rud+i;
|
||||
break;
|
||||
}
|
||||
|
|
|
@ -282,6 +282,12 @@ void memswap(void * a, void * b, uint8_t size);
|
|||
#define IS_MULTIPOS_CALIBRATED(cal) (false)
|
||||
#endif
|
||||
|
||||
#if NUM_XPOTS > 0
|
||||
#define IS_SWITCH_MULTIPOS(x) (SWSRC_FIRST_MULTIPOS_SWITCH <= (x) && (x) <= SWSRC_LAST_MULTIPOS_SWITCH)
|
||||
#else
|
||||
#define IS_SWITCH_MULTIPOS(x) (false)
|
||||
#endif
|
||||
|
||||
#if defined(PWR_BUTTON_PRESS)
|
||||
#define pwrOffPressed() pwrPressed()
|
||||
#else
|
||||
|
|
|
@ -520,6 +520,7 @@ swsrc_t getMovedSwitch()
|
|||
swsrc_t result = 0;
|
||||
|
||||
#if defined(PCBTARANIS) || defined(PCBHORUS)
|
||||
// Switches
|
||||
for (int i = 0; i < NUM_SWITCHES; i++) {
|
||||
if (SWITCH_EXISTS(i)) {
|
||||
swarnstate_t mask = ((swarnstate_t) 0x03 << (i * 2));
|
||||
|
@ -531,6 +532,19 @@ swsrc_t getMovedSwitch()
|
|||
}
|
||||
}
|
||||
}
|
||||
// Multipos
|
||||
for (int i = 0; i < NUM_XPOTS; i++) {
|
||||
if (IS_POT_MULTIPOS(POT1 + i)) {
|
||||
StepsCalibData * calib = (StepsCalibData *) &g_eeGeneral.calib[POT1 + i];
|
||||
if (IS_MULTIPOS_CALIBRATED(calib)) {
|
||||
uint8_t prev = potsPos[i] & 0x0F;
|
||||
uint8_t next = anaIn(POT1 + i) / (2 * RESX / calib->count);
|
||||
if (prev != next) {
|
||||
result = SWSRC_LAST_SWITCH + i * XPOTS_MULTIPOS_COUNT + next + 1;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
#else
|
||||
// return delivers 1 to 3 for ID1 to ID3
|
||||
// 4..8 for all other switches if changed to true
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue