Skip to content

Instantly share code, notes, and snippets.

@aragaer
Created December 3, 2010 09:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aragaer/726742 to your computer and use it in GitHub Desktop.
Save aragaer/726742 to your computer and use it in GitHub Desktop.
import android
import time
from math import sqrt
droid = android.Android()
droid.wakeLockAcquirePartial()
def main():
while True:
total = 0
droid.startSensing()
time.sleep(2)
data = [0, 0, 0]
for cnt in xrange(0, 10):
of = data
data = None
while True:
try:
data = droid.sensorsReadAccelerometer().result
except:
pass
if data is not None:
break
time.sleep(1)
if cnt == 0:
continue
df = [of[i] - data[i] for i in xrange(0,2)]
total += sqrt(sum([d*d for d in df]))
droid.stopSensing()
prnt = "%s: %f" % (time.asctime(), total)
with open('/sdcard/dropbox/accel.log', 'a') as out:
out.write(unicode(prnt+"\n", "utf-8").encode("utf-8", "ignore"))
print '.',
time.sleep(108)
if __name__ == "__main__":
try:
main()
except Exception as inst:
with open('/sdcard/dropbox/accel.err', 'a') as err:
errstr = "%s: %s\n" % (time.asctime(), str(inst))
err.write(unicode(str, "utf-8").encode("utf-8", "ignore"))
finally:
droid.wakeLockRelease()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment