rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
function_pointer_sensor.h
Go to the documentation of this file.
1/**
2 * @file function_pointer_sensor.h
3 * @brief A sensor to provide a bridge from old getX()-style functions to the new sensor registry.
4 *
5 * @date September 12, 2019
6 * @author Matthew Kennedy, (c) 2019
7 */
8
9#pragma once
10
11#include "sensor.h"
12
13/* This class is intended as a bridge to bridge from old getMySensor() functions
14 * to the new system. This way, producers and consumers can be independently
15 * updated to the new system, with sensors being usable either way for some time.
16 */
17class FunctionPointerSensor final : public Sensor {
18public:
20 : Sensor(type)
21 , m_func(func) {}
22
23 SensorResult get() const final {
24 float result = m_func();
25
26 // check for NaN
27 bool valid = !(result != result);
28
29 if (!valid) {
30 return unexpected;
31 }
32
33 return result;
34 }
35
36 void showInfo(const char* /*sensorName*/) const override {}
37
38private:
40};
SensorResult get() const final
FunctionPointerSensor(SensorType type, float(*func)())
void showInfo(const char *) const override
SensorType type() const
Definition sensor.h:162
Base class for sensors. Inherit this class to implement a new type of sensor.
expected< float > SensorResult
Definition sensor.h:46
SensorType
Definition sensor_type.h:18