-
Notifications
You must be signed in to change notification settings - Fork 0
/
solenoid.py
executable file
·67 lines (56 loc) · 1.61 KB
/
solenoid.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
59
60
61
62
63
64
65
66
67
#!/usr/bin/python3
# -*- coding: utf-8 -*-
import term
import sensor
import traceback
import hardConf
class Solenoid(sensor.Sensor):
typeNum = 15
onOff = ['off','ON ']
def __init__(self,address,param):
super().__init__(Solenoid.typeNum,address,param)
def set(self,value):
if float(value) > 0.0:
value = 1
else:
value = 0
changed = super().set(value)
#if changed:
# Value written may have to be reversed...
try:
if hardConf.io:
hardConf.io.write_pin(self.param,value)
#print ("%d=%d" % (self.param,value))
#traceback.print_stack()
except:
print ("%d=%d" % (self.param,value))
traceback.print_exc()
return changed
def display(self, format_param=" %s"):
if self.changed < 0.0:
attr = term.blue
elif self.changed > 0.0:
attr = term.red
else:
attr = term.black
term.write(format_param % Solenoid.onOff[self.value], attr, term.bgwhite)
def close(self):
self.set(0) # Or whatever the "non heating" solenoid value
if __name__ == "__main__":
while True:
try:
onOff = input("(-)Port=")
if not onOff:
break
onOff = int(onOff)
if onOff < 0:
port = -onOff
val = 0
else:
port = onOff
val = 1
hardConf.io.write_pin(port,val)
except:
traceback.print_exc()
break
hardConf.close()