Browse Source

Implemented flow sensor, some HAL testing

Philipp Hinz 8 years ago
parent
commit
6835f0ec0e
2 changed files with 34 additions and 4 deletions
  1. 29 4
      CoffeeCode/hal.cpp
  2. 5 0
      CoffeeCode/hal.h

+ 29 - 4
CoffeeCode/hal.cpp

@@ -8,19 +8,23 @@
 #include <stdlib.h>
 #include <stdlib.h>
 #include <errno.h>
 #include <errno.h>
 #include <string.h>
 #include <string.h>
+#include "lcd.h"
 #include "hal.h"
 #include "hal.h"
 #include "global.h"
 #include "global.h"
 #include "logger.h"
 #include "logger.h"
 
 
+int flowcnt = 0;
+
 void halInit(void) {
 void halInit(void) {
-	halRelaisOff(RELAIS_HEAT);
+	halRelaisOn(RELAIS_HEAT);
 	halRelaisOff(RELAIS_PUMP);
 	halRelaisOff(RELAIS_PUMP);
-	halRelaisOff(RELAIS_POWER);
+	halRelaisOn(RELAIS_POWER);
 	pinMode(RELAIS_HEAT, OUTPUT);
 	pinMode(RELAIS_HEAT, OUTPUT);
 	pinMode(RELAIS_PUMP, OUTPUT);
 	pinMode(RELAIS_PUMP, OUTPUT);
 	pinMode(RELAIS_POWER, OUTPUT);
 	pinMode(RELAIS_POWER, OUTPUT);
 	pinMode(HAL_INT0, INPUT);
 	pinMode(HAL_INT0, INPUT);
 	pinMode(HAL_INT1, INPUT);
 	pinMode(HAL_INT1, INPUT);
+	pinMode(HAL_FLOW, INPUT);
 	if (wiringPiISR(HAL_INT0, INT_EDGE_FALLING, &halInt0) < 0) {
 	if (wiringPiISR(HAL_INT0, INT_EDGE_FALLING, &halInt0) < 0) {
 		logger_error("Unable to setup ISR0: %s\n", strerror(errno));
 		logger_error("Unable to setup ISR0: %s\n", strerror(errno));
 		return;
 		return;
@@ -29,6 +33,10 @@ void halInit(void) {
 		logger_error("Unable to setup ISR1: %s\n", strerror(errno));
 		logger_error("Unable to setup ISR1: %s\n", strerror(errno));
 		return;
 		return;
 	}
 	}
+	if (wiringPiISR(HAL_FLOW, INT_EDGE_FALLING, &halIntFlow) < 0) {
+		logger_error("Unable to setup ISRFLOW: %s\n", strerror(errno));
+		return;
+	}
 }
 }
 void halRelaisOn(int relais) {
 void halRelaisOn(int relais) {
 	halRelaisSet(relais, LOW);
 	halRelaisSet(relais, LOW);
@@ -51,12 +59,29 @@ void halRelaisSet(int relais, int state) {
 }
 }
 
 
 void halInt0(void) {
 void halInt0(void) {
-	halRelaisOn(RELAIS_POWER);
+	//halRelaisOn(RELAIS_POWER);
 	logger(V_BASIC, "Int0 triggered\n");
 	logger(V_BASIC, "Int0 triggered\n");
+	flowcnt = 0;
+	halRelaisOn(RELAIS_PUMP);
 }
 }
 
 
 void halInt1(void) {
 void halInt1(void) {
-	halRelaisOff(RELAIS_POWER);
+	//halRelaisOff(RELAIS_POWER);
 	logger(V_BASIC, "Int1 triggered\n");
 	logger(V_BASIC, "Int1 triggered\n");
 }
 }
 
 
+void halIntFlow(void) {
+	//halRelaisOff(RELAIS_POWER);
+	logger(V_BASIC, "IntFlow triggered #%d total: %f\n", flowcnt, halGetFlow());
+	lcdPosition(lcd, 0, 0);
+	lcdPrintf(lcd, "ml = %.2f   ", halGetFlow());
+	if (flowcnt == 99) {
+		halRelaisOff(RELAIS_PUMP);
+	}
+	flowcnt++;
+}
+
+float halGetFlow(void) {
+	return flowcnt*FLOW_ML_PULSE;
+}
+

+ 5 - 0
CoffeeCode/hal.h

@@ -14,6 +14,9 @@
 
 
 #define HAL_INT0		0 // buttom button
 #define HAL_INT0		0 // buttom button
 #define HAL_INT1		2 // top button
 #define HAL_INT1		2 // top button
+#define HAL_FLOW		3 // flow sensor
+
+#define FLOW_ML_PULSE	(1000.0/990) // Flow sensor: volume (ml) per pulse
 
 
 void halInit(void);
 void halInit(void);
 void halRelaisOn(int relais);
 void halRelaisOn(int relais);
@@ -21,6 +24,8 @@ void halRelaisOff(int relais);
 void halRelaisSet(int relais, int state);
 void halRelaisSet(int relais, int state);
 void halInt0(void);
 void halInt0(void);
 void halInt1(void);
 void halInt1(void);
+void halIntFlow(void);
+float halGetFlow(void);
 
 
 
 
 #endif /* HAL_H_ */
 #endif /* HAL_H_ */