Rev Author Line No. Line
4939 kaklik 1 #!/usr/bin/python
2 import hid
3 import time
4 from time import sleep
5 import os, sys
6  
7 def init():
8 global h
9 print "Opening device"
10 h = hid.device()
11 h.open(0x10C4, 0xEA90)
12  
13 print "Manufacturer: %s" % h.get_manufacturer_string()
14 print "Product: %s" % h.get_product_string()
15 print "Serial No: %s" % h.get_serial_number_string()
16  
17 h.write([0x02, 0b00000110, 0x00, 0x00, 0x00]) # setup io pin direction
18 sleep( 1.00 )
19  
20  
21 def light(timea):
22 h.write([0x04, 0xFF, 0xFF])
23 time.sleep(timea)
24  
25 def dark(timea):
26 h.write([0x04, 0x00, 0xFF])
27 time.sleep(timea)
28  
29 def blik():
30 dark(0.8)
31 light(1)
32  
33 def check_button():
34 response = h.get_feature_report(0x03,2)
35 return response[1]
36  
37 def main():
38 init()
39 while True:
40 try:
41  
42 while True:
43 inputs = check_button()
44 print bin(inputs)
45 if not (inputs & 0b00000001) and (0b00000001):
46 blik()
47  
48 time.sleep(0.5)
49  
50 except IOError, ex:
51 print ex
52  
53 except KeyboardInterrupt:
54 print "Closing device"
55 h.close()
56  
57 print "Done"
58  
59  
60 if __name__ == "__main__":
61 main()