Updated `Load_HandleLoadPortB()` to pass new tests.

This commit is contained in:
jakeg00dwin 2024-09-23 12:57:21 -07:00
parent bd2f396bac
commit 3b9845487c
1 changed files with 8 additions and 3 deletions

View File

@ -79,13 +79,18 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin) void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
{ {
uint16_t val = sample_adc(adc_pin); uint16_t val = sample_adc(adc_pin);
if(portb_disabled[adc_pin]){
if(is_valid_load(val) && !portb_disabled[adc_pin]){ RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
}
else if(!is_valid_load(val)){
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
portb_disabled[adc_pin] = true;
}
else if(is_below_target(val)) {
RegEdit_SetBit((void *) &PORTB.DIR, out_pin); RegEdit_SetBit((void *) &PORTB.DIR, out_pin);
RegEdit_SetBit((void *) &PORTB.OUT, out_pin); RegEdit_SetBit((void *) &PORTB.OUT, out_pin);
} }
else{ else{
RegEdit_ClearBit((void *) &PORTB.OUT, out_pin); RegEdit_ClearBit((void *) &PORTB.OUT, out_pin);
portb_disabled[adc_pin] = true;
} }
} }