From cfdf40bd9c9063bd854a55cd282c7d7c406b4b24 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 25 Aug 2024 06:44:32 -0700 Subject: [PATCH] Wrote code to pass tests for the showbyte function. + Added statment for checking bits for hi/low --- src/LedController/LedController.c | 9 ++++++++- tests/LedController/test_LedController.cpp | 21 +++++++++++++++++++++ 2 files changed, 29 insertions(+), 1 deletion(-) diff --git a/src/LedController/LedController.c b/src/LedController/LedController.c index 91f1f8d..9eae2eb 100644 --- a/src/LedController/LedController.c +++ b/src/LedController/LedController.c @@ -37,7 +37,14 @@ void LedController_ShowByte(LedByte *led_byte, uint8_t byte) { for (int i = 0; i < 8; i++) { - LedController_SetHigh(&led_byte->leds[i]); + if (byte & (1 << i)) + { + LedController_SetHigh(&led_byte->leds[i]); + } + else + { + LedController_SetLow(&led_byte->leds[i]); + } } } diff --git a/tests/LedController/test_LedController.cpp b/tests/LedController/test_LedController.cpp index 599667b..b721854 100644 --- a/tests/LedController/test_LedController.cpp +++ b/tests/LedController/test_LedController.cpp @@ -119,3 +119,24 @@ TEST(test_LedController, LedByteDisplay) CHECK_EQUAL(0xFF, fake_port); } + +TEST(test_LedController, LedByteDisplayPattern) +{ + uint8_t fake_port = 0x00; + uint8_t byte = 0xAA; + LedByte led_byte = LedController_New(&fake_port); + + + LedController_ShowByte(&led_byte, byte); + + for(int i = 0; i < 8; i++){ + if(byte & (1<