forked from schinken/py-webrelais
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparport.py
63 lines (42 loc) · 1.13 KB
/
parport.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
__author__ = 'schinken'
import parallel
class Parport(object):
conn = None
data = 0x00
def __init__(self):
self.conn = parallel.Parallel()
self.setPort()
def setPin(self, pin, value=1):
if pin > 7 or pin < 0:
raise Exception('PortPin is out of range')
if value:
self.data |= ( 0x01 << pin )
else:
self.data &= ~( 0x01 << pin )
self.setPort()
def setPins(self):
self.data = 0xFF
self.setPort()
def togglePin(self, pin ):
val = self.getPin( pin )
if val:
self.setPin( pin, 0 )
else:
self.setPin( pin, 1 )
def getPin(self, pin):
if self.data & ( 0x01 << pin ):
return True
else:
return False
def getPins(self):
pins = []
for pin in range(8):
pins.append( self.getPin( pin ) )
return pins
def resetPin(self, pin):
self.setPin(pin, 0)
def resetPins(self):
self.data = 0x00
self.setPort()
def setPort(self):
self.conn.setData( self.data )