diff options
author | Walter Bender <walter.bender@gmail.com> | 2011-02-18 14:19:14 (GMT) |
---|---|---|
committer | Walter Bender <walter.bender@gmail.com> | 2011-02-18 14:19:14 (GMT) |
commit | 676d559cd62e35d7718d15a821b43aa7c4cfd28d (patch) | |
tree | 3038d4c84c4a7f9c3aeac8bc20c9f3263f41f0ff /TurtleArt | |
parent | 404683aaf6f71f1a3902195098bbfa049cc652ad (diff) |
moved rfid code to plugin
Diffstat (limited to 'TurtleArt')
-rw-r--r-- | TurtleArt/taconstants.py | 6 | ||||
-rw-r--r-- | TurtleArt/talogo.py | 18 | ||||
-rw-r--r-- | TurtleArt/tawindow.py | 81 |
3 files changed, 5 insertions, 100 deletions
diff --git a/TurtleArt/taconstants.py b/TurtleArt/taconstants.py index 54fc099..4cf6ee1 100644 --- a/TurtleArt/taconstants.py +++ b/TurtleArt/taconstants.py @@ -223,7 +223,7 @@ BOX_STYLE = ['number', 'xcor', 'ycor', 'heading', 'pensize', 'color', 'shade', 'toppos', 'rightpos', 'bottompos', 'width', 'height', 'pop', 'keyboard', 'red', 'orange', 'yellow', 'green', 'cyan', 'blue', 'purple', 'white', 'black', 'titlex', 'titley', 'leftx', 'topy', 'rightx', 'bottomy', - 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see', 'rfid', + 'sound', 'volume', 'pitch', 'voltage', 'resistance', 'gray', 'see', 'time'] BOX_STYLE_MEDIA = ['description', 'audio', 'journal', 'video'] NUMBER_STYLE = ['plus2', 'product2', 'myfunc'] @@ -396,7 +396,6 @@ BLOCK_NAMES = { 'resistance': [_('resistance')], 'restore': [_('restore last')], 'restoreall': [_('restore all')], - 'rfid': [_('RFID')], 'right': [_('right')], 'rightpos': [_('right')], 'rightx': [_('picture right')], @@ -520,7 +519,6 @@ PRIMITIVES = { 'leftx': 'leftx', 'less2': 'less?', 'list': 'bulletlist', - 'luminance': 'luminance', 'mediawait': 'mediawait', 'minus2': 'minus', 'myfunc': 'myfunction', @@ -550,7 +548,6 @@ PRIMITIVES = { 'remainder2': 'mod', 'repeat': 'repeat', 'resistance': 'resistance', - 'rfid': 'rfid', 'right': 'right', 'rightpos': 'rpos', 'rightx': 'rightx', @@ -880,7 +877,6 @@ HELP_STRINGS = { 'reskin': _("put a custom 'shell' on the turtle"), 'restore': _("restores most recent blocks from trash"), 'restoreall': _("restore all blocks from trash"), - 'rfid': _("RFID"), 'rightpos': _("xcor of right of screen"), 'right': _("turns turtle clockwise (angle in degrees)"), 'run-fastoff': _("Run"), diff --git a/TurtleArt/talogo.py b/TurtleArt/talogo.py index 38f2586..953c296 100644 --- a/TurtleArt/talogo.py +++ b/TurtleArt/talogo.py @@ -61,23 +61,6 @@ import logging _logger = logging.getLogger('turtleart-activity') -def find_device(): - """ Search for RFID devices. Return a device instance or None. """ - device = None - for i in os.listdir(os.path.join('.', 'devices')): - if not os.path.isdir(os.path.join('.', 'devices', i)): - try: - _tempmod = __import__('devices.%s' % i.split('.')[0], - globals(), locals(), ['RFIDReader'], -1) - devtemp = _tempmod.RFIDReader() - if devtemp.get_present() == True: - device = devtemp - except Exception, e: - _logger.error("FIND_DEVICE: %s: %s" % (i, e)) - pass - return device - - class noKeyError(UserDict): __missing__ = lambda x, y: 0 @@ -398,7 +381,6 @@ class LogoCode: 'red': [0, lambda self: CONSTANTS['red']], 'repeat': [2, self._prim_repeat, True], 'resistance': [0, lambda self: self._get_resistance()], - 'rfid': [0, lambda self: self.tw.rfid_idn], 'right': [1, lambda self, x: self._prim_right(x)], 'rightx': [0, lambda self: CONSTANTS['rightx']], 'rpos': [0, lambda self: CONSTANTS['rightpos']], diff --git a/TurtleArt/tawindow.py b/TurtleArt/tawindow.py index 73894e4..589e60c 100644 --- a/TurtleArt/tawindow.py +++ b/TurtleArt/tawindow.py @@ -2,7 +2,6 @@ #Copyright (c) 2007, Playful Invention Company #Copyright (c) 2008-11, Walter Bender #Copyright (c) 2009-11 Raúl Gutiérrez Segalés -#Copyright (C) 2010 Emiliano Pastorino <epastorino@plan.ceibal.edu.uy> #Copyright (c) 2011 Collabora Ltd. <http://www.collabora.co.uk/> #Permission is hereby granted, free of charge, to any person obtaining a copy @@ -84,20 +83,12 @@ from tautils import magnitude, get_load_name, get_save_name, data_from_file, \ get_hardware from tasprite_factory import SVG, svg_str_to_pixbuf, svg_from_file from sprites import Sprites, Sprite -from rfidutils import strhex2bin, strbin2dec, find_device from dbus.mainloop.glib import DBusGMainLoop if GST_AVAILABLE: from tagplay import stop_media from audiograb import AudioGrab_Unknown, AudioGrab_XO1, AudioGrab_XO15 -HAL_SERVICE = 'org.freedesktop.Hal' -HAL_MGR_PATH = '/org/freedesktop/Hal/Manager' -HAL_MGR_IFACE = 'org.freedesktop.Hal.Manager' -HAL_DEV_IFACE = 'org.freedesktop.Hal.Device' -REGEXP_SERUSB = '\/org\/freedesktop\/Hal\/devices\/usb_device['\ - 'a-z,A-Z,0-9,_]*serial_usb_[0-9]' - import logging _logger = logging.getLogger('turtleart-activity') @@ -288,40 +279,6 @@ class TurtleArtWindow(): self.saved_pictures = [] self.block_operation = '' - """ - The following code will initialize a USB RFID reader. Please note that - in order to make this initialization function work, it is necessary to - set the permission for the ttyUSB device to 0666. You can do this by - adding a rule to /etc/udev/rules.d - - As root (using sudo or su), copy the following text into a new file in - /etc/udev/rules.d/94-ttyUSB-rules - - KERNEL=="ttyUSB[0-9]",MODE="0666" - - You only have to do this once. - """ - - self.rfid_connected = False - self.rfid_device = find_device() - self.rfid_idn = '' - - if self.rfid_device is not None: - _logger.info("RFID device found") - self.rfid_connected = self.rfid_device.do_connect() - if self.rfid_connected: - self.rfid_device.connect("tag-read", self._tag_read_cb) - self.rfid_device.connect("disconnected", self._disconnected_cb) - - loop = DBusGMainLoop() - bus = dbus.SystemBus(mainloop=loop) - hmgr_iface = dbus.Interface(bus.get_object(HAL_SERVICE, - HAL_MGR_PATH), HAL_MGR_IFACE) - - hmgr_iface.connect_to_signal('DeviceAdded', self._device_added_cb) - - PALETTES[PALETTE_NAMES.index('sensor')].append('rfid') - #### def _get_plugin_home(self): @@ -364,50 +321,20 @@ class TurtleArtWindow(): f = "def f(self): from plugins.%s import %s; return %s(self)" \ % (p, P, P) plugin = {} + exec f in globals(), plugin + self._plugins.append(plugin.values()[0](self)) + ''' try: exec f in globals(), plugin self._plugins.append(plugin.values()[0](self)) except ImportError: print 'failed to import %s' % (P) + ''' def _run_plugins(self): for p in self._plugins: p.setup() - #### - - def _device_added_cb(self, path): - """ - Called from hal connection when a new device is plugged. - """ - if not self.rfid_connected: - self.rfid_device = find_device() - _logger.debug("DEVICE_ADDED: %s" % self.rfid_device) - if self.rfid_device is not None: - _logger.debug("DEVICE_ADDED: RFID device is not None!") - self.rfid_connected = self._device.do_connect() - if self.rfid_connected: - _logger.debug("DEVICE_ADDED: Connected!") - self.rfid_device.connect("tag-read", self._tag_read_cb) - self.rfid_device.connect("disconnected", self._disconnected_cb) - - def _disconnected_cb(self, device, text): - """ - Called when the device is disconnected. - """ - self.rfid_connected = False - self.rfid_device = None - - def _tag_read_cb(self, device, tagid): - """ - Callback for "tag-read" signal. Receives the read tag id. - """ - idbin = strhex2bin(tagid) - self.rfid_idn = strbin2dec(idbin[26:64]) - while self.rfid_idn.__len__() < 9: - self.rfid_idn = '0' + self.rfid_idn - print tagid, idbin, self.rfid_idn - def new_buffer(self, buf): """ Append a new buffer to the ringbuffer """ self.lc.ringbuffer.append(buf) |