-
Notifications
You must be signed in to change notification settings - Fork 104
Expand file tree
/
Copy pathsensors.py
More file actions
57 lines (49 loc) · 1.31 KB
/
sensors.py
File metadata and controls
57 lines (49 loc) · 1.31 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from __future__ import print_function, unicode_literals
import android
import time
skip_each = False
n_loop = 1
timeout = 3
# tests for python modification for android {{{1
def sensor(n):
print("-" * 10 + "start %d sensor" % n + "-" * 10)
droid = android.Android()
ret = droid.startSensingTimed(n, 100)
if ret.error:
if "your OS version..." in ret.error:
return True
return False
for i in range(n_loop):
tn = tb = time.time()
while tn - tb < timeout:
events = droid.eventPoll(1).result
tn = time.time()
if events:
break
time.sleep(1)
else:
print("time out...")
continue
evsensor = []
for ev in events:
if ev["name"] != "sensors":
continue
evsensor.append(ev)
if not evsensor:
continue
for ev in evsensor:
print(time.time(), end="")
print(":", end="")
print(ev["data"])
droid.stopSensing()
return False
def main():
sensor(1)
if skip_each:
return
for i in range(2, 999):
if sensor(i):
break
if __name__ == '__main__': # {{{1
main()
# vi: ft=python:et:ts=4:fdm=marker