Yet Another WebIOPi+
 All Classes Namespaces Files Functions Variables Macros Pages
tmpXXX.py
Go to the documentation of this file.
1 # Copyright 2012-2013 Eric Ptak - trouch.com
2 #
3 # Licensed under the Apache License, Version 2.0 (the "License");
4 # you may not use this file except in compliance with the License.
5 # You may obtain a copy of the License at
6 #
7 # http://www.apache.org/licenses/LICENSE-2.0
8 #
9 # Unless required by applicable law or agreed to in writing, software
10 # distributed under the License is distributed on an "AS IS" BASIS,
11 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12 # See the License for the specific language governing permissions and
13 # limitations under the License.
14 
15 from webiopi.utils.types import toint, signInteger
16 from webiopi.devices.i2c import I2C
17 from webiopi.devices.sensor import Temperature
18 
20  def __init__(self, slave=0x48):
21  I2C.__init__(self, toint(slave))
22 
23  def __str__(self):
24  return "TMP102(slave=0x%02X)" % self.slave
25 
26  def __getKelvin__(self):
27  return self.Celsius2Kelvin()
28 
29  def __getCelsius__(self):
30  d = self.readBytes(2)
31  count = ((d[0] << 4) | (d[1] >> 4)) & 0xFFF
32  return signInteger(count, 12)*0.0625
33 
34  def __getFahrenheit__(self):
35  return self.Celsius2Fahrenheit()
36 
37 class TMP75(TMP102):
38  def __init__(self, slave=0x48, resolution=12):
39  TMP102.__init__(self, slave)
40  resolution = toint(resolution)
41  if not resolution in range(9,13):
42  raise ValueError("%dbits resolution out of range [%d..%d]bits" % (resolution, 9, 12))
43  self.resolution = resolution
44 
45  config = self.readRegister(0x01)
46  config &= ~0x60
47  config |= (self.resolution - 9) << 5
48  self.writeRegister(0x01, config)
49  self.readRegisters(0x00, 2)
50 
51  def __str__(self):
52  return "TMP75(slave=0x%02X, resolution=%d-bits)" % (self.slave, self.resolution)
53 
54 class TMP275(TMP75):
55  def __init__(self, slave=0x48, resolution=12):
56  TMP75.__init__(self, slave, resolution)
57 
58  def __str__(self):
59  return "TMP275(slave=0x%02X, resolution=%d-bits)" % (self.slave, self.resolution)
60