137 lines
3.5 KiB
C
137 lines
3.5 KiB
C
/*
|
|
* This file is part of Cleanflight and Betaflight.
|
|
*
|
|
* Cleanflight and Betaflight are free software. You can redistribute
|
|
* this software and/or modify this software under the terms of the
|
|
* GNU General Public License as published by the Free Software
|
|
* Foundation, either version 3 of the License, or (at your option)
|
|
* any later version.
|
|
*
|
|
* Cleanflight and Betaflight are distributed in the hope that they
|
|
* will be useful, but WITHOUT ANY WARRANTY; without even the implied
|
|
* warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
|
|
* See the GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* along with this software.
|
|
*
|
|
* If not, see <http://www.gnu.org/licenses/>.
|
|
*/
|
|
|
|
#pragma once
|
|
|
|
#include <stdbool.h>
|
|
|
|
#include "pg/pg.h"
|
|
|
|
#define BOXID_NONE 255
|
|
|
|
typedef enum {
|
|
// ARM flag
|
|
BOXARM = 0,
|
|
// FLIGHT_MODE
|
|
BOXANGLE,
|
|
BOXHORIZON,
|
|
BOXMAG,
|
|
BOXBARO,
|
|
BOXGPSHOME,
|
|
BOXGPSHOLD,
|
|
BOXHEADFREE,
|
|
BOXPASSTHRU,
|
|
BOXRANGEFINDER,
|
|
BOXFAILSAFE,
|
|
BOXGPSRESCUE,
|
|
BOXID_FLIGHTMODE_LAST = BOXGPSRESCUE,
|
|
|
|
// RCMODE flags
|
|
BOXANTIGRAVITY,
|
|
BOXHEADADJ,
|
|
BOXCAMSTAB,
|
|
BOXCAMTRIG,
|
|
BOXBEEPERON,
|
|
BOXLEDMAX,
|
|
BOXLEDLOW,
|
|
BOXLLIGHTS,
|
|
BOXCALIB,
|
|
BOXGOV,
|
|
BOXOSD,
|
|
BOXTELEMETRY,
|
|
BOXGTUNE,
|
|
BOXSERVO1,
|
|
BOXSERVO2,
|
|
BOXSERVO3,
|
|
BOXBLACKBOX,
|
|
BOXAIRMODE,
|
|
BOX3D,
|
|
BOXFPVANGLEMIX,
|
|
BOXBLACKBOXERASE,
|
|
BOXCAMERA1,
|
|
BOXCAMERA2,
|
|
BOXCAMERA3,
|
|
BOXFLIPOVERAFTERCRASH,
|
|
BOXPREARM,
|
|
BOXBEEPGPSCOUNT,
|
|
BOXVTXPITMODE,
|
|
BOXPARALYZE,
|
|
BOXUSER1,
|
|
BOXUSER2,
|
|
BOXUSER3,
|
|
BOXUSER4,
|
|
BOXPIDAUDIO,
|
|
CHECKBOX_ITEM_COUNT
|
|
} boxId_e;
|
|
|
|
typedef enum {
|
|
MODELOGIC_OR = 0,
|
|
MODELOGIC_AND
|
|
} modeLogic_e;
|
|
|
|
// type to hold enough bits for CHECKBOX_ITEM_COUNT. Struct used for value-like behavior
|
|
typedef struct boxBitmask_s { uint32_t bits[(CHECKBOX_ITEM_COUNT + 31) / 32]; } boxBitmask_t;
|
|
|
|
#define MAX_MODE_ACTIVATION_CONDITION_COUNT 20
|
|
|
|
#define CHANNEL_RANGE_MIN 900
|
|
#define CHANNEL_RANGE_MAX 2100
|
|
|
|
#define MODE_STEP_TO_CHANNEL_VALUE(step) (CHANNEL_RANGE_MIN + 25 * step)
|
|
#define CHANNEL_VALUE_TO_STEP(channelValue) ((constrain(channelValue, CHANNEL_RANGE_MIN, CHANNEL_RANGE_MAX) - CHANNEL_RANGE_MIN) / 25)
|
|
|
|
#define MIN_MODE_RANGE_STEP 0
|
|
#define MAX_MODE_RANGE_STEP ((CHANNEL_RANGE_MAX - CHANNEL_RANGE_MIN) / 25)
|
|
|
|
// steps are 25 apart
|
|
// a value of 0 corresponds to a channel value of 900 or less
|
|
// a value of 48 corresponds to a channel value of 2100 or more
|
|
// 48 steps between 900 and 2100
|
|
typedef struct channelRange_s {
|
|
uint8_t startStep;
|
|
uint8_t endStep;
|
|
} channelRange_t;
|
|
|
|
typedef struct modeActivationCondition_s {
|
|
boxId_e modeId;
|
|
uint8_t auxChannelIndex;
|
|
channelRange_t range;
|
|
modeLogic_e modeLogic;
|
|
} modeActivationCondition_t;
|
|
|
|
PG_DECLARE_ARRAY(modeActivationCondition_t, MAX_MODE_ACTIVATION_CONDITION_COUNT, modeActivationConditions);
|
|
|
|
typedef struct modeActivationProfile_s {
|
|
modeActivationCondition_t modeActivationConditions[MAX_MODE_ACTIVATION_CONDITION_COUNT];
|
|
} modeActivationProfile_t;
|
|
|
|
#define IS_RANGE_USABLE(range) ((range)->startStep < (range)->endStep)
|
|
|
|
bool IS_RC_MODE_ACTIVE(boxId_e boxId);
|
|
void rcModeUpdate(boxBitmask_t *newState);
|
|
void preventModeChanges(void);
|
|
|
|
bool isAirmodeActive(void);
|
|
bool isAntiGravityModeActive(void);
|
|
|
|
bool isRangeActive(uint8_t auxChannelIndex, const channelRange_t *range);
|
|
void updateActivatedModes(void);
|
|
bool isModeActivationConditionPresent(boxId_e modeId);
|