HDC1080 support
[owSlave2.git] / tools / owReadBMP.py
diff --git a/tools/owReadBMP.py b/tools/owReadBMP.py
new file mode 100644 (file)
index 0000000..00eac22
--- /dev/null
@@ -0,0 +1,130 @@
+#!/usr/bin/python\r
+# Copyright (c) 2015, Tobias Mueller tm(at)tm3d.de\r
+# All rights reserved. \r
+# \r
+# Redistribution and use in source and binary forms, with or without \r
+# modification, are permitted provided that the following conditions are \r
+# met: \r
+# \r
+#  * Redistributions of source code must retain the above copyright \r
+#    notice, this list of conditions and the following disclaimer. \r
+#  * Redistributions in binary form must reproduce the above copyright \r
+#    notice, this list of conditions and the following disclaimer in the \r
+#    documentation and/or other materials provided with the \r
+#    distribution. \r
+#  * All advertising materials mentioning features or use of this \r
+#    software must display the following acknowledgement: This product \r
+#    includes software developed by tm3d.de and its contributors. \r
+#  * Neither the name of tm3d.de nor the names of its contributors may \r
+#    be used to endorse or promote products derived from this software \r
+#    without specific prior written permission. \r
+# \r
+# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \r
+# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT \r
+# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR \r
+# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT \r
+# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, \r
+# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT \r
+# LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, \r
+# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY \r
+# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT \r
+# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE \r
+# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. \r
+\r
+\r
+\r
+\r
+import time\r
+import subprocess\r
+import sys\r
+\r
+def owcom(dev,send,rc):\r
+       res=[]\r
+       f=open("/sys/bus/w1/devices/%s/rw" %(dev),"r+b",0)\r
+       f.write("".join(map(chr, send)))\r
+       if (rc!=0):\r
+               res=map(ord,f.read(rc))\r
+       f.close()\r
+       return res\r
+               \r
+\r
+def crc8(arr):\r
+       lscrc=0x0;\r
+       for v in arr:\r
+               bit=1;\r
+               while bit<256:\r
+                       if (v&bit)==bit:\r
+                               lb=1\r
+                       else:\r
+                               lb=0\r
+                       if (lscrc&1)!=lb:\r
+                               lscrc=(lscrc>>1)^0x8c \r
+                       else:\r
+                               lscrc=(lscrc>>1)\r
+                       bit=bit*2\r
+       return lscrc\r
+       \r
+def testnr(s):\r
+       for c in s.lower()[:]:\r
+               if not((c) in ['0','1','2','3','4','5','6','7','8','9','a','b','c','d','e','f','-']):\r
+                       return False\r
+       return True\r
\r
+def addid(id,val):\r
+       for i in range(7):\r
+               id[i+1]=id[i+1]+val\r
+               if id[i+1]>254:\r
+                       id[i+1]=id[i+1]-254\r
+                       val=1\r
+               else:\r
+                       return id\r
+       return id\r
+#\r
+\r
+\r
+l=subprocess.check_output("ls /sys/bus/w1/devices/", shell=True)\r
+dc=0\r
+dl=[]\r
+for g in  (l.split("\n")):\r
+       if len(g)>2:\r
+               if testnr(g[0:2]):\r
+                       if (g[0:2]=="26"):\r
+                               dl.append(g)\r
+                               dc=dc+1\r
+                               print dc,") ",g\r
+if dc==0:\r
+       print "No 26 1-Wire Device found"\r
+       exit(0)\r
+n=int(raw_input("No. of Device (28-Device will get automatically): "))\r
+n=n-1\r
+if (n>dc-1)or(n<0):\r
+               exit(0)\r
+s=dl[n]\r
+config=owcom(s,[0x85],17)\r
+print(config)\r
+s2="%02x-%02x%02x%02x%02x%02x%02x" % (config[9],config[15],config[14],config[13],config[12],config[11],config[10])\r
+print("Second Device: %s" %( s2))\r
+f=open("/sys/bus/w1/devices/%s/w1_slave" %(s2),"rb",0)\r
+res=f.read().split(" ")\r
+f.close()\r
+Press=((int(res[0],16)+int(res[1],16)*256)/16.0*3.2+700)\r
+owcom(s,[0x4E,0x00,0x01],0)\r
+owcom(s,[0x44],0)\r
+time.sleep(1)\r
+owcom(s,[0xB4],0)\r
+time.sleep(1)\r
+\r
+p=owcom(s,[0xBE,0x00],10)\r
+print (p)\r
+T=((p[1]+p[2]*256)/256.0)\r
+if (config[5]==8):\r
+       RH=((p[3]+p[4]*256)/100.0)\r
+if (config[5]==7):\r
+       RH=(((p[3]+p[4]*256)/ 500.0 - 0.16) / 0.0062) / (1.0546 - 0.00216*T); \r
+\r
+print("Temperatur: %f °C" %(T));\r
+print("Luftfeuchte: %f %%" %(RH));\r
+print("Druck (absolut): %f hPa" %(Press));\r
+h=float(raw_input("Höhe über Meerespiegel in m: "))\r
+P0=Press/((1-h/44330)**5.255)\r
+print("Druck (normalisiert): %f hPa" %(P0));\r