Wrote tests and code for PCDisable and relay enable functions.
This commit is contained in:
parent
36108f4108
commit
c440f48f0f
|
@ -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; }
|
||||
|
|
|
@ -10,18 +10,20 @@
|
|||
#ifndef RELAYS
|
||||
#define RELAYS
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
|
||||
/**
|
||||
* 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;
|
||||
|
||||
/**
|
||||
|
|
|
@ -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<<i), *(uint8_t *)relay.output_port);
|
||||
}
|
||||
}
|
||||
|
||||
TEST(test_Relays, EnableDoesNothingOnPCDisabledRelay)
|
||||
{
|
||||
Relay_DisableForPowerCycle(&relay);
|
||||
Relay_Enable(&relay);
|
||||
CHECK_EQUAL(0x00, *(uint8_t *)relay.output_port);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue