import logging logging.basicConfig(level=logging.DEBUG) import time import ioio port = '/dev/ttyACM0' pin = 0 state = 0 # 0 = floating # 1 = pull-up # 2 = pull-down try: import qarg ns = qarg.get('interface[str=%s,pin[int=%i,state[int=%i' % \ (port, pin, state)) port = ns.interface pin = ns.pin state = ns.state except ImportError: print "please install qarg for argument parsing: github.com/braingram/qarg" i = ioio.IOIO(port) i.write('set_pin_digital_in', pin=pin, pull=state) i.write('set_change_notify', pin=pin, cn=True) # change notify cn = i.read() # should be a 'set_change_notify' event print cn assert cn['name'] == 'set_change_notify'
# 2 250 kHz # 3 62.5 kHz mode = 1 # 0 positive # 1 negative # 2 frequency # 3 frequency 4x # 4 frequncy 16x double_prec = True incap_num = 0 try: import qarg ns = qarg.get("interface[str=%s,pin[int=%i" % (port, pin)) port = ns.interface pin = ns.pin except ImportError: print "please install qarg for argument parsing: github.com/braingram/qarg" i = ioio.IOIO(port, timeout=0.01) i.write("set_pin_digital_in", pin=pin, pull=pull) i.write("set_pin_incap", pin=pin, incap_num=incap_num, enable=True) i.write("incap_config", incap_num=incap_num, clock=clock, mode=mode, double_prec=double_prec) sp = i.read() print sp print "waiting for pulse on %s" % pin pp = i.read() try:
# return pulse_width_usec / base_usec def dc_in_clocks(pulse_width_clocks): pulse_width_clocks -= 1 if (pulse_width_clocks < 1): pw = 0 fraction = 0 else: pw = int(pulse_width_clocks) fraction = (int(pulse_width_clocks * 4) & 0x03) return pw, fraction try: import qarg ns = qarg.get('interface[str=%s,pin[int=%i' % \ (port, pin)) port = ns.interface pin = ns.pin except ImportError: print "please install qarg for argument parsing: github.com/braingram/qarg" def pwm_params(freq, duty_cycle): # dc (in clocks) # scale # period scale, period = find_scale_and_period(freq) dcc = duty_cycle_to_clocks(period, duty_cycle) pw, fraction = dc_in_clocks(dcc) se = scale_encodings[scale] sl = (se & 0x01)
def run(tilestore, *args, **kwargs): if isinstance(tilestore, (str, unicode)): tilestore = db.get_store(tilestore) set_tilestore(tilestore) # get static and template locations d = os.path.dirname(os.path.abspath(__file__)) app.static_folder = os.path.join(d, 'static') app.template_folder = os.path.join(d, 'templates') app.run(*args, **kwargs) if __name__ == '__main__': #run(debug=True) import qarg import pylab args = qarg.get('x[int=0,y[int=0,z[int=0,g(grid') if args.grid is None: im = test_render_tile(dict(x=args.x, y=args.y, z=args.z)) pylab.imshow(im) pylab.gray() pylab.show() else: pylab.subplot(221) im = test_render_tile(dict(x=0, y=0, z=1)) pylab.imshow(im) pylab.gray() pylab.subplot(222) im = test_render_tile(dict(x=1, y=0, z=1)) pylab.imshow(im) pylab.subplot(223) im = test_render_tile(dict(x=0, y=1, z=1))