-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathLED.py
More file actions
executable file
·80 lines (68 loc) · 2.46 KB
/
Copy pathLED.py
File metadata and controls
executable file
·80 lines (68 loc) · 2.46 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
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import term
import sensor
import traceback
import hardConf
class LED(sensor.Sensor):
typeNum = 12
def __init__(self,address,param):
try:
if hardConf.localGPIOtype and hardConf.localGPIOtype.startswith('gpio'):
#print("GPIO %s"%hardConf.localGPIO)
if hardConf.localGPIOtype == 'gpio':
hardConf.localGPIO.setup(param, hardConf.gpio_OUTPUT)
#hardConf.localGPIO.pinMode(param, hardConf.gpio_OUTPUT)
elif hardConf.localGPIOtype == 'pigpio':
hardConf.localGPIO.set_mode(param, hardConf.gpio_OUTPUT)
except:
print ("%s: init GPIO no.%d" % (address,param))
traceback.print_exc()
self.lastwrite = 0
self.phase = False # more precise blinking twice a second...
super().__init__(LED.typeNum,address,param)
def write(self,value):
self.lastwrite = value
try:
if hardConf.localGPIOtype and hardConf.localGPIOtype.startswith('gpio'):
hardConf.localGPIO.output(self.param,1 if value > 0 else 0)
elif hardConf.localGPIOtype == 'pigpio':
hardConf.localGPIO.write(self.param,1 if value > 0 else 0)
#print ("%d=%d" % (self.param,value))
#traceback.print_stack()
except:
print ("%s: %d=%d" % (self.address, self.param,value))
traceback.print_exc()
def set(self,value):
if float(value) > 1.0:
value = int(value)
elif float(value) > 0.0:
value = 1
else:
value = 0
self.write(value)
changed = super().set(value)
return changed
def display(self, format_parameter=" %d"):
if self.changed < 0.0:
attr = term.blue
elif self.changed > 0.0:
attr = term.red
else:
attr = term.black
term.write(format_parameter % self.value, attr, term.bgwhite)
def close(self):
self.set(0) # Or whatever the "non heating" solenoid value
def off(self):
self.set(0)
def blink(self,flashPerSeconds=2):
# if self.value == int(flashPerSeconds):
# if self.lastwrite == 0:
# self.write(1)
# else:
# self.write(0)
# else:
# self.set(flashPerSeconds)
self.write(1 if self.phase else 0)
def on(self):
self.set(1)