Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins/accelerometer/accelerometer.py
diff options
context:
space:
mode:
authorWalter Bender <walter.bender@gmail.com>2011-08-09 20:15:08 (GMT)
committer Walter Bender <walter.bender@gmail.com>2011-08-09 20:15:08 (GMT)
commite8928e328c4d9aa552207551314fcf304e8d8d3b (patch)
tree1086ba5c3ac5149821dfc9b73479a0f3d9433e47 /plugins/accelerometer/accelerometer.py
parent1e69925fd32d901a5ec08c9482476b60d29dd814 (diff)
accelerometer plugin for XO 1.75 hardware
Diffstat (limited to 'plugins/accelerometer/accelerometer.py')
-rw-r--r--plugins/accelerometer/accelerometer.py86
1 files changed, 86 insertions, 0 deletions
diff --git a/plugins/accelerometer/accelerometer.py b/plugins/accelerometer/accelerometer.py
new file mode 100644
index 0000000..da3b1fa
--- /dev/null
+++ b/plugins/accelerometer/accelerometer.py
@@ -0,0 +1,86 @@
+#!/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 accelerometer plugin')
+
+
+class Accelerometer(Plugin):
+
+ def __init__(self, parent):
+ self._parent = parent
+ if os.path.exists('/sys/devices/platform/lis3lv02d/position'):
+ self._status = True
+ else:
+ self._status = False
+ self.running_sugar = self._parent.running_sugar
+
+ def setup(self):
+ # set up accelerometer specific blocks
+ palette = make_palette('sensor',
+ colors=["#FF6060", "#A06060"],
+ help_string=_('Palette of sensor blocks'))
+
+ primitive_dictionary['xyz'] = self.prim_xyz
+ if self._status:
+ palette.add_block('xyz',
+ style='basic-style-extended-vertical',
+ label=_('acceleration'),
+ 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'),
+ hidden=True,
+ prim_name='xyz')
+
+ self._parent.lc.def_prim(
+ 'xyz', 0, lambda self: primitive_dictionary['xyz']())
+
+ def _status_report(self):
+ debug_output('Reporting accelerator status: %s' % (str(self._status)))
+ return self._status
+
+ # Block primitives used in talogo
+
+ def prim_xyz(self):
+ ''' push accelerometer xyz to stack '''
+ if not self._status:
+ self._parent.lc.heap.append(0)
+ self._parent.lc.heap.append(0)
+ self._parent.lc.heap.append(0)
+ else:
+ fh = open('/sys/devices/platform/lis3lv02d/position')
+ 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]))
+ fh.close()