feat(radio): add trims to autosource and autoswitch if configured as 3P switch (#7024)
This commit is contained in:
@@ -482,6 +482,16 @@ int8_t getMovedSource(uint8_t min)
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static int16_t trimStates[MAX_TRIMS];
|
||||||
|
if (result == 0) {
|
||||||
|
for (uint8_t i = 0; i < MAX_TRIMS; i++) {
|
||||||
|
if (abs(getTrimValue(mixerCurrentFlightMode, i) - trimStates[i]) > 0) {
|
||||||
|
result = MIXSRC_FIRST_TRIM + i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static int16_t sourcesStates[MAX_ANALOG_INPUTS];
|
static int16_t sourcesStates[MAX_ANALOG_INPUTS];
|
||||||
if (result == 0) {
|
if (result == 0) {
|
||||||
for (uint8_t i = 0; i < MAX_ANALOG_INPUTS; i++) {
|
for (uint8_t i = 0; i < MAX_ANALOG_INPUTS; i++) {
|
||||||
@@ -505,9 +515,11 @@ int8_t getMovedSource(uint8_t min)
|
|||||||
if (result || recent) {
|
if (result || recent) {
|
||||||
memcpy(inputsStates, anas, sizeof(inputsStates));
|
memcpy(inputsStates, anas, sizeof(inputsStates));
|
||||||
memcpy(sourcesStates, calibratedAnalogs, sizeof(sourcesStates));
|
memcpy(sourcesStates, calibratedAnalogs, sizeof(sourcesStates));
|
||||||
|
for (uint8_t i = 0; i < MAX_TRIMS; i++) trimStates[i] = getTrimValue(mixerCurrentFlightMode, i);
|
||||||
}
|
}
|
||||||
|
|
||||||
s_move_last_time = get_tmr10ms();
|
s_move_last_time = get_tmr10ms();
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|||||||
+14
-5
@@ -88,7 +88,7 @@ uint8_t potsPos[MAX_POTS];
|
|||||||
|
|
||||||
#if defined(FUNCTION_SWITCHES)
|
#if defined(FUNCTION_SWITCHES)
|
||||||
// Customizable switches
|
// Customizable switches
|
||||||
//
|
//
|
||||||
// Non pushed : SWSRC_Sx0 = -1024 = Sx(up) = state 0
|
// Non pushed : SWSRC_Sx0 = -1024 = Sx(up) = state 0
|
||||||
// Pushed : SWSRC_Sx2 = +1024 = Sx(down) = state 1
|
// Pushed : SWSRC_Sx2 = +1024 = Sx(down) = state 1
|
||||||
|
|
||||||
@@ -311,17 +311,17 @@ int switchLookupIdx(const char* name, size_t len)
|
|||||||
if (strncmp(sw_name, name, len) == 0) return i;
|
if (strncmp(sw_name, name, len) == 0) return i;
|
||||||
}
|
}
|
||||||
|
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
|
||||||
char switchGetLetter(uint8_t idx)
|
char switchGetLetter(uint8_t idx)
|
||||||
{
|
{
|
||||||
if (idx >= switchGetMaxAllSwitches() + MAX_FLEX_SWITCHES)
|
if (idx >= switchGetMaxAllSwitches() + MAX_FLEX_SWITCHES)
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
const char* name = switchGetDefaultName(idx);
|
const char* name = switchGetDefaultName(idx);
|
||||||
if (!name) return -1;
|
if (!name) return -1;
|
||||||
|
|
||||||
return name[strlen(name) - 1];
|
return name[strlen(name) - 1];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -393,7 +393,7 @@ void getSwitchesPosition(bool startup)
|
|||||||
if (!SWITCH_EXISTS(i)) continue;
|
if (!SWITCH_EXISTS(i)) continue;
|
||||||
newPos |= checkSwitchPosition(i, startup);
|
newPos |= checkSwitchPosition(i, startup);
|
||||||
}
|
}
|
||||||
|
|
||||||
switchesPos = newPos;
|
switchesPos = newPos;
|
||||||
|
|
||||||
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
|
auto max_pots = adcGetMaxInputs(ADC_INPUT_FLEX);
|
||||||
@@ -861,6 +861,15 @@ swsrc_t getMovedSwitch()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Trims: only detect trims configured as 3P
|
||||||
|
for (int i = 0; i < keysGetMaxTrims(); i++) {
|
||||||
|
if (getRawTrimValue(mixerCurrentFlightMode, i).mode == TRIM_MODE_3POS) {
|
||||||
|
uint8_t tidx = inputMappingConvertMode(i) * 2;
|
||||||
|
if (trimDown(tidx)) result = SWSRC_FIRST_TRIM + i * 2;
|
||||||
|
else if (trimDown(tidx+1)) result = SWSRC_FIRST_TRIM + i * 2 + 1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if ((tmr10ms_t)(get_tmr10ms() - s_move_last_time) > 100)
|
if ((tmr10ms_t)(get_tmr10ms() - s_move_last_time) > 100)
|
||||||
result = 0;
|
result = 0;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user