1
0
Fork 0
mirror of https://github.com/iNavFlight/inav.git synced 2025-07-26 17:55:28 +03:00

[fc_msp_box.c] Add macro to Active and Reset boxes

This commit is contained in:
JuliooCesarMDM 2022-02-06 15:30:54 -03:00
parent 3147d5423f
commit 8d23d967d4

View file

@ -102,6 +102,9 @@ static uint8_t activeBoxIds[CHECKBOX_ITEM_COUNT];
// this is the number of filled indexes in above array // this is the number of filled indexes in above array
uint8_t activeBoxIdCount = 0; uint8_t activeBoxIdCount = 0;
#define RESET_BOX_ID_COUNT activeBoxIdCount = 0;
#define ACTIVE_THIS_BOX(box) activeBoxIds[activeBoxIdCount++] = box;
const box_t *findBoxByActiveBoxId(uint8_t activeBoxId) const box_t *findBoxByActiveBoxId(uint8_t activeBoxId)
{ {
for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) { for (uint8_t boxIndex = 0; boxIndex < sizeof(boxes) / sizeof(box_t); boxIndex++) {
@ -169,39 +172,39 @@ void initActiveBoxIds(void)
// calculate used boxes based on features and fill availableBoxes[] array // calculate used boxes based on features and fill availableBoxes[] array
memset(activeBoxIds, 0xFF, sizeof(activeBoxIds)); memset(activeBoxIds, 0xFF, sizeof(activeBoxIds));
activeBoxIdCount = 0; RESET_BOX_ID_COUNT;
activeBoxIds[activeBoxIdCount++] = BOXARM; ACTIVE_THIS_BOX(BOXARM);
activeBoxIds[activeBoxIdCount++] = BOXPREARM; ACTIVE_THIS_BOX(BOXPREARM);
if (sensors(SENSOR_ACC) && STATE(ALTITUDE_CONTROL)) { if (sensors(SENSOR_ACC) && STATE(ALTITUDE_CONTROL)) {
activeBoxIds[activeBoxIdCount++] = BOXANGLE; ACTIVE_THIS_BOX(BOXANGLE);
activeBoxIds[activeBoxIdCount++] = BOXHORIZON; ACTIVE_THIS_BOX(BOXHORIZON);
activeBoxIds[activeBoxIdCount++] = BOXTURNASSIST; ACTIVE_THIS_BOX(BOXTURNASSIST);
} }
if (!feature(FEATURE_AIRMODE) && STATE(ALTITUDE_CONTROL)) { if (!feature(FEATURE_AIRMODE) && STATE(ALTITUDE_CONTROL)) {
activeBoxIds[activeBoxIdCount++] = BOXAIRMODE; ACTIVE_THIS_BOX(BOXAIRMODE);
} }
activeBoxIds[activeBoxIdCount++] = BOXHEADINGHOLD; ACTIVE_THIS_BOX(BOXHEADINGHOLD);
if ((sensors(SENSOR_ACC) || sensors(SENSOR_MAG)) && STATE(MULTIROTOR)) { if ((sensors(SENSOR_ACC) || sensors(SENSOR_MAG)) && STATE(MULTIROTOR)) {
activeBoxIds[activeBoxIdCount++] = BOXHEADFREE; ACTIVE_THIS_BOX(BOXHEADFREE);
activeBoxIds[activeBoxIdCount++] = BOXHEADADJ; ACTIVE_THIS_BOX(BOXHEADADJ);
} }
if (STATE(ALTITUDE_CONTROL) && STATE(MULTIROTOR)) { if (STATE(ALTITUDE_CONTROL) && STATE(MULTIROTOR)) {
activeBoxIds[activeBoxIdCount++] = BOXFPVANGLEMIX; ACTIVE_THIS_BOX(BOXFPVANGLEMIX);
} }
//Camstab mode is enabled always //Camstab mode is enabled always
activeBoxIds[activeBoxIdCount++] = BOXCAMSTAB; ACTIVE_THIS_BOX(BOXCAMSTAB);
#ifdef USE_GPS #ifdef USE_GPS
if (STATE(ALTITUDE_CONTROL) && (sensors(SENSOR_BARO) || (feature(FEATURE_GPS) && (STATE(AIRPLANE) || positionEstimationConfig()->use_gps_no_baro)))) { if (STATE(ALTITUDE_CONTROL) && (sensors(SENSOR_BARO) || (feature(FEATURE_GPS) && (STATE(AIRPLANE) || positionEstimationConfig()->use_gps_no_baro)))) {
activeBoxIds[activeBoxIdCount++] = BOXNAVALTHOLD; ACTIVE_THIS_BOX(BOXNAVALTHOLD);
if (STATE(MULTIROTOR)) { if (STATE(MULTIROTOR)) {
activeBoxIds[activeBoxIdCount++] = BOXSURFACE; ACTIVE_THIS_BOX(BOXSURFACE);
} }
} }
@ -210,53 +213,53 @@ void initActiveBoxIds(void)
const bool navFlowDeadReckoning = sensors(SENSOR_OPFLOW) && sensors(SENSOR_ACC) && positionEstimationConfig()->allow_dead_reckoning; const bool navFlowDeadReckoning = sensors(SENSOR_OPFLOW) && sensors(SENSOR_ACC) && positionEstimationConfig()->allow_dead_reckoning;
if (navFlowDeadReckoning || navReadyMultirotor || navReadyOther) { if (navFlowDeadReckoning || navReadyMultirotor || navReadyOther) {
if (!STATE(ROVER) && !STATE(BOAT)) { if (!STATE(ROVER) && !STATE(BOAT)) {
activeBoxIds[activeBoxIdCount++] = BOXNAVPOSHOLD; ACTIVE_THIS_BOX(BOXNAVPOSHOLD);
} }
if (STATE(AIRPLANE)) { if (STATE(AIRPLANE)) {
activeBoxIds[activeBoxIdCount++] = BOXLOITERDIRCHN; ACTIVE_THIS_BOX(BOXLOITERDIRCHN);
} }
} }
if (navReadyMultirotor || navReadyOther) { if (navReadyMultirotor || navReadyOther) {
activeBoxIds[activeBoxIdCount++] = BOXNAVRTH; ACTIVE_THIS_BOX(BOXNAVRTH);
activeBoxIds[activeBoxIdCount++] = BOXNAVWP; ACTIVE_THIS_BOX(BOXNAVWP);
activeBoxIds[activeBoxIdCount++] = BOXHOMERESET; ACTIVE_THIS_BOX(BOXHOMERESET);
activeBoxIds[activeBoxIdCount++] = BOXGCSNAV; ACTIVE_THIS_BOX(BOXGCSNAV);
activeBoxIds[activeBoxIdCount++] = BOXPLANWPMISSION; ACTIVE_THIS_BOX(BOXPLANWPMISSION);
if (STATE(AIRPLANE)) { if (STATE(AIRPLANE)) {
activeBoxIds[activeBoxIdCount++] = BOXNAVCOURSEHOLD; ACTIVE_THIS_BOX(BOXNAVCOURSEHOLD);
activeBoxIds[activeBoxIdCount++] = BOXNAVCRUISE; ACTIVE_THIS_BOX(BOXNAVCRUISE);
activeBoxIds[activeBoxIdCount++] = BOXSOARING; ACTIVE_THIS_BOX(BOXSOARING);
} }
} }
#ifdef USE_MR_BRAKING_MODE #ifdef USE_MR_BRAKING_MODE
if (mixerConfig()->platformType == PLATFORM_MULTIROTOR) { if (mixerConfig()->platformType == PLATFORM_MULTIROTOR) {
activeBoxIds[activeBoxIdCount++] = BOXBRAKING; ACTIVE_THIS_BOX(BOXBRAKING);
} }
#endif #endif
#endif #endif
if (STATE(AIRPLANE) || STATE(ROVER) || STATE(BOAT)) { if (STATE(AIRPLANE) || STATE(ROVER) || STATE(BOAT)) {
activeBoxIds[activeBoxIdCount++] = BOXMANUAL; ACTIVE_THIS_BOX(BOXMANUAL);
} }
if (STATE(AIRPLANE)) { if (STATE(AIRPLANE)) {
if (!feature(FEATURE_FW_LAUNCH)) { if (!feature(FEATURE_FW_LAUNCH)) {
activeBoxIds[activeBoxIdCount++] = BOXNAVLAUNCH; ACTIVE_THIS_BOX(BOXNAVLAUNCH);
} }
if (!feature(FEATURE_FW_AUTOTRIM)) { if (!feature(FEATURE_FW_AUTOTRIM)) {
activeBoxIds[activeBoxIdCount++] = BOXAUTOTRIM; ACTIVE_THIS_BOX(BOXAUTOTRIM);
} }
#if defined(USE_AUTOTUNE_FIXED_WING) #if defined(USE_AUTOTUNE_FIXED_WING)
activeBoxIds[activeBoxIdCount++] = BOXAUTOTUNE; ACTIVE_THIS_BOX(BOXAUTOTUNE);
#endif #endif
if (sensors(SENSOR_BARO)) { if (sensors(SENSOR_BARO)) {
activeBoxIds[activeBoxIdCount++] = BOXAUTOLEVEL; ACTIVE_THIS_BOX(BOXAUTOLEVEL);
} }
} }
@ -265,68 +268,70 @@ void initActiveBoxIds(void)
* flying wing can cause bad thing * flying wing can cause bad thing
*/ */
if (STATE(FLAPERON_AVAILABLE)) { if (STATE(FLAPERON_AVAILABLE)) {
activeBoxIds[activeBoxIdCount++] = BOXFLAPERON; ACTIVE_THIS_BOX(BOXFLAPERON);
} }
activeBoxIds[activeBoxIdCount++] = BOXBEEPERON; ACTIVE_THIS_BOX(BOXBEEPERON);
#ifdef USE_LIGHTS #ifdef USE_LIGHTS
activeBoxIds[activeBoxIdCount++] = BOXLIGHTS; ACTIVE_THIS_BOX(BOXLIGHTS);
#endif #endif
#ifdef USE_LED_STRIP #ifdef USE_LED_STRIP
if (feature(FEATURE_LED_STRIP)) { if (feature(FEATURE_LED_STRIP)) {
activeBoxIds[activeBoxIdCount++] = BOXLEDLOW; ACTIVE_THIS_BOX(BOXLEDLOW);
} }
#endif #endif
activeBoxIds[activeBoxIdCount++] = BOXOSD; ACTIVE_THIS_BOX(BOXOSD);
#ifdef USE_TELEMETRY #ifdef USE_TELEMETRY
if (feature(FEATURE_TELEMETRY) && telemetryConfig()->telemetry_switch) if (feature(FEATURE_TELEMETRY) && telemetryConfig()->telemetry_switch) {
activeBoxIds[activeBoxIdCount++] = BOXTELEMETRY; ACTIVE_THIS_BOX(BOXTELEMETRY);
}
#endif #endif
#ifdef USE_BLACKBOX #ifdef USE_BLACKBOX
if (feature(FEATURE_BLACKBOX)){ if (feature(FEATURE_BLACKBOX)) {
activeBoxIds[activeBoxIdCount++] = BOXBLACKBOX; ACTIVE_THIS_BOX(BOXBLACKBOX);
} }
#endif #endif
activeBoxIds[activeBoxIdCount++] = BOXKILLSWITCH; ACTIVE_THIS_BOX(BOXKILLSWITCH);
activeBoxIds[activeBoxIdCount++] = BOXFAILSAFE; ACTIVE_THIS_BOX(BOXFAILSAFE);
#ifdef USE_RCDEVICE #ifdef USE_RCDEVICE
activeBoxIds[activeBoxIdCount++] = BOXCAMERA1; ACTIVE_THIS_BOX(BOXCAMERA1);
activeBoxIds[activeBoxIdCount++] = BOXCAMERA2; ACTIVE_THIS_BOX(BOXCAMERA2);
activeBoxIds[activeBoxIdCount++] = BOXCAMERA3; ACTIVE_THIS_BOX(BOXCAMERA3);
#endif #endif
#ifdef USE_PINIOBOX #ifdef USE_PINIOBOX
// USER modes are only used for PINIO at the moment // USER modes are only used for PINIO at the moment
activeBoxIds[activeBoxIdCount++] = BOXUSER1; ACTIVE_THIS_BOX(BOXUSER1);
activeBoxIds[activeBoxIdCount++] = BOXUSER2; ACTIVE_THIS_BOX(BOXUSER2);
#endif #endif
#if defined(USE_OSD) && defined(OSD_LAYOUT_COUNT) #if defined(USE_OSD) && defined(OSD_LAYOUT_COUNT)
#if OSD_LAYOUT_COUNT > 0 #if OSD_LAYOUT_COUNT > 0
activeBoxIds[activeBoxIdCount++] = BOXOSDALT1; ACTIVE_THIS_BOX(BOXOSDALT1);
#if OSD_LAYOUT_COUNT > 1 #if OSD_LAYOUT_COUNT > 1
activeBoxIds[activeBoxIdCount++] = BOXOSDALT2; ACTIVE_THIS_BOX(BOXOSDALT2);
#if OSD_LAYOUT_COUNT > 2 #if OSD_LAYOUT_COUNT > 2
activeBoxIds[activeBoxIdCount++] = BOXOSDALT3; ACTIVE_THIS_BOX(BOXOSDALT3);
#endif #endif
#endif #endif
#endif #endif
#endif #endif
#if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE) #if defined(USE_RX_MSP) && defined(USE_MSP_RC_OVERRIDE)
activeBoxIds[activeBoxIdCount++] = BOXMSPRCOVERRIDE; ACTIVE_THIS_BOX(BOXMSPRCOVERRIDE);
#endif #endif
#ifdef USE_DSHOT #ifdef USE_DSHOT
if(STATE(MULTIROTOR) && isMotorProtocolDshot()) if(STATE(MULTIROTOR) && isMotorProtocolDshot()) {
activeBoxIds[activeBoxIdCount++] = BOXTURTLE; ACTIVE_THIS_BOX(BOXTURTLE);
}
#endif #endif
} }