From 1fa705293c53b4ee537d1df00474cdc4255582da Mon Sep 17 00:00:00 2001 From: Rafael Ortiz Date: Tue, 14 Jun 2011 23:06:29 +0000 Subject: re-ordering --- diff --git a/plugins/arduino/arduino_plugin.py b/plugins/arduino/arduino_plugin.py index 3babe66..4e47a8f 100644 --- a/plugins/arduino/arduino_plugin.py +++ b/plugins/arduino/arduino_plugin.py @@ -22,53 +22,21 @@ from TurtleArt.taconstants import BLACK, WHITE, CONSTANTS, BOX_COLORS from TurtleArt.tautils import debug_output from gettext import gettext as _ - -# Arduino Setup -import firmata - -class TAArduino(object): - def __init__(self, dev='/dev/ttyUSB0', baud=115200): - object.__init__(self) - self._dev = dev - self._baud = baud - self._arduino = None # Do not initialize this now - - self.HIGH = firmata.HIGH - self.LOW = firmata.LOW - self.INPUT = firmata.INPUT - self.OUTPUT = firmata.OUTPUT - self.PWM = firmata.PWM - self.SERVO = firmata.SERVO - - def _check_init(self): - if self._arduino is None: - self._arduino = firmata.Arduino(port = self._dev, \ - baudrate=self._baud) - self._arduino.parse() - - def delay(self, secs): - # Do not use this. The firmata module uses time.sleep() to - # implement this, which breaks gtk+ (unresponsive window) - self._check_init() - self._arduino.delay(secs) - - def pin_mode(self, pin, mode): - self._check_init() - self._arduino.pin_mode(int(pin), mode) - - def analog_write(self, pin, value): - self._check_init() - self._arduino.analog_write(int(pin), int(value)) - - def digital_write(self, pin, value): - self._check_init() - self._arduino.digital_write(int(pin), value) - - def analog_read(self, pin): - self._check_init() - self._arduino.parse() #XXX: Not sure why I have to do this here. - return self._arduino.analog_read(int(pin)) - - def digital_read(self, pin): - self._check_init() - return self._arduino.digital_read(int(pin)) +from taarduino import TAArduino # Arduino setup + + +class Arduino_plugin(Plugin): # plugin class + palette = make_palette('Arduino', # the name of your palette + colors=["#00FF00", "#00A000"], + help_string=_('Arduino Commands')) + + palette.add_block('blink', # the name of your block + style='basic-style', # the block style + label=_('blink'), # the label for the block + prim_name='uturn', # code reference (see below) + help_string=_('blinks the onboard arduino led')) + # Next, you need to define what your block will do: + # def_prim takes 3 arguments: the primitive name, the number of + # of arguments, 0 in this case, and the function to call, in this + # case, the canvas function to set the heading. + self.tw.lc.def_prim('blink', 0, lambda self: self.tw.canvas.seth(self.tw.canvas.heading + 180)) #aca debe ir la funcionde arduino diff --git a/plugins/arduino/taarduino.py b/plugins/arduino/taarduino.py new file mode 100644 index 0000000..00d7abf --- /dev/null +++ b/plugins/arduino/taarduino.py @@ -0,0 +1,68 @@ +#!/usr/bin/python +# -*- coding: utf-8 -*- +# +# 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 firmata + + +class TAArduino(object): + def __init__(self, fdev='/dev/ttyUSB0', baud=115200): + object.__init__(self) + self._dev = dev + self._baud = baud + self._arduino = None # Do not initialize this now + + self.HIGH = firmata.HIGH + self.LOW = firmata.LOW + self.INPUT = firmata.INPUT + self.OUTPUT = firmata.OUTPUT + self.PWM = firmata.PWM + self.SERVO = firmata.SERVO + + def _check_init(self): + if self._arduino is None: + self._arduino = firmata.Arduino(port = self._dev, \ + baudrate = self._baud) + self._arduino.parse() + + def delay(self, secs): + # Do not use this. The firmata module uses time.sleep() to + # implement this, which breaks gtk+ (unresponsive window) + self._check_init() + self._arduino.delay(secs) + + def pin_mode(self, pin, mode): + self._check_init() + self._arduino.pin_mode(int(pin), mode) + + def analog_write(self, pin, value): + self._check_init() + self._arduino.analog_write(int(pin), int(value)) + + def digital_write(self, pin, value): + self._check_init() + self._arduino.digital_write(int(pin), value) + + def analog_read(self, pin): + self._check_init() + self._arduino.parse() # XXX: Not sure why I have to do this here. + return self._arduino.analog_read(int(pin)) + + def digital_read(self, pin): + self._check_init() + return self._arduino.digital_read(int(pin)) + + -- cgit v0.9.1