diff --git a/src/Relays/Relays.c b/src/Relays/Relays.c index e10ee88..6c468d0 100644 --- a/src/Relays/Relays.c +++ b/src/Relays/Relays.c @@ -6,3 +6,15 @@ */ #include "Relays.h" + +void Relay_MeasureMakeTime(Relay *relay) {} + +void Relay_Enable(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; } diff --git a/src/Relays/Relays.h b/src/Relays/Relays.h index d25b347..136c4c7 100644 --- a/src/Relays/Relays.h +++ b/src/Relays/Relays.h @@ -10,18 +10,20 @@ #ifndef RELAYS #define RELAYS +#include #include /** * Represents an individual relay. */ typedef struct Relay { - uint8_t output_port; + void *output_port; uint8_t output_pin; - uint8_t input_port; + void *input_port; uint8_t input_pin; uint16_t make_time; uint16_t break_time; + bool disabled_fpc; } Relay; /** diff --git a/tests/Relays/test_Relays.cpp b/tests/Relays/test_Relays.cpp index 8dca280..b00396f 100644 --- a/tests/Relays/test_Relays.cpp +++ b/tests/Relays/test_Relays.cpp @@ -12,20 +12,61 @@ extern "C" #include "Relays.h" } +void zero_relay_struct(Relay *relay) +{ + relay->input_pin = 0; + relay->output_pin = 0; + relay->break_time = 0; + relay->make_time = 0; + relay->disabled_fpc = false; + *(uint8_t *)relay->output_port = 0x00; + *(uint8_t *)relay->input_port = 0x00; +} + TEST_GROUP(test_Relays) { + uint8_t fake_input_port; + uint8_t fake_ouput_port; + Relay relay; + void setup() { - + relay.input_port = &fake_input_port; + relay.output_port = &fake_ouput_port; + zero_relay_struct(&relay); } void teardown() { - + fake_input_port = 0x00; + fake_ouput_port = 0x00; } }; -TEST(test_Relays, FirstTest) + +TEST(test_Relays, CreateRelayStruct) { - FAIL("Fail me!"); + CHECK(relay.input_port == &fake_input_port); } +TEST(test_Relays, DisabledForPowerCycleSetsDisabledBit) +{ + Relay_DisableForPowerCycle(&relay); + CHECK_TRUE(relay.disabled_fpc); +} + +TEST(test_Relays, EnableSetsCorrectPinsInPort) +{ + for(uint8_t i = 0; i <= 7; i++) { + zero_relay_struct(&relay); + relay.output_pin = i; + Relay_Enable(&relay); + CHECK_EQUAL((1<