/Designs/Measuring_instruments/ISMS01A/SW/button/button_monitor.py
14,69 → 14,48
print "Product: %s" % h.get_product_string()
print "Serial No: %s" % h.get_serial_number_string()
 
h.write([0x02, 0xFF, 0xFF, 0x00, 0x00])
h.write([0x02, 0b00000010, 0x00, 0x00, 0x00]) # setup io pin direction
sleep( 1.00 )
 
 
def light(timea):
global h
h.write([0x04, 0xFF, 0xFF])
print timea
time.sleep(timea)
return 0
 
def dark(timea):
global h
h.write([0x04, 0x00, 0xFF])
print timea
time.sleep(timea)
return 0
 
def neon():
light(1.15)
dark(0.02)
light(3.24)
dark(0.01)
light(1.12)
dark(0.2)
light(0.8)
def blik():
dark(0.8)
light(0.45)
dark(0.11)
light(1.0)
dark(0.2)
light(3.0)
dark(0.1)
light(4.0)
dark(0.4)
light(5)
dark(0.04)
light(0.8)
dark(0.04)
light(1)
dark(0.01)
light(2)
 
def check_button():
response = h.get_feature_report(0x03,2)
return response[1]
 
def blik():
light(1)
dark(0.8)
 
def main():
init()
try:
while 1:
#blik()
neon()
while True:
try:
 
print "Closing device"
h.close()
while True:
inputs = check_button()
print bin(inputs)
if not (inputs & 0b00000001) and (0b00000001):
blik()
 
except IOError, ex:
print ex
time.sleep(0.5)
 
print "Done"
except IOError, ex:
print ex
 
except KeyboardInterrupt:
print "Closing device"
h.close()
 
print "Done"
 
 
if __name__ == "__main__":
main()