static long cmsx_PidWriteback(const OSD_Entry *self) { UNUSED(self); pidProfile_t *pidProfile = currentPidProfile; for (uint8_t i = 0; i < 3; i++) { pidProfile->pid[i].P = tempPid[i][0]; pidProfile->pid[i].I = tempPid[i][1]; pidProfile->pid[i].D = tempPid[i][2]; } pidInitConfig(currentPidProfile); return 0; }
static long cmsx_profileOtherOnExit(const OSD_Entry *self) { UNUSED(self); pidProfile_t *pidProfile = pidProfilesMutable(pidProfileIndex); pidProfile->dtermSetpointWeight = cmsx_dtermSetpointWeight; pidProfile->setpointRelaxRatio = cmsx_setpointRelaxRatio; pidInitConfig(currentPidProfile); pidProfile->pid[PID_LEVEL].P = cmsx_angleStrength; pidProfile->pid[PID_LEVEL].I = cmsx_horizonStrength; pidProfile->pid[PID_LEVEL].D = cmsx_horizonTransition; return 0; }
void processRcAdjustments(controlRateConfig_t *controlRateConfig) { const uint32_t now = millis(); int newValue = -1; const bool canUseRxData = rxIsReceivingSignal(); for (int adjustmentIndex = 0; adjustmentIndex < MAX_SIMULTANEOUS_ADJUSTMENT_COUNT; adjustmentIndex++) { adjustmentState_t *adjustmentState = &adjustmentStates[adjustmentIndex]; if (!adjustmentState->config) { continue; } const uint8_t adjustmentFunction = adjustmentState->config->adjustmentFunction; if (adjustmentFunction == ADJUSTMENT_NONE) { continue; } if (cmp32(now, adjustmentState->timeoutAt) >= 0) { adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ; MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex); #if defined(USE_OSD) && defined(USE_OSD_ADJUSTMENTS) adjustmentRangeValue = -1; #endif } if (!canUseRxData) { continue; } const uint8_t channelIndex = NON_AUX_CHANNEL_COUNT + adjustmentState->auxChannelIndex; if (adjustmentState->config->mode == ADJUSTMENT_MODE_STEP) { int delta; if (rcData[channelIndex] > rxConfig()->midrc + 200) { delta = adjustmentState->config->data.step; } else if (rcData[channelIndex] < rxConfig()->midrc - 200) { delta = -adjustmentState->config->data.step; } else { // returning the switch to the middle immediately resets the ready state MARK_ADJUSTMENT_FUNCTION_AS_READY(adjustmentIndex); adjustmentState->timeoutAt = now + RESET_FREQUENCY_2HZ; continue; } if (IS_ADJUSTMENT_FUNCTION_BUSY(adjustmentIndex)) { continue; } newValue = applyStepAdjustment(controlRateConfig, adjustmentFunction, delta); pidInitConfig(pidProfile); } else if (adjustmentState->config->mode == ADJUSTMENT_MODE_SELECT) { const uint16_t rangeWidth = ((2100 - 900) / adjustmentState->config->data.switchPositions); const uint8_t position = (constrain(rcData[channelIndex], 900, 2100 - 1) - 900) / rangeWidth; newValue = applySelectAdjustment(adjustmentFunction, position); } #if defined(USE_OSD) && defined(USE_OSD_ADJUSTMENTS) if (newValue != -1 && adjustmentState->config->adjustmentFunction != ADJUSTMENT_RATE_PROFILE) { // Rate profile already has an OSD element adjustmentRangeName = &adjustmentLabels[adjustmentFunction - 1][0]; adjustmentRangeValue = newValue; } #else UNUSED(newValue); #endif MARK_ADJUSTMENT_FUNCTION_AS_BUSY(adjustmentIndex); } }