Selaa lähdekoodia

updated doxygen
updated define names for better readability

pek72 8 vuotta sitten
vanhempi
commit
ce40fc8e12
4 muutettua tiedostoa jossa 47 lisäystä ja 26 poistoa
  1. 1 1
      CoffeeCode/buildno
  2. 17 4
      CoffeeCode/coffee.cpp
  3. 24 14
      CoffeeCode/hal.cpp
  4. 5 7
      CoffeeCode/hal.h

+ 1 - 1
CoffeeCode/buildno

@@ -1 +1 @@
-59
+60

+ 17 - 4
CoffeeCode/coffee.cpp

@@ -27,6 +27,13 @@ int sigValue;
 int brewTime; //Brew time in ms
 timer brewTimer(&brewTimeHandler);
 
+/**
+ * Thread for the finite state machine
+ * It represents the current state of the machine and handles signals coming from
+ * the pressure control, buttons, the brew switch and the proximity sensor
+ * @param threadid the ID of the thread
+ */
+
 void *coffeeThread(void *threadid) {
 	logger(V_BREW, "Initializing coffee thread...\n");
 
@@ -199,23 +206,29 @@ void *coffeeThread(void *threadid) {
 	}
 	pthread_exit(EXIT_SUCCESS);
 }
-/*
- * Saves value delivered by the signal
+/**
+ * Handler for the Signal send to this thread
+ * It safes a value sent with the signal in sigValue
+ * @param signum
+ * @param siginfo
+ * @param context
  */
 void coffeeHandler(int signum, siginfo_t *siginfo, void *context) {
 	sigval_t sigVal = (siginfo->si_value);
 	sigValue = sigVal.sival_int;
 	logger(V_BREW, "CoffeeHandler called with %d\n", sigValue);
 }
-/*
+
+/**
  * returns the Signal value from the last received Signal and clears the variable
+ * @return value sent with the last signal
  */
 int getSigValue(void){
 	int tmp = sigValue;
 	sigValue = 0;
 	return tmp;
 }
-/*
+/**
  * Counter for the brew time
  * refresh every 200ms
  */

+ 24 - 14
CoffeeCode/hal.cpp

@@ -32,28 +32,28 @@ void halInit(void) {
 	pinMode(RELAIS_HEAT, OUTPUT);
 	pinMode(RELAIS_PUMP, OUTPUT);
 	pinMode(RELAIS_POWER, OUTPUT);
-	pinMode(PRESSURE_CTRL, INPUT);
-	pinMode(PROXIMITY_SENSOR, INPUT);
-	pinMode(INT0, INPUT);
-	pinMode(INT1, INPUT);
-	pinMode(FLOW, INPUT);
-	if (wiringPiISR(INT0, INT_EDGE_BOTH, &halInt0) < 0) {
+	pinMode(PIN_PRESSURE_CTRL, INPUT);
+	pinMode(PIN_PROXIMITY_SENSOR, INPUT);
+	pinMode(PIN_INT0, INPUT);
+	pinMode(PIN_INT1, INPUT);
+	pinMode(PIN_FLOW, INPUT);
+	if (wiringPiISR(PIN_INT0, INT_EDGE_BOTH, &halInt0) < 0) {
 		logger_error("Unable to setup ISR0: %s\n", strerror(errno));
 		return;
 	}
-	if (wiringPiISR(INT1, INT_EDGE_BOTH, &halInt1) < 0) {
+	if (wiringPiISR(PIN_INT1, INT_EDGE_BOTH, &halInt1) < 0) {
 		logger_error("Unable to setup ISR1: %s\n", strerror(errno));
 		return;
 	}
-	if (wiringPiISR(FLOW, INT_EDGE_FALLING, &halIntFlow) < 0) {
+	if (wiringPiISR(PIN_FLOW, INT_EDGE_FALLING, &halIntFlow) < 0) {
 		logger_error("Unable to setup ISRFLOW: %s\n", strerror(errno));
 		return;
 	}
-	if(wiringPiISR(PRESSURE_CTRL, INT_EDGE_BOTH, &halIntPressure) < 0) {
+	if(wiringPiISR(PIN_PRESSURE_CTRL, INT_EDGE_BOTH, &halIntPressure) < 0) {
 		logger_error("Unable to setup ISRPressure: %s\n", strerror(errno));
 		return;
 	}
-	if(wiringPiISR(PROXIMITY_SENSOR, INT_EDGE_BOTH, &halIntProximity) < 0) {
+	if(wiringPiISR(PIN_PROXIMITY_SENSOR, INT_EDGE_BOTH, &halIntProximity) < 0) {
 		logger_error("Unable to setup ISRProximity: %s\n", strerror(errno));
 		return;
 	}
@@ -108,6 +108,9 @@ int halGetRelaisState(int relais) {
 	return -1;
 }
 
+/**
+ * Interrupt routine for Int0 (bottom button)
+ */
 void halInt0(void) {
 	logger(V_BASIC, "Int0 triggered\n");
 	if (halGetInt0()) {
@@ -117,6 +120,9 @@ void halInt0(void) {
 	}
 }
 
+/**
+ * Interrupt routine for Int1 (top button)
+ */
 void halInt1(void) {
 	logger(V_BASIC, "Int1 triggered\n");
 	if (halGetInt1()) {
@@ -126,6 +132,10 @@ void halInt1(void) {
 	}
 }
 
+/**
+ * Interrupt routine for the flow sensor
+ * It counts the edgdes and stores the value in flowcnt
+ */
 void halIntFlow(void) {
 	//halRelaisOff(RELAIS_POWER);
 	logger(V_BASIC, "IntFlow triggered #%d total: %.2fml\n", flowcnt, halGetFlow());
@@ -138,7 +148,7 @@ void halIntFlow(void) {
 }
 
 /**
- * Method to handle toggle of the pressure control
+ * Interrupt routine for the pressure control
  */
 void halIntPressure(void) {
 	logger(V_BASIC, "IntPressure Control triggered\n");
@@ -180,7 +190,7 @@ void halResetFlow(void){
  * @return 0 for closed Pressure Control(heating) and 1 for open
  */
 bool halIsHeating(void) {
-	if(digitalRead(PRESSURE_CTRL) == 0){
+	if(digitalRead(PIN_PRESSURE_CTRL) == 0){
 		return true;
 	} else {
 		return false;
@@ -205,7 +215,7 @@ bool halProxSensorCovered(void){
  * @return LOW or HIGH
  */
 int halGetInt0(void){
-	return digitalRead(INT0);
+	return digitalRead(PIN_INT0);
 }
 
 /**
@@ -213,7 +223,7 @@ int halGetInt0(void){
  * @return LOW or HIGH
  */
 int halGetInt1(void){
-	return digitalRead(INT1);
+	return digitalRead(PIN_INT1);
 }
 
 /**

+ 5 - 7
CoffeeCode/hal.h

@@ -11,13 +11,11 @@
 #define RELAIS_HEAT		29
 #define RELAIS_PUMP		25
 #define RELAIS_POWER	28
-#define PRESSURE_CTRL	7
-#define PROXIMITY_SENSOR	6
-
-#define INT0		0 // bottom button
-#define INT1		2 // top button
-#define FLOW		3 // flow sensor
-#define PROX_COVERED	1 //proximity sensor
+#define PIN_PRESSURE_CTRL	7
+#define PIN_PROXIMITY_SENSOR	6
+#define PIN_INT0		0 // bottom button
+#define PIN_INT1		2 // top button
+#define PIN_FLOW		3 // flow sensor
 #define FLOW_ML_PULSE	(1000.0/990) // Flow sensor: volume (ml) per pulse
 /*
  * Explanation for the signal levels