Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # generic_sensor.py >>> Ref: XYZircle.py
- import appuifw
- import sensor
- def circle(x, y, r, color):
- r=abs(r)
- canvas.ellipse((x-r, y-r, x+r, y+r), fill=color)
- xyz=(0,0,0)
- def draw(rect):
- canvas.clear(0x000000)
- radius = (xyz[2]*-2)+120
- point_x = (-xyz[0]+60) * canvas.size[0] / 120
- point_y = (xyz[1]+60) * canvas.size[1] / 120
- circle(point_x,point_y,radius,(255,0,0))
- #canvas.text((20,40),'X:'+unicode(-xyz[0]),(255,255,255))
- #canvas.text((20,80),'Y:'+unicode(xyz[1]),(255,255,255))
- #canvas.text((20,120),'Z:'+unicode(xyz[2]),(255,255,255))
- #canvas.blit(img) <<< not required ???
- def redraw():
- global xyz
- xyz=(sens.x,sens.y,sens.z)
- draw(canvas.size)
- appuifw.app.orientation='portrait'
- #appuifw.app.title=u'generic sensor'
- appuifw.app.directional_pad=False
- canvas=appuifw.Canvas(redraw_callback=draw)
- appuifw.app.body=canvas
- sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
- sens.set_callback(data_callback=redraw)
- ### >>> Additional Python Code <<<
- def forLight():
- appuifw.e32.reset_inactivity()
- timer.after(10,forLight)
- def exit():
- app_lock.signal()
- appuifw.app.exit_key_handler=exit
- timer=appuifw.e32.Ao_timer()
- sens.start_listening()
- forLight()
- app_lock=appuifw.e32.Ao_lock()
- app_lock.wait()
- sens.stop_listening()
- timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement