mirror of https://github.com/FOME-Tech/fome-fw.git
remove functionpointer sensor (#442)
* remove functionpointer sensor * remove function_pointer_sensor.cpp from tests.mk
This commit is contained in:
parent
8336187eeb
commit
cd38fa1f61
|
@ -1,40 +0,0 @@
|
|||
/**
|
||||
* @file function_pointer_sensor.h
|
||||
* @brief A sensor to provide a bridge from old getX()-style functions to the new sensor registry.
|
||||
*
|
||||
* @date September 12, 2019
|
||||
* @author Matthew Kennedy, (c) 2019
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "sensor.h"
|
||||
|
||||
/* This class is intended as a bridge to bridge from old getMySensor() functions
|
||||
* to the new system. This way, producers and consumers can be independently
|
||||
* updated to the new system, with sensors being usable either way for some time.
|
||||
*/
|
||||
class FunctionPointerSensor final : public Sensor {
|
||||
public:
|
||||
FunctionPointerSensor(SensorType type, float (*func)())
|
||||
: Sensor(type)
|
||||
, m_func(func) {}
|
||||
|
||||
SensorResult get() const final {
|
||||
float result = m_func();
|
||||
|
||||
// check for NaN
|
||||
bool valid = !(result != result);
|
||||
|
||||
if (!valid) {
|
||||
return unexpected;
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
void showInfo(const char* /*sensorName*/) const override {}
|
||||
|
||||
private:
|
||||
float (*m_func)();
|
||||
};
|
|
@ -1,27 +0,0 @@
|
|||
#include "pch.h"
|
||||
|
||||
#include "function_pointer_sensor.h"
|
||||
|
||||
class SensorFunctionPointer : public ::testing::Test {
|
||||
protected:
|
||||
void SetUp() override {
|
||||
Sensor::resetRegistry();
|
||||
}
|
||||
|
||||
void TearDown() override {
|
||||
Sensor::resetRegistry();
|
||||
}
|
||||
};
|
||||
|
||||
float testFunc() {
|
||||
return 23;
|
||||
}
|
||||
|
||||
TEST_F(SensorFunctionPointer, TestValue) {
|
||||
FunctionPointerSensor dut(SensorType::Clt, testFunc);
|
||||
ASSERT_TRUE(dut.Register());
|
||||
|
||||
auto result = Sensor::get(SensorType::Clt);
|
||||
EXPECT_TRUE(result.Valid);
|
||||
EXPECT_FLOAT_EQ(result.Value, 23);
|
||||
}
|
|
@ -79,7 +79,6 @@ TESTS_SRC_CPP = \
|
|||
tests/test_lambda_monitor.cpp \
|
||||
tests/sensor/basic_sensor.cpp \
|
||||
tests/sensor/func_sensor.cpp \
|
||||
tests/sensor/function_pointer_sensor.cpp \
|
||||
tests/sensor/mock_sensor.cpp \
|
||||
tests/sensor/sensor_reader.cpp \
|
||||
tests/sensor/lin_func.cpp \
|
||||
|
|
Loading…
Reference in New Issue