Skip to content

Commit

Permalink
chore: update embedded-infra (#111)
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
gabrielsantosphilips authored Jan 23, 2024
1 parent e20e9e2 commit 415780a
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 35 deletions.
4 changes: 2 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
10 changes: 5 additions & 5 deletions preview/touch/TouchScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
});
Expand All @@ -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());
});
Expand Down Expand Up @@ -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());
});
Expand All @@ -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());
});
})
{}
Expand Down
3 changes: 3 additions & 0 deletions preview/touch/TouchScreen.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ namespace services
infra::TimerSingleShot startConversion;
bool finalMeasurement;
uint32_t xTouchResult;
PixelPosition pixelPosition;
};

class StateXMeasurement
Expand All @@ -72,6 +73,7 @@ namespace services
hal::OutputPin yMinus;
infra::ProxyCreator<AnalogToDigitalPin, void()> xPlusAnalogPin;
infra::TimerSingleShot startConversion;
PixelPosition pixelPosition;
};

class StateYMeasurement
Expand All @@ -89,6 +91,7 @@ namespace services
hal::OutputPin xMinus;
infra::ProxyCreator<AnalogToDigitalPin, void()> yPlusAnalogPin;
infra::TimerSingleShot startConversion;
PixelPosition pixelPosition;
};

private:
Expand Down
80 changes: 52 additions & 28 deletions preview/touch/test/TestTouchScreen.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ class AnalogToDigitalPinMock
: public services::TouchScreen::AnalogToDigitalPin
{
public:
MOCK_METHOD1(Measure, void(const infra::Function<void(services::TouchScreen::PixelPosition pixelPosition)>& onDone));
MOCK_METHOD2(Measure, void(services::TouchScreen::AnalogToDigitalPin::SamplesRange samples, const infra::Function<void()>& onDone));
};

class TouchScreenTest
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -91,12 +115,12 @@ class TouchScreenTest
infra::Creator<services::TouchScreen::AnalogToDigitalPin, AnalogToDigitalPinMock, void()> 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<void(services::TouchScreen::PixelPosition pixelPosition)> onMeasurementDone;
infra::Function<void()> onMeasurementDone;
infra::Function<void(infra::Optional<infra::Point> position)> onResult = [](infra::Optional<infra::Point> position) {};
};

Expand All @@ -116,12 +140,12 @@ TEST_F(TouchScreenTest, on_no_touch_none_is_reported)
infra::VerifyingFunctionMock<void(infra::Optional<infra::Point>)> 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)
Expand All @@ -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());
Expand All @@ -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());
Expand All @@ -161,23 +185,23 @@ 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)
{
infra::VerifyingFunctionMock<void(infra::Optional<infra::Point>)> 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();
}

0 comments on commit 415780a

Please sign in to comment.