forked from Dan-in-CA/SIP
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgpio_pins.py
More file actions
executable file
·133 lines (107 loc) · 3.8 KB
/
Copy pathgpio_pins.py
File metadata and controls
executable file
·133 lines (107 loc) · 3.8 KB
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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# -*- coding: utf-8 -*-
import gv
try:
import RPi.GPIO as GPIO # Required for accessing General Purpose Input Output pins on Raspberry Pi
gv.platform = 'pi'
except ImportError:
try:
import Adafruit_BBIO.GPIO as GPIO # Required for accessing General Purpose Input Output pins on Beagle Bone Black
gv.platform = 'bo'
except ImportError:
gv.platform = '' # if no platform, allows program to still run.
print 'No GPIO module was loaded from GPIO Pins module'
from blinker import signal
zone_change = signal('zone_change')
try:
GPIO.setwarnings(False)
except Exception:
pass
global pin_rain_sense
global pin_relay
try:
if gv.platform == 'pi': # If this will run on Raspberry Pi:
GPIO.setmode(GPIO.BOARD) # IO channels are identified by header connector pin numbers. Pin numbers are always the same regardless of Raspberry Pi board revision.
pin_rain_sense = 8
pin_relay = 10
elif gv.platform == 'bo': # If this will run on Beagle Bone Black:
pin_rain_sense = "P9_15"
pin_relay = "P9_16"
except AttributeError:
pass
try:
GPIO.setup(pin_rain_sense, GPIO.IN)
GPIO.setup(pin_relay, GPIO.OUT)
except NameError:
pass
def setup_pins():
"""
Define and setup GPIO pins for shift register operation
"""
global pin_sr_dat
global pin_sr_clk
global pin_sr_noe
global pin_sr_lat
try:
if gv.platform == 'pi': # If this will run on Raspberry Pi:
GPIO.setmode(GPIO.BOARD) # IO channels are identified by header connector pin numbers. Pin numbers are always the same regardless of Raspberry Pi board revision.
pin_sr_dat = 13
pin_sr_clk = 7
pin_sr_noe = 11
pin_sr_lat = 15
elif gv.platform == 'bo': # If this will run on Beagle Bone Black:
pin_sr_dat = "P9_11"
pin_sr_clk = "P9_13"
pin_sr_noe = "P9_14"
pin_sr_lat = "P9_12"
except AttributeError:
pass
#### setup GPIO pins as output or input ####
try:
GPIO.setup(pin_sr_noe, GPIO.OUT)
GPIO.output(pin_sr_noe, GPIO.HIGH)
GPIO.setup(pin_sr_clk, GPIO.OUT)
GPIO.output(pin_sr_clk, GPIO.LOW)
GPIO.setup(pin_sr_dat, GPIO.OUT)
GPIO.output(pin_sr_dat, GPIO.LOW)
GPIO.setup(pin_sr_lat, GPIO.OUT)
GPIO.output(pin_sr_lat, GPIO.LOW)
except NameError:
pass
def disableShiftRegisterOutput():
"""Disable output from shift register."""
try:
pin_sr_noe
except NameError:
if gv.use_gpio_pins:
setup_pins()
try:
GPIO.output(pin_sr_noe, GPIO.HIGH)
except Exception:
pass
def enableShiftRegisterOutput():
"""Enable output from shift register."""
try:
GPIO.output(pin_sr_noe, GPIO.LOW)
except Exception:
pass
def setShiftRegister(srvals):
"""Set the state of each output pin on the shift register from the srvals list."""
try:
GPIO.output(pin_sr_clk, GPIO.LOW)
GPIO.output(pin_sr_lat, GPIO.LOW)
for s in range(gv.sd['nst']):
GPIO.output(pin_sr_clk, GPIO.LOW)
if srvals[gv.sd['nst']-1-s]:
GPIO.output(pin_sr_dat, GPIO.HIGH)
else:
GPIO.output(pin_sr_dat, GPIO.LOW)
GPIO.output(pin_sr_clk, GPIO.HIGH)
GPIO.output(pin_sr_lat, GPIO.HIGH)
except Exception:
pass
def set_output():
"""Activate triacs according to shift register state."""
disableShiftRegisterOutput()
setShiftRegister(gv.srvals) # gv.srvals stores shift register state
enableShiftRegisterOutput()
zone_change.send()