Line | Branch | Decision | Exec | Source |
---|---|---|---|---|
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 | ||||
16 | class ProxySensor final : public Sensor { | |||
17 | public: | |||
18 |
1/1✓ Decision 'true' taken 3 times.
|
3 | explicit ProxySensor(SensorType type) : Sensor(type) {} | |
19 | ||||
20 | 40 | void setProxiedSensor(SensorType proxiedSensor) { | ||
21 | 40 | m_proxiedSensor = proxiedSensor; | ||
22 | 40 | } | ||
23 | ||||
24 | void showInfo(const char* sensorName) const override; | |||
25 | ||||
26 |
1/1✓ Decision 'true' taken 204 times.
|
204 | bool isRedundant() const override { | |
27 | 204 | const Sensor *proxied = getSensorOfType(m_proxiedSensor); | ||
28 |
2/4✓ Branch 0 taken 204 times.
✗ Branch 1 not taken.
✓ Branch 3 taken 204 times.
✗ Branch 4 not taken.
|
204 | return proxied ? proxied->isRedundant() : false; | |
29 | } | |||
30 | ||||
31 | typedef SensorResult (*functionFunctionPtr)(SensorResult); | |||
32 | ||||
33 | 18 | void setConverter(functionFunctionPtr p_converter) { | ||
34 | 18 | converter = p_converter; | ||
35 | 18 | } | ||
36 | ||||
37 | private: | |||
38 | 2 | functionFunctionPtr converter = [](SensorResult arg) { | ||
39 | 2 | return arg; | ||
40 | }; | |||
41 | ||||
42 | 209 | SensorResult get() const override { | ||
43 |
1/1✓ Branch 2 taken 209 times.
|
209 | SensorResult proxiedValue = Sensor::get(m_proxiedSensor); | |
44 |
1/1✓ Branch 1 taken 209 times.
|
418 | return converter(proxiedValue); | |
45 | } | |||
46 | ||||
47 | 214 | bool hasSensor() const override { | ||
48 | // query if the underlying sensor exists | |||
49 | 214 | return Sensor::hasSensor(m_proxiedSensor); | ||
50 | } | |||
51 | ||||
52 | SensorType m_proxiedSensor = SensorType::Invalid; | |||
53 | }; | |||
54 |