/Designs/Measuring_instruments/ISMS01A/SW/Geozor.json
File deleted
/Designs/Measuring_instruments/ISMS01A/SW/button_monitor.py
1,69 → 1,49
#!/usr/bin/python
import hid
import time
import datetime
from time import sleep
import os, sys
 
from mlabutils import ejson
def init():
global h
print "Opening device"
h = hid.device()
h.open(0x10C4, 0xEA90)
 
parser = ejson.Parser()
print "Manufacturer: %s" % h.get_manufacturer_string()
print "Product: %s" % h.get_product_string()
print "Serial No: %s" % h.get_serial_number_string()
 
#### Script Arguments ###############################################
h.write([0x02, 0b00000110, 0x00, 0x00, 0x00]) # setup io pin direction
sleep( 1.00 )
 
if len(sys.argv) != 2:
sys.stderr.write("Invalid number of arguments.\n")
sys.stderr.write("Usage: %s CONFIG_FILE\n" % (sys.argv[0], ))
sys.exit(1)
 
value = parser.parse_file(sys.argv[1])
path = value['data_path']
stationName = value['origin']
def light(timea):
h.write([0x04, 0xFF, 0xFF])
time.sleep(timea)
 
def main():
def dark(timea):
h.write([0x04, 0x00, 0xFF])
time.sleep(timea)
 
while True:
def blik():
dark(0.8)
light(1)
 
print "Opening device"
h = hid.device()
h.open(0x10C4, 0xEA90)
def check_button():
response = h.get_feature_report(0x03,2)
return response[1]
 
print "Manufacturer: %s" % h.get_manufacturer_string()
print "Product: %s" % h.get_product_string()
print "Serial No: %s" % h.get_serial_number_string()
 
h.write([0x02, 0b00000110, 0x00, 0x00, 0x00]) # setup io pin direction
sleep( 1.00 )
 
response = h.get_feature_report(0x03,2)
previous_inputs = response[1]
 
def main():
init()
while True:
try:
 
while True:
response = h.get_feature_report(0x03,2)
inputs = response[1]
 
inputs = check_button()
print bin(inputs)
 
now = datetime.datetime.now()
filename = path + time.strftime("%Y%m%d%H", time.gmtime())+"0000_"+stationName+"_freq.csv"
 
if not os.path.exists(filename):
with open(filename, "a") as f:
f.write('#timestamp,IO_state \n')
f.write("%.1f,%s\n" % (time.time(), hex(inputs)))
 
if (previous_inputs != inputs):
with open(filename, "a") as f:
f.write("%.1f,%s\n" % (time.time(), hex(inputs)))
previous_inputs = inputs
 
if not (inputs & 0b00000001) and (0b00000001):
h.write([0x04, 0x00, 0xFF])
time.sleep(0.8)
h.write([0x04, 0xFF, 0xFF])
time.sleep(0.5)
blik()
 
time.sleep(0.5)
 
73,7 → 53,6
except KeyboardInterrupt:
print "Closing device"
h.close()
exit()
 
print "Done"