-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtoggleOneChannel.py
47 lines (39 loc) · 1.24 KB
/
toggleOneChannel.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
import RPi.GPIO as GPIO
from pwmPCA9685 import pwm as pwm
import time
import threading
class toggleOneChannel(threading.Thread):
def __init__(self, config = {}, name="pump"):
threading.Thread.__init__(self, name=name)
self.out = pwm(config['output'],255)
self.tempTimer = -1
self.timer = -1
if 'timer' in config:
self.timer = config['timer']
self.on = False
def set(self, value):
print("setting channel (pump)")
if (value == 1):
self.on = True
self.out.set(255)
if (self.timer != -1):
self.startTimer()
else:
self.on = False
self.out.set(0)
if (self.tempTimer != -1):
self.timer = self.tempTimer
self.tempTimer = -1
return
def setMQTT(self,value,timer=-1):
self.set(int(value))
def setScheduler(self,timer):
if (timer != -1):
self.tempTimer = self.timer
self.timer = timer
self.set(1)
def startTimer(self):
start = time.time()
while (time.time() < start + self.timer):
time.sleep(0.1)
self.set(0)