Make pumps initialization and actuation more dynamic by checking which one are declared in config.h

This commit is contained in:
2025-05-17 13:01:33 +02:00
parent 8ad766c377
commit d6bd1932d3
2 changed files with 46 additions and 14 deletions
+15 -13
View File
@@ -1,30 +1,32 @@
#include <stdint.h>
#include <avr/io.h>
#include <avr/interrupt.h>
#include "pump.h"
#include "config.h"
void pumpsInit(void) {
// Set as input
DDRD &= ~((1 << PUMP_D7) |
(1 << PUMP_D6) |
(1 << PUMP_D5) |
(1 << PUMP_D4) |
(1 << PUMP_D3) |
0 | 0 | 0 );
uint8_t actuatorMask = 0;
for (uint8_t i = 0; i < ACTUATORS_NUM; i++) {
actuatorMask |= (1 << actuatorPins[i]);
}
DDRD |= actuatorMask;
}
void triggerPump(int8_t pump_pin, int16_t milliseconds) {
void triggerPump(int8_t pump_pin) {
// Turn on pump
PORTD |= (1 << pump_pin);
// timer for n milliseconds
// NOTE: watchout for overflows!! create a safety net.
// timer for a fixed n milliseconds
// hardcoded for now
// Turn off pump
//PORTD &= ~(1 << pump_pin);
PORTD &= ~(1 << pump_pin);
}
void waterPlant(void) {
//for each pump --> turn em on
//better to have it here as function instead of doing it in main
for (int i=0; i < ACTUATORS_NUM; i++) {
triggerPump(actuatorPins[i]);
}
}