From e3cd70448ba099d711023bc1b5ecb0455faf20c8 Mon Sep 17 00:00:00 2001 From: jakeg00dwin Date: Tue, 3 Sep 2024 16:42:02 -0700 Subject: [PATCH] Added function for setting up relays and called it in the `main()` --- src/main.c | 24 +++++++++++++++++------- 1 file changed, 17 insertions(+), 7 deletions(-) diff --git a/src/main.c b/src/main.c index 5816d94..776be6b 100644 --- a/src/main.c +++ b/src/main.c @@ -33,17 +33,27 @@ #define RELAY2_ENPIN (1 << 2) // PORTB #define RELAY2_INPIN (1 << 0) // PORTB +#define N_RELAYS 3 + // Set the function pointer for the delay func void (*Delay_MicroSeconds)(double us) = _delay_us; -int main(int argc, char **argv) { - Relay relay_array[3]; +void setup_relays(Relay *arr) { + // setup the first relay + arr[0].output_port = &PORTA.OUT; + arr[0].output_pin = RELAY0_ENPIN; + arr[0].input_port = &PORTA.IN; + arr[0].input_pin = RELAY0_INPIN; - // setup for the first relay - relay_array[0].output_port = PORTA.OUT; - relay_array[0].output_pin = RELAY0_ENPIN; - relay_array[0].input_port = PORTA.IN; - relay_array[0].input_pin = RELAY0_INPIN; + for (int i = 0; i < N_RELAYS; i++) { + Relay_MeasureMakeTime(&arr[0]); + Relay_MeasureBreakTime(&arr[0]); + } +} + +int main(int argc, char **argv) { + Relay relay_array[N_RELAYS]; + setup_relays(relay_array); // Setup for Infinite Loop SuperLoop_SetIterations(0);