add formel 18
[owPython.git] / owlib.py
index 04f2ade..434b12c 100644 (file)
--- a/owlib.py
+++ b/owlib.py
@@ -42,7 +42,7 @@ devUnit= ["","°C","hPa","lux","%","","V","mA","ppm","","ppm","kOhm"]
 
 devController=["","Old code","Attiny84A","Attiny44","Atmega328"]
 
-devChip=["","DS18B20","DS2438","DS2438","DS2438","DS2450","Thermoelement","SHT21","SHT25","DHT22","HIH9021","HDC1080","HIH4030","HIH5030","BMP280","MAX44009","CDM7160","MAX1164/TGS8100","TGS8100","DS2423"]
+devChip=["","DS18B20","DS2438","DS2438","DS2438","DS2450","Thermoelement","SHT21","SHT25","DHT22","HIH9021","HDC1080","HIH4030","HIH5030","BMP280","MAX44009","CDM7160","MAX1164/TGS8100","TGS8100","DS2423","intern ADC","SHT35","SHT31"]
 
 
 def calcValue(code,vn,V):
@@ -80,6 +80,10 @@ def calcValue(code,vn,V):
                return exp((V[vn]-32767.0)/1000.0);
        if code==16:
                return V[vn]/32.0;  
+       if code==17:
+               return V[vn]*0.2441/1000;  
+       if code==18:
+               return V[vn]/8.0;
        return 0;
 
 
@@ -182,12 +186,13 @@ class owDevice:
        
        def readConfig(self):
                self.config=owcom(self.owid,[0x85],26)
+               print self.config
                if self.config[0]==0xFF:
                        print("No Deviceconfig. Not a Device form tm3d.de. Set Default");
                        self.setdefaultConfig()
                else:
                        if self.config[25]==0xFF:
-                               if not(crc8(self.config[0:24])):
+                               if crc8(self.config[0:24]):
                                        print("CRC Error reading Deviceconfig. Set Default")
                                        self.setdefaultConfig()
                        else:
@@ -256,7 +261,7 @@ class owDS18B20(owDevice):
 
 class owDS2438(owDevice):
        def setdefaultConfig(self):
-               self.config=[1,6, 6,8, 4,7, 7,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0]
+               self.config=[1,6, 6,8, 4,7, 6,17, 0,2,3,12,4,0,0,0,0,0,0,0,0,0,0,0]
 
        def readScratchpad(self,page,recall):
                if (recall):
@@ -285,12 +290,16 @@ class owDS2438(owDevice):
                owcom(self.owid,[0xB4],0)
                time.sleep(0.01)
                sp=self.readScratchpad(0,True)
+               if sp==[]:
+                       return
                temp=ow_fconvert(sp[1],sp[2]);
                VDD=ow_fconvert(sp[3],sp[4]);
                self.setConfigByte(0x00)
                owcom(self.owid,[0xB4],0)
                time.sleep(0.01)
                sp=self.readScratchpad(0,True);
+               if sp==[]: 
+                       return
                I=ow_fconvert(sp[5],sp[6]);
                VAD=ow_fconvert(sp[3],sp[4]);
                self.raw[0]=temp;