refactoring: LaunchCondition enum

This commit is contained in:
Andrey 2024-03-09 08:39:58 -05:00
parent 452c600b18
commit 946bc82376
4 changed files with 22 additions and 16 deletions

View File

@ -3,6 +3,7 @@
* *
* @date 10. sep. 2019 * @date 10. sep. 2019
* Author: Ola Ruud * Author: Ola Ruud
* Rework: Patryk Chmura
*/ */
#include "pch.h" #include "pch.h"
@ -75,19 +76,19 @@ bool LaunchControlBase::isInsideTpsCondition() const {
/** /**
* Condition is true as soon as we are above LaunchRpm * Condition is true as soon as we are above LaunchRpm
*/ */
bool LaunchControlBase::isInsideRPMCondition(int rpm) const { LaunchCondition LaunchControlBase::isInsideRPMCondition(int rpm) const {
int launchRpm = engineConfiguration->launchRpm; int launchRpm = engineConfiguration->launchRpm;
return (launchRpm < rpm); return (launchRpm < rpm) ? LaunchCondition::Launch : LaunchCondition::NotMet;
} }
bool LaunchControlBase::isLaunchConditionMet(int rpm) { LaunchCondition LaunchControlBase::isLaunchConditionMet(int rpm) {
LaunchCondition rpmLaunchCondition = isInsideRPMCondition(rpm);
activateSwitchCondition = isInsideSwitchCondition(); activateSwitchCondition = isInsideSwitchCondition();
rpmCondition = isInsideRPMCondition(rpm); rpmCondition = (rpmLaunchCondition == LaunchCondition::Launch);
speedCondition = isInsideSpeedCondition(); speedCondition = isInsideSpeedCondition();
tpsCondition = isInsideTpsCondition(); tpsCondition = isInsideTpsCondition();
return speedCondition && activateSwitchCondition && rpmCondition && tpsCondition; return ((speedCondition && activateSwitchCondition && tpsCondition) == true) ? rpmLaunchCondition : LaunchCondition::NotMet;
} }
LaunchControlBase::LaunchControlBase() { LaunchControlBase::LaunchControlBase() {
@ -106,7 +107,7 @@ void LaunchControlBase::update() {
} }
int rpm = Sensor::getOrZero(SensorType::Rpm); int rpm = Sensor::getOrZero(SensorType::Rpm);
combinedConditions = isLaunchConditionMet(rpm); combinedConditions = isLaunchConditionMet(rpm) == LaunchCondition::Launch;
//and still recalculate in case user changed the values //and still recalculate in case user changed the values
retardThresholdRpm = engineConfiguration->launchRpm retardThresholdRpm = engineConfiguration->launchRpm

View File

@ -12,6 +12,11 @@
void initLaunchControl(); void initLaunchControl();
enum class LaunchCondition {
Launch,
NotMet
};
class LaunchControlBase : public launch_control_state_s { class LaunchControlBase : public launch_control_state_s {
public: public:
LaunchControlBase(); LaunchControlBase();
@ -22,8 +27,8 @@ public:
bool isInsideSpeedCondition() const; bool isInsideSpeedCondition() const;
bool isInsideTpsCondition() const; bool isInsideTpsCondition() const;
bool isInsideSwitchCondition(); bool isInsideSwitchCondition();
bool isInsideRPMCondition(int rpm) const; LaunchCondition isInsideRPMCondition(int rpm) const;
bool isLaunchConditionMet(int rpm); LaunchCondition isLaunchConditionMet(int rpm);
bool isLaunchSparkRpmRetardCondition() const; bool isLaunchSparkRpmRetardCondition() const;
bool isLaunchFuelRpmRetardCondition() const; bool isLaunchFuelRpmRetardCondition() const;

View File

@ -483,7 +483,7 @@ MAP_sensor_config_s map;@see isMapAveragingEnabled
ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here! ThermistorConf clt;todo: merge with channel settings, use full-scale Thermistor here!
ThermistorConf iat; ThermistorConf iat;
int launchTimingRetard;;"deg", 1, 0, -180, 180, 2 float launchTimingRetard;;"deg", 1, 0, -180, 180, 2
int hip9011PrescalerAndSDO;value '6' for 8MHz hw osc\nread hip9011 datasheet for details\ntodo split into two bit fields;"integer", 1, 0, 0, 32, 0 int hip9011PrescalerAndSDO;value '6' for 8MHz hw osc\nread hip9011 datasheet for details\ntodo split into two bit fields;"integer", 1, 0, 0, 32, 0
float knockBandCustom;We calculate knock band based of cylinderBore\n Use this to override - kHz knock band override\nRequires power cycling to effect;"kHz", 1, 0, 0, 20, 2 float knockBandCustom;We calculate knock band based of cylinderBore\n Use this to override - kHz knock band override\nRequires power cycling to effect;"kHz", 1, 0, 0, 20, 2

View File

@ -78,9 +78,9 @@ TEST(LaunchControl, RPMCondition) {
engineConfiguration->launchRpm = 3000; engineConfiguration->launchRpm = 3000;
EXPECT_FALSE(dut.isInsideRPMCondition(2900)); EXPECT_EQ(dut.isInsideRPMCondition(2900), LaunchCondition::NotMet);
EXPECT_TRUE(dut.isInsideRPMCondition(3100)); EXPECT_EQ(dut.isInsideRPMCondition(3100), LaunchCondition::Launch);
} }
TEST(LaunchControl, SwitchInputCondition) { TEST(LaunchControl, SwitchInputCondition) {
@ -141,13 +141,13 @@ TEST(LaunchControl, CombinedCondition) {
Sensor::setMockValue(SensorType::VehicleSpeed, 10.0); Sensor::setMockValue(SensorType::VehicleSpeed, 10.0);
Sensor::setMockValue(SensorType::Rpm, 1200); Sensor::setMockValue(SensorType::Rpm, 1200);
EXPECT_FALSE(dut.isLaunchConditionMet(1200)); EXPECT_EQ(dut.isLaunchConditionMet(1200), LaunchCondition::NotMet);
Sensor::setMockValue(SensorType::Rpm, 3200); Sensor::setMockValue(SensorType::Rpm, 3200);
EXPECT_TRUE(dut.isLaunchConditionMet(3200)); EXPECT_EQ(dut.isLaunchConditionMet(3200), LaunchCondition::Launch);
Sensor::setMockValue(SensorType::VehicleSpeed, 40.0); Sensor::setMockValue(SensorType::VehicleSpeed, 40.0);
EXPECT_FALSE(dut.isLaunchConditionMet(3200)); EXPECT_EQ(dut.isLaunchConditionMet(3200), LaunchCondition::NotMet);
} }