Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins
diff options
context:
space:
mode:
authorWalter Bender <walter@sugarlabs.org>2013-11-02 21:43:02 (GMT)
committer Walter Bender <walter@sugarlabs.org>2013-11-02 21:43:02 (GMT)
commit169a9e0b04aa92b53882f78e5827f0b1921468b8 (patch)
tree6cefe54ab1797576ec9c0760add076f4aa8c9707 /plugins
parentff1bb3aad03aa51f53336850c9d67594f8f353ce (diff)
add return type
Diffstat (limited to 'plugins')
-rw-r--r--plugins/audio_sensors/audio_sensors.py8
-rw-r--r--plugins/camera_sensor/camera_sensor.py45
-rw-r--r--plugins/light_sensor/light_sensor.py2
-rw-r--r--plugins/rfid/rfid.py2
4 files changed, 43 insertions, 14 deletions
diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py
index 525a244..f520330 100644
--- a/plugins/audio_sensors/audio_sensors.py
+++ b/plugins/audio_sensors/audio_sensors.py
@@ -36,6 +36,7 @@ from TurtleArt.taconstants import XO1, XO15, XO175, XO30, XO4
from TurtleArt.talogo import primitive_dictionary
from TurtleArt.tautils import debug_output
from TurtleArt.taprimitive import (ConstantArg, Primitive)
+from TurtleArt.tatype import TYPE_NUMBER
import logging
_logger = logging.getLogger('turtleart-activity audio sensors plugin')
@@ -115,12 +116,14 @@ class Audio_sensors(Plugin):
self._parent.lc.def_prim(
'sound', 0,
Primitive(self.prim_sound,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(0)},
call_afterwards=self.after_sound))
self._parent.lc.def_prim(
'volume', 0,
Primitive(self.prim_volume,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(0)},
call_afterwards=self.after_volume))
@@ -142,6 +145,7 @@ class Audio_sensors(Plugin):
self._parent.lc.def_prim(
'pitch', 0,
Primitive(self.prim_pitch,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(0)},
call_afterwards=self.after_pitch))
@@ -214,21 +218,25 @@ class Audio_sensors(Plugin):
self._parent.lc.def_prim(
'resistance', 0,
Primitive(self.prim_resistance,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(0)},
call_afterwards=self.after_resistance))
self._parent.lc.def_prim(
'voltage', 0,
Primitive(self.prim_voltage,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(0)},
call_afterwards=self.after_voltage))
self._parent.lc.def_prim(
'resistance2', 0,
Primitive(self.prim_resistance,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(1)},
call_afterwards=self.after_resistance))
self._parent.lc.def_prim(
'voltage2', 0,
Primitive(self.prim_voltage,
+ return_type=TYPE_NUMBER,
kwarg_descs={'channel': ConstantArg(1)},
call_afterwards=self.after_voltage))
diff --git a/plugins/camera_sensor/camera_sensor.py b/plugins/camera_sensor/camera_sensor.py
index 585174c..d6eac89 100644
--- a/plugins/camera_sensor/camera_sensor.py
+++ b/plugins/camera_sensor/camera_sensor.py
@@ -34,6 +34,8 @@ from TurtleArt.talogo import media_blocks_dictionary, primitive_dictionary
from TurtleArt.tautils import get_path, debug_output
from TurtleArt.taconstants import MEDIA_SHAPES, NO_IMPORT, SKIN_PATHS, \
BLOCKS_WITH_SKIN
+from TurtleArt.taprimitive import (ConstantArg, Primitive)
+from TurtleArt.tatype import TYPE_NUMBER
class Camera_sensor(Plugin):
@@ -46,6 +48,7 @@ class Camera_sensor(Plugin):
self._ag_control = None
self.devices = []
self.cameras = []
+ self.luminance = 0
if os.path.exists('/dev/video0'):
self.devices.append('/dev/video0')
@@ -69,7 +72,6 @@ class Camera_sensor(Plugin):
position=7)
# set up camera-specific blocks
- primitive_dictionary['read_camera'] = self.prim_read_camera
media_blocks_dictionary['camera'] = self.prim_take_picture0
media_blocks_dictionary['camera1'] = self.prim_take_picture1
@@ -83,9 +85,12 @@ class Camera_sensor(Plugin):
'light level detected by camera'),
value_block=True,
prim_name='luminance')
- self._parent.lc.def_prim('luminance', 0,
- lambda self: primitive_dictionary['read_camera'](
- luminance_only=True))
+ self._parent.lc.def_prim(
+ 'luminance', 0,
+ Primitive(self.prim_read_camera,
+ return_type=TYPE_NUMBER,
+ kwarg_descs={'luminance_only': ConstantArg(True)},
+ call_afterwards=self.after_luminance))
# Depreciated block
sensors_palette.add_block('read_camera',
@@ -97,8 +102,10 @@ class Camera_sensor(Plugin):
is pushed to the stack'),
value_block=True,
prim_name='read_camera')
- self._parent.lc.def_prim('read_camera', 0,
- lambda self: primitive_dictionary['read_camera']())
+ self._parent.lc.def_prim(
+ 'read_camera', 0,
+ Primitive(self.prim_read_camera,
+ kwarg_descs={'luminance_only': ConstantArg(False)}))
media_palette.add_block('camera',
style='box-style-media',
@@ -131,9 +138,12 @@ is pushed to the stack'),
_('light level detected by camera'),
value_block=True,
prim_name='read_camera')
- self._parent.lc.def_prim('luminance', 0,
- lambda self: primitive_dictionary['read_camera'](
- luminance_only=True))
+ self._parent.lc.def_prim(
+ 'luminance', 0,
+ Primitive(self.prim_read_camera,
+ return_type=TYPE_NUMBER,
+ kwarg_descs={'luminance_only': ConstantArg(True)},
+ call_afterwards=self.after_luminance))
# Depreciated block
sensors_palette.add_block('read_camera',
@@ -145,8 +155,11 @@ is pushed to the stack'),
is pushed to the stack'),
value_block=True,
prim_name='read_camera')
- self._parent.lc.def_prim('read_camera', 0,
- lambda self: primitive_dictionary['read_camera']())
+ self._parent.lc.def_prim(
+ 'read_camera', 0,
+ Primitive(self.prim_read_camera,
+ return_type=TYPE_NUMBER,
+ kwarg_descs={'luminance_only': ConstantArg(False)}))
media_palette.add_block('camera',
hidden=True,
@@ -228,19 +241,19 @@ is pushed to the stack'),
self._parent.lc.heap.append(-1)
self._parent.lc.heap.append(-1)
self._parent.lc.heap.append(-1)
- return
+ return
array = None
self._set_autogain(0, camera=camera) # disable AUTOGAIN
self._get_pixbuf_from_camera(camera=camera)
self.calc_luminance(camera=camera)
if self.luminance_only:
- self._parent.lc.update_label_value('luminance', self.luminance)
- return self.luminance
+ return int(self.luminance)
else:
self._parent.lc.heap.append(self.b)
self._parent.lc.heap.append(self.g)
self._parent.lc.heap.append(self.r)
+ return
def calc_luminance(self, camera=0):
array = self.cameras[camera].pixbuf.get_pixels()
@@ -282,6 +295,10 @@ is pushed to the stack'),
self.g = -1
self.b = -1
+ def after_luminance(self, luminance_only=False):
+ if self._parent.lc.update_values and luminance_only:
+ self._parent.lc.update_label_value('luminance', self.luminance)
+
def _set_autogain(self, state, camera=0):
''' 0 is off; 1 is on '''
if self._ag_control is not None and self._ag_control.value == state:
diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py
index 2e81c28..cd28c14 100644
--- a/plugins/light_sensor/light_sensor.py
+++ b/plugins/light_sensor/light_sensor.py
@@ -25,6 +25,7 @@ from TurtleArt.tapalette import make_palette
from TurtleArt.talogo import primitive_dictionary
from TurtleArt.tautils import debug_output
from TurtleArt.taprimitive import Primitive
+from TurtleArt.tatype import TYPE_NUMBER
import logging
_logger = logging.getLogger('turtleart-activity light-sensor plugin')
@@ -73,6 +74,7 @@ class Light_sensor(Plugin):
self._parent.lc.def_prim(
'lightsensor', 0,
Primitive(self.prim_lightsensor,
+ return_type=TYPE_NUMBER,
call_afterwards=self.after_light))
def _status_report(self):
diff --git a/plugins/rfid/rfid.py b/plugins/rfid/rfid.py
index 2b825e4..8deac63 100644
--- a/plugins/rfid/rfid.py
+++ b/plugins/rfid/rfid.py
@@ -27,6 +27,7 @@ from TurtleArt.tapalette import make_palette
from TurtleArt.talogo import primitive_dictionary
from TurtleArt.tautils import debug_output
from TurtleArt.taprimitive import Primitive
+from TurtleArt.tatype import TYPE_STRING
import logging
_logger = logging.getLogger('turtleart-activity RFID plugin')
@@ -106,6 +107,7 @@ class Rfid(Plugin):
self._parent.lc.def_prim(
'rfid', 0,
Primitive(self.prim_read_rfid,
+ return_type=TYPE_STRING,
call_afterwards=self.after_rfid))
def _status_report(self):