/* * hal.cpp * * Created on: Aug 3, 2016 * Author: Philipp Hinz */ #include #include #include #include #include "hal.h" #include "global.h" #include "logger.h" void halInit(void) { halRelaisOff(RELAIS_HEAT); halRelaisOff(RELAIS_PUMP); halRelaisOff(RELAIS_POWER); pinMode(RELAIS_HEAT, OUTPUT); pinMode(RELAIS_PUMP, OUTPUT); pinMode(RELAIS_POWER, OUTPUT); pinMode(HAL_INT0, INPUT); pinMode(HAL_INT1, INPUT); if (wiringPiISR(HAL_INT0, INT_EDGE_FALLING, &halInt0) < 0) { logger_error("Unable to setup ISR0: %s\n", strerror(errno)); return; } if (wiringPiISR(HAL_INT1, INT_EDGE_FALLING, &halInt1) < 0) { logger_error("Unable to setup ISR1: %s\n", strerror(errno)); return; } } void halRelaisOn(int relais) { halRelaisSet(relais, LOW); } void halRelaisOff(int relais) { halRelaisSet(relais, HIGH); } void halRelaisSet(int relais, int state) { if (state != HIGH && state != LOW) return; switch (relais) { case RELAIS_POWER: case RELAIS_HEAT: case RELAIS_PUMP: digitalWrite(relais, state); break; } } void halInt0(void) { halRelaisOn(RELAIS_POWER); logger(V_BASIC, "Int0 triggered\n"); } void halInt1(void) { halRelaisOff(RELAIS_POWER); logger(V_BASIC, "Int1 triggered\n"); }