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
ds2408.py
Go to the documentation of this file.
1
# Copyright 2013 Stuart Marsden
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.devices.onewire
import
OneWire
16
from
webiopi.devices.digital
import
GPIOPort
17
18
class
DS2408
(
OneWire
,
GPIOPort
):
19
FUNCTIONS = [GPIOPort.IN
for
i
in
range(8)]
20
21
def
__init__
(self, slave=None):
22
OneWire.__init__(self, slave, 0x29,
"2408"
)
23
GPIOPort.__init__(self, 8)
24
self.
portWrite
(0x00)
25
26
def
__str__
(self):
27
return
"DS2408(slave=%s)"
% self.
slave
28
29
def
__getFunction__
(self, channel):
30
return
self.
FUNCTIONS
[channel]
31
32
def
__setFunction__
(self, channel, value):
33
if
not
value
in
[self.
IN
, self.
OUT
]:
34
raise
ValueError(
"Requested function not supported"
)
35
self.
FUNCTIONS
[channel] = value
36
if
value == self.
IN
:
37
self.__output__(channel, 0)
38
39
def
__digitalRead__
(self, channel):
40
mask = 1 << channel
41
d = self.
readState
()
42
if
d !=
None
:
43
return
(d & mask) == mask
44
45
46
def
__digitalWrite__
(self, channel, value):
47
mask = 1 << channel
48
b = self.
readByte
()
49
if
value:
50
b |= mask
51
else
:
52
b &= ~mask
53
self.
writeByte
(b)
54
55
def
__portWrite__
(self, value):
56
self.
writeByte
(value)
57
58
def
__portRead__
(self):
59
return
self.
readByte
()
60
61
def
readState
(self):
62
try
:
63
with
open
(
"/sys/bus/w1/devices/%s/state"
% self.
slave
,
"rb"
)
as
f:
64
data = f.read(1)
65
return
ord(data)
66
except
IOError:
67
return
-1
68
69
def
readByte
(self):
70
try
:
71
with
open
(
"/sys/bus/w1/devices/%s/output"
% self.
slave
,
"rb"
)
as
f:
72
data = f.read(1)
73
return
bytearray(data)[0]
74
except
IOError:
75
return
-1
76
77
def
writeByte
(self, value):
78
try
:
79
with
open
(
"/sys/bus/w1/devices/%s/output"
% self.
slave
,
"wb"
)
as
f:
80
f.write(bytearray([value]))
81
except
IOError:
82
pass
83
84
webiopi.devices.digital.ds2408.DS2408.__setFunction__
def __setFunction__
Definition:
ds2408.py:32
webiopi.devices.digital.GPIOPort.portWrite
def portWrite
Definition:
__init__.py:147
webiopi.devices.digital.ds2408.DS2408.FUNCTIONS
list FUNCTIONS
Definition:
ds2408.py:19
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.ds2408.DS2408.__portWrite__
def __portWrite__
Definition:
ds2408.py:55
webiopi.devices.digital.ds2408.DS2408.__getFunction__
def __getFunction__
Definition:
ds2408.py:29
webiopi.devices.digital.GPIOPort.OUT
int OUT
Definition:
__init__.py:20
webiopi.devices.onewire
Definition:
onewire.py:1
webiopi.devices.digital.ds2408.DS2408
Definition:
ds2408.py:18
webiopi.devices.digital.ds2408.DS2408.readState
def readState
Definition:
ds2408.py:61
webiopi.devices.digital.ds2408.DS2408.__digitalWrite__
def __digitalWrite__
Definition:
ds2408.py:46
webiopi.devices.bus.Bus.writeByte
def writeByte
Definition:
bus.py:115
webiopi.devices.digital
Definition:
__init__.py:1
webiopi.devices.digital.ds2408.DS2408.__portRead__
def __portRead__
Definition:
ds2408.py:58
webiopi.devices.digital.ds2408.DS2408.writeByte
def writeByte
Definition:
ds2408.py:77
webiopi.devices.digital.ds2408.DS2408.__digitalRead__
def __digitalRead__
Definition:
ds2408.py:39
webiopi.devices.digital.ds2408.DS2408.readByte
def readByte
Definition:
ds2408.py:69
webiopi.devices.digital.GPIOPort
Definition:
__init__.py:18
webiopi.devices.bus.Bus.open
def open
Definition:
bus.py:87
webiopi.devices.digital.ds2408.DS2408.__str__
def __str__
Definition:
ds2408.py:26
webiopi.devices.digital.ds2408.DS2408.__init__
def __init__
Definition:
ds2408.py:21
webiopi.devices.onewire.OneWire
Definition:
onewire.py:29
webiopi.devices.onewire.OneWire.slave
slave
Definition:
onewire.py:40
Generated on Sat Sep 10 2016 09:37:00 for Yet Another WebIOPi+ by
1.8.8