-
Notifications
You must be signed in to change notification settings - Fork 3
/
platform_chip.py
54 lines (47 loc) · 1.45 KB
/
platform_chip.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
#!/usr/bin/env python3
# *****************************************
# Irrigator Raspberry Pi Interface Library
# *****************************************
#
# Description: This library supports controlling
# via the Raspberry Pi GPIOs,
# to a 8-channel relay
#
# *****************************************
# *****************************************
# Imported Libraries
# *****************************************
import CHIP_IO.GPIO as GPIO
# *****************************************
# Class Definition
# *****************************************
class Platform:
def __init__(self, _outpins, relay_trigger=0):
self.outpins = _outpins # { 'zone_00' : 17, 'zone_01': 18, etc... }
# Set the Zone / Gate Pins High
for item in self.outpins:
pin_name = "XIO-P" + str(self.outpins[item])
GPIO.setup(pin_name, GPIO.OUT)
GPIO.output(pin_name, GPIO.HIGH)
if(relay_trigger == 1):
GPIO.output(pin_name, GPIO.LOW)
else:
GPIO.output(pin_name, GPIO.HIGH)
def setrelay(self, value, zonename):
try:
pin_name = "XIO-P" + str(self.outpins[zonename])
if(value == 0):
GPIO.output(pin_name, GPIO.LOW)
else:
GPIO.output(pin_name, GPIO.HIGH)
except:
print(f'An exception occurred when changing zone {zonename} to {value}')
return(1)
return(0) # Return ErrorCode = 0
def getoutputstatus(self):
current = {}
for item in self.outpins:
current[item] = GPIO.input(self.outpins[item])
return current
def cleanup(self):
GPIO.cleanup()