diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-08-27 12:30:28 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-08-27 12:30:28 (GMT) |
commit | 0a7c8b78631e651799c07488eaedd01f93437e04 (patch) | |
tree | e5ecc5631ddb2a67fb9e61dd9961a1b58bcf1cbe /plugins | |
parent | ba58030ed43e842972081a7bf13a97ab356ed927 (diff) |
using float values as per OLPC #11166
Diffstat (limited to 'plugins')
-rw-r--r-- | plugins/accelerometer/accelerometer.py | 19 | ||||
-rw-r--r-- | plugins/light_sensor/light_sensor.py | 16 |
2 files changed, 21 insertions, 14 deletions
diff --git a/plugins/accelerometer/accelerometer.py b/plugins/accelerometer/accelerometer.py index 76e9c35..615b253 100644 --- a/plugins/accelerometer/accelerometer.py +++ b/plugins/accelerometer/accelerometer.py @@ -29,11 +29,14 @@ import logging _logger = logging.getLogger('turtleart-activity accelerometer plugin') +ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position' + + class Accelerometer(Plugin): def __init__(self, parent): self._parent = parent - if os.path.exists('/sys/devices/platform/lis3lv02d/position'): + if os.path.exists(ACCELEROMETER_DEVICE): self._status = True else: self._status = False @@ -50,13 +53,15 @@ class Accelerometer(Plugin): palette.add_block('xyz', style='basic-style-extended-vertical', label=_('acceleration'), - help_string=_('push accereration in x, y, z to heap'), + help_string=\ + _('push accereration in x, y, z to heap'), prim_name='xyz') else: palette.add_block('xyz', style='basic-style-extended-vertical', label=_('acceleration'), - help_string=_('push accereration in x, y, z to heap'), + help_string=\ + _('push accereration in x, y, z to heap'), hidden=True, prim_name='xyz') @@ -76,10 +81,10 @@ class Accelerometer(Plugin): self._parent.lc.heap.append(0) self._parent.lc.heap.append(0) else: - fh = open('/sys/devices/platform/lis3lv02d/position') + fh = open(ACCELEROMETER_DEVICE) string = fh.read() xyz = string[1:-2].split(',') - self._parent.lc.heap.append(int(xyz[2])) - self._parent.lc.heap.append(int(xyz[1])) - self._parent.lc.heap.append(int(xyz[0])) + self._parent.lc.heap.append(float(xyz[2]) / 18) + self._parent.lc.heap.append(float(xyz[1]) / 18) + self._parent.lc.heap.append(float(xyz[0]) / 18) fh.close() diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py index cadf969..bf07f95 100644 --- a/plugins/light_sensor/light_sensor.py +++ b/plugins/light_sensor/light_sensor.py @@ -22,7 +22,6 @@ from gettext import gettext as _ from plugins.plugin import Plugin from TurtleArt.tapalette import make_palette -from TurtleArt.taconstants import XO1, XO15 from TurtleArt.talogo import primitive_dictionary from TurtleArt.tautils import debug_output @@ -30,11 +29,14 @@ import logging _logger = logging.getLogger('turtleart-activity light-sensor plugin') -class Accelerometer(Plugin): +LIGHT_SENSOR_DEVICE = '/sys/devices/platform/olpc-ols.0/power_state' + + +class Light_sensor(Plugin): def __init__(self, parent): self._parent = parent - if os.path.exists('/sys/devices/platform/olpc-ols.0/power_state'): + if os.path.exists(LIGHT_SENSOR_DEVICE): self._status = True else: self._status = False @@ -49,14 +51,14 @@ class Accelerometer(Plugin): primitive_dictionary['lightsensor'] = self.prim_lightsensor if self._status: palette.add_block('lightsensor', - style='basic-style-extended-vertical', + style='box-style', label=_('brightness'), help_string=\ _('light level detected by light sensor'), prim_name='lightsensor') else: palette.add_block('lightsensor', - style='basic-style-extended-vertical', + style='box-style', label=_('brightness'), help_string=\ _('light level detected by light sensor'), @@ -78,7 +80,7 @@ class Accelerometer(Plugin): if not self._status: return -1 else: - fh = open('/sys/devices/platform/olpc-ols.0/power_state') + fh = open(LIGHT_SENSOR_DEVICE) string = fh.read() fh.close() - return int(string) + return float(string) |