diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-06-06 19:02:30 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-06-16 15:26:37 (GMT) |
commit | bc902e9c0ecf8641c79bec1a85b6d2a9581d213e (patch) | |
tree | 39e0f36ed7d4159b81637bebb6196f5ce321167f | |
parent | a5267f1a1fc8a7cd3cec158758630787b69a00ea (diff) |
Add a class to read the accelerator
-rw-r--r-- | sensors.py | 20 |
1 files changed, 20 insertions, 0 deletions
@@ -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' |