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
analog
pcf8591.py
Go to the documentation of this file.
1
# Copyright 2014 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
16
from
webiopi.devices.i2c
import
I2C
17
from
webiopi.devices.analog
import
DAC, ADC
18
19
20
class
PCF8591
(
DAC
,
I2C
):
21
def
__init__
(self, slave=0x48, vref=3.3):
22
I2C.__init__(self,
toint
(slave))
23
DAC.__init__(self, 5, 8, float(vref))
24
self.
daValue
= 0
25
26
27
def
__str__
(self):
28
return
"PCF8591(slave=0x%02X)"
% self.
slave
29
30
def
__family__
(self):
31
return
[DAC.__family__(self), ADC.__family__(self)]
32
33
def
__command__
(self, adChannel=0):
34
d = bytearray(2)
35
d[0] = 0x40
# enable output
36
d[0] |= adChannel & 0x03
37
d[1] = self.
daValue
38
return
d
39
40
41
def
__analogRead__
(self, channel, diff=False):
42
if
(channel == 0):
43
return
self.
daValue
44
else
:
45
self.
writeBytes
(self.
__command__
(channel-1))
46
return
self.
readBytes
(3)[2]
47
48
49
def
__analogWrite__
(self, channel, value):
50
if
(channel == 0):
51
self.
daValue
= value
52
self.
writeBytes
(self.
__command__
())
webiopi.utils.types
Definition:
types.py:1
webiopi.devices.analog.pcf8591.PCF8591.daValue
daValue
Definition:
pcf8591.py:24
webiopi.devices.analog
Definition:
__init__.py:1
webiopi.devices.analog.pcf8591.PCF8591.__analogWrite__
def __analogWrite__
Definition:
pcf8591.py:49
webiopi.devices.analog.pcf8591.PCF8591.__str__
def __str__
Definition:
pcf8591.py:27
webiopi.devices.analog.DAC
Definition:
__init__.py:101
webiopi.devices.bus.Bus.writeBytes
def writeBytes
Definition:
bus.py:112
webiopi.devices.i2c.I2C.slave
slave
Definition:
i2c.py:53
webiopi.devices.analog.pcf8591.PCF8591.__init__
def __init__
Definition:
pcf8591.py:21
webiopi.devices.i2c.I2C
Definition:
i2c.py:46
webiopi.devices.i2c
Definition:
i2c.py:1
webiopi.devices.analog.pcf8591.PCF8591
Definition:
pcf8591.py:20
webiopi.devices.analog.pcf8591.PCF8591.__command__
def __command__
Definition:
pcf8591.py:33
webiopi.devices.analog.pcf8591.PCF8591.__family__
def __family__
Definition:
pcf8591.py:30
webiopi.devices.analog.pcf8591.PCF8591.__analogRead__
def __analogRead__
Definition:
pcf8591.py:41
webiopi.utils.types.toint
def toint
Definition:
types.py:16
webiopi.devices.bus.Bus.readBytes
def readBytes
Definition:
bus.py:101
Generated on Sat Sep 10 2016 09:36:57 for Yet Another WebIOPi+ by
1.8.8