diff --git a/src/load/load.c b/src/load/load.c index 6343875..7d4d01a 100644 --- a/src/load/load.c +++ b/src/load/load.c @@ -22,6 +22,18 @@ #include "MockRegEdit.h" #endif +//These two arrays allow us to track the A and B ports to know when +//one has been disabled before. +static bool porta_disabled[8] = {0}; +static bool portb_disabled[8] = {0}; + +static bool valid_load(uint16_t val) +{ + if(val > 527 && val < 1000) { + return true; + } + return false; +} void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin) @@ -32,12 +44,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin) uint16_t val = ADC_ReadValue(adc_pin); ADC_Disable(); - if(val > 527 && val < 1000){ + if(valid_load(val) && !porta_disabled[adc_pin]){ RegEdit_SetBit((void *) &PORTA.DIR, out_pin); RegEdit_SetBit((void *) &PORTA.OUT, out_pin); } else{ RegEdit_ClearBit((void *) &PORTA.OUT, out_pin); + porta_disabled[adc_pin] = true; } } @@ -49,11 +62,12 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin) uint16_t val = ADC_ReadValue(adc_pin); ADC_Disable(); - if(val > 527 && val < 1000){ + if(valid_load(val) && !portb_disabled[adc_pin]){ RegEdit_SetBit((void *) &PORTB.DIR, out_pin); RegEdit_SetBit((void *) &PORTB.OUT, out_pin); } else{ RegEdit_ClearBit((void *) &PORTB.OUT, out_pin); + portb_disabled[adc_pin] = true; } } diff --git a/tests/load/test_load.cpp b/tests/load/test_load.cpp index 72fd3a9..3bdcc7e 100644 --- a/tests/load/test_load.cpp +++ b/tests/load/test_load.cpp @@ -47,10 +47,15 @@ TEST(test_load, PortAHandlerSuccess) mock().expectOneCall("ADC_Enable"); mock().expectOneCall("ADC_ReadValue_Impl") .withUnsignedIntParameter("pin_num", 4); + mock().expectOneCall("ADC_Disable"); + mock().expectOneCall("RegEdit_ClearBit") .withPointerParameter("reg", (void *) &PORTA.OUT) .withUnsignedIntParameter("bit_num", 7); Load_HandleLoadPortA(4, 7); } + + +//Need to setup a one-shot or way for it to only enable once.