-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbmp085.py
46 lines (44 loc) · 1.42 KB
/
bmp085.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
import sensor
import bmpBackend
class BMP085(sensor.Sensor):
bmpClass = None
requiredData = ["measurement","i2cbus"]
optionalData = ["altitude","mslp","unit"]
def __init__(self,data):
self.sensorName = "BMP085"
if "temp" in data["measurement"].lower():
self.valName = "BMPTemperature"
self.valUnit = "Celsius"
self.valSymbol = "C"
if "unit" in data:
if data["unit"]=="F":
self.valUnit = "Fahrenheit"
self.valSymbol = "F"
elif "pres" in data["measurement"].lower():
self.valName = "Pressure"
self.valSymbol = "hPa"
self.valUnit = "Hectopascal"
self.altitude = 0
self.mslp = False
if "mslp" in data:
if data["mslp"].lower in ["on","true","1","yes"]:
self.mslp = True
if "altitude" in data:
self.altitude=data["altitude"]
else:
print "To calculate MSLP, please provide an 'altitude' config setting (in m) for the BMP085 pressure module"
self.mslp = False
if (BMP085.bmpClass==None):
BMP085.bmpClass = bmpBackend.BMP085(bus=int(data["i2cbus"]))
return
def getVal(self):
if self.valName == "BMPTemperature":
temp = BMP085.bmpClass.readTemperature()
if self.valUnit == "Fahrenheit":
temp = temp * 1.8 + 32
return temp
elif self.valName == "Pressure":
if self.mslp:
return BMP085.bmpClass.readMSLPressure(self.altitude) * 0.01 #to convert to Hectopascals
else:
return BMP085.bmpClass.readPressure() * 0.01 #to convert to Hectopascals