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