From dad3f8f82ab9f26c83b6a84a1a66e80e5f433791 Mon Sep 17 00:00:00 2001 From: jake Date: Sun, 25 Aug 2024 06:54:18 -0700 Subject: [PATCH] Defined the clear byte function --- src/LedController/LedController.c | 4 ++++ src/LedController/LedController.h | 3 +++ tests/LedController/test_LedController.cpp | 19 +++++++++++++++++++ 3 files changed, 26 insertions(+) diff --git a/src/LedController/LedController.c b/src/LedController/LedController.c index 9eae2eb..e21ae6b 100644 --- a/src/LedController/LedController.c +++ b/src/LedController/LedController.c @@ -50,6 +50,10 @@ void LedController_ShowByte(LedByte *led_byte, uint8_t byte) void LedControler_ClearByte(LedByte *led_byte) { + for (int i = 0; i < 8; i++) + { + LedController_SetLow(&led_byte->leds[i]); + } } void LedController_SetHigh(Led *led) diff --git a/src/LedController/LedController.h b/src/LedController/LedController.h index 9f7d60b..510b8a7 100644 --- a/src/LedController/LedController.h +++ b/src/LedController/LedController.h @@ -35,11 +35,14 @@ LedByte LedController_New(uint8_t *port); /** * Displays the byte of data via led pins. + * @param led_byte A pointer to a LedByte structure. + * @param byte A uint8_t representing the byte to be displayed. */ void LedController_ShowByte(LedByte *led_byte, uint8_t byte); /** * Clears out the byte led representation + * @param led_byte A pointer to the LedByte structure. */ void LedControler_ClearByte(LedByte *led_byte); diff --git a/tests/LedController/test_LedController.cpp b/tests/LedController/test_LedController.cpp index b721854..d1df944 100644 --- a/tests/LedController/test_LedController.cpp +++ b/tests/LedController/test_LedController.cpp @@ -140,3 +140,22 @@ TEST(test_LedController, LedByteDisplayPattern) CHECK_EQUAL(0xAA, fake_port); } + +TEST(test_LedController, ClearingLedByteWorks) +{ + uint8_t fake_port = 0xFF; + LedByte led_byte = LedController_New(&fake_port); + + for(int i = 0; i < 8; i++){ + led_byte.leds[i].state = true; + } + + LedControler_ClearByte(&led_byte); + + for(int i = 0; i < 8; i++){ + CHECK_TRUE(!led_byte.leds[i].state); + /*loop body*/ + } + + CHECK_EQUAL(0x00, fake_port); +}