Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/plugins/arduino/arduino.py
blob: 747d2b01079c0d6720f7e71d53e0bdb9fd086763 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
# -*- coding: utf-8 -*-
# Copyright (c) 2011 Rafael Ortiz rafael@activitycentral.com 
# Arduino plugin for TurtleArt http://wiki.sugarlabs.org/go/Activities/TurtleArt
# 
# 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
# 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
                           
#Imports for TA plugins

from TurtleArt.tapalette import make_palette, palette_name_to_index
from TurtleArt.taconstants import BLACK, WHITE, CONSTANTS, BOX_COLORS
import gst
import gtk
from fcntl import ioctl
import os
from plugins.plugin import Plugin
from TurtleArt.talogo import media_blocks_dictionary, primitive_dictionary
from TurtleArt.tautils import get_path, debug_output

import logging
_logger = logging.getLogger('TurtleArt-activity plugin Arduino')


from gettext import gettext as _
#from taarduino import TAArduino  # Arduino setup TODO look at rfid implementation for arduino setup


class Arduino(Plugin):
        # plugin class
        def __init__(self, parent):
                self._parent = parent
                self._status = False

       """
         The following code will initialize a USB-arduino connection . 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.

       """
        
        def setup(self):                  # set up Arduino-specific blocks

                palette = make_palette('Arduino',  # the name of your palette
                colors=["#006060", "#A00000"],
                help_string=_('Arduino Commands'))
               
                primitive_dictionary['blink'] = self._blink_boton
                
                palette.add_block('blink',  # the name of your block
                style='basic-style',  # the block style - (more styles on tapallete.py)
                label=_('blink'),  # the label for the block
                prim_name='blink',  # 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._parent.lc.def_prim('blink', 0, lambda self, blink: primitive_dictionary['blink'](blink)) #aca debe ir las funciones para hacer blink con  arduino
                          
        def _blink_boton(self, blink):
                print "El valor del boton ", blink