2024-09-27 10:16:13 -07:00
|
|
|
//
|
|
|
|
// Created by kifir on 9/27/24.
|
|
|
|
//
|
|
|
|
|
|
|
|
#include "pch.h"
|
|
|
|
|
2024-10-02 07:00:39 -07:00
|
|
|
#if EFI_LAUNCH_CONTROL
|
2024-09-27 10:16:13 -07:00
|
|
|
#include "shift_torque_reduction_controller.h"
|
2024-10-02 07:00:39 -07:00
|
|
|
#include "boost_control.h"
|
|
|
|
#include "launch_control.h"
|
|
|
|
#include "advance_map.h"
|
|
|
|
#include "engine_state.h"
|
|
|
|
#include "advance_map.h"
|
|
|
|
#include "tinymt32.h"
|
|
|
|
|
|
|
|
void ShiftTorqueReductionController::update() {
|
|
|
|
if (engineConfiguration->torqueReductionEnabled) {
|
|
|
|
updateTriggerPinState();
|
2024-10-02 10:54:35 -07:00
|
|
|
updateTimeConditionSatisfied();
|
2024-10-03 11:07:33 -07:00
|
|
|
updateRpmConditionSatisfied();
|
2024-10-03 13:27:15 -07:00
|
|
|
updateAppConditionSatisfied();
|
2024-10-03 13:45:13 -07:00
|
|
|
|
|
|
|
isFlatShiftConditionSatisfied = torqueReductionTriggerPinState && isTimeConditionSatisfied
|
|
|
|
&& isRpmConditionSatisfied && isAppConditionSatisfied;
|
2024-10-02 07:00:39 -07:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-04 15:19:48 -07:00
|
|
|
float ShiftTorqueReductionController::getSparkSkipRatio() const {
|
|
|
|
float result = 0.0f;
|
|
|
|
if (engineConfiguration->torqueReductionEnabled && isFlatShiftConditionSatisfied) {
|
|
|
|
result = engineConfiguration->torqueReductionIgnitionCut / 100.0f;
|
|
|
|
}
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2024-10-02 07:00:39 -07:00
|
|
|
void ShiftTorqueReductionController::updateTriggerPinState() {
|
|
|
|
switch (engineConfiguration->torqueReductionActivationMode) {
|
|
|
|
case TORQUE_REDUCTION_BUTTON: {
|
|
|
|
updateTriggerPinState(
|
|
|
|
engineConfiguration->torqueReductionTriggerPin,
|
|
|
|
engineConfiguration->torqueReductionTriggerPinInverted
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
case LAUNCH_BUTTON: {
|
|
|
|
updateTriggerPinState(
|
|
|
|
engineConfiguration->launchActivatePin,
|
|
|
|
engineConfiguration->launchActivateInverted
|
|
|
|
);
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
default: {
|
|
|
|
break; // we shouldn't be here!
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void ShiftTorqueReductionController::updateTriggerPinState(const switch_input_pin_e pin, const bool isPinInverted) {
|
|
|
|
#if !EFI_SIMULATOR
|
|
|
|
isTorqueReductionTriggerPinValid = isBrainPinValid(pin);
|
|
|
|
if (isTorqueReductionTriggerPinValid) {
|
2024-10-02 10:54:35 -07:00
|
|
|
const bool previousTorqueReductionTriggerPinState = torqueReductionTriggerPinState;
|
2024-10-02 07:00:39 -07:00
|
|
|
torqueReductionTriggerPinState = isPinInverted ^ efiReadPin(pin);
|
2024-10-02 10:54:35 -07:00
|
|
|
if (!previousTorqueReductionTriggerPinState && torqueReductionTriggerPinState) {
|
|
|
|
m_pinTriggeredTimer.reset();
|
|
|
|
}
|
2024-10-02 07:00:39 -07:00
|
|
|
} else {
|
|
|
|
torqueReductionTriggerPinState = false;
|
|
|
|
}
|
|
|
|
#endif // !EFI_SIMULATOR
|
|
|
|
}
|
|
|
|
|
2024-10-02 10:54:35 -07:00
|
|
|
void ShiftTorqueReductionController::updateTimeConditionSatisfied() {
|
|
|
|
isTimeConditionSatisfied = torqueReductionTriggerPinState
|
2024-11-02 10:39:26 -07:00
|
|
|
? !engineConfiguration->limitTorqueReductionTime ||
|
|
|
|
((0.0f < engineConfiguration->torqueReductionTime)
|
|
|
|
&& !m_pinTriggeredTimer.hasElapsedMs(engineConfiguration->torqueReductionTime)
|
|
|
|
)
|
2024-10-02 10:54:35 -07:00
|
|
|
: false;
|
|
|
|
}
|
|
|
|
|
2024-10-03 11:07:33 -07:00
|
|
|
void ShiftTorqueReductionController::updateRpmConditionSatisfied() {
|
|
|
|
const float currentRpm = Sensor::getOrZero(SensorType::Rpm);
|
|
|
|
isRpmConditionSatisfied = (engineConfiguration->torqueReductionArmingRpm <= currentRpm);
|
|
|
|
}
|
|
|
|
|
2024-10-03 13:27:15 -07:00
|
|
|
void ShiftTorqueReductionController::updateAppConditionSatisfied() {
|
|
|
|
const SensorResult currentApp = Sensor::get(SensorType::DriverThrottleIntent);
|
|
|
|
|
|
|
|
if (currentApp.Valid) {
|
|
|
|
isAppConditionSatisfied = (engineConfiguration->torqueReductionArmingApp <= currentApp.Value);
|
|
|
|
} else {
|
|
|
|
isAppConditionSatisfied = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2024-10-02 07:00:39 -07:00
|
|
|
#endif // EFI_LAUNCH_CONTROL
|