1
0
Fork 0
mirror of https://github.com/betaflight/betaflight.git synced 2025-07-16 12:55:19 +03:00

Replace profile.activate and rcOptions with

profile.modeActivationCondition and rcModeActivationMask.

Implementation of using and setting modeActivationConditions is missing.
This commit is contained in:
Dominic Clifton 2014-10-12 10:38:04 +01:00
parent 6f4ef82f7d
commit c0fd0c1f33
11 changed files with 119 additions and 108 deletions

View file

@ -43,14 +43,7 @@
int16_t rcCommand[4]; // interval [1000;2000] for THROTTLE and [-500;+500] for ROLL/PITCH/YAW
// each entry in the array is a bitmask, 3 bits per aux channel (only aux 1 to 4), aux1 is first, each bit corresponds to an rc channel reading
// bit 1 - stick LOW
// bit 2 - stick MIDDLE
// bit 3 - stick HIGH
// an option is enabled when ANY channel has an appropriate reading corresponding to the bit.
// an option is disabled when NO channel has an appropriate reading corresponding to the bit.
// example: 110000000001 - option is only enabled when AUX1 is LOW or AUX4 is MEDIUM or HIGH.
uint8_t rcOptions[CHECKBOX_ITEM_COUNT];
uint32_t rcModeActivationMask; // one bit per mode defined in boxId_e
bool areSticksInApModePosition(uint16_t ap_mode)
{
@ -67,7 +60,9 @@ throttleStatus_e calculateThrottleStatus(rxConfig_t *rxConfig, uint16_t deadband
return THROTTLE_HIGH;
}
void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStatus, uint32_t *activate, bool retarded_arm, bool disarm_kill_switch)
void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStatus, modeActivationCondition_t *modeActivationConditions, bool retarded_arm, bool disarm_kill_switch)
{
static uint8_t rcDelayCommand; // this indicates the number of time (multiple of RC measurement at 50Hz) the sticks must be maintained to run or switch off motors
static uint8_t rcSticks; // this hold sticks position for command combos
@ -90,10 +85,12 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
rcDelayCommand = 0;
rcSticks = stTmp;
// perform actions
if (activate[BOXARM] > 0) {
bool isUsingSticksToArm = true; // FIXME calculate from modeActivationConditions // FIXME this calculation only needs to be done after loading a profile
if (rcOptions[BOXARM]) {
// perform actions
if (!isUsingSticksToArm) {
if (IS_RC_MODE_ACTIVE(BOXARM)) {
// Arming via ARM BOX
if (throttleStatus == THROTTLE_LOW) {
if (ARMING_FLAG(OK_TO_ARM)) {
@ -119,14 +116,15 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
if (ARMING_FLAG(ARMED)) {
// actions during armed
// Disarm on throttle down + yaw
if (activate[BOXARM] == 0 && (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE))
mwDisarm();
// Disarm on roll (only when retarded_arm is enabled)
if (retarded_arm && activate[BOXARM] == 0 && (rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO))
mwDisarm();
if (isUsingSticksToArm) {
// Disarm on throttle down + yaw
if (rcSticks == THR_LO + YAW_LO + PIT_CE + ROL_CE)
mwDisarm();
// Disarm on roll (only when retarded_arm is enabled)
if (retarded_arm && (rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_LO))
mwDisarm();
}
return;
}
@ -172,16 +170,19 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
return;
}
if (activate[BOXARM] == 0 && (rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE)) {
// Arm via YAW
mwArm();
return;
}
if (isUsingSticksToArm) {
if (retarded_arm && activate[BOXARM] == 0 && (rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI)) {
// Arm via ROLL
mwArm();
return;
if (rcSticks == THR_LO + YAW_HI + PIT_CE + ROL_CE) {
// Arm via YAW
mwArm();
return;
}
if (retarded_arm && (rcSticks == THR_LO + YAW_CE + PIT_CE + ROL_HI)) {
// Arm via ROLL
mwArm();
return;
}
}
if (rcSticks == THR_HI + YAW_LO + PIT_LO + ROL_CE) {
@ -226,40 +227,7 @@ void processRcStickPositions(rxConfig_t *rxConfig, throttleStatus_e throttleStat
#define MAX_AUX_STATE_CHANNELS 8
void updateRcOptions(uint32_t *activate)
void updateRcOptions(modeActivationCondition_t *modeActivationConditions)
{
// auxState is a bitmask, 3 bits per channel.
// lower 16 bits contain aux 4 to 1 (msb to lsb)
// upper 16 bits contain aux 8 to 5 (msb to lsb)
//
// the three bits are as follows:
// bit 1 is SET when the stick is less than 1300
// bit 2 is SET when the stick is between 1300 and 1700
// bit 3 is SET when the stick is above 1700
// if the value is 1300 or 1700 NONE of the three bits are set.
int i;
uint32_t auxState = 0;
uint8_t shift = 0;
int8_t chunkOffset = 0;
for (i = 0; i < rxRuntimeConfig.auxChannelCount && i < MAX_AUX_STATE_CHANNELS; i++) {
if (i > 0 && i % 4 == 0) {
chunkOffset -= 4;
shift += 16;
}
uint8_t bitIndex = 3 * (i + chunkOffset);
uint32_t temp =
(rcData[AUX1 + i] < 1300) << bitIndex |
(1300 < rcData[AUX1 + i] && rcData[AUX1 + i] < 1700) << (bitIndex + 1) |
(rcData[AUX1 + i] > 1700) << (bitIndex + 2);
auxState |= temp << shift;
}
for (i = 0; i < CHECKBOX_ITEM_COUNT; i++)
rcOptions[i] = (auxState & activate[i]) > 0;
rcModeActivationMask = 0; // FIXME implement, use rcData & modeActivationConditions
}