register/unregister

This commit is contained in:
Matthew Kennedy 2023-04-01 23:17:50 -07:00
parent 9be0f63235
commit c682c49d46
3 changed files with 7 additions and 1 deletions

View File

@ -7,6 +7,11 @@ static constexpr float geometricMean(float x, float y) {
GearDetector::GearDetector() GearDetector::GearDetector()
: StoredValueSensor(SensorType::DetectedGear, MS2NT(100)) : StoredValueSensor(SensorType::DetectedGear, MS2NT(100))
{ {
Register();
}
GearDetector::~GearDetector() {
unregister();
} }
void GearDetector::onConfigurationChange(engine_configuration_s const * /*previousConfig*/) { void GearDetector::onConfigurationChange(engine_configuration_s const * /*previousConfig*/) {

View File

@ -3,6 +3,7 @@
class GearDetector : public EngineModule, public StoredValueSensor { class GearDetector : public EngineModule, public StoredValueSensor {
public: public:
GearDetector(); GearDetector();
~GearDetector();
void onSlowCallback() override; void onSlowCallback() override;
void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override; void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override;

View File

@ -12,7 +12,7 @@ float GetGearRatioFor(float revPerKm, float axle, float kph, float rpm) {
GearDetector dut; GearDetector dut;
dut.onSlowCallback(); dut.onSlowCallback();
return dut.get().value_or(0); return Sensor::getOrZero(SensorType::DetectedGear);
} }
TEST(GearDetector, ComputeGearRatio) { TEST(GearDetector, ComputeGearRatio) {