Wrote code to pass tests for the showbyte function.

+ Added statment for checking bits for hi/low
This commit is contained in:
Jake Goodwin 2024-08-25 06:44:32 -07:00
parent 9fc9e43cd6
commit cfdf40bd9c
2 changed files with 29 additions and 1 deletions

View File

@ -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]);
}
}
}

View File

@ -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<<i)) {
CHECK_TRUE(led_byte.leds[i].state);
}
else {
CHECK_TRUE(!led_byte.leds[i].state);
}
}
CHECK_EQUAL(0xAA, fake_port);
}