2022-07-07 20:16:56 -07:00
|
|
|
#pragma once
|
2022-04-06 13:15:58 -07:00
|
|
|
|
2023-04-19 01:20:13 -07:00
|
|
|
class GearDetector : public EngineModule, public Sensor {
|
2022-04-06 13:15:58 -07:00
|
|
|
public:
|
2023-04-01 23:08:06 -07:00
|
|
|
GearDetector();
|
2023-04-01 23:17:50 -07:00
|
|
|
~GearDetector();
|
2023-04-01 23:08:06 -07:00
|
|
|
|
2022-04-06 13:15:58 -07:00
|
|
|
void onSlowCallback() override;
|
2022-04-07 06:21:11 -07:00
|
|
|
void onConfigurationChange(engine_configuration_s const * /*previousConfig*/) override;
|
2022-04-06 13:15:58 -07:00
|
|
|
|
|
|
|
float getGearboxRatio() const;
|
|
|
|
|
2022-04-07 06:21:11 -07:00
|
|
|
// Returns 0 for neutral, 1 for 1st, 5 for 5th, etc.
|
|
|
|
size_t determineGearFromRatio(float ratio) const;
|
|
|
|
|
2022-07-07 20:16:56 -07:00
|
|
|
float getRpmInGear(size_t gear) const;
|
|
|
|
|
2023-10-24 01:23:51 -07:00
|
|
|
SensorResult get() const override;
|
|
|
|
void showInfo(const char* sensorName) const override;
|
2023-04-19 01:20:13 -07:00
|
|
|
|
2022-04-06 13:15:58 -07:00
|
|
|
private:
|
|
|
|
float computeGearboxRatio() const;
|
2022-07-07 20:16:56 -07:00
|
|
|
float getDriveshaftRpm() const;
|
2023-06-04 17:30:46 -07:00
|
|
|
void initGearDetector();
|
2023-06-05 11:34:23 -07:00
|
|
|
bool isInitialized = false;
|
2022-04-06 13:15:58 -07:00
|
|
|
|
|
|
|
float m_gearboxRatio = 0;
|
2022-04-07 06:21:11 -07:00
|
|
|
size_t m_currentGear = 0;
|
|
|
|
|
2023-10-19 09:32:59 -07:00
|
|
|
float m_gearThresholds[TCU_GEAR_COUNT - 1];
|
2022-04-06 13:15:58 -07:00
|
|
|
};
|