mirror of
https://github.com/betaflight/betaflight.git
synced 2025-07-25 01:05:27 +03:00
Removed a number of static config pointers
This commit is contained in:
parent
a3951a3340
commit
5851b21e4a
26 changed files with 67 additions and 173 deletions
|
@ -43,9 +43,9 @@
|
|||
/*
|
||||
* Usage:
|
||||
*
|
||||
* failsafeInit() and useFailsafeConfig() must be called before the other methods are used.
|
||||
* failsafeInit() and resetFailsafe() must be called before the other methods are used.
|
||||
*
|
||||
* failsafeInit() and useFailsafeConfig() can be called in any order.
|
||||
* failsafeInit() and resetFailsafe() can be called in any order.
|
||||
* failsafeInit() should only be called once.
|
||||
*
|
||||
* enable() should be called after system initialisation.
|
||||
|
@ -53,16 +53,14 @@
|
|||
|
||||
static failsafeState_t failsafeState;
|
||||
|
||||
#ifndef USE_PARAMETER_GROPUS
|
||||
static const failsafeConfig_t *failsafeConfig;
|
||||
static const rxConfig_t *rxConfig;
|
||||
#endif
|
||||
|
||||
static uint16_t deadband3dThrottle; // default throttle deadband from MIDRC
|
||||
|
||||
static void failsafeReset(void)
|
||||
/*
|
||||
* Should called when the failsafe config needs to be changed - e.g. a different profile has been selected.
|
||||
*/
|
||||
void failsafeReset(void)
|
||||
{
|
||||
failsafeState.rxDataFailurePeriod = PERIOD_RXDATA_FAILURE + failsafeConfig->failsafe_delay * MILLIS_PER_TENTH_SECOND;
|
||||
failsafeState.rxDataFailurePeriod = PERIOD_RXDATA_FAILURE + failsafeConfig()->failsafe_delay * MILLIS_PER_TENTH_SECOND;
|
||||
failsafeState.validRxDataReceivedAt = 0;
|
||||
failsafeState.validRxDataFailedAt = 0;
|
||||
failsafeState.throttleLowPeriod = 0;
|
||||
|
@ -73,27 +71,8 @@ static void failsafeReset(void)
|
|||
failsafeState.rxLinkState = FAILSAFE_RXLINK_DOWN;
|
||||
}
|
||||
|
||||
/*
|
||||
* Should called when the failsafe config needs to be changed - e.g. a different profile has been selected.
|
||||
*/
|
||||
void useFailsafeConfig(const failsafeConfig_t *failsafeConfigToUse)
|
||||
void failsafeInit(uint16_t deadband3d_throttle)
|
||||
{
|
||||
#ifdef USE_PARAMETER_GROUPS
|
||||
(void)(failsafeConfigToUse);
|
||||
#else
|
||||
failsafeConfig = failsafeConfigToUse;
|
||||
#endif
|
||||
failsafeReset();
|
||||
}
|
||||
|
||||
void failsafeInit(const rxConfig_t *intialRxConfig, uint16_t deadband3d_throttle)
|
||||
{
|
||||
#ifdef USE_PARAMETER_GROUPS
|
||||
(void)(intialRxConfig);
|
||||
#else
|
||||
rxConfig = intialRxConfig;
|
||||
#endif
|
||||
|
||||
deadband3dThrottle = deadband3d_throttle;
|
||||
failsafeState.events = 0;
|
||||
failsafeState.monitoring = false;
|
||||
|
@ -131,7 +110,7 @@ static void failsafeActivate(void)
|
|||
failsafeState.active = true;
|
||||
failsafeState.phase = FAILSAFE_LANDING;
|
||||
ENABLE_FLIGHT_MODE(FAILSAFE_MODE);
|
||||
failsafeState.landingShouldBeFinishedAt = millis() + failsafeConfig->failsafe_off_delay * MILLIS_PER_TENTH_SECOND;
|
||||
failsafeState.landingShouldBeFinishedAt = millis() + failsafeConfig()->failsafe_off_delay * MILLIS_PER_TENTH_SECOND;
|
||||
|
||||
failsafeState.events++;
|
||||
}
|
||||
|
@ -139,9 +118,9 @@ static void failsafeActivate(void)
|
|||
static void failsafeApplyControlInput(void)
|
||||
{
|
||||
for (int i = 0; i < 3; i++) {
|
||||
rcData[i] = rxConfig->midrc;
|
||||
rcData[i] = rxConfig()->midrc;
|
||||
}
|
||||
rcData[THROTTLE] = failsafeConfig->failsafe_throttle;
|
||||
rcData[THROTTLE] = failsafeConfig()->failsafe_throttle;
|
||||
}
|
||||
|
||||
bool failsafeIsReceivingRxData(void)
|
||||
|
@ -201,11 +180,11 @@ void failsafeUpdateState(void)
|
|||
case FAILSAFE_IDLE:
|
||||
if (armed) {
|
||||
// Track throttle command below minimum time
|
||||
if (THROTTLE_HIGH == calculateThrottleStatus(rxConfig, deadband3dThrottle)) {
|
||||
failsafeState.throttleLowPeriod = millis() + failsafeConfig->failsafe_throttle_low_delay * MILLIS_PER_TENTH_SECOND;
|
||||
if (THROTTLE_HIGH == calculateThrottleStatus(rxConfig(), deadband3dThrottle)) {
|
||||
failsafeState.throttleLowPeriod = millis() + failsafeConfig()->failsafe_throttle_low_delay * MILLIS_PER_TENTH_SECOND;
|
||||
}
|
||||
// Kill switch logic (must be independent of receivingRxData to skip PERIOD_RXDATA_FAILURE delay before disarming)
|
||||
if (failsafeSwitchIsOn && failsafeConfig->failsafe_kill_switch) {
|
||||
if (failsafeSwitchIsOn && failsafeConfig()->failsafe_kill_switch) {
|
||||
// KillswitchEvent: failsafe switch is configured as KILL switch and is switched ON
|
||||
failsafeActivate();
|
||||
failsafeState.phase = FAILSAFE_LANDED; // skip auto-landing procedure
|
||||
|
@ -238,7 +217,7 @@ void failsafeUpdateState(void)
|
|||
if (receivingRxData) {
|
||||
failsafeState.phase = FAILSAFE_RX_LOSS_RECOVERED;
|
||||
} else {
|
||||
switch (failsafeConfig->failsafe_procedure) {
|
||||
switch (failsafeConfig()->failsafe_procedure) {
|
||||
default:
|
||||
case FAILSAFE_PROCEDURE_AUTO_LANDING:
|
||||
// Stabilize, and set Throttle to specified level
|
||||
|
@ -300,7 +279,7 @@ void failsafeUpdateState(void)
|
|||
// Entering IDLE with the requirement that throttle first must be at min_check for failsafe_throttle_low_delay period.
|
||||
// This is to prevent that JustDisarm is activated on the next iteration.
|
||||
// Because that would have the effect of shutting down failsafe handling on intermittent connections.
|
||||
failsafeState.throttleLowPeriod = millis() + failsafeConfig->failsafe_throttle_low_delay * MILLIS_PER_TENTH_SECOND;
|
||||
failsafeState.throttleLowPeriod = millis() + failsafeConfig()->failsafe_throttle_low_delay * MILLIS_PER_TENTH_SECOND;
|
||||
failsafeState.phase = FAILSAFE_IDLE;
|
||||
failsafeState.active = false;
|
||||
DISABLE_FLIGHT_MODE(FAILSAFE_MODE);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue