fome-fw/firmware/init/sensor/init_fuel_level.cpp

37 lines
1.0 KiB
C++
Raw Normal View History

#include "init.h"
#include "adc_inputs.h"
#include "adc_subscription.h"
#include "engine_configuration.h"
#include "functional_sensor.h"
#include "table_func.h"
EXTERN_CONFIG;
static FunctionalSensor fuelSensor(SensorType::FuelLevel, /* timeout = */ MS2NT(500));
#if !EFI_UNIT_TEST
// extract the type of the elements in the bin/value arrays
using BinType = std::remove_extent_t<decltype(CONFIG(fuelLevelBins))>;
using ValueType = std::remove_extent_t<decltype(CONFIG(fuelLevelValues))>;
static TableFunc
<BinType, ValueType, FUEL_LEVEL_TABLE_COUNT,
// Bins are stored in millivolts
efi::ratio<1, PACK_MULT_VOLTAGE>,
// Values are stored in percent
efi::ratio<1>>
fuelCurve(CONFIG(fuelLevelBins), CONFIG(fuelLevelValues));
void initFuelLevel(DECLARE_CONFIG_PARAMETER_SIGNATURE) {
adc_channel_e channel = CONFIG(fuelLevelSensor);
if (!isAdcChannelValid(channel)) {
return;
}
fuelSensor.setFunction(fuelCurve);
AdcSubscription::SubscribeSensor(fuelSensor, channel, /*lowpassCutoff =*/ 1);
fuelSensor.Register();
}
#endif // ! EFI_UNIT_TEST