diff options
author | Gonzalo Odiard <godiard@gmail.com> | 2014-06-06 19:02:30 (GMT) |
---|---|---|
committer | Gonzalo Odiard <godiard@gmail.com> | 2014-06-06 19:03:00 (GMT) |
commit | 08bdd4cb5739981100e335e720cffef40f06c5da (patch) | |
tree | a467a7c7ca2e9e71e0fc6bd8050eedc85cf769e0 | |
parent | 85dc5f990ccff6572a51e53ebf8ec20af997fede (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' |