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-06 19:03:00 (GMT)
commit08bdd4cb5739981100e335e720cffef40f06c5da (patch)
treea467a7c7ca2e9e71e0fc6bd8050eedc85cf769e0
parent85dc5f990ccff6572a51e53ebf8ec20af997fede (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'