mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-17 05:15:25 +03:00
Prearm MSP Enable Fix
Added PREARM to rcMode dependant enables. Fixes Issue #4756 Added other rcMode dependant BOX* enables. Reordered copy mask, too. Made ARMED check a block Added note about flight and arm modes
This commit is contained in:
parent
a0f6d10b72
commit
2526b1ab80
1 changed files with 38 additions and 10 deletions
|
@ -281,12 +281,17 @@ int packFlightModeFlags(boxBitmask_t *mspFlightModeFlags)
|
||||||
boxBitmask_t boxEnabledMask;
|
boxBitmask_t boxEnabledMask;
|
||||||
memset(&boxEnabledMask, 0, sizeof(boxEnabledMask));
|
memset(&boxEnabledMask, 0, sizeof(boxEnabledMask));
|
||||||
|
|
||||||
|
// copy ARM state
|
||||||
|
if (ARMING_FLAG(ARMED)) {
|
||||||
|
bitArraySet(&boxEnabledMask, BOXARM);
|
||||||
|
}
|
||||||
|
|
||||||
// enable BOXes dependent on FLIGHT_MODE, use mapping table (from runtime_config.h)
|
// enable BOXes dependent on FLIGHT_MODE, use mapping table (from runtime_config.h)
|
||||||
// flightMode_boxId_map[HORIZON_MODE] == BOXHORIZON
|
// flightMode_boxId_map[HORIZON_MODE] == BOXHORIZON
|
||||||
static const int8_t flightMode_boxId_map[] = FLIGHT_MODE_BOXID_MAP_INITIALIZER;
|
static const int8_t flightMode_boxId_map[] = FLIGHT_MODE_BOXID_MAP_INITIALIZER;
|
||||||
flightModeFlags_e flightModeCopyMask = ~0; // only modes with bit set will be copied
|
flightModeFlags_e flightModeCopyMask = ~0; // only modes with bit set will be copied
|
||||||
for (unsigned i = 0; i < ARRAYLEN(flightMode_boxId_map); i++) {
|
for (unsigned i = 0; i < ARRAYLEN(flightMode_boxId_map); i++) {
|
||||||
if (flightMode_boxId_map[i] != -1 // boxId_e does exist for this FLIGHT_MODE
|
if (flightMode_boxId_map[i] != -1 // boxId_e does exist for this FLIGHT_MODE
|
||||||
&& (flightModeCopyMask & (1 << i)) // this flightmode is copy is enabled
|
&& (flightModeCopyMask & (1 << i)) // this flightmode is copy is enabled
|
||||||
&& FLIGHT_MODE(1 << i)) { // this flightmode is active
|
&& FLIGHT_MODE(1 << i)) { // this flightmode is active
|
||||||
bitArraySet(&boxEnabledMask, flightMode_boxId_map[i]);
|
bitArraySet(&boxEnabledMask, flightMode_boxId_map[i]);
|
||||||
|
@ -294,14 +299,40 @@ int packFlightModeFlags(boxBitmask_t *mspFlightModeFlags)
|
||||||
}
|
}
|
||||||
|
|
||||||
// enable BOXes dependent on rcMode bits, indexes are the same.
|
// enable BOXes dependent on rcMode bits, indexes are the same.
|
||||||
// only subset of BOXes depend on rcMode, use mask to select them
|
// only subset of BOXes depend on rcMode (non-ARM or FLIGHT_MODE), use mask to select them
|
||||||
|
// NOTE: ARM and FLIGHT modes are potentially contingent on other conditions.
|
||||||
|
// Therefore, they must be masked/enabled separately from simple "range conditions" (RC)
|
||||||
#define BM(x) (1ULL << (x))
|
#define BM(x) (1ULL << (x))
|
||||||
// limited to 64 BOXes now to keep code simple
|
// limited to 64 BOXes now to keep code simple
|
||||||
const uint64_t rcModeCopyMask = BM(BOXHEADADJ) | BM(BOXCAMSTAB) | BM(BOXCAMTRIG) | BM(BOXBEEPERON)
|
const uint64_t rcModeCopyMask = BM(BOXANTIGRAVITY)
|
||||||
| BM(BOXLEDMAX) | BM(BOXLEDLOW) | BM(BOXLLIGHTS) | BM(BOXCALIB) | BM(BOXGOV) | BM(BOXOSD)
|
| BM(BOXHEADADJ)
|
||||||
| BM(BOXTELEMETRY) | BM(BOXGTUNE) | BM(BOXBLACKBOX) | BM(BOXBLACKBOXERASE) | BM(BOXAIRMODE)
|
| BM(BOXCAMSTAB)
|
||||||
| BM(BOXANTIGRAVITY) | BM(BOXFPVANGLEMIX) | BM(BOXFLIPOVERAFTERCRASH) | BM(BOX3DDISABLE)
|
| BM(BOXCAMTRIG)
|
||||||
| BM(BOXBEEPGPSCOUNT) | BM(BOXVTXPITMODE);
|
| BM(BOXBEEPERON)
|
||||||
|
| BM(BOXLEDMAX)
|
||||||
|
| BM(BOXLEDLOW)
|
||||||
|
| BM(BOXLLIGHTS)
|
||||||
|
| BM(BOXCALIB)
|
||||||
|
| BM(BOXGOV)
|
||||||
|
| BM(BOXOSD)
|
||||||
|
| BM(BOXTELEMETRY)
|
||||||
|
| BM(BOXGTUNE)
|
||||||
|
| BM(BOXSERVO1)
|
||||||
|
| BM(BOXSERVO2)
|
||||||
|
| BM(BOXSERVO3)
|
||||||
|
| BM(BOXBLACKBOX)
|
||||||
|
| BM(BOXAIRMODE)
|
||||||
|
| BM(BOX3DDISABLE)
|
||||||
|
| BM(BOXFPVANGLEMIX)
|
||||||
|
| BM(BOXBLACKBOXERASE)
|
||||||
|
| BM(BOXCAMERA1)
|
||||||
|
| BM(BOXCAMERA2)
|
||||||
|
| BM(BOXCAMERA3)
|
||||||
|
| BM(BOXFLIPOVERAFTERCRASH)
|
||||||
|
| BM(BOXPREARM)
|
||||||
|
| BM(BOXBEEPGPSCOUNT)
|
||||||
|
| BM(BOX3DONASWITCH)
|
||||||
|
| BM(BOXVTXPITMODE);
|
||||||
STATIC_ASSERT(sizeof(rcModeCopyMask) * 8 >= CHECKBOX_ITEM_COUNT, copy_mask_too_small_for_boxes);
|
STATIC_ASSERT(sizeof(rcModeCopyMask) * 8 >= CHECKBOX_ITEM_COUNT, copy_mask_too_small_for_boxes);
|
||||||
for (unsigned i = 0; i < CHECKBOX_ITEM_COUNT; i++) {
|
for (unsigned i = 0; i < CHECKBOX_ITEM_COUNT; i++) {
|
||||||
if ((rcModeCopyMask & BM(i)) // mode copy is enabled
|
if ((rcModeCopyMask & BM(i)) // mode copy is enabled
|
||||||
|
@ -310,9 +341,6 @@ int packFlightModeFlags(boxBitmask_t *mspFlightModeFlags)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#undef BM
|
#undef BM
|
||||||
// copy ARM state
|
|
||||||
if (ARMING_FLAG(ARMED))
|
|
||||||
bitArraySet(&boxEnabledMask, BOXARM);
|
|
||||||
|
|
||||||
// map boxId_e enabled bits to MSP status indexes
|
// map boxId_e enabled bits to MSP status indexes
|
||||||
// only active boxIds are sent in status over MSP, other bits are not counted
|
// only active boxIds are sent in status over MSP, other bits are not counted
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue