fome-fw/firmware/controllers/sensors/converters/table_func.h

35 lines
905 B
C
Raw Normal View History

/**
* @author Matthew Kennedy, (c) 2021
*
* A function to convert input voltage output value based on a 2d table.
*/
#pragma once
#include "sensor_converter_func.h"
#include "interpolation.h"
#include "efi_ratio.h"
template <class TBin, class TValue, int TSize, typename TInputScale = efi::ratio<1>, typename TOutputScale = efi::ratio<1>>
class TableFunc final : public SensorConverter {
public:
TableFunc(TBin (&bins)[TSize], TValue (&values)[TSize])
: m_bins(bins)
, m_values(values)
{
}
SensorResult convert(float inputValue) const override {
// Multiply by the reciprocal instead of dividing
inputValue = inputValue * TInputScale::recip::asFloat();
return interpolate2d(inputValue, m_bins, m_values) * TOutputScale::asFloat();
}
void showInfo(Logging* /*logger*/, float /*testInputValue*/) const override { }
private:
TBin (&m_bins)[TSize];
TValue (&m_values)[TSize];
};