Added offset value for sensor that need it

Sun, 10 Aug 2014 17:25:50 +0200

author
Michiel Broek <mbroek@mbse.eu>
date
Sun, 10 Aug 2014 17:25:50 +0200
changeset 209
c5b1dfd83e81
parent 208
934d45d9751d
child 210
8976069c6b29

Added offset value for sensor that need it

thermferm/devices.c file | annotate | diff | comparison | revisions
thermferm/rdconfig.c file | annotate | diff | comparison | revisions
thermferm/server.c file | annotate | diff | comparison | revisions
thermferm/thermferm.c file | annotate | diff | comparison | revisions
thermferm/thermferm.h file | annotate | diff | comparison | revisions
www-thermferm/devices.php file | annotate | diff | comparison | revisions
--- a/thermferm/devices.c	Sun Aug 10 16:56:22 2014 +0200
+++ b/thermferm/devices.c	Sun Aug 10 17:25:50 2014 +0200
@@ -40,8 +40,6 @@
 int             dht11_temperature = -1;
 int             dht11_humidity = -1;
 int             dht11_valid = FALSE;
-int             dht11_t_offset = 0;
-int             dht11_h_offset = 0;
 
 
 static uint8_t sizecvt(const int read_value) {
@@ -144,8 +142,6 @@
 
 		int h = dht11_dat[0] + dht11_dat[1];
 		int t = (dht11_dat[2] & 0x7F) + dht11_dat[3];
-		t += dht11_t_offset;
-		h += dht11_h_offset;
 
 		if ((dht11_dat[2] & 0x80) != 0) 
 		    t *= -1;
--- a/thermferm/rdconfig.c	Sun Aug 10 16:56:22 2014 +0200
+++ b/thermferm/rdconfig.c	Sun Aug 10 17:25:50 2014 +0200
@@ -532,6 +532,10 @@
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
 		return 1;
 	    }
+	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "OFFSET", "%d", device->offset)) < 0) {
+		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteElement");
+		return 1;
+	    }
 	    if ((rc = xmlTextWriterWriteFormatElement(writer, BAD_CAST "PRESENT", "%s", DEVPRESENT[device->present])) < 0) {
 		syslog(LOG_NOTICE, "wrconfig: error at xmlTextWriterWriteFormatElement");
 		return 1;                           
@@ -1036,7 +1040,7 @@
     device->next = NULL;
     device->version = 1;
     device->uuid = device->address = device->description = device->comment = NULL;
-    device->type = device->direction = device->present = device->subdevice = device->inuse = 0;
+    device->type = device->direction = device->present = device->subdevice = device->inuse = device->offset = 0;
     device->gpiopin = -1;
     device->timestamp = (time_t)0;
 
@@ -1080,6 +1084,12 @@
 			device->value = ival;
 		xmlFree(key);
 	}
+	if ((!xmlStrcmp(cur->name, (const xmlChar *)"OFFSET"))) {
+	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
+	    if (sscanf((const char *)key, "%d", &ival) == 1)
+		device->offset = ival;
+	    xmlFree(key);
+	}
 	if ((!xmlStrcmp(cur->name, (const xmlChar *)"PRESENT"))) {
 	    key = xmlNodeListGetString(doc, cur->xmlChildrenNode, 1);
 	    for (i = 0; i < 4; i++) {
--- a/thermferm/server.c	Sun Aug 10 16:56:22 2014 +0200
+++ b/thermferm/server.c	Sun Aug 10 17:25:50 2014 +0200
@@ -262,7 +262,7 @@
 		}
 	    }
 	    device->direction = DEVDIR_UNDEF;
-	    device->value = device->subdevice = device->inuse = 0;
+	    device->value = device->offset = device->subdevice = device->inuse = 0;
 	    device->present = DEVPRESENT_UNDEF;
 	    device->address = xstrcpy((char *)"Enter address here");
 	    device->gpiopin = -1;
@@ -308,6 +308,7 @@
 		srv_send((char *)"TYPE,%s", DEVTYPE[device->type]);
 		srv_send((char *)"DIRECTION,%s", DEVDIR[device->direction]);
 		srv_send((char *)"VALUE,%d", device->value);
+		srv_send((char *)"OFFSET,%d", device->offset);
 		srv_send((char *)"PRESENT,%s", DEVPRESENT[device->present]);
 		srv_send((char *)"ADDRESS,%s", device->address);
 		srv_send((char *)"SUBDEVICE,%d", device->subdevice);
@@ -380,6 +381,10 @@
 				if (sscanf(val, "%d", &ival) == 1)
 				    device->value = ival;
 
+			    } else if (strcmp(kwd, (char *)"OFFSET") == 0) {
+				if (sscanf(val, "%d", &ival) == 1)
+				    device->offset = ival;
+
 			    } else if (strcmp(kwd, (char *)"PRESENT") == 0) {
 				for (i = 0; i < 4; i++) {
 				    if (strcmp(val, DEVPRESENT[i]) == 0) {
--- a/thermferm/thermferm.c	Sun Aug 10 16:56:22 2014 +0200
+++ b/thermferm/thermferm.c	Sun Aug 10 17:25:50 2014 +0200
@@ -110,7 +110,7 @@
 
     for (device = Config.devices; device; device = device->next) {
 	if (strcmp(address, device->uuid) == 0) {
-	    tmp = device->value;
+	    tmp = device->value + device->offset;
 	    *val = tmp;
 	    return device->present;
 	}
--- a/thermferm/thermferm.h	Sun Aug 10 16:56:22 2014 +0200
+++ b/thermferm/thermferm.h	Sun Aug 10 17:25:50 2014 +0200
@@ -146,6 +146,7 @@
     int			type;			/* Device type			*/
     int			direction;		/* Device direction		*/
     int			value;			/* Device value			*/
+    int			offset;			/* Device offset value		*/
     int			present;		/* Device present		*/
     char		*address;		/* Device address		*/
     int			subdevice;		/* Device sub address		*/
--- a/www-thermferm/devices.php	Sun Aug 10 16:56:22 2014 +0200
+++ b/www-thermferm/devices.php	Sun Aug 10 17:25:50 2014 +0200
@@ -95,6 +95,7 @@
  * @param string $_POST['Type'] The device Type
  * @param string $_POST['Direction'] The device IO Direction
  * @param string $_POST['Value'] The device value
+ * @param string $_POST['Offset'] The device offset
  * @param string $_POST['Present'] The device Present state
  * @param string $_POST['Address'] The device Address
  * @param string $_POST['Subdevice'] The device Subaddress
@@ -125,6 +126,8 @@
 	    usleep(20000);
 	    socket_write($sock, "VALUE,".$_POST['Value'], 4096);
 	    usleep(20000);
+	    socket_write($sock, "OFFSET,".$_POST['Offset'], 4096);
+	    usleep(20000);
 	    socket_write($sock, "PRESENT,".$_POST['Present'], 4096);
 	    usleep(20000);
 	    socket_write($sock, "ADDRESS,".$_POST['Address'], 4096);
@@ -172,6 +175,7 @@
  * @param string $_POST['Type'] Device Type
  * @param string $_POST['Direction']
  * @param string $_POST['Value']
+ * @param string $_POST['Offset']
  * @param string $_POST['Present']
  * @param string $_POST['Address']
  * @param string $_POST['Subdevice']
@@ -193,7 +197,7 @@
 
     global $arr;
 
-    if (isset($_POST['UUID']) && isset($_POST['Type']) && isset($_POST['Direction']) && isset($_POST['Value']) &&
+    if (isset($_POST['UUID']) && isset($_POST['Type']) && isset($_POST['Direction']) && isset($_POST['Value']) && isset($_POST['Offset']) &&
 	isset($_POST['Present']) && isset($_POST['Address']) && isset($_POST['Subdevice']) && isset($_POST['Gpiopin']) &&
 	isset($_POST['Description']) && isset($_POST['Comment']) && isset($_POST['key']) && isset($_POST['command'])) {
 
@@ -363,6 +367,15 @@
 		    $outstr .= '        <td class="editfield"><input type="hidden" name="Value" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL;
 		$outstr .= '       </tr>'.PHP_EOL;
 	    }
+	    if ($f[0] == "OFFSET") {
+		$outstr .= '       <tr class="editor">'.PHP_EOL;
+		$outstr .= '        <td class="editname">Value</td>'.PHP_EOL;
+		if ($direction == "IN_ANALOG")
+		    $outstr .= '        <td class="editfield"><input type="text" name="Offset" size="50" value="'.$f[1].'"></td>'.PHP_EOL;
+		else
+		    $outstr .= '        <td class="editfield"><input type="hidden" name="Offset" value="'.$f[1].'">'.$f[1].'</td>'.PHP_EOL;
+		$outstr .= '       </tr>'.PHP_EOL;
+	    }
 	    if ($f[0] == "PRESENT") {
 		/*
 		 * Only devices that cannot auto detect can be changed.

mercurial