Skip to content

Commit

Permalink
minor simplification to TableFunc template params
Browse files Browse the repository at this point in the history
  • Loading branch information
mck1117 committed Sep 26, 2024
1 parent 0f1843f commit 2c7a902
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 22 deletions.
4 changes: 2 additions & 2 deletions firmware/controllers/sensors/converters/table_func.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

#include <rusefi/interpolation.h>

template <class TBin, class TValue, int TSize, typename TOutputScale = efi::ratio<1>>
template <class TBin, class TValue, size_t TSize>
class TableFunc final : public SensorConverter {
public:
TableFunc(TBin (&bins)[TSize], TValue (&values)[TSize])
Expand All @@ -21,7 +21,7 @@ class TableFunc final : public SensorConverter {
}

SensorResult convert(float inputValue) const override {
return interpolate2d(inputValue, m_bins, m_values) * TOutputScale::asFloat();
return interpolate2d(inputValue, m_bins, m_values);
}

void showInfo(float /*testInputValue*/) const override { }
Expand Down
6 changes: 1 addition & 5 deletions firmware/init/sensor/init_fuel_level.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,7 @@ static FunctionalSensor fuelSensor(SensorType::FuelLevel, /* timeout = */ MS2NT(
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,
// Values are stored in percent
efi::ratio<1>>
fuelCurve(config->fuelLevelBins, config->fuelLevelValues);
static TableFunc fuelCurve(config->fuelLevelBins, config->fuelLevelValues);

void initFuelLevel() {
adc_channel_e channel = engineConfiguration->fuelLevelSensor;
Expand Down
15 changes: 0 additions & 15 deletions unit_tests/tests/sensor/table_func.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,3 @@ TEST(TableFuncTest, basic) {
EXPECT_EQ(40, dut.convert(10).value_or(0));
EXPECT_EQ(40, dut.convert(20).value_or(0));
}

TEST(TableFuncTest, scaled) {
scaled_channel<uint16_t, 1000> in[] = { 0, 1, 2 };
uint8_t out[] = { 70, 60, 50 };

using BinType = std::remove_extent_t<decltype(in)>;

TableFunc<BinType, uint8_t, 3,
// output units are 1/100
efi::ratio<1, 100>>
dut(in, out);

EXPECT_EQ(0.65f, dut.convert(0.5f).value_or(0));
EXPECT_EQ(0.55f, dut.convert(1.5f).value_or(0));
}

0 comments on commit 2c7a902

Please sign in to comment.