gear detector doesn't need StoredValueSensor

This commit is contained in:
Matthew Kennedy 2023-04-19 01:20:13 -07:00
parent fa804609b7
commit d01fac09ed
2 changed files with 18 additions and 5 deletions

View File

@ -5,9 +5,8 @@ static constexpr float geometricMean(float x, float y) {
}
GearDetector::GearDetector()
: StoredValueSensor(SensorType::DetectedGear, MS2NT(100))
: Sensor(SensorType::DetectedGear)
{
Register();
}
GearDetector::~GearDetector() {
@ -48,14 +47,15 @@ void GearDetector::onConfigurationChange(engine_configuration_s const * /*previo
m_gearThresholds[i] = geometricMean(gearI, gearIplusOne);
}
Register();
}
void GearDetector::onSlowCallback() {
float ratio = computeGearboxRatio();
m_gearboxRatio = ratio;
auto gear = determineGearFromRatio(ratio);
setValidValue(gear, getTimeNowNt());
m_currentGear = determineGearFromRatio(ratio);
}
size_t GearDetector::determineGearFromRatio(float ratio) const {
@ -135,3 +135,13 @@ float GearDetector::getRpmInGear(size_t gear) const {
float GearDetector::getGearboxRatio() const {
return m_gearboxRatio;
}
SensorResult GearDetector::get() const {
return m_currentGear;
}
void GearDetector::showInfo(const char* sensorName) const {
efiPrintf("Sensor \"%s\" is gear detector.", sensorName);
efiPrintf(" Gearbox ratio: %.3f", m_gearboxRatio);
efiPrintf(" Detected gear: %d", m_currentGear);
}

View File

@ -1,6 +1,6 @@
#pragma once
class GearDetector : public EngineModule, public StoredValueSensor {
class GearDetector : public EngineModule, public Sensor {
public:
GearDetector();
~GearDetector();
@ -15,6 +15,9 @@ public:
float getRpmInGear(size_t gear) const;
SensorResult get() const;
void showInfo(const char* sensorName) const;
private:
float computeGearboxRatio() const;
float getDriveshaftRpm() const;