Wrote tests ensuring correct bit checking and then code to pass it for the reading of input.
This commit is contained in:
parent
307ae22aa8
commit
069ab127bf
|
@ -7,8 +7,24 @@
|
|||
|
||||
#include "Relays.h"
|
||||
|
||||
/*
|
||||
static void WaitForRelayConnect(void) {
|
||||
while (!(PORTA.IN & RELAYREADINGPIN)) {
|
||||
;
|
||||
}
|
||||
}
|
||||
|
||||
static void WaitForRelayDisconnect(void) {
|
||||
while (PORTA.IN & RELAYREADINGPIN) {
|
||||
;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
void Relay_MeasureMakeTime(Relay *relay) {}
|
||||
|
||||
void Relay_MeasureBreakTime(Relay *relay) {}
|
||||
|
||||
void Relay_Enable(Relay *relay) {
|
||||
if (relay->disabled_fpc) {
|
||||
return;
|
||||
|
@ -25,6 +41,11 @@ void Relay_Disable(Relay *relay) {
|
|||
(*(uint8_t *)relay->output_port) &= ~(1 << (relay->output_pin));
|
||||
}
|
||||
|
||||
|
||||
|
||||
void Relay_DisableForPowerCycle(Relay *relay) { relay->disabled_fpc = true; }
|
||||
|
||||
bool Relay_ReadState(Relay *relay) {
|
||||
if (*(uint8_t *)relay->input_port & (1 << relay->input_pin)) {
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -63,4 +63,10 @@ void Relay_Disable(Relay *relay);
|
|||
*/
|
||||
void Relay_DisableForPowerCycle(Relay *relay);
|
||||
|
||||
/**
|
||||
* Reads the relay's input pin on the input port.
|
||||
* @return True for enabled false for disabled relays.
|
||||
*/
|
||||
bool Relay_ReadState(Relay *relay);
|
||||
|
||||
#endif // RELAYS
|
||||
|
|
|
@ -112,8 +112,15 @@ TEST(test_Relays, ReadStateOfEnabledRelayReadsTrue)
|
|||
for(uint8_t i = 0; i <= 7; i++){
|
||||
zero_relay_struct(&relay);
|
||||
relay.input_pin = i;
|
||||
Relay_Enable(&relay);
|
||||
*(uint8_t *)relay.input_port |= (1<<i);
|
||||
CHECK_TRUE(Relay_ReadState(&relay));
|
||||
}
|
||||
|
||||
//Ensures that it's accounting for bit number.
|
||||
for(uint8_t i = 0; i <= 7; i++){
|
||||
zero_relay_struct(&relay);
|
||||
relay.input_pin = 7 - i;
|
||||
*(uint8_t *)relay.input_port |= (1<<i);
|
||||
CHECK_FALSE(Relay_ReadState(&relay));
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue