-
Notifications
You must be signed in to change notification settings - Fork 0
/
switchDevice.py
72 lines (56 loc) · 1.54 KB
/
switchDevice.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
68
69
70
71
72
#!/usr/bin/python
import os
import os.path
import sys
import cgi
import cgitb;
from subprocess import call
cgitb.enable()
import FhzUtils
import FS20
import array
import time
print "content-type: text/html\n"
print "<pre>Running test program"
fhz = FhzUtils.FhzUtils('/dev/ttyUSB0')
#address = fhz.calculateByteAddress('233244141119')
address = fhz.calculateByteAddress('233244141115')
mainCode = array.array('B', [0x00,0x00])
deviceCode = array.array('B', [0x00])
mainCode[0] = address[0]
mainCode[1] = address[1]
deviceCode[0] = address[2]
form = cgi.FieldStorage()
if form.has_key("Helligkeit"):
print "****",form["Helligkeit"]
brightness = int (form["Helligkeit"].value)
else:
brightness =0
if form.has_key("device"):
print "****",form["device"]
address = fhz.calculateByteAddress(form["device"].value)
else:
address = fhz.calculateByteAddress('233244141115')
#address = fhz.calculateByteAddress('233244141119')
#address = fhz.calculateByteAddress('233244141115')
mainCode = array.array('B', [0x00,0x00])
deviceCode = array.array('B', [0x00])
mainCode[0] = address[0]
mainCode[1] = address[1]
deviceCode[0] = address[2]
print "codes ..."
print "%x : %x @ %x"%(mainCode[0], mainCode[1], deviceCode[0])
fhz.bootUpSystem()
time.sleep(1)
fs20 = FS20.FS20(mainCode, deviceCode)
#fhz.sendCommand(fs20.off())
#time.sleep(10)
print "powered off"
fhz.sendCommand(fs20.dimm(brightness))
#while True:
# try:
# fhz.recvData(True)
# except:
# pass #evil !
print "<A href='/home/index.html'>xxxxxxxxxxxxxxxxx</a>"
fhz.shutdown()