diff --git a/firmware/controllers/algo/gear_detector.cpp b/firmware/controllers/algo/gear_detector.cpp index ad7faec728..b2df6a4d7a 100644 --- a/firmware/controllers/algo/gear_detector.cpp +++ b/firmware/controllers/algo/gear_detector.cpp @@ -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); +} diff --git a/firmware/controllers/algo/gear_detector.h b/firmware/controllers/algo/gear_detector.h index b07af8c4af..b5a08843a3 100644 --- a/firmware/controllers/algo/gear_detector.h +++ b/firmware/controllers/algo/gear_detector.h @@ -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;