Patched with updates from the LOW repo

This commit is contained in:
jakeg00dwin 2024-08-14 13:15:11 -07:00
parent 155c4cce9e
commit 597441b978
1 changed files with 18 additions and 2 deletions

View File

@ -24,6 +24,20 @@
//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) void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
{ {
ADC_Init(adc_pin); ADC_Init(adc_pin);
@ -32,12 +46,13 @@ void Load_HandleLoadPortA(uint8_t adc_pin, uint8_t out_pin)
uint16_t val = ADC_ReadValue(adc_pin); uint16_t val = ADC_ReadValue(adc_pin);
ADC_Disable(); 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.DIR, out_pin);
RegEdit_SetBit((void *) &PORTA.OUT, out_pin); RegEdit_SetBit((void *) &PORTA.OUT, out_pin);
} }
else{ else{
RegEdit_ClearBit((void *) &PORTA.OUT, out_pin); RegEdit_ClearBit((void *) &PORTA.OUT, out_pin);
porta_disabled[adc_pin] = true;
} }
} }
@ -49,11 +64,12 @@ void Load_HandleLoadPortB(uint8_t adc_pin, uint8_t out_pin)
uint16_t val = ADC_ReadValue(adc_pin); uint16_t val = ADC_ReadValue(adc_pin);
ADC_Disable(); 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.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;
} }
} }