Guest User

FreePIE - Walk with Android Phone, to Keyboard Press

a guest
Feb 23rd, 2015
323
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.71 KB | None | 0 0
  1. from threading import Timer
  2.  
  3. WalkingAccelThreshold = 4
  4. KeyDelaySeconds = 0.1
  5.  
  6. def update():
  7.    global accel
  8.    global maxaccel
  9.    accel = math.sqrt(math.fabs(math.pow(android[0].raw.ax, 2) + math.pow(android[0].raw.ay, 2) + math.pow(android[0].raw.az, 2) - math.pow(9.8, 2)))
  10.    maxaccel = max(accel, maxaccel)
  11.  
  12. def timertick():
  13.     global maxaccel
  14.     if isexecuting:
  15.         global timer
  16.         timer = Timer(KeyDelaySeconds, timertick)
  17.         timer.start()
  18.         if maxaccel >= WalkingAccelThreshold:
  19.             keyboard.setPressed(Key.W)
  20.         maxaccel = 0
  21.  
  22. if starting:
  23.    android[0].update += update
  24.    accel = 0
  25.    maxaccel = 0
  26.    isexecuting = True
  27.    timertick()
  28.    
  29. if stopping:
  30.     if timer:
  31.         timer.cancel()
  32.     isexecuting = False
Advertisement
Add Comment
Please, Sign In to add comment