Unify throttle source check/conversion code

This commit is contained in:
Raphael Coeffic
2021-07-14 13:54:12 +02:00
committed by Raphael Coeffic
parent 2cbc7a6209
commit 90bd1b6329
7 changed files with 51 additions and 62 deletions
+19
View File
@@ -174,3 +174,22 @@ void evalTimers(int16_t throttle, uint8_t tick10ms)
}
}
}
int16_t throttleSource2Source(int16_t thrSrc)
{
if (thrSrc == 0) return (int16_t)MIXSRC_Thr;
if (--thrSrc < NUM_POTS + NUM_SLIDERS)
return (int16_t)(thrSrc + MIXSRC_FIRST_POT);
return (int16_t)(thrSrc - (NUM_POTS + NUM_SLIDERS) + MIXSRC_FIRST_CH);
}
int16_t source2ThrottleSource(int16_t src)
{
if (src == MIXSRC_Thr)
return 0;
else if (src <= MIXSRC_LAST_POT)
return src - MIXSRC_FIRST_POT + 1;
else if (src <= MIXSRC_LAST_CH)
return src - MIXSRC_FIRST_CH + NUM_POTS + NUM_SLIDERS + 1;
return -1;
}