From 415780a020d3faea99ed0f08ff4df76222003f36 Mon Sep 17 00:00:00 2001 From: Gabriel Santos <118445638+gabrielsantosphilips@users.noreply.github.com> Date: Tue, 23 Jan 2024 13:02:14 +0100 Subject: [PATCH] chore: update embedded-infra (#111) * changes on touch screen class in order to be aligned with the new interface * embedded-infra commit updated * unit tests fixed * hal-st commit reference updated * embedded-infra commit updated * update emil and hal-st commit hashes * amp-hal-st hash updated --- CMakeLists.txt | 4 +- preview/touch/TouchScreen.cpp | 10 ++-- preview/touch/TouchScreen.hpp | 3 + preview/touch/test/TestTouchScreen.cpp | 80 +++++++++++++++++--------- 4 files changed, 62 insertions(+), 35 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 399b7fa..5f761ce 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -21,7 +21,7 @@ if (PREVIEW_STANDALONE) FetchContent_Declare( emil GIT_REPOSITORY https://github.com/philips-software/amp-embedded-infra-lib - GIT_TAG 8e990e6d88c928b402397e4b453df0829f5f7626 # unreleased + GIT_TAG 419f636bd76f2c0ee2f7524ca548e724bf479e27 # unreleased ) FetchContent_MakeAvailable(emil) @@ -30,7 +30,7 @@ if (PREVIEW_STANDALONE) FetchContent_Declare( halst GIT_REPOSITORY https://github.com/philips-software/amp-hal-st - GIT_TAG 51306ab6abfc10fefb40ff6257d3c9ba766529b8 # unreleased + GIT_TAG c359e609ea3313d2d8fb1e71becca80cc28f34a8 # unreleased ) FetchContent_MakeAvailable(halst) diff --git a/preview/touch/TouchScreen.cpp b/preview/touch/TouchScreen.cpp index 7712d69..9a4082b 100644 --- a/preview/touch/TouchScreen.cpp +++ b/preview/touch/TouchScreen.cpp @@ -29,7 +29,7 @@ namespace services , yPlusAnalogPin(touchScreen.yPlusAnalogPin) , startConversion(std::chrono::microseconds(100), [this]() { - xPlusAnalogPin->Measure([this](PixelPosition pixelPosition) + xPlusAnalogPin->Measure(infra::MakeRangeFromSingleObject(this->pixelPosition), [this]() { OnMeasurementXDone(pixelPosition.Value()); }); @@ -40,7 +40,7 @@ namespace services void TouchScreen::StateTouchMeasurement::OnMeasurementXDone(uint32_t xTouchResult) { this->xTouchResult = xTouchResult; - yPlusAnalogPin->Measure([this](PixelPosition pixelPosition) + yPlusAnalogPin->Measure(infra::MakeRangeFromSingleObject(this->pixelPosition), [this]() { OnMeasurementYDone(pixelPosition.Value()); }); @@ -69,7 +69,7 @@ namespace services , xPlusAnalogPin(touchScreen.xPlusAnalogPin) , startConversion(std::chrono::microseconds(100), [this]() { - xPlusAnalogPin->Measure([this](PixelPosition pixelPosition) + xPlusAnalogPin->Measure(infra::MakeRangeFromSingleObject(this->pixelPosition), [this]() { OnMeasurementDone(pixelPosition.Value()); }); @@ -89,9 +89,9 @@ namespace services , yPlusAnalogPin(touchScreen.yPlusAnalogPin) , startConversion(std::chrono::microseconds(100), [this]() { - yPlusAnalogPin->Measure([this](PixelPosition pixelPosition) + yPlusAnalogPin->Measure(infra::MakeRangeFromSingleObject(this->pixelPosition), [this]() { - OnMeasurementDone(pixelPosition.Value()); + OnMeasurementDone(this->pixelPosition.Value()); }); }) {} diff --git a/preview/touch/TouchScreen.hpp b/preview/touch/TouchScreen.hpp index 56c5f01..ca63794 100644 --- a/preview/touch/TouchScreen.hpp +++ b/preview/touch/TouchScreen.hpp @@ -55,6 +55,7 @@ namespace services infra::TimerSingleShot startConversion; bool finalMeasurement; uint32_t xTouchResult; + PixelPosition pixelPosition; }; class StateXMeasurement @@ -72,6 +73,7 @@ namespace services hal::OutputPin yMinus; infra::ProxyCreator xPlusAnalogPin; infra::TimerSingleShot startConversion; + PixelPosition pixelPosition; }; class StateYMeasurement @@ -89,6 +91,7 @@ namespace services hal::OutputPin xMinus; infra::ProxyCreator yPlusAnalogPin; infra::TimerSingleShot startConversion; + PixelPosition pixelPosition; }; private: diff --git a/preview/touch/test/TestTouchScreen.cpp b/preview/touch/test/TestTouchScreen.cpp index 490df9b..1801399 100644 --- a/preview/touch/test/TestTouchScreen.cpp +++ b/preview/touch/test/TestTouchScreen.cpp @@ -8,7 +8,7 @@ class AnalogToDigitalPinMock : public services::TouchScreen::AnalogToDigitalPin { public: - MOCK_METHOD1(Measure, void(const infra::Function& onDone)); + MOCK_METHOD2(Measure, void(services::TouchScreen::AnalogToDigitalPin::SamplesRange samples, const infra::Function& onDone)); }; class TouchScreenTest @@ -27,11 +27,19 @@ class TouchScreenTest touchScreen.Measure(onResult); - EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); + EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = xTouchResult; + onMeasurementDone = onDone; + }); ForwardTime(std::chrono::microseconds(100)); - EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); - onMeasurementDone(services::TouchScreen::PixelPosition(xTouchResult)); + EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = yTouchResult; + onMeasurementDone = onDone; + }); + onMeasurementDone(); EXPECT_CALL(yMinus, ResetConfig()); EXPECT_CALL(xMinus, ResetConfig()); @@ -42,9 +50,13 @@ class TouchScreenTest EXPECT_CALL(yPlus, Config(hal::PinConfigType::output, true)); EXPECT_CALL(yMinus, Config(hal::PinConfigType::output, false)); - onMeasurementDone(services::TouchScreen::PixelPosition(yTouchResult)); + onMeasurementDone(); - EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); + EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = xResult; + onMeasurementDone = onDone; + }); ForwardTime(std::chrono::microseconds(100)); EXPECT_CALL(yMinus, ResetConfig()); @@ -56,9 +68,13 @@ class TouchScreenTest EXPECT_CALL(xPlus, Config(hal::PinConfigType::output, true)); EXPECT_CALL(xMinus, Config(hal::PinConfigType::output, false)); - onMeasurementDone(services::TouchScreen::PixelPosition(xResult)); + onMeasurementDone(); - EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); + EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = yResult; + onMeasurementDone = onDone; + }); ForwardTime(std::chrono::microseconds(100)); EXPECT_CALL(xMinus, ResetConfig()); @@ -70,13 +86,21 @@ class TouchScreenTest EXPECT_CALL(xMinus, Config(hal::PinConfigType::output, true)); EXPECT_CALL(yMinus, Config(hal::PinConfigType::output, false)); - onMeasurementDone(services::TouchScreen::PixelPosition(yResult)); + onMeasurementDone(); - EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); + EXPECT_CALL(*xPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = yResult; + onMeasurementDone = onDone; + }); ForwardTime(std::chrono::microseconds(100)); - EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_)).WillOnce(testing::SaveArg<0>(&onMeasurementDone)); - onMeasurementDone(services::TouchScreen::PixelPosition(xTouchResult)); + EXPECT_CALL(*yPlusAnalogPin, Measure(testing::_, testing::_)).WillOnce([this](auto samples, const auto& onDone) + { + samples.front() = xTouchResult; + onMeasurementDone = onDone; + }); + onMeasurementDone(); EXPECT_CALL(yMinus, ResetConfig()); EXPECT_CALL(xMinus, ResetConfig()); @@ -91,12 +115,12 @@ class TouchScreenTest infra::Creator yPlusAnalogPin; services::TouchScreen touchScreen; - uint32_t xResult = 0; - uint32_t yResult = 0; - uint32_t xTouchResult = 0; - uint32_t yTouchResult = 0; + services::TouchScreen::PixelPosition xResult{ 0 }; + services::TouchScreen::PixelPosition yResult{ 0 }; + services::TouchScreen::PixelPosition xTouchResult{ 0 }; + services::TouchScreen::PixelPosition yTouchResult{ 0 }; - infra::Function onMeasurementDone; + infra::Function onMeasurementDone; infra::Function position)> onResult = [](infra::Optional position) {}; }; @@ -116,12 +140,12 @@ TEST_F(TouchScreenTest, on_no_touch_none_is_reported) infra::VerifyingFunctionMock)> expectOnResult(infra::none); onResult = expectOnResult; - xTouchResult = 400; - yTouchResult = 100; + xTouchResult = services::TouchScreen::PixelPosition{ 400 }; + yTouchResult = services::TouchScreen::PixelPosition{ 100 }; DoTouchMeasurement(); - onMeasurementDone(services::TouchScreen::PixelPosition(yTouchResult)); + onMeasurementDone(); } TEST_F(TouchScreenTest, after_touch_measurement_is_done_x_measurement_starts) @@ -131,7 +155,7 @@ TEST_F(TouchScreenTest, after_touch_measurement_is_done_x_measurement_starts) EXPECT_CALL(yPlus, Config(hal::PinConfigType::output, true)); EXPECT_CALL(yMinus, Config(hal::PinConfigType::output, false)); - onMeasurementDone(services::TouchScreen::PixelPosition(yTouchResult)); + onMeasurementDone(); EXPECT_CALL(yMinus, ResetConfig()); EXPECT_CALL(yPlus, ResetConfig()); @@ -145,7 +169,7 @@ TEST_F(TouchScreenTest, after_measurement_is_done_y_measurement_starts) EXPECT_CALL(xPlus, Config(hal::PinConfigType::output, true)); EXPECT_CALL(xMinus, Config(hal::PinConfigType::output, false)); - onMeasurementDone(services::TouchScreen::PixelPosition(xResult)); + onMeasurementDone(); EXPECT_CALL(xMinus, ResetConfig()); EXPECT_CALL(xPlus, ResetConfig()); @@ -161,7 +185,7 @@ TEST_F(TouchScreenTest, after_last_measurement_result_is_reported) DoYMeasurement(); DoFinalTouchMeasurement(); - onMeasurementDone(services::TouchScreen::PixelPosition(yTouchResult)); + onMeasurementDone(); } TEST_F(TouchScreenTest, on_touch_position_is_reported) @@ -169,15 +193,15 @@ TEST_F(TouchScreenTest, on_touch_position_is_reported) infra::VerifyingFunctionMock)> expectOnResult(infra::MakeOptional(infra::Point(42, 134))); onResult = expectOnResult; - xResult = 42; - yResult = 134; - xTouchResult = 190; - yTouchResult = 100; + xResult = services::TouchScreen::PixelPosition{ 42 }; + yResult = services::TouchScreen::PixelPosition{ 134 }; + xTouchResult = services::TouchScreen::PixelPosition{ 190 }; + yTouchResult = services::TouchScreen::PixelPosition{ 100 }; DoTouchMeasurement(); DoXMeasurement(); DoYMeasurement(); DoFinalTouchMeasurement(); - onMeasurementDone(services::TouchScreen::PixelPosition(yTouchResult)); + onMeasurementDone(); }