diff --git a/drivers/CoreVideo/include/CoreLCDDriverOTM8009A.hpp b/drivers/CoreVideo/include/CoreLCDDriverOTM8009A.hpp index c9b97ce528..dfc88643ab 100644 --- a/drivers/CoreVideo/include/CoreLCDDriverOTM8009A.hpp +++ b/drivers/CoreVideo/include/CoreLCDDriverOTM8009A.hpp @@ -30,6 +30,8 @@ class CoreLCDDriverOTM8009A : public interface::LCDDriver private: interface::DSIBase &_dsi; mbed::PwmOut _backlight; + + float _previous_brightness_value = {0.F}; }; namespace lcd::otm8009a { diff --git a/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp b/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp index 86e2ab7656..441d0c5cbd 100644 --- a/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp +++ b/drivers/CoreVideo/source/CoreLCDDriverOTM8009A.cpp @@ -15,16 +15,22 @@ using namespace lcd::otm8009a; void CoreLCDDriverOTM8009A::turnOn() { _dsi.write(display::turn_on::array, std::size(display::turn_on::array)); + setBrightness(_previous_brightness_value); } void CoreLCDDriverOTM8009A::turnOff() { _dsi.write(display::turn_off::array, std::size(display::turn_off::array)); + setBrightness(0.F); } void CoreLCDDriverOTM8009A::setBrightness(float value) { _backlight.write(value); + + if (value != 0.F) { + _previous_brightness_value = value; + } } void CoreLCDDriverOTM8009A::initialize() diff --git a/drivers/CoreVideo/tests/CoreLCDDriverOTM8009A_test.cpp b/drivers/CoreVideo/tests/CoreLCDDriverOTM8009A_test.cpp index 3fbe816f7e..5c7f13a14c 100644 --- a/drivers/CoreVideo/tests/CoreLCDDriverOTM8009A_test.cpp +++ b/drivers/CoreVideo/tests/CoreLCDDriverOTM8009A_test.cpp @@ -92,3 +92,23 @@ TEST_F(CoreOTM8009ATest, setBrightness) ASSERT_EQ(spy_PwmOut_getValue(), 0.5); } + +TEST_F(CoreOTM8009ATest, setBrightnessTurnOffThenTurnOn) +{ + auto initial_brightness_value = 0.4F; + + otm.setBrightness(initial_brightness_value); + + EXPECT_EQ(spy_PwmOut_getValue(), initial_brightness_value); + + EXPECT_CALL(dsimock, write).Times(1); + otm.turnOff(); + + EXPECT_EQ(spy_PwmOut_getValue(), 0); + EXPECT_NE(spy_PwmOut_getValue(), initial_brightness_value); + + EXPECT_CALL(dsimock, write).Times(1); + otm.turnOn(); + + EXPECT_EQ(spy_PwmOut_getValue(), initial_brightness_value); +}