Переглянути джерело

created hal layer with first functions for relais and interrupt buttons

Philipp Hinz 9 роки тому
батько
коміт
3d6e51fc97
3 змінених файлів з 90 додано та 0 видалено
  1. 62 0
      CoffeeCode/hal.cpp
  2. 26 0
      CoffeeCode/hal.h
  3. 2 0
      CoffeeCode/main.cpp

+ 62 - 0
CoffeeCode/hal.cpp

@@ -0,0 +1,62 @@
+/*
+ * hal.cpp
+ *
+ *  Created on: Aug 3, 2016
+ *      Author: Philipp Hinz
+ */
+#include <wiringPi.h>
+#include <stdlib.h>
+#include <errno.h>
+#include <string.h>
+#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");
+}
+

+ 26 - 0
CoffeeCode/hal.h

@@ -0,0 +1,26 @@
+/*
+ * hal.h
+ *
+ *  Created on: Aug 3, 2016
+ *      Author: sebastian
+ */
+
+#ifndef HAL_H_
+#define HAL_H_
+
+#define RELAIS_HEAT		29
+#define RELAIS_PUMP		25
+#define RELAIS_POWER	28
+
+#define HAL_INT0		0 // buttom button
+#define HAL_INT1		2 // top button
+
+void halInit(void);
+void halRelaisOn(int relais);
+void halRelaisOff(int relais);
+void halRelaisSet(int relais, int state);
+void halInt0(void);
+void halInt1(void);
+
+
+#endif /* HAL_H_ */

+ 2 - 0
CoffeeCode/main.cpp

@@ -21,6 +21,7 @@
 #include "database.h"
 #include "logger.h"
 #include "lcd.h"
+#include "hal.h"
 
 const int buildno = (1+(int)(
 #include "buildno"
@@ -165,6 +166,7 @@ int main(int argc, char *argv[]) {
 
 	logger_reset();
 	initTimers();
+	halInit();
 	//initLed();