Make pumps initialization and actuation more dynamic by checking which one are declared in config.h
This commit is contained in:
@@ -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]);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user