Yet Another WebIOPi+
Main Page
Related Pages
Packages
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Macros
Pages
python
webiopi
devices
sensor
mcptmp.py
Go to the documentation of this file.
1
# Copyright 2016 Andreas Riegg - t-h-i-n-x.net
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
# Changelog
16
#
17
# 1.0 2016-02-07 Initial release.
18
#
19
# Config parameters
20
#
21
# - slave 8 bit Value of the I2C slave address for the I2C
22
# versions of the chips. Defaults to 0x18.
23
#
24
# - resolution Integer Value of the resolution bits of the chip.
25
# Valid values are 9 ... 12, defaults to 12.
26
#
27
#
28
# Implementation remarks
29
#
30
# - Derived from tmpXXX driver.
31
#
32
33
from
webiopi.utils.types
import
toint, signInteger
34
from
webiopi.devices.i2c
import
I2C
35
from
webiopi.devices.sensor
import
Temperature
36
37
class
MCP9808
(
I2C
,
Temperature
):
38
def
__init__
(self, slave=0x18, resolution=12):
39
I2C.__init__(self,
toint
(slave))
40
41
resolution =
toint
(resolution)
42
if
not
resolution
in
range(9,13):
43
raise
ValueError(
"%dbits resolution out of range [%d..%d]bits"
% (resolution, 9, 12))
44
self.
resolution
= resolution
45
self.
writeRegister
(0x08, (resolution - 9))
46
47
def
__str__
(self):
48
return
"MCP9808(slave=0x%02X, resolution=%d-bits)"
% (self.
slave
, self.
resolution
)
49
50
def
__getKelvin__
(self):
51
return
self.
Celsius2Kelvin
()
52
53
def
__getCelsius__
(self):
54
d = self.
readRegisters
(0x05, 2)
55
count = ((d[0] << 8) | d[1]) & 0x1FFF
56
return
signInteger
(count, 13)*0.0625
57
58
def
__getFahrenheit__
(self):
59
return
self.
Celsius2Fahrenheit
()
60
webiopi.utils.types
Definition:
types.py:1
webiopi.devices.sensor.mcptmp.MCP9808.__getFahrenheit__
def __getFahrenheit__
Definition:
mcptmp.py:58
webiopi.devices.i2c.I2C.readRegisters
def readRegisters
Definition:
i2c.py:64
webiopi.devices.sensor.Temperature
Definition:
__init__.py:65
webiopi.devices.i2c.I2C.slave
slave
Definition:
i2c.py:53
webiopi.devices.sensor.Temperature.Celsius2Kelvin
def Celsius2Kelvin
Definition:
__init__.py:88
webiopi.devices.i2c.I2C.writeRegister
def writeRegister
Definition:
i2c.py:68
webiopi.devices.sensor.mcptmp.MCP9808.resolution
resolution
Definition:
mcptmp.py:44
webiopi.devices.sensor.mcptmp.MCP9808
Definition:
mcptmp.py:37
webiopi.devices.sensor.mcptmp.MCP9808.__init__
def __init__
Definition:
mcptmp.py:38
webiopi.devices.i2c.I2C
Definition:
i2c.py:46
webiopi.devices.sensor.mcptmp.MCP9808.__getCelsius__
def __getCelsius__
Definition:
mcptmp.py:53
webiopi.devices.sensor.mcptmp.MCP9808.__str__
def __str__
Definition:
mcptmp.py:47
webiopi.devices.i2c
Definition:
i2c.py:1
webiopi.utils.types.signInteger
def signInteger
Definition:
types.py:27
webiopi.devices.sensor.Temperature.Celsius2Fahrenheit
def Celsius2Fahrenheit
Definition:
__init__.py:93
webiopi.devices.sensor
Definition:
__init__.py:1
webiopi.devices.sensor.mcptmp.MCP9808.__getKelvin__
def __getKelvin__
Definition:
mcptmp.py:50
webiopi.utils.types.toint
def toint
Definition:
types.py:16
Generated on Sat Sep 10 2016 09:37:10 for Yet Another WebIOPi+ by
1.8.8