Replace hasPedalPositionSensor (#1245)

* remove

* add Sensor::hasSensor

* consume in etb

* remove unused state

* don't use it there either

* format

* fix up tests

Co-authored-by: Matthew Kennedy <makenne@microsoft.com>
This commit is contained in:
Matthew Kennedy 2020-04-02 05:04:12 -07:00 committed by GitHub
parent 8151793ec7
commit 22267e5479
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
9 changed files with 54 additions and 25 deletions

View File

@ -242,7 +242,6 @@ void EtbController::PeriodicTask() {
}
DISPLAY_STATE(Engine)
DISPLAY(DISPLAY_IF(hasEtbPedalPositionSensor))
DISPLAY_TEXT(Electronic_Throttle);
DISPLAY_SENSOR(TPS)
DISPLAY_TEXT(eol);
@ -543,13 +542,11 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
addConsoleActionI("etb_freq", setEtbFrequency);
#endif /* EFI_PROD_CODE */
engine->engineState.hasEtbPedalPositionSensor = hasPedalPositionSensor(PASS_ENGINE_PARAMETER_SIGNATURE);
if (!engine->engineState.hasEtbPedalPositionSensor) {
#if EFI_PROD_CODE
// TODO: Once switched to new sensor model for pedal, we don't need this to be test-guarded.
// If you don't have a pedal, we have no business here.
if (!Sensor::hasSensor(SensorType::AcceleratorPedal)) {
return;
#endif
}
engine->etbActualCount = hasSecondThrottleBody(PASS_ENGINE_PARAMETER_SIGNATURE) ? 2 : 1;
for (int i = 0 ; i < engine->etbActualCount; i++) {
@ -619,7 +616,6 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
addConsoleActionI("set_etbat_offset", setAutoOffset);
#endif /* EFI_PROD_CODE */
etbPidReset(PASS_ENGINE_PARAMETER_SIGNATURE);
for (int i = 0 ; i < engine->etbActualCount; i++) {
@ -629,15 +625,14 @@ void doInitElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
void initElectronicThrottle(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
if (hasFirmwareError()) {
return;
return;
}
for (int i = 0; i < ETB_COUNT; i++) {
engine->etbControllers[i] = &etbControllers[i];
}
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
}
#endif /* EFI_ELECTRONIC_THROTTLE_BODY */

View File

@ -120,6 +120,16 @@ bool Sensor::Register() {
return 0;
}
/*static*/ bool Sensor::hasSensor(SensorType type) {
const auto entry = getEntryForType(type);
if (!entry) {
return false;
}
return entry->useMock || entry->sensor;
}
/*static*/ void Sensor::setMockValue(SensorType type, float value) {
auto entry = getEntryForType(type);

View File

@ -103,6 +103,11 @@ public:
*/
static float getRaw(SensorType type);
/*
* Query whether there is a sensor of a particular type currently registered.
*/
static bool hasSensor(SensorType type);
/*
* Mock a value for a particular sensor.
*/

View File

@ -195,10 +195,6 @@ static percent_t getPrimaryRawTPS(int index DECLARE_ENGINE_PARAMETER_SUFFIX) {
#define NO_TPS_MAGIC_VALUE 66.611
bool hasPedalPositionSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->throttlePedalPositionAdcChannel != EFI_ADC_NONE;
}
bool hasSecondThrottleBody(DECLARE_ENGINE_PARAMETER_SIGNATURE) {
return engineConfiguration->tps2_1AdcChannel != EFI_ADC_NONE;
}

View File

@ -15,7 +15,6 @@
// Scaled to 1000 counts = 5.0 volts
#define TPS_TS_CONVERSION 200
bool hasPedalPositionSensor(DECLARE_ENGINE_PARAMETER_SIGNATURE);
/**
* Throttle Position Sensor
* In case of dual TPS this function would return logical TPS position

View File

@ -411,13 +411,10 @@ static void printTpsSenser(const char *msg, SensorType sensor, int16_t min, int1
scheduleMsg(&logger, "current 10bit=%d value=%.2f rate=%.2f", convertVoltageTo10bitADC(raw), tps.Value, getTpsRateOfChange());
}
void printTPSInfo(void) {
if (hasPedalPositionSensor()) {
scheduleMsg(&logger, "pedal up %f / down %f",
engineConfiguration->throttlePedalUpVoltage,
engineConfiguration->throttlePedalWOTVoltage);
}
scheduleMsg(&logger, "pedal up %f / down %f",
engineConfiguration->throttlePedalUpVoltage,
engineConfiguration->throttlePedalWOTVoltage);
printTpsSenser("TPS", SensorType::Tps1, engineConfiguration->tpsMin, engineConfiguration->tpsMax, engineConfiguration->tps1_1AdcChannel);
printTpsSenser("TPS2", SensorType::Tps2, engineConfiguration->tps2Min, engineConfiguration->tps2Max, engineConfiguration->tps2_1AdcChannel);

View File

@ -55,7 +55,6 @@ float tpsVoltageBoard
float baroCorrection;
bit isCrankingState
bit hasEtbPedalPositionSensor;
bit isAutomaticIdle
struct cranking_fuel_s

View File

@ -79,3 +79,29 @@ TEST_F(SensorBasic, SensorInitialized) {
EXPECT_TRUE(result2.Valid);
EXPECT_FLOAT_EQ(result2.Value, 75);
}
TEST_F(SensorBasic, HasSensor) {
MockSensor dut(SensorType::Clt);
// Check that we don't have the sensor
ASSERT_FALSE(Sensor::hasSensor(SensorType::Clt));
// Register it
ASSERT_TRUE(dut.Register());
// Now we should!
ASSERT_TRUE(Sensor::hasSensor(SensorType::Clt));
}
TEST_F(SensorBasic, HasSensorMock) {
MockSensor dut(SensorType::Clt);
// Check that we don't have the sensor
ASSERT_FALSE(Sensor::hasSensor(SensorType::Clt));
// Mock the sensor - this should count as having it
Sensor::setMockValue(SensorType::Clt, 25);
// Now we should!
ASSERT_TRUE(Sensor::hasSensor(SensorType::Clt));
}

View File

@ -50,7 +50,8 @@ TEST(etb, singleEtbInitialization) {
engine->etbControllers[i] = &mocks[i];
}
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_9;
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
@ -71,9 +72,10 @@ TEST(etb, singleEtbInitialization) {
TEST(etb, testTargetTpsIsFloatBug945) {
WITH_ENGINE_TEST_HELPER(TEST_ENGINE);
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
// Must have a sensor configured before init
Sensor::setMockValue(SensorType::AcceleratorPedal, 0);
engineConfiguration->throttlePedalPositionAdcChannel = EFI_ADC_0;
doInitElectronicThrottle(PASS_ENGINE_PARAMETER_SIGNATURE);
Sensor::setMockValue(SensorType::AcceleratorPedal, 50.0f);
engine->etbControllers[0]->PeriodicTask();