Advertisement
here2share

# generic_sensor.py >>> Ref: XYZircle.py

Jan 11th, 2015
402
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # generic_sensor.py >>> Ref: XYZircle.py
  2.  
  3. import appuifw
  4. import sensor
  5.  
  6. def circle(x, y, r, color):
  7.     r=abs(r)
  8.     canvas.ellipse((x-r, y-r, x+r, y+r), fill=color)
  9.  
  10. xyz=(0,0,0)
  11. def draw(rect):
  12.     canvas.clear(0x000000)
  13.     radius = (xyz[2]*-2)+120
  14.     point_x = (-xyz[0]+60) * canvas.size[0] / 120
  15.     point_y = (xyz[1]+60) * canvas.size[1] / 120
  16.     circle(point_x,point_y,radius,(255,0,0))
  17.     #canvas.text((20,40),'X:'+unicode(-xyz[0]),(255,255,255))
  18.     #canvas.text((20,80),'Y:'+unicode(xyz[1]),(255,255,255))
  19.     #canvas.text((20,120),'Z:'+unicode(xyz[2]),(255,255,255))
  20.     #canvas.blit(img) <<< not required ???
  21.  
  22. def redraw():
  23.     global xyz
  24.     xyz=(sens.x,sens.y,sens.z)
  25.     draw(canvas.size)
  26.  
  27. appuifw.app.orientation='portrait'
  28. #appuifw.app.title=u'generic sensor'
  29. appuifw.app.directional_pad=False
  30. canvas=appuifw.Canvas(redraw_callback=draw)
  31. appuifw.app.body=canvas
  32. sens=sensor.AccelerometerXYZAxisData(data_filter=sensor.LowPassFilter())
  33. sens.set_callback(data_callback=redraw)
  34.  
  35. ### >>> Additional Python Code <<<
  36.  
  37. def forLight():
  38.     appuifw.e32.reset_inactivity()
  39.     timer.after(10,forLight)
  40.  
  41. def exit():
  42.     app_lock.signal()
  43. appuifw.app.exit_key_handler=exit
  44.  
  45. timer=appuifw.e32.Ao_timer()
  46. sens.start_listening()
  47. forLight()
  48. app_lock=appuifw.e32.Ao_lock()
  49. app_lock.wait()
  50. sens.stop_listening()
  51. timer.cancel()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement