Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGonzalo Odiard <godiard@gmail.com>2014-06-06 19:02:30 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-06-16 15:26:37 (GMT)
commitbc902e9c0ecf8641c79bec1a85b6d2a9581d213e (patch)
tree39e0f36ed7d4159b81637bebb6196f5ce321167f
parenta5267f1a1fc8a7cd3cec158758630787b69a00ea (diff)
Add a class to read the accelerator
-rw-r--r--sensors.py20
1 files changed, 20 insertions, 0 deletions
diff --git a/sensors.py b/sensors.py
index 7469612..8bbafb9 100644
--- a/sensors.py
+++ b/sensors.py
@@ -6,6 +6,26 @@ from gi.repository import GObject
GObject.threads_init()
+class Accelerometer():
+
+ ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position'
+
+ def read():
+ """
+ return x, y, z values or None if no accelerometer is available
+ """
+ try:
+ fh = open(ACCELEROMETER_DEVICE)
+ string = fh.read()
+ xyz = string[1:-2].split(',')
+ x = float(xyz[0]) / (64 * 18)
+ y = float(xyz[1]) / (64 * 18)
+ z = float(xyz[2]) / (64 * 18)
+ fh.close()
+ return x, y, z
+ except:
+ return None
+
class EbookModeDetector(GObject.GObject):
EBOOK_DEVICE = '/dev/input/event4'