Native SENT TPS input #5079

only:alphax-4chan
This commit is contained in:
Andrey 2023-02-22 13:41:43 -05:00
parent eed7521035
commit 5a735c9059
2 changed files with 11 additions and 7 deletions

View File

@ -108,6 +108,13 @@ static SensorType functionToPositionSensor(dc_function_e func) {
}
}
static SensorType functionToTpsSensor(dc_function_e func) {
switch(func) {
case DC_Throttle1: return SensorType::Tps1;
default: return SensorType::Tps2;
}
}
static SensorType functionToTpsSensorPrimary(dc_function_e func) {
switch(func) {
case DC_Throttle1: return SensorType::Tps1Primary;
@ -177,7 +184,7 @@ bool EtbController::init(dc_function_e function, DcMotor *motor, pid_s *pidParam
}
// If no sensor is configured for this throttle, skip initialization.
if (!Sensor::hasSensor(functionToTpsSensorPrimary(function))) {
if (!Sensor::hasSensor(functionToTpsSensor(function))) {
etbErrorCode = (int8_t)TpsState::TpsError;
return false;
}

View File

@ -210,7 +210,7 @@ TEST(etb, initializationNotRedundantPedal) {
EXPECT_FATAL_ERROR(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));
}
TEST(etb, initializationNoPrimarySensor) {
TEST(etb, initializationNoSensor) {
Sensor::resetAllMocks();
EtbController dut;
@ -218,13 +218,10 @@ TEST(etb, initializationNoPrimarySensor) {
// Needs pedal for init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0.0f, true);
// Redundant, but no primary configured
Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true);
EXPECT_FALSE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));
// Now configure primary TPS
Sensor::setMockValue(SensorType::Tps1Primary, 0);
// Redundant
Sensor::setMockValue(SensorType::Tps1, /*value*/0, /*mockRedundant*/true);
// With primary TPS, should return true (ie, throttle was configured)
EXPECT_TRUE(dut.init(DC_Throttle1, nullptr, nullptr, nullptr, true));