-
Notifications
You must be signed in to change notification settings - Fork 1
/
gio.py
66 lines (47 loc) · 1.82 KB
/
gio.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
64
65
66
import logging
"""
logger.basicConfig(filename='GIO.log', filemode='w',
level=logger.DEBUG,
format='%(asctime)s %(message)s',
datefmt='%m/%d/%Y %I:%M:%S %p')
"""
logger = logging.getLogger('_GIO_')
fh = logging.FileHandler('logs/GIO.log')
fh.setLevel(logging.DEBUG)
formatter = logging.Formatter('%(asctime)s - %(name)s - %(levelname)s - %(message)s')
fh.setFormatter(formatter)
logger.addHandler(fh)
class GIO:
BCM = 'BCM'
IN = 'IN'
OUT = 'OUT'
# entrada de agua
inputs = [False, False, False, False, # 0
False, False, False, True, # 1
False, False, True, False, # 2
False, False, True, True, # 3
False, True, False, False, # 4
False, True, False, False, # 4
# salida de agua
False, False, True, True, # 3
False, False, True, False, # 2
False, False, False, True, # 1
False, False, False, False, # 0
]
in_pos = 0
def setup(self, pin, pin_type):
logger.debug('Setup %d is %s'%( pin, str(pin_type) ) )
def cleanup(self):
logger.debug('Cleanup')
def setmode(self, mode):
logger.debug('set mode %s'%(mode,))
def input(self, pin):
value = self.inputs[self.in_pos]
logger.debug('Input %d is %s in %s'%(self.in_pos,
str(value),
str(pin)
))
self.in_pos = (self.in_pos+1) % (len(self.inputs))
return value
def output(self, pin, state):
logger.debug('Output pin %d is %s'%(pin, str(state) ))