Debian Codegraph @

plyer/platforms/linux/accelerometer.py

raw symbols SCIP
1 '''
2 Linux accelerometer
3 ---------------------
4 '''
5
6 from plyer.facades import Accelerometer
7 import glob
8 import re
9
10
11 class LinuxAccelerometer(Accelerometer):
12
13 def _enable(self):
14 pass
15
16 def _disable(self):
17 pass
18
19 def _get_acceleration(self):
20 try:
21 pos = glob.glob("/sys/devices/platform/*/position")[0]
22 except IndexError:
23 raise Exception('Could not enable accelerometer!')
24
25 with open(pos, "r") as p:
26 t = p.read()
27 coords = re.findall(r"[-]?\d+\.?\d*", t)
28 # Apparently the acceleration on sysfs goes from -1000 to 1000.
29 # I divide it by 100 to make it equivalent to Android.
30 # The negative is because the coordinates are inverted on Linux
31 return [float(i) / -100 for i in coords]
32
33
34 def instance():
35 return LinuxAccelerometer()