mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-15 20:35:33 +03:00
First cut of code that passed the unit tests for mod activations,
however it uses / operations and doesn't handle the case where the channel value is on the boundary between two ranges.
This commit is contained in:
parent
c0fd0c1f33
commit
2369a63df0
5 changed files with 117 additions and 52 deletions
|
@ -225,9 +225,39 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
|
|||
}
|
||||
}
|
||||
|
||||
#define MAX_AUX_STATE_CHANNELS 8
|
||||
#define MAX_AUX_CHANNEL_COUNT (MAX_SUPPORTED_RC_CHANNEL_COUNT - NON_AUX_CHANNEL_COUNT)
|
||||
|
||||
#include <stdio.h>
|
||||
void updateRcOptions(modeActivationCondition_t *modeActivationConditions)
|
||||
{
|
||||
rcModeActivationMask = 0; // FIXME implement, use rcData & modeActivationConditions
|
||||
|
||||
uint8_t index;
|
||||
uint8_t auxChannelSteps[MAX_AUX_CHANNEL_COUNT];
|
||||
for (index = 0; index < MAX_AUX_CHANNEL_COUNT; index++) {
|
||||
uint16_t channelValue = rcData[index + NON_AUX_CHANNEL_COUNT];
|
||||
uint16_t normalizedChannelValue = (constrain(channelValue, 900, 2100) - 900);
|
||||
|
||||
auxChannelSteps[index] = normalizedChannelValue / 25;
|
||||
|
||||
if (normalizedChannelValue > 0 && normalizedChannelValue % 25 == 0) {
|
||||
auxChannelSteps[index]--;
|
||||
}
|
||||
printf("%d\n", auxChannelSteps[index]);
|
||||
}
|
||||
|
||||
for (index = 0; index < MAX_MODE_ACTIVATION_CONDITION_COUNT; index++) {
|
||||
modeActivationCondition_t *modeActivationCondition = &modeActivationConditions[index];
|
||||
|
||||
if (modeActivationCondition->rangeStartStep == modeActivationCondition->rangeEndStep) {
|
||||
printf("skipping %d\n", index);
|
||||
continue;
|
||||
}
|
||||
|
||||
uint8_t auxChannelStep = auxChannelSteps[modeActivationCondition->auxChannelIndex];
|
||||
if (auxChannelStep >= modeActivationCondition->rangeStartStep &&
|
||||
auxChannelStep < modeActivationCondition->rangeEndStep) {
|
||||
ACTIVATE_RC_MODE(modeActivationCondition->modeId);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue