From 6da5279736ac2e9752b90156d5f673115219d93e Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Thu, 25 Aug 2011 15:53:03 +0000 Subject: adding support for XO 1.75 light sensor --- (limited to 'plugins/light_sensor') diff --git a/plugins/light_sensor/__init__.py b/plugins/light_sensor/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/plugins/light_sensor/__init__.py diff --git a/plugins/light_sensor/icons/sensoroff.svg b/plugins/light_sensor/icons/sensoroff.svg new file mode 100644 index 0000000..2d56090 --- /dev/null +++ b/plugins/light_sensor/icons/sensoroff.svg @@ -0,0 +1,36 @@ + + + +image/svg+xml + + + + + + \ No newline at end of file diff --git a/plugins/light_sensor/icons/sensoron.svg b/plugins/light_sensor/icons/sensoron.svg new file mode 100644 index 0000000..e902656 --- /dev/null +++ b/plugins/light_sensor/icons/sensoron.svg @@ -0,0 +1,41 @@ + + + +image/svg+xml + + + + + \ No newline at end of file diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py new file mode 100644 index 0000000..cadf969 --- /dev/null +++ b/plugins/light_sensor/light_sensor.py @@ -0,0 +1,84 @@ +#!/usr/bin/env python +#Copyright (c) 2011 Walter Bender +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + +import os + +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 + +import logging +_logger = logging.getLogger('turtleart-activity light-sensor plugin') + + +class Accelerometer(Plugin): + + def __init__(self, parent): + self._parent = parent + if os.path.exists('/sys/devices/platform/olpc-ols.0/power_state'): + self._status = True + else: + self._status = False + self.running_sugar = self._parent.running_sugar + + def setup(self): + # set up light-sensor specific blocks + palette = make_palette('sensor', + colors=["#FF6060", "#A06060"], + help_string=_('Palette of sensor blocks')) + + primitive_dictionary['lightsensor'] = self.prim_lightsensor + if self._status: + palette.add_block('lightsensor', + style='basic-style-extended-vertical', + label=_('brightness'), + help_string=\ + _('light level detected by light sensor'), + prim_name='lightsensor') + else: + palette.add_block('lightsensor', + style='basic-style-extended-vertical', + label=_('brightness'), + help_string=\ + _('light level detected by light sensor'), + hidden=True, + prim_name='lightsensor') + + self._parent.lc.def_prim( + 'lightsensor', 0, + lambda self: primitive_dictionary['lightsensor']()) + + def _status_report(self): + debug_output('Reporting light-sensor status: %s' % (str(self._status))) + return self._status + + # Block primitives used in talogo + + def prim_lightsensor(self): + ''' push accelerometer xyz to stack ''' + if not self._status: + return -1 + else: + fh = open('/sys/devices/platform/olpc-ols.0/power_state') + string = fh.read() + fh.close() + return int(string) -- cgit v0.9.1