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 20:35:00 (GMT)
committer Gonzalo Odiard <godiard@gmail.com>2014-06-16 15:26:37 (GMT)
commite5d667273d209b17b43ed3bbb666161c8786364f (patch)
tree0dc4296c0ea7afca3bde6b74c9458a39bda0c1f4
parentbc902e9c0ecf8641c79bec1a85b6d2a9581d213e (diff)
Make the sensors work when the hardware is not available
-rw-r--r--sensors.py26
1 files changed, 13 insertions, 13 deletions
diff --git a/sensors.py b/sensors.py
index 8bbafb9..8cd9e36 100644
--- a/sensors.py
+++ b/sensors.py
@@ -10,21 +10,19 @@ class Accelerometer():
ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position'
- def read():
+ def read_position(self):
"""
return x, y, z values or None if no accelerometer is available
"""
try:
- fh = open(ACCELEROMETER_DEVICE)
+ fh = open(self.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
+ return int(xyz[0]), int(xyz[1]), int(xyz[2])
except:
- return None
+ return 0, 0, 0
+
class EbookModeDetector(GObject.GObject):
@@ -42,11 +40,13 @@ class EbookModeDetector(GObject.GObject):
return self._ebook_mode
def _get_initial_value(self):
- output = subprocess.call(['evtest', '--query', self.EBOOK_DEVICE,
- 'EV_SW', 'SW_TABLET_MODE'])
- # 10 is ebook_mode, 0 is normal
- return (output == 10)
- logging.error('Initial state %s', (output == 10))
+ try:
+ output = subprocess.call(['evtest', '--query', self.EBOOK_DEVICE,
+ 'EV_SW', 'SW_TABLET_MODE'])
+ # 10 is ebook_mode, 0 is normal
+ return (output == 10)
+ except:
+ return False
def _start_reading(self):
thread = threading.Thread(target=self._read)
@@ -65,7 +65,7 @@ class EbookModeDetector(GObject.GObject):
# restart
GObject.idle_add(self._start_reading)
-# Move to tests
+# TODO: Move to tests
import logging
from gi.repository import Gtk