hal.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. /*
  2. * hal.cpp
  3. *
  4. * Created on: Aug 3, 2016
  5. * Author: Philipp Hinz
  6. */
  7. #include <wiringPi.h>
  8. #include <stdlib.h>
  9. #include <errno.h>
  10. #include <string.h>
  11. #include "hal.h"
  12. #include "global.h"
  13. #include "logger.h"
  14. void halInit(void) {
  15. halRelaisOff(RELAIS_HEAT);
  16. halRelaisOff(RELAIS_PUMP);
  17. halRelaisOff(RELAIS_POWER);
  18. pinMode(RELAIS_HEAT, OUTPUT);
  19. pinMode(RELAIS_PUMP, OUTPUT);
  20. pinMode(RELAIS_POWER, OUTPUT);
  21. pinMode(HAL_INT0, INPUT);
  22. pinMode(HAL_INT1, INPUT);
  23. if (wiringPiISR(HAL_INT0, INT_EDGE_FALLING, &halInt0) < 0) {
  24. logger_error("Unable to setup ISR0: %s\n", strerror(errno));
  25. return;
  26. }
  27. if (wiringPiISR(HAL_INT1, INT_EDGE_FALLING, &halInt1) < 0) {
  28. logger_error("Unable to setup ISR1: %s\n", strerror(errno));
  29. return;
  30. }
  31. }
  32. void halRelaisOn(int relais) {
  33. halRelaisSet(relais, LOW);
  34. }
  35. void halRelaisOff(int relais) {
  36. halRelaisSet(relais, HIGH);
  37. }
  38. void halRelaisSet(int relais, int state) {
  39. if (state != HIGH && state != LOW)
  40. return;
  41. switch (relais) {
  42. case RELAIS_POWER:
  43. case RELAIS_HEAT:
  44. case RELAIS_PUMP:
  45. digitalWrite(relais, state);
  46. break;
  47. }
  48. }
  49. void halInt0(void) {
  50. halRelaisOn(RELAIS_POWER);
  51. logger(V_BASIC, "Int0 triggered\n");
  52. }
  53. void halInt1(void) {
  54. halRelaisOff(RELAIS_POWER);
  55. logger(V_BASIC, "Int1 triggered\n");
  56. }