1
0
Fork 0
mirror of https://github.com/opentx/opentx.git synced 2025-07-13 03:19:53 +03:00

Merge pull request #8232 from opentx/3djc/autoswitch-multipos

Support multipos in autosource/autoswitch
This commit is contained in:
Bertrand Songis 2021-01-19 15:28:38 +01:00 committed by GitHub
commit b01e948157
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
8 changed files with 35 additions and 13 deletions

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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);
}
}

View file

@ -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;
}

View file

@ -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

View file

@ -520,14 +520,28 @@ swsrc_t getMovedSwitch()
swsrc_t result = 0;
#if defined(PCBTARANIS) || defined(PCBHORUS)
for (int i=0; i<NUM_SWITCHES; i++) {
// Switches
for (int i = 0; i < NUM_SWITCHES; i++) {
if (SWITCH_EXISTS(i)) {
swarnstate_t mask = ((swarnstate_t)0x03 << (i*2));
uint8_t prev = (switches_states & mask) >> (i*2);
uint8_t next = (1024+getValue(MIXSRC_SA+i)) / 1024;
swarnstate_t mask = ((swarnstate_t) 0x03 << (i * 2));
uint8_t prev = (switches_states & mask) >> (i * 2);
uint8_t next = (1024 + getValue(MIXSRC_SA + i)) / 1024;
if (prev != next) {
switches_states = (switches_states & (~mask)) | ((swarnstate_t)next << (i*2));
result = 1+(3*i)+next;
switches_states = (switches_states & (~mask)) | ((swarnstate_t) next << (i * 2));
result = 1 + (3 * i) + next;
}
}
}
// 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;
}
}
}
}