Wrote tests and code for disabling relays

This commit is contained in:
jakeg00dwin 2024-09-01 13:18:46 -07:00
parent c440f48f0f
commit fe20ad2fb0
2 changed files with 29 additions and 0 deletions

View File

@ -17,4 +17,12 @@ void Relay_Enable(Relay *relay) {
(*(uint8_t *)relay->output_port) |= (1 << (relay->output_pin));
}
void Relay_Disable(Relay *relay) {
if (relay->disabled_fpc) {
return;
}
(*(uint8_t *)relay->output_port) &= ~(1 << (relay->output_pin));
}
void Relay_DisableForPowerCycle(Relay *relay) { relay->disabled_fpc = true; }

View File

@ -70,3 +70,24 @@ TEST(test_Relays, EnableDoesNothingOnPCDisabledRelay)
Relay_Enable(&relay);
CHECK_EQUAL(0x00, *(uint8_t *)relay.output_port);
}
TEST(test_Relays, DisableClearsCorrectPinsInPort)
{
for(uint8_t i = 0; i <= 7; i++) {
zero_relay_struct(&relay);
*(uint8_t *)relay.output_port = 0xFF;
relay.output_pin = i;
Relay_Disable(&relay);
CHECK_EQUAL(0xFF & ~(1<<i), *(uint8_t *)relay.output_port);
}
}
TEST(test_Relays, DisableDoesNothingOnPCDisabledRelay)
{
Relay_DisableForPowerCycle(&relay);
*(uint8_t *)relay.output_port = 0xFF;
Relay_Disable(&relay);
CHECK_EQUAL(0xFF, *(uint8_t *)relay.output_port);
}