A bit of code cleanup

Fri, 01 Aug 2014 16:13:55 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Fri, 01 Aug 2014 16:13:55 +0200
changeset 170
3cb99272b84b
parent 169
47358c2cc285
child 171
15f92e5eecef

A bit of code cleanup

thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/units.c file | annotate | diff | comparison | revisions
--- a/thermferm/server.c	Fri Aug 01 14:45:32 2014 +0200
+++ b/thermferm/server.c	Fri Aug 01 16:13:55 2014 +0200
@@ -280,6 +280,10 @@
 /*
  * GET AIR uuid
  * GET BEER uuid
+ * GET LED1 uuid
+ * GET LED2 uuid
+ * GET LED3 uuid
+ * GET MODE uuid
  * GET TARGET uuid
  */
 int cmd_get(char *buf)
@@ -305,12 +309,30 @@
 		else
 		    srv_send((char *)"215 AIR,NA");
 		return 0;
+
 	    } else if (strcmp(opt, (char *)"BEER") == 0) {
 		if (unit->beer_state == 0)
 		    srv_send((char *)"215 BEER,%.3f", unit->beer_temperature / 1000.0);
 		else
 		    srv_send((char *)"215 BEER,NA");
 		return 0;
+
+	    } else if (strcmp(opt, (char *)"LED1") == 0) {
+		srv_send((char *)"215 HEATER,%d", (unit->heater_available && unit->heater_state) ? 1:0);
+		return 0;
+
+	    } else if (strcmp(opt, (char *)"LED2") == 0) {
+		srv_send((char *)"215 COOLER,%d", (unit->cooler_available && unit->cooler_state) ? 1:0);
+		return 0;
+
+	    } else if (strcmp(opt, (char *)"LED3") == 0) {
+		srv_send((char *)"215 FAN,%d", (unit->fan_available && unit->fan_state) ? 1:0);
+		return 0;
+
+	    } else if (strcmp(opt, (char *)"MODE") == 0) {
+		srv_send((char *)"215 MODE,%s", UNITMODE[unit->mode]);
+		return 0;
+
 	    } else if (strcmp(opt, (char *)"TARGET") == 0) {
 		if (unit->mode == UNITMODE_BEER) {
 		    srv_send((char *)"215 TARGET,%.3f", unit->beer_set);
@@ -465,12 +487,15 @@
 		}
 		if (unit->heater_available) {
 		    srv_send((char *)"HEATER_AVAILABLE,%s", unit->heater_available);
+		    srv_send((char *)"HEATER_STATE,%d", unit->heater_state);
 		}
 		if (unit->cooler_available) {
 		    srv_send((char *)"COOLER_AVAILABLE,%s", unit->cooler_available);
+		    srv_send((char *)"COOLER_STATE,%d", unit->cooler_state);
 		}
 		if (unit->fan_available) {
 		    srv_send((char *)"FAN_AVAILABLE,%s", unit->fan_available);
+		    srv_send((char *)"FAN_STATE,%d", unit->fan_state);
 		}
 		srv_send((char *)"MODE,%s", UNITMODE[unit->mode]);
 		srv_send((char *)"FRIDGE_SET,%.1f", unit->fridge_set);
@@ -995,10 +1020,13 @@
 //		srv_send((char *)"DEL UNIT uuid                 Delete unit with uuid");
 		srv_send((char *)"GET AIR uuid                  Get Air temperature with uuid");
 		srv_send((char *)"GET BEER uuid                 Get Beer temperature with uuid");
-//		srv_send((char *)"GET LED1 uuid                 Get LED 1 (cooler) state");
-//		srv_send((char *)"GET LED2 uuid                 Get LED 2 (heater) state");
-//		srv_send((char *)"GET LED3 uuid                 Get LED 3 (fan) state");
-//		srv_send((char *)"GET DOOR uuid                 Get Door state");
+		srv_send((char *)"GET LED1 uuid                 Get LED 1 (cooler) state");
+		srv_send((char *)"GET LED2 uuid                 Get LED 2 (heater) state");
+		srv_send((char *)"GET LED3 uuid                 Get LED 3 (fan) state");
+		srv_send((char *)"GET MODE uuid                 Get Unit Mode");
+//		srv_send((char *)"GET SW1 uuid                  Get Switch 1 (cooler) state");
+//		srv_send((char *)"GET SW2 uuid                  Get Switch 2 (heater) state");
+//		srv_send((char *)"GET SW3 uuid                  Get Switch 3 (fan) state");
 		srv_send((char *)"GET TARGET uuid               Get Target temperature with uuid");
 		srv_send((char *)"LCD                           Get LCD screen (allways 4 rows of 20 characters)");
 		srv_send((char *)"LIST                          List all fermenter units");
--- a/thermferm/units.c	Fri Aug 01 14:45:32 2014 +0200
+++ b/thermferm/units.c	Fri Aug 01 16:13:55 2014 +0200
@@ -46,7 +46,7 @@
 	}
     }
 
-    return 1;
+    return DEVPRESENT_NO;
 }
 
 
@@ -103,7 +103,7 @@
 
 	    if (unit->air_address) {
 		rc = read_w1_28(unit->air_address, &temp);
-		if (rc == 2) {
+		if (rc == DEVPRESENT_YES) {
 		    /*
 		     * It is possible to have read errors or extreme values.
 		     * This can happen with bad connections so we compare the
@@ -123,7 +123,7 @@
 			    fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->air_temperature, temp);
 			}
 		    }
-		} else if (rc == 3) {
+		} else if (rc == DEVPRESENT_ERROR) {
 		    unit->air_state = 1;
 		} else {
 		    unit->air_state = 2;
@@ -134,7 +134,7 @@
 
 	    if (unit->beer_address) {
 		rc = read_w1_28(unit->beer_address, &temp);
-		if (rc == 2) {
+		if (rc == DEVPRESENT_YES) {
 		    deviation = 20000;
 		    if ((unit->beer_temperature == 0) ||
 		    	(unit->beer_temperature && (temp > (int)unit->beer_temperature - deviation) && (temp < ((int)unit->beer_temperature + deviation)))) {
@@ -146,7 +146,7 @@
 			    fprintf(stdout, "deviation error deviation=%d, old=%d new=%d\n", deviation, unit->beer_temperature, temp);
 		    	}
 		    }
-		} else if (rc == 3) {
+		} else if (rc == DEVPRESENT_ERROR) {
 		    unit->beer_state = 1;
 		} else {
 		    unit->beer_state = 2;

mercurial