-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathbackendRelay.py
58 lines (51 loc) · 1.78 KB
/
backendRelay.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
# !/usr/bin/python
# Library for PiRelay
# Developed by: SB Components
# Author: Ankur
# Project: PiRelay
# Python: 3.4.2
#===========================================================================
import time
class Relay:
''' Class to handle Relay
Arguments:
relay = string Relay label (i.e. "RELAY1","RELAY2","RELAY3","RELAY4")
'''
relaypins = {"RELAY1":15, "RELAY2":13, "RELAY3":11, "RELAY4":7}
def __init__(self, relay, device, gpiomanager):
self.pin = self.relaypins[relay]
self.relay = relay
self.gpiomanager = gpiomanager
self.gpiomanager.initGPIO(self.pin)
self.device = device
# assume off at beginning
self.ison=False
print("{} device initialised on {}.".format(self.device, self.relay))
def on(self):
self.gpiomanager.onGPIO(self.pin)
self.ison = True
print("{} connected to {} - ON".format(self.device, self.relay))
def off(self):
self.gpiomanager.offGPIO(self.pin)
self.ison = False
print("{} connected to {} - OFF".format(self.device, self.relay))
#===========================================================================
# class Relay:
# # dummy class for testing purposes
# relaypins = {"RELAY1":15, "RELAY2":13, "RELAY3":11, "RELAY4":7}
#
# def __init__(self, relay, device):
# self.pin = self.relaypins[relay]
# self.relay = relay
# self.device = device
# # assume off at beginning
# self.ison=False
# print("{} device initialised on {}.".format(self.device, self.relay))
#
# def on(self):
# self.ison = True
# print("{} on {} - ON".format(self.device, self.relay))
#
# def off(self):
# self.ison = False
# print("{} on {} - OFF".format(self.device, self.relay))