rusEFI
The most advanced open source ECU
Loading...
Searching...
No Matches
proxy_sensor.h
Go to the documentation of this file.
1/**
2 * @file proxy_sensor.h
3 * @brief A sensor to duplicate a sensor to an additional SensorType.
4 *
5 * This was built for the use case of "driver throttle intent" where we care what the driver's
6 * right foot is doing, but that might mean TPS (cable throttle) or pedal (electronic throttle).
7 *
8 * @date March 22, 2020
9 * @author Matthew Kennedy, (c) 2019
10 */
11
12#pragma once
13
14#include "sensor.h"
15
16class ProxySensor final : public Sensor {
17public:
19
20 void setProxiedSensor(SensorType proxiedSensor) {
21 m_proxiedSensor = proxiedSensor;
22 }
23
24 void showInfo(const char* sensorName) const override;
25
26 bool isRedundant() const override {
27 const Sensor *proxied = getSensorOfType(m_proxiedSensor);
28 return proxied ? proxied->isRedundant() : false;
29 }
30
32
34 converter = p_converter;
35 }
36
37private:
39 return arg;
40 };
41
42 SensorResult get() const override {
44 return converter(proxiedValue);
45 }
46
47 bool hasSensor() const override {
48 // query if the underlying sensor exists
50 }
51
53};
SensorResult(* functionFunctionPtr)(SensorResult)
void setConverter(functionFunctionPtr p_converter)
void showInfo(const char *sensorName) const override
void setProxiedSensor(SensorType proxiedSensor)
bool hasSensor() const override
SensorResult get() const override
ProxySensor(SensorType type)
bool isRedundant() const override
functionFunctionPtr converter
SensorType m_proxiedSensor
static bool isRedundant(SensorType type)
Definition sensor.cpp:183
virtual bool hasSensor() const
Definition sensor.h:141
static const Sensor * getSensorOfType(SensorType type)
Definition sensor.cpp:158
virtual SensorResult get() const =0
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