diff --git a/drivers/CoreTouchSensor/include/CoreTouchSensor.h b/drivers/CoreTouchSensor/include/CoreTouchSensor.h index 678cd51fec..33e42d8d6c 100644 --- a/drivers/CoreTouchSensor/include/CoreTouchSensor.h +++ b/drivers/CoreTouchSensor/include/CoreTouchSensor.h @@ -15,6 +15,9 @@ namespace leka { class CoreTouchSensor : public interface::TouchSensor { public: + static constexpr auto default_max_sensitivity_value = uint16_t {0x0FFF}; + static constexpr auto default_min_sensitivity_value = uint16_t {0x0000}; + explicit CoreTouchSensor(mbed::interface::DigitalIn &detect_pin, mbed::interface::DigitalOut &power_mode_pin, interface::QDAC &dac, Channel channel) : _detect_pin(detect_pin), _power_mode_pin(power_mode_pin), _sensitivity_pin({dac, channel}) {}; @@ -22,7 +25,6 @@ class CoreTouchSensor : public interface::TouchSensor auto read() -> bool final; void reset() final; void setSensitivity(uint16_t value, bool saved = false) final; - auto getState() -> bool final; private: enum class PowerMode : uint8_t diff --git a/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp b/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp index e3afa4d3a4..df8e7f8c46 100644 --- a/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp +++ b/drivers/CoreTouchSensor/source/CoreTouchSensor.cpp @@ -6,6 +6,8 @@ #include "rtos/ThisThread.h" +#include "MathUtils.h" + using namespace leka; using namespace std::chrono_literals; @@ -25,14 +27,17 @@ auto CoreTouchSensor::read() -> bool void CoreTouchSensor::reset() { setPowerMode(PowerMode::low); - rtos::ThisThread::sleep_for(10ms); + rtos::ThisThread::sleep_for(1ms); setPowerMode(PowerMode::normal); - rtos::ThisThread::sleep_for(10ms); + rtos::ThisThread::sleep_for(1ms); } void CoreTouchSensor::setSensitivity(uint16_t value, bool saved) { - _sensitivity_pin.dac.write(_sensitivity_pin.channel, value, saved); + auto inverted_value = + utils::math::map(value, default_min_sensitivity_value, default_max_sensitivity_value, + default_max_sensitivity_value, default_min_sensitivity_value); + _sensitivity_pin.dac.write(_sensitivity_pin.channel, inverted_value, saved); } void CoreTouchSensor::setPowerMode(PowerMode power_mode) @@ -40,8 +45,3 @@ void CoreTouchSensor::setPowerMode(PowerMode power_mode) auto pm = static_cast(power_mode); _power_mode_pin.write(pm); } - -auto CoreTouchSensor::getState() -> bool -{ - return _state; -} diff --git a/drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp b/drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp index 8b267053f6..607090a08a 100644 --- a/drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp +++ b/drivers/CoreTouchSensor/tests/CoreTouchSensor_test.cpp @@ -6,6 +6,7 @@ #include "IOKit/DigitalIn.h" #include "IOKit/DigitalOut.h" +#include "MathUtils.h" #include "gmock/gmock.h" #include "gtest/gtest.h" #include "mocks/leka/CoreI2C.h" @@ -74,14 +75,10 @@ TEST_F(CoreTouchSensorTest, reset) TEST_F(CoreTouchSensorTest, setSensitivity) { - EXPECT_CALL(dac, write(channel, 0x0ABC, false)).Times(1); - auto value = 0x0ABC; + auto value = 0x0ABC; + auto expected_value = utils::math::map( + value, CoreTouchSensor::default_min_sensitivity_value, CoreTouchSensor::default_max_sensitivity_value, + CoreTouchSensor::default_max_sensitivity_value, CoreTouchSensor::default_min_sensitivity_value); + EXPECT_CALL(dac, write(channel, expected_value, false)).Times(1); sensor.setSensitivity(value); } - -TEST_F(CoreTouchSensorTest, getState) -{ - auto expected_state = false; - auto state = sensor.getState(); - EXPECT_EQ(expected_state, state); -} diff --git a/include/interface/drivers/TouchSensor.h b/include/interface/drivers/TouchSensor.h index ed88f633fa..bd2f347616 100644 --- a/include/interface/drivers/TouchSensor.h +++ b/include/interface/drivers/TouchSensor.h @@ -16,7 +16,6 @@ class TouchSensor virtual auto read() -> bool = 0; virtual void reset() = 0; virtual void setSensitivity(uint16_t value, bool saved = false) = 0; - virtual auto getState() -> bool = 0; }; } // namespace leka::interface