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
digital
pcf8574.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
16
from
webiopi.devices.i2c
import
I2C
17
from
webiopi.devices.digital
import
GPIOPort
18
19
class
PCF8574
(
I2C
,
GPIOPort
):
20
FUNCTIONS = [GPIOPort.IN
for
i
in
range(8)]
21
22
def
__init__
(self, slave=0x20):
23
slave =
toint
(slave)
24
if
slave
in
range(0x20, 0x28):
25
self.
name
=
"PCF8574"
26
elif
slave
in
range(0x38, 0x40):
27
self.
name
=
"PCF8574A"
28
else
:
29
raise
ValueError(
"Bad slave address for PCF8574(A) : 0x%02X not in range [0x20..0x27, 0x38..0x3F]"
% slave)
30
31
I2C.__init__(self, slave)
32
GPIOPort.__init__(self, 8)
33
self.
portWrite
(0xFF)
34
self.
portRead
()
35
36
def
__str__
(self):
37
return
"%s(slave=0x%02X)"
% (self.
name
, self.
slave
)
38
39
def
__getFunction__
(self, channel):
40
return
self.
FUNCTIONS
[channel]
41
42
def
__setFunction__
(self, channel, value):
43
if
not
value
in
[self.
IN
, self.
OUT
]:
44
raise
ValueError(
"Requested function not supported"
)
45
self.
FUNCTIONS
[channel] = value
46
47
def
__digitalRead__
(self, channel):
48
mask = 1 << channel
49
d = self.
readByte
()
50
return
(d & mask) == mask
51
52
def
__portRead__
(self):
53
return
self.
readByte
()
54
55
def
__digitalWrite__
(self, channel, value):
56
mask = 1 << channel
57
b = self.
readByte
()
58
if
value:
59
b |= mask
60
else
:
61
b &= ~mask
62
self.
writeByte
(b)
63
64
def
__portWrite__
(self, value):
65
self.
writeByte
(value)
66
67
class
PCF8574A
(
PCF8574
):
68
def
__init__
(self, slave=0x38):
69
PCF8574.__init__(self, slave)
70
webiopi.utils.types
Definition:
types.py:1
webiopi.devices.digital.GPIOPort.portWrite
def portWrite
Definition:
__init__.py:147
webiopi.devices.digital.pcf8574.PCF8574A
Definition:
pcf8574.py:67
webiopi.devices.digital.pcf8574.PCF8574.__digitalWrite__
def __digitalWrite__
Definition:
pcf8574.py:55
webiopi.devices.bus.Bus.readByte
def readByte
Definition:
bus.py:104
webiopi.devices.digital.GPIOPort.IN
int IN
Definition:
__init__.py:19
webiopi.devices.digital.GPIOPort.portRead
def portRead
Definition:
__init__.py:134
webiopi.devices.digital.GPIOPort.OUT
int OUT
Definition:
__init__.py:20
webiopi.devices.digital.pcf8574.PCF8574.name
name
Definition:
pcf8574.py:25
webiopi.devices.digital.pcf8574.PCF8574.__digitalRead__
def __digitalRead__
Definition:
pcf8574.py:47
webiopi.devices.i2c.I2C.slave
slave
Definition:
i2c.py:53
webiopi.devices.digital.pcf8574.PCF8574A.__init__
def __init__
Definition:
pcf8574.py:68
webiopi.devices.digital.pcf8574.PCF8574
Definition:
pcf8574.py:19
webiopi.devices.digital.pcf8574.PCF8574.__portWrite__
def __portWrite__
Definition:
pcf8574.py:64
webiopi.devices.digital.pcf8574.PCF8574.__init__
def __init__
Definition:
pcf8574.py:22
webiopi.devices.bus.Bus.writeByte
def writeByte
Definition:
bus.py:115
webiopi.devices.digital
Definition:
__init__.py:1
webiopi.devices.i2c.I2C
Definition:
i2c.py:46
webiopi.devices.digital.pcf8574.PCF8574.__setFunction__
def __setFunction__
Definition:
pcf8574.py:42
webiopi.devices.i2c
Definition:
i2c.py:1
webiopi.devices.digital.GPIOPort
Definition:
__init__.py:18
webiopi.devices.digital.pcf8574.PCF8574.FUNCTIONS
list FUNCTIONS
Definition:
pcf8574.py:20
webiopi.devices.digital.pcf8574.PCF8574.__str__
def __str__
Definition:
pcf8574.py:36
webiopi.devices.digital.pcf8574.PCF8574.__portRead__
def __portRead__
Definition:
pcf8574.py:52
webiopi.devices.digital.pcf8574.PCF8574.__getFunction__
def __getFunction__
Definition:
pcf8574.py:39
webiopi.utils.types.toint
def toint
Definition:
types.py:16
Generated on Sat Sep 10 2016 09:37:03 for Yet Another WebIOPi+ by
1.8.8