From 29851fcbe3b4d392efd5a873f92666da27ec0e99 Mon Sep 17 00:00:00 2001 From: Walter Bender Date: Sat, 25 May 2013 22:12:48 +0000 Subject: patches to create confusion --- diff --git a/TurtleArtActivity.py b/TurtleArtActivity.py index 268f703..d9c89d7 100644 --- a/TurtleArtActivity.py +++ b/TurtleArtActivity.py @@ -43,6 +43,10 @@ from sugar.graphics.toolbutton import ToolButton from sugar.graphics.radiotoolbutton import RadioToolButton from sugar.graphics.alert import (ConfirmationAlert, NotifyAlert) from sugar.graphics import style +from sugar.graphics.combobox import ComboBox +from sugar.graphics.toolcombobox import ToolComboBox +from sugar.graphics.objectchooser import ObjectChooser +from sugar import mime from sugar.datastore import datastore from sugar import profile @@ -90,6 +94,9 @@ class TurtleArtActivity(activity.Activity): self._check_ver_change(get_path(activity, 'data')) self.connect("notify::active", self._notify_active_cb) + self._level = 0 + self._custom_filepath = None + self.has_toolbarbox = HAS_TOOLBARBOX _logger.debug('_setup_toolbar') self._setup_toolbar() @@ -292,8 +299,10 @@ class TurtleArtActivity(activity.Activity): return if not self.has_toolbarbox: self.palette_buttons[i].set_icon(palette_names[i] + 'on') + ''' else: self._help_button.set_current_palette(palette_names[i]) + ''' self.tw.show_palette(n=i) self.do_showpalette() @@ -341,6 +350,13 @@ class TurtleArtActivity(activity.Activity): self.tw.eraser_button() gobject.timeout_add(250, self.eraser_button.set_icon, 'eraseron') + def restore_challenge(self): + ''' Restore the current challange after a clear screen ''' + if self._custom_filepath is None: + self._load_level() + else: + self._load_level(custom=True) + def do_run_cb(self, button): ''' Callback for run button (rabbit) ''' self.run_button.set_icon('run-faston') @@ -500,6 +516,14 @@ class TurtleArtActivity(activity.Activity): # Given the change in how overlays are handled (v123), there is no way # to erase and then redraw the overlays. + def _do_help_cb(self, button): + if os.path.exists(os.path.join( + activity.get_bundle_path(), 'challenges', + 'help-' + str(self._level + 1) + '.ta')): + self.read_file(os.path.join( + activity.get_bundle_path(), 'challenges', + 'help-' + str(self._level + 1) + '.ta')) + def get_document_path(self, async_cb, async_err_cb): ''' View TA code as part of view source. ''' ta_code_path = self._dump_ta_code() @@ -597,7 +621,11 @@ class TurtleArtActivity(activity.Activity): self.palette_toolbar_button = ToolbarButton( page=self._palette_toolbar, icon_name='palette') - self._help_button = HelpButton(self) + self._help_button = self._add_button('help-toolbar', + _('Help'), + self._do_help_cb, + None) + # self._help_button = HelpButton(self) self._make_load_save_buttons(self.activity_toolbar_button) @@ -852,6 +880,9 @@ class TurtleArtActivity(activity.Activity): self._overflow_box.remove(button) if self._overflow_palette_button in self._palette_toolbar: self._palette_toolbar.remove(self._overflow_palette_button) + if hasattr(self, '_levels_combo') and \ + self._levels_tool in self._palette_toolbar: + self._palette_toolbar.remove(self._levels_tool) for i in range(len(self.palette_buttons)): if i < max_palettes: @@ -870,6 +901,8 @@ class TurtleArtActivity(activity.Activity): if self.tw.hw in [XO1, XO15, XO175, XO4]: self._make_palette_buttons(self._palette_toolbar) ''' + self._make_confusion_combo(self._palette_toolbar) + self._palette_toolbar.show() self._overflow_box.show_all() self._overflow_palette.set_content(self._overflow_sw) @@ -992,6 +1025,17 @@ class TurtleArtActivity(activity.Activity): self._palette.popdown(immediate=True) return + def _make_confusion_combo(self, toolbar): + if hasattr(self, '_levels_tools'): + toolbar.insert(self._levels_tools, -1) + else: + self._levels = self._get_levels(activity.get_bundle_path()) + self._levels_combo, self._levels_tool = \ + self._combo_factory(self._levels, + _('Select a challenge'), + toolbar, + self._levels_cb) + def _make_palette_buttons(self, toolbar, palette_button=False): ''' Creates the palette and block buttons for both toolbar types''' if palette_button: # old-style toolbars need this button @@ -1508,6 +1552,89 @@ in order to use the plugin.')) help_strings[name] = tooltip return button + def _combo_factory(self, options, tooltip, toolbar, callback, default=0): + ''' Combo box factory ''' + combo = ComboBox() + if hasattr(combo, 'set_tooltip_text'): + combo.set_tooltip_text(tooltip) + combo.connect('changed', callback) + for i, option in enumerate(options): + combo.append_item(i, option.replace('-', ' '), None) + combo.set_active(default) + combo.show() + tool = ToolComboBox(combo) + tool.show() + if hasattr(toolbar, 'insert'): + toolbar.insert(tool, -1) + else: + toolbar.props.page.insert(tool, -1) + return combo, tool + + def _get_levels(self, path): + ''' Look for level files in lessons directory. ''' + level_files = [] + """ + if path is not None: + candidates = os.listdir(os.path.join(path, 'challenges')) + for filename in candidates: + level_files.append(filename.split('.')[0]) + """ + for i in range(40): + level_files.append('confusion-%d' % (i+1)) + + ''' + ''' + self.offsets = {} + offset_fd = open(os.path.join(activity.get_bundle_path(), 'challenges', + 'offsets')) + for line in offset_fd: + try: + idx, offsets = line.strip('\n').split(':') + xoffset, yoffset = offsets.split(',') + self.offsets[int(idx)] = (int(xoffset), int(yoffset)) + except ValueError: + pass + offset_fd.close() + return level_files + + def _levels_cb(self, combobox=None): + ''' The combo box has changed. ''' + if hasattr(self, '_levels_combo'): + i = self._levels_combo.get_active() + if i != -1: # and i != self._level: + self._level = i + self._load_level() + self._custom_filepath = None + + def _load_level(self, custom=False): + self.tw.canvas.clearscreen() + if custom: + self.tw.canvas.setxy(0, 0, pendown=False) + self.tw.lc.insert_image(center=True, + filepath=self._custom_filepath, + resize=True, offset=False) + else: + self.tw.canvas.setxy(int(-gtk.gdk.screen_width() / 2), 0, + pendown=False) + self.tw.lc.insert_image(center=False, resize=False, + filepath=os.path.join( + activity.get_bundle_path(), 'images', + 'turtle-a.png')) + # Slight offset to account for stroke width + if self._level + 1 in self.offsets: + xoffset = self.offsets[self._level + 1][0] + yoffset = self.offsets[self._level + 1][1] + else: + xoffset = 0 + yoffset = 0 + self.tw.canvas.setxy(-2.5 + xoffset, -2.5 + yoffset, pendown=False) + self.tw.lc.insert_image(center=False, + filepath=os.path.join( + activity.get_bundle_path(), 'challenges', + self._levels[self._level] + '.svg'), resize=False, + offset=True) + self.tw.canvas.setxy(0, 0, pendown=False) + def _radio_button_factory(self, button_name, toolbar, cb, arg, tooltip, group, position=-1): ''' Add a radio button to a toolbar ''' diff --git a/activity/activity-turtleart.svg b/activity/activity-turtleart.svg index 9c2147f..b627d91 100644 --- a/activity/activity-turtleart.svg +++ b/activity/activity-turtleart.svg @@ -2,25 +2,210 @@ ]> - - - - - - - + + + + - - - + + + - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/activity/activity.info b/activity/activity.info index e9190ef..eeeb760 100644 --- a/activity/activity.info +++ b/activity/activity.info @@ -1,8 +1,8 @@ [Activity] -name = TurtleBlocks +name = Turtle Confusion activity_version = 179 license = MIT -bundle_id = org.laptop.TurtleArtActivity +bundle_id = org.laptop.TurtleConfusionActivity exec = sugar-activity TurtleArtActivity.TurtleArtActivity icon = activity-turtleart show_launcher = yes diff --git a/challenges/confusion-1.svg b/challenges/confusion-1.svg new file mode 100644 index 0000000..d46a36b --- /dev/null +++ b/challenges/confusion-1.svg @@ -0,0 +1,92 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + 200 + diff --git a/challenges/confusion-10.svg b/challenges/confusion-10.svg new file mode 100644 index 0000000..3854e12 --- /dev/null +++ b/challenges/confusion-10.svg @@ -0,0 +1,96 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + 150 + + diff --git a/challenges/confusion-11.svg b/challenges/confusion-11.svg new file mode 100644 index 0000000..acdd96d --- /dev/null +++ b/challenges/confusion-11.svg @@ -0,0 +1,100 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-12.svg b/challenges/confusion-12.svg new file mode 100644 index 0000000..979e9e8 --- /dev/null +++ b/challenges/confusion-12.svg @@ -0,0 +1,108 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-13.svg b/challenges/confusion-13.svg new file mode 100644 index 0000000..82f9fd5 --- /dev/null +++ b/challenges/confusion-13.svg @@ -0,0 +1,555 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 230 + + diff --git a/challenges/confusion-14.svg b/challenges/confusion-14.svg new file mode 100644 index 0000000..15bbc4d --- /dev/null +++ b/challenges/confusion-14.svg @@ -0,0 +1,139 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + diff --git a/challenges/confusion-15.svg b/challenges/confusion-15.svg new file mode 100644 index 0000000..4c637dc --- /dev/null +++ b/challenges/confusion-15.svg @@ -0,0 +1,95 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + 200 + + diff --git a/challenges/confusion-16.svg b/challenges/confusion-16.svg new file mode 100644 index 0000000..a3a156e --- /dev/null +++ b/challenges/confusion-16.svg @@ -0,0 +1,274 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + + + + 50 + + diff --git a/challenges/confusion-17.svg b/challenges/confusion-17.svg new file mode 100644 index 0000000..373428f --- /dev/null +++ b/challenges/confusion-17.svg @@ -0,0 +1,172 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-18.svg b/challenges/confusion-18.svg new file mode 100644 index 0000000..45d5b42 --- /dev/null +++ b/challenges/confusion-18.svg @@ -0,0 +1,250 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + 70 + + diff --git a/challenges/confusion-19.svg b/challenges/confusion-19.svg new file mode 100644 index 0000000..907708f --- /dev/null +++ b/challenges/confusion-19.svg @@ -0,0 +1,292 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + diff --git a/challenges/confusion-2.svg b/challenges/confusion-2.svg new file mode 100644 index 0000000..61b3bdd --- /dev/null +++ b/challenges/confusion-2.svg @@ -0,0 +1,139 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 200 + + + + 100 + diff --git a/challenges/confusion-20.svg b/challenges/confusion-20.svg new file mode 100644 index 0000000..918c8aa --- /dev/null +++ b/challenges/confusion-20.svg @@ -0,0 +1,236 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-21.svg b/challenges/confusion-21.svg new file mode 100644 index 0000000..3dde6af --- /dev/null +++ b/challenges/confusion-21.svg @@ -0,0 +1,274 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + 70 + + diff --git a/challenges/confusion-22.svg b/challenges/confusion-22.svg new file mode 100644 index 0000000..2ca3ff4 --- /dev/null +++ b/challenges/confusion-22.svg @@ -0,0 +1,267 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + diff --git a/challenges/confusion-23.svg b/challenges/confusion-23.svg new file mode 100644 index 0000000..87fbfa2 --- /dev/null +++ b/challenges/confusion-23.svg @@ -0,0 +1,172 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + diff --git a/challenges/confusion-24.svg b/challenges/confusion-24.svg new file mode 100644 index 0000000..0a8ce5b --- /dev/null +++ b/challenges/confusion-24.svg @@ -0,0 +1,244 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-25.svg b/challenges/confusion-25.svg new file mode 100644 index 0000000..da87507 --- /dev/null +++ b/challenges/confusion-25.svg @@ -0,0 +1,313 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 75 + + + + + + 25 + + + diff --git a/challenges/confusion-26.svg b/challenges/confusion-26.svg new file mode 100644 index 0000000..9ce1c9b --- /dev/null +++ b/challenges/confusion-26.svg @@ -0,0 +1,196 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + diff --git a/challenges/confusion-27.svg b/challenges/confusion-27.svg new file mode 100644 index 0000000..bbf6e8c --- /dev/null +++ b/challenges/confusion-27.svg @@ -0,0 +1,459 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + diff --git a/challenges/confusion-28.svg b/challenges/confusion-28.svg new file mode 100644 index 0000000..6721145 --- /dev/null +++ b/challenges/confusion-28.svg @@ -0,0 +1,315 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + 100 + + diff --git a/challenges/confusion-29.svg b/challenges/confusion-29.svg new file mode 100644 index 0000000..ba20d6b --- /dev/null +++ b/challenges/confusion-29.svg @@ -0,0 +1,300 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-3.svg b/challenges/confusion-3.svg new file mode 100644 index 0000000..eddd464 --- /dev/null +++ b/challenges/confusion-3.svg @@ -0,0 +1,237 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 200 + + + + 150 + + + + 200 + + + + + 75 + + + diff --git a/challenges/confusion-30.svg b/challenges/confusion-30.svg new file mode 100644 index 0000000..0c5353a --- /dev/null +++ b/challenges/confusion-30.svg @@ -0,0 +1,219 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 75 + + diff --git a/challenges/confusion-31.svg b/challenges/confusion-31.svg new file mode 100644 index 0000000..6b7e9be --- /dev/null +++ b/challenges/confusion-31.svg @@ -0,0 +1,221 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + + + + 200 + + + + + + 175 + + + diff --git a/challenges/confusion-32.svg b/challenges/confusion-32.svg new file mode 100644 index 0000000..f3f2b15 --- /dev/null +++ b/challenges/confusion-32.svg @@ -0,0 +1,331 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + diff --git a/challenges/confusion-33.svg b/challenges/confusion-33.svg new file mode 100644 index 0000000..50d7927 --- /dev/null +++ b/challenges/confusion-33.svg @@ -0,0 +1,442 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 70 + + + + + 100 + + diff --git a/challenges/confusion-34.svg b/challenges/confusion-34.svg new file mode 100644 index 0000000..047a68b --- /dev/null +++ b/challenges/confusion-34.svg @@ -0,0 +1,321 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + + + + + 25 + + + diff --git a/challenges/confusion-35.svg b/challenges/confusion-35.svg new file mode 100644 index 0000000..60c9631 --- /dev/null +++ b/challenges/confusion-35.svg @@ -0,0 +1,363 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 75 + + diff --git a/challenges/confusion-36.svg b/challenges/confusion-36.svg new file mode 100644 index 0000000..822d3ad --- /dev/null +++ b/challenges/confusion-36.svg @@ -0,0 +1,641 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 50 + + + + + + 25 + + + diff --git a/challenges/confusion-37.svg b/challenges/confusion-37.svg new file mode 100644 index 0000000..08ea0d8 --- /dev/null +++ b/challenges/confusion-37.svg @@ -0,0 +1,260 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + + + 75 + + + + + 50 + + diff --git a/challenges/confusion-38.svg b/challenges/confusion-38.svg new file mode 100644 index 0000000..38b09eb --- /dev/null +++ b/challenges/confusion-38.svg @@ -0,0 +1,364 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 150 + + diff --git a/challenges/confusion-39.svg b/challenges/confusion-39.svg new file mode 100644 index 0000000..9cbd268 --- /dev/null +++ b/challenges/confusion-39.svg @@ -0,0 +1,410 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + + + + 70 + + diff --git a/challenges/confusion-4.svg b/challenges/confusion-4.svg new file mode 100644 index 0000000..97cdcc3 --- /dev/null +++ b/challenges/confusion-4.svg @@ -0,0 +1,200 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 200 + + + + + 200 + + + + + 140 + + diff --git a/challenges/confusion-40.svg b/challenges/confusion-40.svg new file mode 100644 index 0000000..798c376 --- /dev/null +++ b/challenges/confusion-40.svg @@ -0,0 +1,769 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 25 + + + + + + 50 + + diff --git a/challenges/confusion-5.svg b/challenges/confusion-5.svg new file mode 100644 index 0000000..f5c766d --- /dev/null +++ b/challenges/confusion-5.svg @@ -0,0 +1,203 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 300 + + + + + 300 + + + diff --git a/challenges/confusion-6.svg b/challenges/confusion-6.svg new file mode 100644 index 0000000..bf84aba --- /dev/null +++ b/challenges/confusion-6.svg @@ -0,0 +1,155 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 230 + + + + + 170 + + + diff --git a/challenges/confusion-7.svg b/challenges/confusion-7.svg new file mode 100644 index 0000000..f8d90c2 --- /dev/null +++ b/challenges/confusion-7.svg @@ -0,0 +1,139 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 200 + + diff --git a/challenges/confusion-8.svg b/challenges/confusion-8.svg new file mode 100644 index 0000000..6cb6454 --- /dev/null +++ b/challenges/confusion-8.svg @@ -0,0 +1,132 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 100 + + diff --git a/challenges/confusion-9.svg b/challenges/confusion-9.svg new file mode 100644 index 0000000..d6d3d08 --- /dev/null +++ b/challenges/confusion-9.svg @@ -0,0 +1,88 @@ + + + + + + + + image/svg+xml + + + + + + + + + + + + + + + + + + + + 200 + + diff --git a/challenges/help-1.ta b/challenges/help-1.ta new file mode 100644 index 0000000..cfc47bf --- /dev/null +++ b/challenges/help-1.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 200.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 90], 278, 371, [2, null]]] diff --git a/challenges/help-10.ta b/challenges/help-10.ta new file mode 100644 index 0000000..9572d85 --- /dev/null +++ b/challenges/help-10.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 150.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 72], 278, 371, [2, null]]] diff --git a/challenges/help-11.ta b/challenges/help-11.ta new file mode 100644 index 0000000..b10aa82 --- /dev/null +++ b/challenges/help-11.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 100.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 60], 278, 371, [2, null]]] diff --git a/challenges/help-12.ta b/challenges/help-12.ta new file mode 100644 index 0000000..a7b5280 --- /dev/null +++ b/challenges/help-12.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 100.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 45], 278, 371, [2, null]]] diff --git a/challenges/help-13.ta b/challenges/help-13.ta new file mode 100644 index 0000000..bb063d9 --- /dev/null +++ b/challenges/help-13.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 6.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 3], 278, 371, [2, null]]] diff --git a/challenges/help-14.ta b/challenges/help-14.ta new file mode 100644 index 0000000..31f378f --- /dev/null +++ b/challenges/help-14.ta @@ -0,0 +1,18 @@ +[[0, "forward", 187, 260, [16, 1, 2]], +[1, ["number", 50], 258, 260, [0, null]], +[2, "left", 187, 302, [0, 3, 4]], +[3, ["number", 45], 245, 302, [2, null]], +[4, "forward", 187, 344, [2, 5, 6]], +[5, ["number", 50], 258, 344, [4, null]], +[6, "right", 187, 386, [4, 7, 8]], +[7, ["number", 90], 245, 386, [6, null]], +[8, "forward", 187, 428, [6, 9, 10]], +[9, ["number", 50], 258, 428, [8, null]], +[10, "left", 187, 470, [8, 11, 12]], +[11, ["number", 45], 245, 470, [10, null]], +[12, "forward", 187, 512, [10, 13, 14]], +[13, ["number", 50], 258, 512, [12, null]], +[14, "right", 187, 554, [12, 15, null]], +[15, ["number", 45], 245, 554, [14, null]], +[16, "right", 187, 218, [null, 17, 0]], +[17, ["number", 45], 245, 218, [16, null]]] diff --git a/challenges/help-15.ta b/challenges/help-15.ta new file mode 100644 index 0000000..5272264 --- /dev/null +++ b/challenges/help-15.ta @@ -0,0 +1,4 @@ +[[0, "forward", 600, 119, [null, 1, 2]], +[1, ["number", 200.0], 769, 119, [0, null]], +[2, "left", 698, 161, [0, 3, null]], +[3, ["number", 144], 756, 161, [2, null]]] diff --git a/challenges/help-16.ta b/challenges/help-16.ta new file mode 100644 index 0000000..18932fb --- /dev/null +++ b/challenges/help-16.ta @@ -0,0 +1,13 @@ +[[0, "forward", 266, 269, [8, 1, 2]], +[1, ["number", 50], 337, 269, [0, null]], +[2, "right", 266, 311, [0, 3, 4]], +[3, ["number", 90], 324, 311, [2, null]], +[4, "forward", 266, 353, [2, 5, 6]], +[5, ["number", 150], 337, 353, [4, null]], +[6, "right", 266, 395, [4, 7, null]], +[7, ["number", 90], 324, 395, [6, null]], +[8, "repeat", 201, 209, [null, 9, 0, 10]], +[9, ["number", 2], 252, 209, [8, null]], +[10, ["vspace", 60], 201, 287, [8, 11]], +[11, "right", 201, 449, [10, 12, null]], +[12, ["number", 90], 259, 449, [11, null]]] diff --git a/challenges/help-17.ta b/challenges/help-17.ta new file mode 100644 index 0000000..ebbf81e --- /dev/null +++ b/challenges/help-17.ta @@ -0,0 +1,11 @@ +[[0, "left", 264, 274, [6, 1, 2]], +[1, ["number", 90], 322, 274, [0, null]], +[2, "forward", 264, 316, [0, 3, 4]], +[3, ["number", 100], 335, 316, [2, null]], +[4, "left", 264, 358, [2, 5, null]], +[5, ["number", 30], 322, 358, [4, null]], +[6, "repeat", 199, 214, [null, 7, 0, 8]], +[7, ["number", 3], 250, 214, [6, null]], +[8, ["vspace", 40], 199, 292, [6, 9]], +[9, "left", 199, 414, [8, 10, null]], +[10, ["number", 60], 257, 414, [9, null]]] diff --git a/challenges/help-18.ta b/challenges/help-18.ta new file mode 100644 index 0000000..86223a4 --- /dev/null +++ b/challenges/help-18.ta @@ -0,0 +1,30 @@ +[[0, "forward", 229, 118, [null, 1, 2]], +[1, ["number", 100], 300, 118, [0, null]], +[2, "right", 229, 160, [0, 3, 4]], +[3, ["number", 90], 287, 160, [2, null]], +[4, "forward", 229, 202, [2, 5, 6]], +[5, ["number", 100], 300, 202, [4, null]], +[6, "right", 229, 244, [4, 7, 8]], +[7, ["number", 90], 287, 244, [6, null]], +[8, "forward", 229, 286, [6, 9, 10]], +[9, ["number", 15], 300, 286, [8, null]], +[10, "right", 229, 328, [8, 11, 12]], +[11, ["number", 90], 287, 328, [10, null]], +[12, "forward", 229, 370, [10, 13, 16]], +[13, ["number", 85], 300, 370, [12, null]], +[14, "forward", 229, 454, [16, 15, 18]], +[15, ["number", 70], 300, 454, [14, null]], +[16, "left", 229, 412, [12, 17, 14]], +[17, ["number", 90], 287, 412, [16, null]], +[18, "left", 229, 496, [14, 19, 20]], +[19, ["number", 90], 287, 496, [18, null]], +[20, "forward", 229, 538, [18, 21, 22]], +[21, ["number", 85], 300, 538, [20, null]], +[22, "right", 229, 580, [20, 23, 24]], +[23, ["number", 90], 287, 580, [22, null]], +[24, "forward", 229, 622, [22, 25, 26]], +[25, ["number", 15.0], 300, 622, [24, null]], +[26, "right", 229, 664, [24, 27, 28]], +[27, ["number", 90], 287, 664, [26, null]], +[28, "forward", 229, 706, [26, 29, null]], +[29, ["number", 100], 300, 706, [28, null]]] diff --git a/challenges/help-19.ta b/challenges/help-19.ta new file mode 100644 index 0000000..23ed84b --- /dev/null +++ b/challenges/help-19.ta @@ -0,0 +1,12 @@ +[[0, "forward", 231, 218, [null, 1, 2]], +[1, ["number", 50], 302, 218, [0, null]], +[2, "right", 231, 260, [0, 3, 4]], +[3, ["number", 90], 289, 260, [2, null]], +[4, "forward", 231, 302, [2, 5, 6]], +[5, ["number", 50], 302, 302, [4, null]], +[6, "left", 231, 344, [4, 7, 8]], +[7, ["number", 90], 289, 344, [6, null]], +[8, "forward", 231, 386, [6, 9, 10]], +[9, ["number", 50], 302, 386, [8, null]], +[10, "right", 231, 428, [8, 11, null]], +[11, ["number", 90], 289, 428, [10, null]]] diff --git a/challenges/help-2.ta b/challenges/help-2.ta new file mode 100644 index 0000000..869b88c --- /dev/null +++ b/challenges/help-2.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 100.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 90], 278, 371, [2, null]]] diff --git a/challenges/help-20.ta b/challenges/help-20.ta new file mode 100644 index 0000000..65e070b --- /dev/null +++ b/challenges/help-20.ta @@ -0,0 +1,10 @@ +[[0, "forward", 255, 343, [2, 1, 8]], +[1, ["number", 50], 326, 343, [0, null]], +[2, "repeat", 190, 283, [6, 3, 0, null]], +[3, ["number", 4], 241, 283, [2, null]], +[4, "forward", 255, 427, [8, 5, null]], +[5, ["number", 50], 326, 427, [4, null]], +[6, "left", 190, 241, [null, 7, 2]], +[7, ["number", 72], 248, 241, [6, null]], +[8, "left", 255, 385, [0, 9, 4]], +[9, ["number", 90], 313, 385, [8, null]]] diff --git a/challenges/help-21.ta b/challenges/help-21.ta new file mode 100644 index 0000000..37a7235 --- /dev/null +++ b/challenges/help-21.ta @@ -0,0 +1,34 @@ +[[0, "forward", 204, 75, [null, 1, 2]], +[1, ["number", 50.0], 275, 75, [0, null]], +[2, "right", 204, 117, [0, 3, 4]], +[3, ["number", 90], 262, 117, [2, null]], +[4, "forward", 204, 159, [2, 5, 6]], +[5, ["number", 100], 275, 159, [4, null]], +[6, "right", 204, 201, [4, 7, 8]], +[7, ["number", 90], 262, 201, [6, null]], +[8, "forward", 204, 243, [6, 9, 10]], +[9, ["number", 15], 275, 243, [8, null]], +[10, "right", 204, 285, [8, 11, 12]], +[11, ["number", 90], 262, 285, [10, null]], +[12, "forward", 204, 327, [10, 13, 14]], +[13, ["number", 85], 275, 327, [12, null]], +[14, "left", 204, 369, [12, 15, 16]], +[15, ["number", 90], 262, 369, [14, null]], +[16, "forward", 204, 411, [14, 17, 18]], +[17, ["number", 70], 275, 411, [16, null]], +[18, "left", 204, 453, [16, 19, 20]], +[19, ["number", 90], 262, 453, [18, null]], +[20, "forward", 204, 495, [18, 21, 22]], +[21, ["number", 85], 275, 495, [20, null]], +[22, "right", 204, 537, [20, 23, 24]], +[23, ["number", 90], 262, 537, [22, null]], +[24, "forward", 204, 579, [22, 25, 26]], +[25, ["number", 15], 275, 579, [24, null]], +[26, "right", 204, 621, [24, 27, 28]], +[27, ["number", 90], 262, 621, [26, null]], +[28, "forward", 204, 663, [26, 29, 32]], +[29, ["number", 100], 275, 663, [28, null]], +[30, "forward", 204, 747, [32, 31, null]], +[31, ["number", 50.0], 275, 747, [30, null]], +[32, "right", 204, 705, [28, 33, 30]], +[33, ["number", 90], 262, 705, [32, null]]] diff --git a/challenges/help-22.ta b/challenges/help-22.ta new file mode 100644 index 0000000..c76c535 --- /dev/null +++ b/challenges/help-22.ta @@ -0,0 +1,9 @@ +[[0, "forward", 276, 294, [4, 1, 2]], +[1, ["number", 50], 347, 294, [0, null]], +[2, "left", 276, 336, [0, 3, null]], +[3, ["number", 60], 334, 336, [2, null]], +[4, "repeat", 211, 234, [null, 5, 0, 6]], +[5, ["number", 6], 262, 234, [4, null]], +[6, ["vspace", 20], 211, 312, [4, 7]], +[7, "left", 211, 394, [6, 8, null]], +[8, ["number", 45], 269, 394, [7, null]]] diff --git a/challenges/help-23.ta b/challenges/help-23.ta new file mode 100644 index 0000000..afaf421 --- /dev/null +++ b/challenges/help-23.ta @@ -0,0 +1,9 @@ +[[0, "forward", 309, 368, [4, 1, 2]], +[1, ["number", 150], 380, 368, [0, null]], +[2, "left", 309, 410, [0, 3, null]], +[3, ["number", 120], 367, 410, [2, null]], +[4, "repeat", 244, 308, [null, 5, 0, 6]], +[5, ["number", 3.0], 295, 308, [4, null]], +[6, ["vspace", 20], 244, 386, [4, 7]], +[7, "left", 244, 468, [6, 8, null]], +[8, ["number", 45], 302, 468, [7, null]]] diff --git a/challenges/help-24.ta b/challenges/help-24.ta new file mode 100644 index 0000000..97e457f --- /dev/null +++ b/challenges/help-24.ta @@ -0,0 +1,9 @@ +[[0, "forward", 281, 313, [4, 1, 2]], +[1, ["number", 100], 352, 313, [0, null]], +[2, "left", 281, 355, [0, 3, null]], +[3, ["number", 120], 339, 355, [2, null]], +[4, "repeat", 216, 253, [null, 5, 0, 6]], +[5, ["number", 3], 267, 253, [4, null]], +[6, ["vspace", 20], 216, 331, [4, 7]], +[7, "left", 216, 413, [6, 8, null]], +[8, ["number", 60], 274, 413, [7, null]]] \ No newline at end of file diff --git a/challenges/help-25.ta b/challenges/help-25.ta new file mode 100644 index 0000000..06ec5b0 --- /dev/null +++ b/challenges/help-25.ta @@ -0,0 +1,15 @@ +[[0, "forward", 291, 280, [4, 1, 2]], +[1, ["number", 25], 362, 280, [0, null]], +[2, "left", 291, 322, [0, 3, 9]], +[3, ["number", 90], 349, 322, [2, null]], +[4, "repeat", 226, 220, [null, 5, 0, 6]], +[5, ["number", 2], 277, 220, [4, null]], +[6, ["vspace", 60], 226, 298, [4, 7]], +[7, "left", 226, 460, [6, 8, 13]], +[8, ["number", 45], 284, 460, [7, null]], +[9, "forward", 291, 364, [2, 10, 11]], +[10, ["number", 75], 362, 364, [9, null]], +[11, "left", 291, 406, [9, 12, null]], +[12, ["number", 90], 349, 406, [11, null]], +[13, "back", 226, 502, [7, 14, null]], +[14, ["number", 25], 284, 502, [13, null]]] diff --git a/challenges/help-26.ta b/challenges/help-26.ta new file mode 100644 index 0000000..c86e8f5 --- /dev/null +++ b/challenges/help-26.ta @@ -0,0 +1,11 @@ +[[0, "forward", 323, 284, [6, 1, 2]], +[1, ["number", 75], 394, 284, [0, null]], +[2, "right", 323, 326, [0, 3, 4]], +[3, ["number", 120], 381, 326, [2, null]], +[4, "forward", 323, 368, [2, 5, null]], +[5, ["number", 75], 394, 368, [4, null]], +[6, "repeat", 258, 224, [null, 7, 0, 8]], +[7, ["number", 3], 309, 224, [6, null]], +[8, ["vspace", 40], 258, 302, [6, 9]], +[9, "left", 258, 424, [8, 10, null]], +[10, ["number", 72], 316, 424, [9, null]]] diff --git a/challenges/help-27.ta b/challenges/help-27.ta new file mode 100644 index 0000000..6cd8eca --- /dev/null +++ b/challenges/help-27.ta @@ -0,0 +1,17 @@ +[[0, "forward", 295, 299, [12, 1, 2]], +[1, ["number", 50], 366, 299, [0, null]], +[2, "right", 295, 341, [0, 3, 4]], +[3, ["number", 90], 353, 341, [2, null]], +[4, "forward", 295, 383, [2, 5, 6]], +[5, ["number", 50], 366, 383, [4, null]], +[6, "left", 295, 425, [4, 7, 8]], +[7, ["number", 90], 353, 425, [6, null]], +[8, "forward", 295, 467, [6, 9, 10]], +[9, ["number", 50], 366, 467, [8, null]], +[10, "right", 295, 509, [8, 11, null]], +[11, ["number", 90], 353, 509, [10, null]], +[12, "repeat", 230, 239, [null, 13, 0, 14]], +[13, ["number", 4], 281, 239, [12, null]], +[14, ["vspace", 100], 230, 317, [12, 15]], +[15, "right", 230, 559, [14, 16, null]], +[16, ["number", 45], 288, 559, [15, null]]] diff --git a/challenges/help-28.ta b/challenges/help-28.ta new file mode 100644 index 0000000..2d250d1 --- /dev/null +++ b/challenges/help-28.ta @@ -0,0 +1,26 @@ +[[0, "forward", 540, 6, [null, 1, null]], +[1, ["number", 100], 611, 6, [0, null]], +[2, "right", 292, 147, [24, 3, 4]], +[3, ["number", 90], 350, 147, [2, null]], +[4, "forward", 292, 189, [2, 5, 10]], +[5, ["number", 50], 363, 189, [4, null]], +[6, "left", 292, 315, [8, 7, 12]], +[7, ["number", 90], 350, 315, [6, null]], +[8, "forward", 292, 273, [10, 9, 6]], +[9, ["number", 50], 363, 273, [8, null]], +[10, "right", 292, 231, [4, 11, 8]], +[11, ["number", 90], 350, 231, [10, null]], +[12, "forward", 292, 357, [6, 13, 14]], +[13, ["number", 50], 363, 357, [12, null]], +[14, "right", 292, 399, [12, 15, 16]], +[15, ["number", 90], 350, 399, [14, null]], +[16, "forward", 292, 441, [14, 17, 18]], +[17, ["number", 50], 363, 441, [16, null]], +[18, "right", 292, 483, [16, 19, 20]], +[19, ["number", 90], 350, 483, [18, null]], +[20, "forward", 292, 525, [18, 21, 22]], +[21, ["number", 100], 363, 525, [20, null]], +[22, "right", 292, 567, [20, 23, null]], +[23, ["number", 90], 350, 567, [22, null]], +[24, "forward", 292, 105, [null, 25, 2]], +[25, ["number", 100], 363, 105, [24, null]]] diff --git a/challenges/help-29.ta b/challenges/help-29.ta new file mode 100644 index 0000000..c456109 --- /dev/null +++ b/challenges/help-29.ta @@ -0,0 +1,9 @@ +[[0, "forward", 287, 318, [4, 1, 2]], +[1, ["number", 100], 358, 318, [0, null]], +[2, "right", 287, 360, [0, 3, null]], +[3, ["number", 72], 345, 360, [2, null]], +[4, "repeat", 222, 258, [null, 5, 0, 6]], +[5, ["number", 5], 273, 258, [4, null]], +[6, ["vspace", 20], 222, 336, [4, 7]], +[7, "right", 222, 418, [6, 8, null]], +[8, ["number", 36], 280, 418, [7, null]]] diff --git a/challenges/help-3.ta b/challenges/help-3.ta new file mode 100644 index 0000000..4c58755 --- /dev/null +++ b/challenges/help-3.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 150.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 90], 278, 371, [2, null]]] diff --git a/challenges/help-30.ta b/challenges/help-30.ta new file mode 100644 index 0000000..aea3b89 --- /dev/null +++ b/challenges/help-30.ta @@ -0,0 +1,9 @@ +[[0, "forward", 327, 307, [4, 1, 2]], +[1, ["number", 75], 398, 307, [0, null]], +[2, "right", 327, 349, [0, 3, null]], +[3, ["number", 60], 385, 349, [2, null]], +[4, "repeat", 262, 247, [null, 5, 0, 6]], +[5, ["number", 6], 313, 247, [4, null]], +[6, ["vspace", 20], 262, 325, [4, 7]], +[7, "right", 262, 407, [6, 8, null]], +[8, ["number", 60], 320, 407, [7, null]]] diff --git a/challenges/help-31.ta b/challenges/help-31.ta new file mode 100644 index 0000000..6d518e2 --- /dev/null +++ b/challenges/help-31.ta @@ -0,0 +1,13 @@ +[[0, "forward", 541, 142, [null, 5, 2]], +[1, ["number", 200.0], 612, 310, [8, null]], +[2, "right", 541, 184, [0, 3, 4]], +[3, ["number", 90], 599, 184, [2, null]], +[4, "forward", 541, 226, [2, 9, 6]], +[5, ["number", 150.0], 612, 142, [0, null]], +[6, "right", 541, 268, [4, 7, 8]], +[7, ["number", 90], 599, 268, [6, null]], +[8, "forward", 541, 310, [6, 1, 10]], +[9, ["number", 175.0], 612, 226, [4, null]], +[10, "right", 541, 352, [8, 11, null]], +[11, ["number", 90], 599, 352, [10, null]], +[12, ["string", "31"], 0, 49, [null, null]]] diff --git a/challenges/help-32.ta b/challenges/help-32.ta new file mode 100644 index 0000000..79607bb --- /dev/null +++ b/challenges/help-32.ta @@ -0,0 +1,9 @@ +[[0, "forward", 257, 323, [4, 1, 2]], +[1, ["number", 50], 328, 323, [0, null]], +[2, "right", 257, 365, [0, 3, null]], +[3, ["number", 45], 315, 365, [2, null]], +[4, "repeat", 192, 263, [null, 5, 0, 6]], +[5, ["number", 8], 243, 263, [4, null]], +[6, ["vspace", 20], 192, 341, [4, 7]], +[7, "right", 192, 423, [6, 8, null]], +[8, ["number", 45], 250, 423, [7, null]]] diff --git a/challenges/help-33.ta b/challenges/help-33.ta new file mode 100644 index 0000000..7e1ecdc --- /dev/null +++ b/challenges/help-33.ta @@ -0,0 +1,34 @@ +[[0, "forward", 201, 70, [null, 1, 2]], +[1, ["number", 50], 272, 70, [0, null]], +[2, "right", 201, 112, [0, 3, 4]], +[3, ["number", 90], 259, 112, [2, null]], +[4, "forward", 201, 154, [2, 5, 6]], +[5, ["number", 100], 272, 154, [4, null]], +[6, "right", 201, 196, [4, 7, 8]], +[7, ["number", 90], 259, 196, [6, null]], +[8, "forward", 201, 238, [6, 9, 10]], +[9, ["number", 15], 272, 238, [8, null]], +[10, "right", 201, 280, [8, 11, 12]], +[11, ["number", 90], 259, 280, [10, null]], +[12, "forward", 201, 322, [10, 13, 14]], +[13, ["number", 85], 272, 322, [12, null]], +[14, "left", 201, 364, [12, 15, 16]], +[15, ["number", 90], 259, 364, [14, null]], +[16, "forward", 201, 406, [14, 17, 18]], +[17, ["number", 70], 272, 406, [16, null]], +[18, "left", 201, 448, [16, 19, 20]], +[19, ["number", 90], 259, 448, [18, null]], +[20, "forward", 201, 490, [18, 21, 22]], +[21, ["number", 85.0], 272, 490, [20, null]], +[22, "right", 201, 532, [20, 23, 24]], +[23, ["number", 90], 259, 532, [22, null]], +[24, "forward", 201, 574, [22, 25, 26]], +[25, ["number", 15.0], 272, 574, [24, null]], +[26, "right", 201, 616, [24, 27, 28]], +[27, ["number", 90], 259, 616, [26, null]], +[28, "forward", 201, 658, [26, 29, 30]], +[29, ["number", 100], 272, 658, [28, null]], +[30, "right", 201, 700, [28, 31, 32]], +[31, ["number", 90], 259, 700, [30, null]], +[32, "forward", 201, 742, [30, 33, null]], +[33, ["number", 50.0], 272, 742, [32, null]]] diff --git a/challenges/help-34.ta b/challenges/help-34.ta new file mode 100644 index 0000000..7e1ecdc --- /dev/null +++ b/challenges/help-34.ta @@ -0,0 +1,34 @@ +[[0, "forward", 201, 70, [null, 1, 2]], +[1, ["number", 50], 272, 70, [0, null]], +[2, "right", 201, 112, [0, 3, 4]], +[3, ["number", 90], 259, 112, [2, null]], +[4, "forward", 201, 154, [2, 5, 6]], +[5, ["number", 100], 272, 154, [4, null]], +[6, "right", 201, 196, [4, 7, 8]], +[7, ["number", 90], 259, 196, [6, null]], +[8, "forward", 201, 238, [6, 9, 10]], +[9, ["number", 15], 272, 238, [8, null]], +[10, "right", 201, 280, [8, 11, 12]], +[11, ["number", 90], 259, 280, [10, null]], +[12, "forward", 201, 322, [10, 13, 14]], +[13, ["number", 85], 272, 322, [12, null]], +[14, "left", 201, 364, [12, 15, 16]], +[15, ["number", 90], 259, 364, [14, null]], +[16, "forward", 201, 406, [14, 17, 18]], +[17, ["number", 70], 272, 406, [16, null]], +[18, "left", 201, 448, [16, 19, 20]], +[19, ["number", 90], 259, 448, [18, null]], +[20, "forward", 201, 490, [18, 21, 22]], +[21, ["number", 85.0], 272, 490, [20, null]], +[22, "right", 201, 532, [20, 23, 24]], +[23, ["number", 90], 259, 532, [22, null]], +[24, "forward", 201, 574, [22, 25, 26]], +[25, ["number", 15.0], 272, 574, [24, null]], +[26, "right", 201, 616, [24, 27, 28]], +[27, ["number", 90], 259, 616, [26, null]], +[28, "forward", 201, 658, [26, 29, 30]], +[29, ["number", 100], 272, 658, [28, null]], +[30, "right", 201, 700, [28, 31, 32]], +[31, ["number", 90], 259, 700, [30, null]], +[32, "forward", 201, 742, [30, 33, null]], +[33, ["number", 50.0], 272, 742, [32, null]]] diff --git a/challenges/help-35.ta b/challenges/help-35.ta new file mode 100644 index 0000000..a8faf26 --- /dev/null +++ b/challenges/help-35.ta @@ -0,0 +1,11 @@ +[[0, ["string", "31"], 0, 49, [null, null]], +[1, "repeat", 260, 289, [8, 2, 4, 3]], +[2, ["number", 6], 311, 289, [1, null]], +[3, ["vspace", 0], 260, 367, [1, null]], +[4, "forward", 325, 349, [1, 5, 6]], +[5, ["number", 75], 396, 349, [4, null]], +[6, "right", 325, 391, [4, 7, null]], +[7, ["number", 60], 383, 391, [6, null]], +[8, "left", 260, 247, [null, 9, 1]], +[9, ["number", 30], 318, 247, [8, null]], +[10, ["string", "31"], 0, 49, [null, null]]] diff --git a/challenges/help-36.ta b/challenges/help-36.ta new file mode 100644 index 0000000..b63a1c8 --- /dev/null +++ b/challenges/help-36.ta @@ -0,0 +1,68 @@ +[[0, "left", 209, 216, [66, 1, 2]], +[1, ["number", 90.0], 267, 216, [0, null]], +[2, "forward", 209, 258, [0, 3, 4]], +[3, ["number", 25], 280, 258, [2, null]], +[4, "right", 209, 300, [2, 5, 6]], +[5, ["number", 45], 267, 300, [4, null]], +[6, "forward", 209, 342, [4, 7, 8]], +[7, ["number", 25], 280, 342, [6, null]], +[8, "right", 209, 384, [6, 9, 10]], +[9, ["number", 45], 267, 384, [8, null]], +[10, "forward", 209, 426, [8, 11, 12]], +[11, ["number", 25], 280, 426, [10, null]], +[12, "left", 209, 468, [10, 13, 14]], +[13, ["number", 45], 267, 468, [12, null]], +[14, "forward", 209, 510, [12, 15, 16]], +[15, ["number", 25], 280, 510, [14, null]], +[16, "left", 209, 552, [14, 17, 18]], +[17, ["number", 90], 267, 552, [16, null]], +[18, "forward", 209, 594, [16, 19, 20]], +[19, ["number", 25], 280, 594, [18, null]], +[20, "right", 209, 636, [18, 21, 22]], +[21, ["number", 45], 267, 636, [20, null]], +[22, "forward", 209, 678, [20, 23, 24]], +[23, ["number", 25], 280, 678, [22, null]], +[24, "right", 209, 720, [22, 25, 26]], +[25, ["number", 135], 267, 720, [24, null]], +[26, "forward", 209, 762, [24, 27, 28]], +[27, ["number", 25], 280, 762, [26, null]], +[28, "left", 209, 804, [26, 29, 30]], +[29, ["number", 45], 267, 804, [28, null]], +[30, "forward", 209, 846, [28, 31, null]], +[31, ["number", 25], 280, 846, [30, null]], +[32, "right", 703, 224, [67, 33, 34]], +[33, ["number", 90], 761, 224, [32, null]], +[34, "forward", 703, 266, [32, 35, 36]], +[35, ["number", 25], 774, 266, [34, null]], +[36, "left", 703, 308, [34, 37, 38]], +[37, ["number", 45], 761, 308, [36, null]], +[38, "forward", 703, 350, [36, 39, 40]], +[39, ["number", 25], 774, 350, [38, null]], +[40, "right", 703, 392, [38, 41, 42]], +[41, ["number", 135], 761, 392, [40, null]], +[42, "forward", 703, 434, [40, 43, 44]], +[43, ["number", 25], 774, 434, [42, null]], +[44, "right", 703, 476, [42, 45, 46]], +[45, ["number", 45], 761, 476, [44, null]], +[46, "forward", 703, 518, [44, 47, 48]], +[47, ["number", 25], 774, 518, [46, null]], +[48, "left", 703, 560, [46, 49, 50]], +[49, ["number", 90], 761, 560, [48, null]], +[50, "forward", 703, 602, [48, 51, 52]], +[51, ["number", 25], 774, 602, [50, null]], +[52, "left", 703, 644, [50, 53, 54]], +[53, ["number", 45], 761, 644, [52, null]], +[54, "forward", 703, 686, [52, 55, 56]], +[55, ["number", 25], 774, 686, [54, null]], +[56, "right", 703, 728, [54, 57, 58]], +[57, ["number", 45], 761, 728, [56, null]], +[58, "forward", 703, 770, [56, 59, 60]], +[59, ["number", 25], 774, 770, [58, null]], +[60, "right", 703, 812, [58, 61, 62]], +[61, ["number", 45], 761, 812, [60, null]], +[62, "forward", 703, 854, [60, 63, 64]], +[63, ["number", 25], 774, 854, [62, null]], +[64, "right", 703, 896, [62, 65, null]], +[65, ["number", 135], 761, 896, [64, null]], +[66, "hat1", 209, 174, [null, 0]], +[67, "hat2", 703, 182, [null, 32]]] diff --git a/challenges/help-37.ta b/challenges/help-37.ta new file mode 100644 index 0000000..42513fd --- /dev/null +++ b/challenges/help-37.ta @@ -0,0 +1,20 @@ +[[0, "forward", 234, 172, [null, 1, 2]], +[1, ["number", 50], 305, 172, [0, null]], +[2, "left", 234, 214, [0, 3, 4]], +[3, ["number", 90], 292, 214, [2, null]], +[4, "forward", 234, 256, [2, 5, 6]], +[5, ["number", 150], 305, 256, [4, null]], +[6, "left", 234, 298, [4, 7, 8]], +[7, ["number", 90], 292, 298, [6, null]], +[8, "forward", 234, 340, [6, 9, 10]], +[9, ["number", 125], 305, 340, [8, null]], +[10, "left", 234, 382, [8, 11, 12]], +[11, ["number", 90], 292, 382, [10, null]], +[12, "forward", 234, 424, [10, 13, 14]], +[13, ["number", 100], 305, 424, [12, null]], +[14, "left", 234, 466, [12, 15, 16]], +[15, ["number", 90], 292, 466, [14, null]], +[16, "forward", 234, 508, [14, 17, 18]], +[17, ["number", 75], 305, 508, [16, null]], +[18, "left", 234, 550, [16, 19, null]], +[19, ["number", 90], 292, 550, [18, null]]] diff --git a/challenges/help-38.ta b/challenges/help-38.ta new file mode 100644 index 0000000..bb5a0d4 --- /dev/null +++ b/challenges/help-38.ta @@ -0,0 +1,23 @@ +[[0, "repeat", 241, 316, [8, 1, 10, 2]], +[1, ["number", 4], 292, 316, [0, null]], +[2, ["vspace", 40], 241, 394, [0, 16]], +[3, "left", 241, 106, [null, 22, 4]], +[4, "penup", 241, 148, [3, 5]], +[5, "forward", 241, 190, [4, 6, 7]], +[6, ["number", 150], 312, 190, [5, null]], +[7, "pendown", 241, 232, [5, 8]], +[8, "right", 241, 274, [7, 9, 0]], +[9, ["number", 90], 299, 274, [8, null]], +[10, "forward", 306, 376, [0, 11, 12]], +[11, ["number", 150], 377, 376, [10, null]], +[12, "right", 306, 418, [10, 13, 14]], +[13, ["number", 90], 364, 418, [12, null]], +[14, "forward", 306, 460, [12, 15, null]], +[15, ["number", 150], 377, 460, [14, null]], +[16, "left", 241, 516, [2, 17, 18]], +[17, ["number", 90], 299, 516, [16, null]], +[18, "penup", 241, 558, [16, 20]], +[19, "pendown", 241, 642, [20, null]], +[20, "back", 241, 600, [18, 21, 19]], +[21, ["number", 150], 299, 600, [20, null]], +[22, ["number", 10], 299, 106, [3, null]]] diff --git a/challenges/help-39.ta b/challenges/help-39.ta new file mode 100644 index 0000000..eaf5f55 --- /dev/null +++ b/challenges/help-39.ta @@ -0,0 +1,32 @@ +[[0, ["number", 15], 263, 264, [9, null]], +[1, "forward", 192, 96, [null, 2, 3]], +[2, ["number", 100], 263, 96, [1, null]], +[3, "right", 192, 138, [1, 4, 5]], +[4, ["number", 90], 250, 138, [3, null]], +[5, "forward", 192, 180, [3, 6, 7]], +[6, ["number", 100], 263, 180, [5, null]], +[7, "right", 192, 222, [5, 8, 9]], +[8, ["number", 90], 250, 222, [7, null]], +[9, "forward", 192, 264, [7, 0, 10]], +[10, "right", 192, 306, [9, 11, 12]], +[11, ["number", 90], 250, 306, [10, null]], +[12, "forward", 192, 348, [10, 13, 14]], +[13, ["number", 85], 263, 348, [12, null]], +[14, "left", 192, 390, [12, 15, 16]], +[15, ["number", 90], 250, 390, [14, null]], +[16, "forward", 192, 432, [14, 17, 18]], +[17, ["number", 70], 263, 432, [16, null]], +[18, "left", 192, 474, [16, 19, 20]], +[19, ["number", 90], 250, 474, [18, null]], +[20, "forward", 192, 516, [18, 21, 22]], +[21, ["number", 85], 263, 516, [20, null]], +[22, "right", 192, 558, [20, 23, 24]], +[23, ["number", 90], 250, 558, [22, null]], +[24, "forward", 192, 600, [22, 31, 25]], +[25, "right", 192, 642, [24, 26, 27]], +[26, ["number", 90], 250, 642, [25, null]], +[27, "forward", 192, 684, [25, 28, 29]], +[28, ["number", 100], 263, 684, [27, null]], +[29, "right", 192, 726, [27, 30, null]], +[30, ["number", 90], 250, 726, [29, null]], +[31, ["number", 15], 263, 600, [24, null]]] diff --git a/challenges/help-4.ta b/challenges/help-4.ta new file mode 100644 index 0000000..cfc47bf --- /dev/null +++ b/challenges/help-4.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 200.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 90], 278, 371, [2, null]]] diff --git a/challenges/help-40.ta b/challenges/help-40.ta new file mode 100644 index 0000000..c79cc97 --- /dev/null +++ b/challenges/help-40.ta @@ -0,0 +1,66 @@ +[[0, "hat1", 293, 397, [null, 2]], +[1, "hat2", 540, 387, [null, 34]], +[2, "right", 293, 439, [0, 3, 4]], +[3, ["number", 45.0], 351, 439, [2, null]], +[4, "forward", 293, 481, [2, 5, 6]], +[5, ["number", 25.0], 364, 481, [4, null]], +[6, "left", 293, 523, [4, 7, 8]], +[7, ["number", 90], 351, 523, [6, null]], +[8, "forward", 293, 565, [6, 9, 10]], +[9, ["number", 25.0], 364, 565, [8, null]], +[10, "right", 293, 607, [8, 11, 12]], +[11, ["number", 45.0], 351, 607, [10, null]], +[12, "forward", 293, 649, [10, 13, 14]], +[13, ["number", 25.0], 364, 649, [12, null]], +[14, "left", 293, 691, [12, 15, 16]], +[15, ["number", 90], 351, 691, [14, null]], +[16, "forward", 293, 733, [14, 17, 18]], +[17, ["number", 25.0], 364, 733, [16, null]], +[18, "right", 293, 775, [16, 19, 20]], +[19, ["number", 90], 351, 775, [18, null]], +[20, "forward", 293, 817, [18, 21, 22]], +[21, ["number", 25.0], 364, 817, [20, null]], +[22, "right", 293, 859, [20, 23, 24]], +[23, ["number", 90], 351, 859, [22, null]], +[24, "forward", 293, 901, [22, 25, 26]], +[25, ["number", 25.0], 364, 901, [24, null]], +[26, "left", 293, 943, [24, 27, 28]], +[27, ["number", 135.0], 351, 943, [26, null]], +[28, "forward", 293, 985, [26, 29, 30]], +[29, ["number", 25.0], 364, 985, [28, null]], +[30, "left", 293, 1027, [28, 31, 32]], +[31, ["number", 90], 351, 1027, [30, null]], +[32, "forward", 293, 1069, [30, 33, null]], +[33, ["number", 25.0], 364, 1069, [32, null]], +[34, "right", 540, 429, [1, 35, 36]], +[35, ["number", 45.0], 598, 429, [34, null]], +[36, "forward", 540, 471, [34, 37, 38]], +[37, ["number", 25.0], 611, 471, [36, null]], +[38, "left", 540, 513, [36, 39, 40]], +[39, ["number", 90], 598, 513, [38, null]], +[40, "forward", 540, 555, [38, 41, 42]], +[41, ["number", 25.0], 611, 555, [40, null]], +[42, "left", 540, 597, [40, 43, 44]], +[43, ["number", 135.0], 598, 597, [42, null]], +[44, "forward", 540, 639, [42, 45, 46]], +[45, ["number", 25.0], 611, 639, [44, null]], +[46, "right", 540, 681, [44, 47, 48]], +[47, ["number", 90], 598, 681, [46, null]], +[48, "forward", 540, 723, [46, 49, 50]], +[49, ["number", 25.0], 611, 723, [48, null]], +[50, "right", 540, 765, [48, 51, 52]], +[51, ["number", 90], 598, 765, [50, null]], +[52, "forward", 540, 807, [50, 53, 54]], +[53, ["number", 25.0], 611, 807, [52, null]], +[54, "left", 540, 849, [52, 55, 56]], +[55, ["number", 90], 598, 849, [54, null]], +[56, "forward", 540, 891, [54, 57, 58]], +[57, ["number", 25.0], 611, 891, [56, null]], +[58, "right", 540, 933, [56, 59, 60]], +[59, ["number", 45.0], 598, 933, [58, null]], +[60, "forward", 540, 975, [58, 61, 62]], +[61, ["number", 25.0], 611, 975, [60, null]], +[62, "left", 540, 1017, [60, 63, 64]], +[63, ["number", 90], 598, 1017, [62, null]], +[64, "forward", 540, 1059, [62, 65, null]], +[65, ["number", 25.0], 611, 1059, [64, null]]] diff --git a/challenges/help-5.ta b/challenges/help-5.ta new file mode 100644 index 0000000..0c2514a --- /dev/null +++ b/challenges/help-5.ta @@ -0,0 +1,12 @@ +[[0, "forward", 532, 176, [null, 1, 2]], +[1, ["number", 100], 603, 176, [0, null]], +[2, "left", 532, 218, [0, 3, 4]], +[3, ["number", 90], 590, 218, [2, null]], +[4, "forward", 532, 260, [2, 5, 6]], +[5, ["number", 100], 603, 260, [4, null]], +[6, "right", 532, 302, [4, 7, 8]], +[7, ["number", 90], 590, 302, [6, null]], +[8, "forward", 532, 344, [6, 9, 10]], +[9, ["number", 100], 603, 344, [8, null]], +[10, "right", 532, 386, [8, 11, null]], +[11, ["number", 90], 590, 386, [10, null]]] diff --git a/challenges/help-6.ta b/challenges/help-6.ta new file mode 100644 index 0000000..1e16e88 --- /dev/null +++ b/challenges/help-6.ta @@ -0,0 +1,12 @@ +[[0, ["number", 230], 278, 288, [4, null]], +[1, "repeat", 175, 243, [null, 2, 4, 3]], +[2, ["number", 4], 214, 243, [1, null]], +[3, ["vspace", 0], 175, 302, [1, 7]], +[4, "forward", 224, 288, [1, 0, 5]], +[5, "right", 224, 320, [4, 6, null]], +[6, ["number", 90], 268, 320, [5, null]], +[7, "penup", 175, 334, [3, 9]], +[8, "pendown", 175, 429, [9, null]], +[9, ["setxy2", 0], 175, 366, [7, 10, 11, 8]], +[10, ["number", 30], 219, 366, [9, null]], +[11, ["number", 30], 219, 398, [9, null]]] diff --git a/challenges/help-7.ta b/challenges/help-7.ta new file mode 100644 index 0000000..e2ac8d1 --- /dev/null +++ b/challenges/help-7.ta @@ -0,0 +1,11 @@ +[[0, ["setxy2", 0], 737, 128, [9, 1, 2, 10]], +[1, ["number", 100], 795, 128, [0, null]], +[2, ["number", 100], 795, 170, [0, null]], +[3, "left", 802, 272, [7, 4, 5]], +[4, ["number", 90], 860, 272, [3, null]], +[5, "forward", 802, 314, [3, 6, null]], +[6, ["number", 200], 873, 314, [5, null]], +[7, "repeat", 737, 212, [10, 8, 3, null]], +[8, ["number", 4], 788, 212, [7, null]], +[9, "penup", 600, 100, [null, 0]], +[10, "pendown", 0, 0, [0, 7]]] diff --git a/challenges/help-8.ta b/challenges/help-8.ta new file mode 100644 index 0000000..10bb958 --- /dev/null +++ b/challenges/help-8.ta @@ -0,0 +1,12 @@ +[[0, "forward", 251, 189, [4, 1, 2]], +[1, ["number", 100], 322, 189, [0, null]], +[2, "right", 251, 231, [0, 3, null]], +[3, ["number", 90], 309, 231, [2, null]], +[4, "repeat", 186, 129, [null, 5, 0, 6]], +[5, ["number", 4], 237, 129, [4, null]], +[6, ["vspace", 15], 186, 207, [4, 10]], +[7, ["setxy2", 0], 186, 291, [10, 8, 9, 11]], +[8, ["number", 50.0], 244, 291, [7, null]], +[9, ["number", 100.0], 244, 333, [7, null]], +[10, "penup", 600, 100, [6, 7]], +[11, "pendown", 0, 0, [7, null]]] diff --git a/challenges/help-9.ta b/challenges/help-9.ta new file mode 100644 index 0000000..010e379 --- /dev/null +++ b/challenges/help-9.ta @@ -0,0 +1,4 @@ +[[0, "forward", 203, 329, [null, 1, 2]], +[1, ["number", 200.0], 282, 329, [0, null]], +[2, "right", 203, 371, [0, 3, null]], +[3, ["number", 120], 278, 371, [2, null]]] diff --git a/challenges/offsets b/challenges/offsets new file mode 100644 index 0000000..995e3af --- /dev/null +++ b/challenges/offsets @@ -0,0 +1,35 @@ +5:-100,0 +7:-141,-141 +10:0,-48 +11:0,-51 +12:0,-72 +13:0,-112 +14:0,-122 +15:-117,0 +16:-150,-150 +17:-100,-85 +18:-100,-100 +19:-150,-150 +20:-100,-111 +21:-100,-100 +22:-100,-100 +23:-150,-150 +24:-175,-150 +25:-75,-94 +26:-105,-125 +27:-150,-150 +28:-107,-107 +29:-155,-161 +30:-130,-152 +31:0,-50 +32:-121,-121 +33:-106,-106 +34:-100,-100 +35:-150,-150 +36:-121,-121 +37:-150,-150 +38:-106,-106 +39:-100,-100 +40:-104,-104 + + diff --git a/images/turtle-a.png b/images/turtle-a.png new file mode 100644 index 0000000..23bb626 --- /dev/null +++ b/images/turtle-a.png Binary files differ diff --git a/plugins/accelerometer/accelerometer.py b/plugins/accelerometer/accelerometer.py deleted file mode 100644 index 26aefd4..0000000 --- a/plugins/accelerometer/accelerometer.py +++ /dev/null @@ -1,91 +0,0 @@ -#!/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.talogo import primitive_dictionary -from TurtleArt.tautils import debug_output - -import logging -_logger = logging.getLogger('turtleart-activity accelerometer plugin') - - -ACCELEROMETER_DEVICE = '/sys/devices/platform/lis3lv02d/position' - - -class Accelerometer(Plugin): - - def __init__(self, parent): - self._parent = parent - if os.path.exists(ACCELEROMETER_DEVICE): - 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'), - position=6) - - primitive_dictionary['xyz'] = self.prim_xyz - if self._status: - palette.add_block('xyz', - style='basic-style-extended-vertical', - label=_('acceleration'), - help_string=\ - _('push acceleration in x, y, z to heap'), - prim_name='xyz') - else: - palette.add_block('xyz', - style='basic-style-extended-vertical', - label=_('acceleration'), - help_string=\ - _('push acceleration 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(ACCELEROMETER_DEVICE) - string = fh.read() - xyz = string[1:-2].split(',') - self._parent.lc.heap.append(float(xyz[2]) / 18) - self._parent.lc.heap.append(float(xyz[1]) / 18) - self._parent.lc.heap.append(float(xyz[0]) / 18) - fh.close() diff --git a/plugins/accelerometer/icons/sensoroff.svg b/plugins/accelerometer/icons/sensoroff.svg deleted file mode 100644 index 0a16670..0000000 --- a/plugins/accelerometer/icons/sensoroff.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/accelerometer/icons/sensoron.svg b/plugins/accelerometer/icons/sensoron.svg deleted file mode 100644 index d756860..0000000 --- a/plugins/accelerometer/icons/sensoron.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/plugins/audio_sensors/audio_sensors.py b/plugins/audio_sensors/audio_sensors.py deleted file mode 100644 index 8d45395..0000000 --- a/plugins/audio_sensors/audio_sensors.py +++ /dev/null @@ -1,468 +0,0 @@ -#!/usr/bin/env python -#Copyright (c) 2011, 2012 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 - -from gettext import gettext as _ - -try: - from numpy import append - from numpy.fft import rfft - PITCH_AVAILABLE = True -except: - PITCH_AVAILABLE = False - -from plugins.plugin import Plugin - -from plugins.audio_sensors.audiograb import (AudioGrab, - SENSOR_DC_NO_BIAS, SENSOR_DC_BIAS, SENSOR_AC_BIAS) - -from plugins.audio_sensors.ringbuffer import RingBuffer1d - -from TurtleArt.tapalette import make_palette -from TurtleArt.taconstants import XO1, XO15, XO175, XO30, XO4 -from TurtleArt.talogo import primitive_dictionary -from TurtleArt.tautils import debug_output - -import logging -_logger = logging.getLogger('turtleart-activity audio sensors plugin') - - -def _avg(array, abs_value=False): - ''' Calc. the average value of an array ''' - if len(array) == 0: - return 0 - array_sum = 0 - if abs_value: - for a in array: - array_sum += abs(a) - else: - for a in array: - array_sum += a - return float(array_sum) / len(array) - - -class Audio_sensors(Plugin): - - def __init__(self, parent): - self._parent = parent - self._status = True # TODO: test for audio device - # These flags are referenced by audiograb - self.hw = self._parent.hw - self.running_sugar = self._parent.running_sugar - - def setup(self): - ''' set up audio-sensor-specific blocks ''' - self.max_samples = 1500 - self.input_step = 1 - - self.ringbuffer = [] - - palette = make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks'), - position=6) - - primitive_dictionary['sound'] = self.prim_sound - primitive_dictionary['volume'] = self.prim_volume - if self._status: - palette.add_block('sound', - style='box-style', - label=_('sound'), - help_string=_('raw microphone input signal'), - value_block=True, - prim_name='sound') - - palette.add_block('volume', - style='box-style', - label=_('loudness'), - help_string=_('microphone input volume'), - value_block=True, - prim_name='volume') - else: - palette.add_block('sound', - hidden=True, - style='box-style', - label=_('sound'), - help_string=_('raw microphone input signal'), - value_block=True, - prim_name='sound') - palette.add_block('volume', - hidden=True, - style='box-style', - label=_('loudness'), - help_string=_('microphone input volume'), - value_block=True, - prim_name='volume') - - self._parent.lc.def_prim( - 'sound', 0, lambda self: primitive_dictionary['sound'](0)) - self._parent.lc.def_prim( - 'volume', 0, lambda self: primitive_dictionary['volume'](0)) - - primitive_dictionary['pitch'] = self.prim_pitch - if PITCH_AVAILABLE and self._status: - palette.add_block('pitch', - style='box-style', - label=_('pitch'), - help_string=_('microphone input pitch'), - value_block=True, - prim_name='pitch') - else: - palette.add_block('pitch', - hidden=True, - style='box-style', - label=_('pitch'), - help_string=_('microphone input pitch'), - value_block=True, - prim_name='pitch') - self._parent.lc.def_prim('pitch', 0, - lambda self: primitive_dictionary['pitch'](0)) - - primitive_dictionary['resistance'] = self.prim_resistance - primitive_dictionary['voltage'] = self.prim_voltage - if self.hw in [XO1, XO15, XO175, XO4, XO30] and self._status: - if self.hw == XO1: - self.voltage_gain = 0.000022 - self.voltage_bias = 1.14 - elif self.hw == XO15: - self.voltage_gain = -0.00015 - self.voltage_bias = 1.70 - elif self.hw in [XO175, XO4]: # recalibrate in light of #3675? - self.voltage_gain = 0.000071 - self.voltage_bias = 0.55 - else: # XO 3.0 - self.voltage_gain = 0.000077 - self.voltage_bias = 0.72 - palette.add_block('resistance', - style='box-style', - label=_('resistance'), - help_string=_('microphone input resistance'), - value_block=True, - prim_name='resistance') - palette.add_block('voltage', - style='box-style', - label=_('voltage'), - help_string=_('microphone input voltage'), - value_block=True, - prim_name='voltage') - else: - palette.add_block('resistance', - hidden=True, - style='box-style', - label=_('resistance'), - help_string=_('microphone input resistance'), - prim_name='resistance') - palette.add_block('voltage', - hidden=True, - style='box-style', - label=_('voltage'), - help_string=_('microphone input voltage'), - prim_name='voltage') - - # FIXME: Only add stereo capture for XO15 (broken on ARM #3675) - if self.hw in [XO15] and self._status: - palette.add_block('resistance2', - style='box-style', - label=_('resistance') + '2', - help_string=_('microphone input resistance'), - value_block=True, - prim_name='resistance2') - palette.add_block('voltage2', - style='box-style', - label=_('voltage') + '2', - help_string=_('microphone input voltage'), - value_block=True, - prim_name='voltage2') - else: - palette.add_block('resistance2', - hidden=True, - style='box-style', - label=_('resistance') + '2', - help_string=_('microphone input resistance'), - prim_name='resistance2') - palette.add_block('voltage2', - hidden=True, - style='box-style', - label=_('voltage') + '2', - help_string=_('microphone input voltage'), - prim_name='voltage2') - self._parent.lc.def_prim( - 'resistance', 0, - lambda self: primitive_dictionary['resistance'](0)) - self._parent.lc.def_prim( - 'voltage', 0, lambda self: primitive_dictionary['voltage'](0)) - self._parent.lc.def_prim( - 'resistance2', 0, - lambda self: primitive_dictionary['resistance'](1)) - self._parent.lc.def_prim( - 'voltage2', 0, lambda self: primitive_dictionary['voltage'](1)) - - self.audio_started = False - if self.hw in [XO175, XO30, XO4]: - self.PARAMETERS = { - SENSOR_AC_BIAS: (False, True, 80, True), - SENSOR_DC_NO_BIAS: (True, False, 80, False), - SENSOR_DC_BIAS: (True, True, 90, False) - } - elif self.hw == XO15: - self.PARAMETERS = { - SENSOR_AC_BIAS: (False, True, 80, True), - SENSOR_DC_NO_BIAS: (True, False, 80, False), - SENSOR_DC_BIAS: (True, True, 90, False) - } - elif self.hw == XO1: - self.PARAMETERS = { - SENSOR_AC_BIAS: (False, True, 40, True), - SENSOR_DC_NO_BIAS: (True, False, 0, False), - SENSOR_DC_BIAS: (True, True, 0, False) - } - else: - self.PARAMETERS = { - SENSOR_AC_BIAS: (None, True, 40, True), - SENSOR_DC_NO_BIAS: (True, False, 80, False), - SENSOR_DC_BIAS: (True, True, 90, False) - } - - def start(self): - ''' Start grabbing audio if there is an audio block in use ''' - if not self._status: - return - if self.audio_started: - self.audiograb.stop_grabbing() - if len(self._parent.block_list.get_similar_blocks( - 'block', ['volume', 'sound', 'pitch'])) > 0: - mode, bias, gain, boost = self.PARAMETERS[SENSOR_AC_BIAS] - elif len(self._parent.block_list.get_similar_blocks( - 'block', ['resistance', 'resistance2'])) > 0: - mode, bias, gain, boost = self.PARAMETERS[SENSOR_DC_BIAS] - elif len(self._parent.block_list.get_similar_blocks( - 'block', ['voltage', 'voltage2'])) > 0: - mode, bias, gain, boost = self.PARAMETERS[SENSOR_DC_NO_BIAS] - else: - return # No audio blocks in use. - self.audiograb = AudioGrab(self.new_buffer, self, - mode, bias, gain, boost) - self._channels = self.audiograb.channels - for i in range(self._channels): - self.ringbuffer.append(RingBuffer1d(self.max_samples, - dtype='int16')) - self.audiograb.start_grabbing() - self.audio_started = True - - def new_buffer(self, buf, channel=0): - ''' Append a new buffer to the ringbuffer ''' - self.ringbuffer[channel].append(buf) - return True - - def stop(self): - ''' This gets called by the stop button ''' - if self._status and self.audio_started: - self.audiograb.on_activity_quit() # reset all setting - self.audio_started = False - - def goto_background(self): - ''' This gets called when your process is sent to the background ''' - pass - - def return_to_foreground(self): - ''' This gets called when your process returns from the background ''' - pass - - def quit(self): - ''' This gets called by the quit button ''' - if self._status and self.audio_started: - self.audiograb.on_activity_quit() - - def _status_report(self): - debug_output( - 'Reporting audio sensor status: %s' % (str(self._status)), - self._parent.running_sugar) - return self._status - - # Block primitives used in talogo - - def prim_volume(self, channel): - if not self._status: - return 0 - # Return average of both channels if sampling in stereo - if self._channels == 2: - chan0 = self._prim_volume(0) - chan1 = self._prim_volume(1) - return (chan0 + chan1) / 2 - else: - return self._prim_volume(0) - - def _prim_volume(self, channel): - ''' return mic in value ''' - buf = self.ringbuffer[channel].read(None, self.input_step) - if len(buf) > 0: - volume = float(_avg(buf, abs_value=True)) - self._parent.lc.update_label_value('volume', volume) - return volume - else: - return 0 - - def prim_sound(self, channel): - if not self._status: - return 0 - # Return average of both channels if sampling in stereo - if self._channels == 2: - chan0 = self._prim_sound(0) - chan1 = self._prim_sound(1) - return (chan0 + chan1) / 2 - else: - return self._prim_sound(0) - - def _prim_sound(self, channel): - ''' return raw mic in value ''' - buf = self.ringbuffer[channel].read(None, self.input_step) - if len(buf) > 0: - sound = float(buf[0]) - if self._parent.lc.update_values: - self._parent.lc.update_label_value('sound', sound) - return sound - else: - return 0 - - def prim_pitch(self, channel): - if not PITCH_AVAILABLE or not self._status: - return 0 - # Return average of both channels if sampling in stereo - if self._channels == 2: - chan0 = self._prim_pitch(0) - chan1 = self._prim_pitch(1) - return (chan0 + chan1) / 2 - else: - return self._prim_pitch(0) - - def _prim_pitch(self, channel): - ''' return index of max value in fft of mic in values ''' - buf = self.ringbuffer[channel].read(None, self.input_step) - if len(buf) > 0: - buf = rfft(buf) - buf = abs(buf) - maxi = buf.argmax() - if maxi == 0: - pitch = 0 - else: # Simple interpolation - a, b, c = buf[maxi - 1], buf[maxi], buf[maxi + 1] - maxi -= a / float(a + b + c) - maxi += c / float(a + b + c) - pitch = maxi * 48000 / (len(buf) * 2) - - if self._parent.lc.update_values: - self._parent.lc.update_label_value('pitch', pitch) - return pitch - else: - return 0 - - def prim_resistance(self, channel): - if not self.hw in [XO1, XO15, XO175, XO30, XO4] or not self._status: - return 0 - if self.hw in [XO1, XO4]: - resistance = self._prim_resistance(0) - if self._parent.lc.update_values: - self._update_resistance_labels(0, resistance) - return resistance - elif self.hw == XO15: - resistance = self._prim_resistance(channel) - if self._parent.lc.update_values: - self._update_resistance_labels(channel, resistance) - return resistance - # FIXME: For XO175: channel assignment is seemingly random - # (#3675), so sum both channels (one of them will be 0) - else: - chan0 = self._prim_resistance(0) - chan1 = self._prim_resistance(1) - resistance = chan0 + chan1 - if self._parent.lc.update_values: - self._update_resistance_labels(0, resistance) - return resistance - - def _prim_resistance(self, channel): - ''' return resistance sensor value ''' - buf = self.ringbuffer[channel].read(None, self.input_step) - if len(buf) > 0: - # See - # TODO: test this calibration on XO 1.5, XO 1.75 - avg_buf = float(_avg(buf)) - if self.hw == XO1: - resistance = 2.718 ** ((avg_buf * 0.000045788) + 8.0531) - elif self.hw == XO15: - if avg_buf > 0: - resistance = (420000000 / avg_buf) - 13500 - else: - resistance = 420000000 - elif self.hw in [XO175, XO4]: - if avg_buf < 30700: - resistance = .12 * ((180000000 / (30700 - avg_buf)) - 3150) - else: - resistance = 999999999 - else: # XO 3.0 - if avg_buf < 30514: - resistance = (46000000 / (30514 - avg_buf)) - 1150 - else: - resistance = 999999999 - if resistance < 0: - resistance = 0 - return resistance - else: - return 0 - - def _update_resistance_labels(self, channel, resistance): - if channel == 0: - self._parent.lc.update_label_value('resistance', resistance) - else: - self._parent.lc.update_label_value('resistance2', resistance) - - def prim_voltage(self, channel): - if not self.hw in [XO1, XO15, XO175, XO30, XO4] or not self._status: - return 0 - if self.hw in [XO1, XO4]: - voltage = self._prim_voltage(0) - if self._parent.lc.update_values: - self._update_voltage_labels(0, voltage) - return voltage - elif self.hw == XO15: - voltage = self._prim_voltage(channel) - if self._parent.lc.update_values: - self._update_voltage_labels(channel, voltage) - return voltage - # FIXME: For XO175: channel assignment is seemingly random - # (#3675), so sum both channels (one of them will be 0) - else: - chan0 = self._prim_voltage(0) - chan1 = self._prim_voltage(1) - voltage = chan0 + chan1 - if self._parent.lc.update_values: - self._update_voltage_labels(0, voltage) - return voltage - - def _prim_voltage(self, channel): - ''' return voltage sensor value ''' - buf = self.ringbuffer[channel].read(None, self.input_step) - if len(buf) > 0: - # See - voltage = float(_avg(buf)) * self.voltage_gain + self.voltage_bias - return voltage - else: - return 0 - - def _update_voltage_labels(self, channel, voltage): - if channel == 0: - self._parent.lc.update_label_value('voltage', voltage) - else: - self._parent.lc.update_label_value('voltage2', voltage) diff --git a/plugins/audio_sensors/audiograb.py b/plugins/audio_sensors/audiograb.py deleted file mode 100644 index 228e4c2..0000000 --- a/plugins/audio_sensors/audiograb.py +++ /dev/null @@ -1,673 +0,0 @@ -#! /usr/bin/python -# -# Author: Arjun Sarwal arjun@laptop.org -# Copyright (C) 2007, Arjun Sarwal -# Copyright (C) 2009-12 Walter Bender -# Copyright (C) 2009, Benjamin Berg, Sebastian Berg -# Copyright (C) 2009, Sayamindu Dasgupta -# Copyright (C) 2010, Sascha Silbe -# -# 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. -# -# You should have received a copy of the GNU General Public License -# along with this library; if not, write to the Free Software -# Foundation, 51 Franklin Street, Suite 500 Boston, MA 02110-1335 USA - -import pygst -import gst -import gst.interfaces -from numpy import fromstring -import subprocess -import traceback -from string import find -from threading import Timer - -from TurtleArt.taconstants import XO1, XO4 -from TurtleArt.tautils import debug_output - -# Initial device settings -RATE = 48000 -MIC_BOOST = True -DC_MODE_ENABLE = False -CAPTURE_GAIN = 50 -BIAS = True - -# Setting on quit -QUIT_MIC_BOOST = False -QUIT_DC_MODE_ENABLE = False -QUIT_CAPTURE_GAIN = 100 -QUIT_BIAS = True - -# Capture modes -SENSOR_AC_NO_BIAS = 'external' -SENSOR_AC_BIAS = 'sound' -SENSOR_DC_NO_BIAS = 'voltage' -SENSOR_DC_BIAS = 'resistance' - - -class AudioGrab(): - """ The interface between measure and the audio device """ - - def __init__(self, callable1, parent, - mode=None, bias=None, gain=None, boost=None): - """ Initialize the class: callable1 is a data buffer; - parent is the parent class""" - - self.callable1 = callable1 - self.parent = parent - self.sensor = None - - self.temp_buffer = [0] - - self.rate = RATE - # Force XO1 and XO4 to use just 1 channel - if self.parent.hw in [XO1, XO4]: - self.channels = 1 - else: - self.channels = None - - self._dc_control = None - self._mic_bias_control = None - self._capture_control = None - self._mic_boost_control = None - self._labels_available = True # Query controls for device names - - self._query_mixer() - # If Channels was not found in the Capture controller, guess. - if self.channels is None: - debug_output('Guessing there are 2 channels', - self.parent.running_sugar) - self.channels = 2 - - # Set mixer to known state - self.set_dc_mode(DC_MODE_ENABLE) - self.set_bias(BIAS) - self.set_capture_gain(CAPTURE_GAIN) - self.set_mic_boost(MIC_BOOST) - - self.master = self.get_master() - self.dc_mode = self.get_dc_mode() - self.bias = self.get_bias() - self.capture_gain = self.get_capture_gain() - self.mic_boost = self.get_mic_boost() - - # Set mixer to desired state - self._set_sensor_type(mode, bias, gain, boost) - self.dc_mode = self.get_dc_mode() - self.bias = self.get_bias() - self.capture_gain = self.get_capture_gain() - self.mic_boost = self.get_mic_boost() - - # Set up gstreamer pipeline - self._pad_count = 0 - self.pads = [] - self.queue = [] - self.fakesink = [] - self.pipeline = gst.Pipeline('pipeline') - self.alsasrc = gst.element_factory_make('alsasrc', 'alsa-source') - self.pipeline.add(self.alsasrc) - self.caps1 = gst.element_factory_make('capsfilter', 'caps1') - self.pipeline.add(self.caps1) - caps_str = 'audio/x-raw-int,rate=%d,channels=%d,depth=16' % ( - RATE, self.channels) - self.caps1.set_property('caps', gst.caps_from_string(caps_str)) - if self.channels == 1: - self.fakesink.append(gst.element_factory_make('fakesink', 'fsink')) - self.pipeline.add(self.fakesink[0]) - self.fakesink[0].connect('handoff', self.on_buffer, 0) - self.fakesink[0].set_property('signal-handoffs', True) - gst.element_link_many(self.alsasrc, self.caps1, self.fakesink[0]) - else: - if not hasattr(self, 'splitter'): - self.splitter = gst.element_factory_make('deinterleave') - self.pipeline.add(self.splitter) - self.splitter.set_properties('keep-positions=true', 'name=d') - self.splitter.connect('pad-added', self._splitter_pad_added) - gst.element_link_many(self.alsasrc, self.caps1, self.splitter) - for i in range(self.channels): - self.queue.append(gst.element_factory_make('queue')) - self.pipeline.add(self.queue[i]) - self.fakesink.append(gst.element_factory_make('fakesink')) - self.pipeline.add(self.fakesink[i]) - self.fakesink[i].connect('handoff', self.on_buffer, i) - self.fakesink[i].set_property('signal-handoffs', True) - - self.dont_queue_the_buffer = False - - # Timer for interval sampling and switch to indicate when to capture - self.capture_timer = None - self.capture_interval_sample = False - - def _query_mixer(self): - self._mixer = gst.element_factory_make('alsamixer') - rc = self._mixer.set_state(gst.STATE_PAUSED) - assert rc == gst.STATE_CHANGE_SUCCESS - - # Query the available controls - tracks_list = self._mixer.list_tracks() - if hasattr(tracks_list[0].props, 'untranslated_label'): - self._capture_control = self._find_control(['capture', 'axi']) - self._dc_control = self._find_control(['dc mode']) - self._mic_bias_control = self._find_control(['mic bias', - 'dc input bias', - 'v_refout']) - self._mic_boost_control = self._find_control(['mic boost', - 'mic1 boost', - 'mic boost (+20db)', - 'internal mic boost', - 'analog mic boost']) - self._mic_gain_control = self._find_control(['mic']) - self._master_control = self._find_control(['master']) - else: # Use hardwired values - self._labels_available = False - - def _unlink_sink_queues(self): - ''' Build the sink pipelines ''' - - # If there were existing pipelines, unlink them - for i in range(self._pad_count): - try: - self.splitter.unlink(self.queue[i]) - self.queue[i].unlink(self.fakesink[i]) - except: - traceback.print_exc() - - # Build the new pipelines - self._pad_count = 0 - self.pads = [] - - def _splitter_pad_added(self, element, pad): - ''' Seems to be the case that ring is right channel 0, - tip is left channel 1''' - ''' - debug_output('splitter pad %d added' % (self._pad_count), - self.parent.running_sugar) - ''' - self.pads.append(pad) - if self._pad_count < self.channels: - pad.link(self.queue[self._pad_count].get_pad('sink')) - self.queue[self._pad_count].get_pad('src').link( - self.fakesink[self._pad_count].get_pad('sink')) - self._pad_count += 1 - else: - debug_output('ignoring channels > %d' % (self.channels), - self.parent.running_sugar) - - def set_handoff_signal(self, handoff_state): - '''Sets whether the handoff signal would generate an interrupt - or not''' - for i in range(len(self.fakesink)): - self.fakesink[i].set_property('signal-handoffs', handoff_state) - - def _new_buffer(self, buf, channel): - ''' Use a new buffer ''' - if not self.dont_queue_the_buffer: - self.temp_buffer = buf - self.callable1(buf, channel=channel) - else: - pass - - def on_buffer(self, element, data_buffer, pad, channel): - '''The function that is called whenever new data is available - This is the signal handler for the handoff signal''' - temp_buffer = fromstring(data_buffer, 'int16') - if not self.dont_queue_the_buffer: - self._new_buffer(temp_buffer, channel=channel) - return False - - def start_sound_device(self): - '''Start or Restart grabbing data from the audio capture''' - gst.event_new_flush_start() - self.pipeline.set_state(gst.STATE_PLAYING) - - def stop_sound_device(self): - '''Stop grabbing data from capture device''' - gst.event_new_flush_stop() - self.pipeline.set_state(gst.STATE_NULL) - - def sample_now(self): - ''' Log the current sample now. This method is called from the - capture_timer object when the interval expires. ''' - self.capture_interval_sample = True - self.make_timer() - - def set_buffer_interval_logging(self, interval=0): - '''Sets the number of buffers after which a buffer needs to be - emitted''' - self.buffer_interval_logging = interval - - def set_sampling_rate(self, sr): - '''Sets the sampling rate of the capture device - Sampling rate must be given as an integer for example 16000 for - setting 16Khz sampling rate - The sampling rate would be set in the device to the nearest available''' - self.pause_grabbing() - caps_str = 'audio/x-raw-int,rate=%d,channels=%d,depth=16' % ( - sr, self.channels) - self.caps1.set_property('caps', gst.caps_from_string(caps_str)) - self.resume_grabbing() - - def get_sampling_rate(self): - '''Gets the sampling rate of the capture device''' - return int(self.caps1.get_property('caps')[0]['rate']) - - def set_callable1(self, callable1): - '''Sets the callable to the drawing function for giving the - data at the end of idle-add''' - self.callable1 = callable1 - - def start_grabbing(self): - '''Called right at the start of the Activity''' - self.start_sound_device() - self.set_handoff_signal(True) - - def pause_grabbing(self): - '''When Activity goes into background''' - self.save_state() - self.stop_sound_device() - - def resume_grabbing(self): - '''When Activity becomes active after going to background''' - self.start_sound_device() - self.resume_state() - self.set_handoff_signal(True) - - def stop_grabbing(self): - '''Not used ???''' - self.stop_sound_device() - self.set_handoff_signal(False) - - def _find_control(self, prefixes): - '''Try to find a mixer control matching one of the prefixes. - - The control with the best match (smallest difference in length - between label and prefix) will be returned. If no match is found, - None is returned. - ''' - def best_prefix(label, prefixes): - matches =\ - [len(label) - len(p) for p in prefixes if label.startswith(p)] - if not matches: - return None - - matches.sort() - return matches[0] - - controls = [] - for track in self._mixer.list_tracks(): - label = track.props.untranslated_label.lower() - diff = best_prefix(label, prefixes) - if diff is not None: - controls.append((track, diff)) - - controls.sort(key=lambda e: e[1]) - if controls: - ''' - debug_output('Found control: %s' %\ - (str(controls[0][0].props.untranslated_label)), - self.parent.running_sugar) - ''' - if self.channels is None: - if hasattr(controls[0][0], 'num_channels'): - channels = controls[0][0].num_channels - if channels > 0: - self.channels = channels - ''' - debug_output('setting channels to %d' % (self.channels), - self.parent.running_sugar) - ''' - - return controls[0][0] - - return None - - def save_state(self): - '''Saves the state of all audio controls''' - self.master = self.get_master() - self.bias = self.get_bias() - self.dc_mode = self.get_dc_mode() - self.capture_gain = self.get_capture_gain() - self.mic_boost = self.get_mic_boost() - - def resume_state(self): - '''Put back all audio control settings from the saved state''' - self.set_master(self.master) - self.set_bias(self.bias) - self.set_dc_mode(self.dc_mode) - self.set_capture_gain(self.capture_gain) - self.set_mic_boost(self.mic_boost) - - def _get_mute(self, control, name, default): - '''Get mute status of a control''' - if not control: - return default - return bool(control.flags & gst.interfaces.MIXER_TRACK_MUTE) - - def _set_mute(self, control, name, value): - '''Mute a control''' - if not control: - return - self._mixer.set_mute(control, value) - - def _get_volume(self, control, name): - '''Get volume of a control and convert to a scale of 0-100''' - if not control: - return 100 - volume = self._mixer.get_volume(control) - if type(volume) == tuple: - hw_volume = volume[0] - else: - hw_volume = volume - min_vol = control.min_volume - max_vol = control.max_volume - if max_vol == min_vol: - percent = 100 - else: - percent = (hw_volume - min_vol) * 100 // (max_vol - min_vol) - return percent - - def _set_volume(self, control, name, value): - '''Sets the level of a control on a scale of 0-100''' - if not control: - return - # convert value to scale of control - min_vol = control.min_volume - max_vol = control.max_volume - if min_vol != max_vol: - hw_volume = value * (max_vol - min_vol) // 100 + min_vol - self._mixer.set_volume(control, - (hw_volume,) * control.num_channels) - - def amixer_set(self, control, state): - ''' Direct call to amixer for old systems. ''' - if state: - output = check_output( - ['amixer', 'set', "%s" % (control), 'unmute'], - 'Problem with amixer set "%s" unmute' % (control), - self.parent.running_sugar) - else: - output = check_output( - ['amixer', 'set', "%s" % (control), 'mute'], - 'Problem with amixer set "%s" mute' % (control), - self.parent.running_sugar) - - def mute_master(self): - '''Mutes the Master Control''' - if self._labels_available and self.parent.hw != XO1: - self._set_mute(self._master_control, 'Master', True) - else: - self.amixer_set('Master', False) - - def unmute_master(self): - '''Unmutes the Master Control''' - if self._labels_available and self.parent.hw != XO1: - self._set_mute(self._master_control, 'Master', True) - else: - self.amixer_set('Master', True) - - def set_master(self, master_val): - '''Sets the Master gain slider settings - master_val must be given as an integer between 0 and 100 indicating the - percentage of the slider to be set''' - if self._labels_available: - self._set_volume(self._master_control, 'Master', master_val) - else: - output = check_output( - ['amixer', 'set', 'Master', "%d%s" % (master_val, '%')], - 'Problem with amixer set Master', - self.parent.running_sugar) - - def get_master(self): - '''Gets the MIC gain slider settings. The value returned is an - integer between 0-100 and is an indicative of the percentage 0 - 100%''' - if self._labels_available: - return self._get_volume(self._master_control, 'master') - else: - output = check_output(['amixer', 'get', 'Master'], - 'amixer: Could not get Master volume', - self.parent.running_sugar) - if output is None: - return 100 - else: - output = output[find(output, 'Front Left:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, '%]')] - return int(output) - - def set_bias(self, bias_state=False): - '''Enables / disables bias voltage.''' - if self._labels_available and self.parent.hw != XO1: - if self._mic_bias_control is None: - return - # If there is a flag property, use set_mute - if self._mic_bias_control not in self._mixer.list_tracks() or \ - hasattr(self._mic_bias_control.props, 'flags'): - self._set_mute( - self._mic_bias_control, 'Mic Bias', not bias_state) - # We assume that values are sorted from lowest (=off) to highest. - # Since they are mixed strings ('Off', '50%', etc.), we cannot - # easily ensure this by sorting with the default sort order. - elif bias_state: # Otherwise, set with volume - self._mixer.set_volume(self._mic_bias_control, - self._mic_bias_control.max_volume) - else: - self._mixer.set_volume(self._mic_bias_control, - self._mic_bias_control.min_volume) - elif not self._labels_available: - self.amixer_set('V_REFOUT Enable', bias_state) - else: - self.amixer_set('MIC Bias Enable', bias_state) - - def get_bias(self): - '''Check whether bias voltage is enabled.''' - if self._labels_available: - if self._mic_bias_control is None: - return False - if self._mic_bias_control not in self._mixer.list_tracks() or \ - hasattr(self._mic_bias_control.props, 'flags'): - return not self._get_mute( - self._mic_bias_control, 'Mic Bias', False) - value = self._mixer.get_volume(self._mic_bias_control) - if value == self._mic_bias_control.min_volume: - return False - return True - else: - output = check_output(['amixer', 'get', "V_REFOUT Enable"], - 'amixer: Could not get mic bias voltage', - self.parent.running_sugar) - if output is None: - return False - else: - output = output[find(output, 'Mono:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, ']')] - if output == 'on': - return True - return False - - def set_dc_mode(self, dc_mode=False): - '''Sets the DC Mode Enable control - pass False to mute and True to unmute''' - if self._labels_available and self.parent.hw != XO1: - if self._dc_control is not None: - self._set_mute(self._dc_control, 'DC mode', not dc_mode) - else: - self.amixer_set('DC Mode Enable', dc_mode) - - def get_dc_mode(self): - '''Returns the setting of DC Mode Enable control - i.e. True: Unmuted and False: Muted''' - if self._labels_available and self.parent.hw != XO1: - if self._dc_control is not None: - return not self._get_mute(self._dc_control, 'DC mode', False) - else: - return False - else: - output = check_output(['amixer', 'get', "DC Mode Enable"], - 'amixer: Could not get DC Mode', - self.parent.running_sugar) - if output is None: - return False - else: - output = output[find(output, 'Mono:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, ']')] - if output == 'on': - return True - return False - - def set_mic_boost(self, mic_boost=False): - '''Set Mic Boost. - True = +20dB, False = 0dB''' - if self._labels_available: - if self._mic_boost_control is None: - return - # If there is a volume, use set volume - if hasattr(self._mic_boost_control, 'min_volume'): - if mic_boost: - self._set_volume(self._mic_boost_control, 'boost', 100) - else: - self._set_volume(self._mic_boost_control, 'boost', 0) - # Else if there is a flag property, use set_mute - elif self._mic_boost_control not in self._mixer.list_tracks() or \ - hasattr(self._mic_boost_control.props, 'flags'): - self._set_mute( - self._mic_boost_control, 'Mic Boost', not mic_boost) - else: - self.amixer_set('Mic Boost (+20dB)', mic_boost) - - def get_mic_boost(self): - '''Return Mic Boost setting. - True = +20dB, False = 0dB''' - if self._labels_available: - if self._mic_boost_control is None: - return False - if self._mic_boost_control not in self._mixer.list_tracks() or \ - hasattr(self._mic_boost_control.props, 'flags'): - return not self._get_mute( - self._mic_boost_control, 'Mic Boost', False) - else: # Compare to min value - value = self._mixer.get_volume(self._mic_boost_control) - if value != self._mic_boost_control.min_volume: - return True - return False - else: - output = check_output(['amixer', 'get', "Mic Boost (+20dB)"], - 'amixer: Could not get mic boost', - self.parent.running_sugar) - if output is None: - return False - else: - output = output[find(output, 'Mono:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, ']')] - if output == 'on': - return True - return False - - def set_capture_gain(self, capture_val): - '''Sets the Capture gain slider settings - capture_val must be given as an integer between 0 and 100 indicating the - percentage of the slider to be set''' - if self._labels_available and self.parent.hw != XO1: - if self._capture_control is not None: - self._set_volume(self._capture_control, 'Capture', capture_val) - else: - output = check_output( - ['amixer', 'set', 'Capture', "%d%s" % (capture_val, '%')], - 'Problem with amixer set Capture', - self.parent.running_sugar) - - def get_capture_gain(self): - '''Gets the Capture gain slider settings. The value returned is an - integer between 0-100 and is an indicative of the percentage 0 - 100%''' - if self._labels_available: - if self._capture_control is not None: - return self._get_volume(self._capture_control, 'Capture') - else: - return 0 - else: - output = check_output(['amixer', 'get', 'Capture'], - 'amixer: Could not get Capture level', - self.parent.running_sugar) - if output is None: - return 100 - else: - output = output[find(output, 'Front Left:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, '%]')] - return int(output) - - def set_mic_gain(self, mic_val): - '''Sets the MIC gain slider settings - mic_val must be given as an integer between 0 and 100 indicating the - percentage of the slider to be set''' - if self._labels_available and self.parent.hw != XO1: - self._set_volume(self._mic_gain_control, 'Mic', mic_val) - else: - output = check_output( - ['amixer', 'set', 'Mic', "%d%s" % (mic_val, '%')], - 'Problem with amixer set Mic', - self.parent.running_sugar) - - def get_mic_gain(self): - '''Gets the MIC gain slider settings. The value returned is an - integer between 0-100 and is an indicative of the percentage 0 - 100%''' - if self._labels_available and self.parent.hw != XO1: - return self._get_volume(self._mic_gain_control, 'Mic') - else: - output = check_output(['amixer', 'get', 'Mic'], - 'amixer: Could not get mic gain level', - self.parent.running_sugar) - if output is None: - return 100 - else: - output = output[find(output, 'Mono:'):] - output = output[find(output, '[') + 1:] - output = output[:find(output, '%]')] - return int(output) - - def _set_sensor_type(self, mode=None, bias=None, gain=None, boost=None): - '''Helper to modify (some) of the sensor settings.''' - if mode is not None: - self.set_dc_mode(mode) - if bias is not None: - self.set_bias(bias) - if gain is not None: - self.set_capture_gain(gain) - if boost is not None: - self.set_mic_boost(boost) - self.save_state() - - def on_activity_quit(self): - '''When Activity quits''' - self.set_mic_boost(QUIT_MIC_BOOST) - self.set_dc_mode(QUIT_DC_MODE_ENABLE) - self.set_capture_gain(QUIT_CAPTURE_GAIN) - self.set_bias(QUIT_BIAS) - self.stop_sound_device() - - -def check_output(command, warning, running_sugar=True): - ''' Workaround for old systems without subprocess.check_output''' - if hasattr(subprocess, 'check_output'): - try: - output = subprocess.check_output(command) - except subprocess.CalledProcessError: - debug_output(warning, running_sugar) - return None - else: - import commands - - cmd = '' - for c in command: - cmd += c - cmd += ' ' - (status, output) = commands.getstatusoutput(cmd) - if status != 0: - debug_output(warning, running_sugar) - return None - return output diff --git a/plugins/audio_sensors/icons/sensoroff.svg b/plugins/audio_sensors/icons/sensoroff.svg deleted file mode 100644 index 0a16670..0000000 --- a/plugins/audio_sensors/icons/sensoroff.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/audio_sensors/icons/sensoron.svg b/plugins/audio_sensors/icons/sensoron.svg deleted file mode 100644 index d756860..0000000 --- a/plugins/audio_sensors/icons/sensoron.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/plugins/audio_sensors/ringbuffer.py b/plugins/audio_sensors/ringbuffer.py deleted file mode 100644 index 2afb5c9..0000000 --- a/plugins/audio_sensors/ringbuffer.py +++ /dev/null @@ -1,108 +0,0 @@ -# Copyright (C) 2009, Benjamin Berg, Sebastian Berg -# Copyright (C) 2010, 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., 675 Mass Ave, Cambridge, MA 02139, USA. - -import numpy as np - - -class RingBuffer1d(object): - """This class implements an array being written in as a ring and that can - be read from continuously ending with the newest data or starting with the - oldest. It returns a numpy array copy of the data; - """ - - def __init__(self, length, dtype=None): - """Initialize the 1 dimensional ring buffer with the given lengths. - The initial values are all 0s - """ - self.offset = 0 - - self._data = np.zeros(length, dtype=dtype) - - self.stored = 0 - - def fill(self, number): - self._data.fill(number) - self.offset = 0 - - def append(self, data): - """Append to the ring buffer (and overwrite old data). If len(data) - is greater then the ring buffers length, the newest data takes - precedence. - """ - data = np.asarray(data) - - if len(self._data) == 0: - return - - if len(data) >= len(self._data): - self._data[:] = data[-len(self._data):] - self.offset = 0 - self.stored = len(self._data) - - elif len(self._data) - self.offset >= len(data): - self._data[self.offset: self.offset + len(data)] = data - self.offset = self.offset + len(data) - self.stored += len(data) - else: - self._data[self.offset:] = data[:len(self._data) - self.offset] - self._data[:len(data) - (len(self._data) - self.offset)] = \ - data[-len(data) + (len(self._data) - self.offset):] - self.offset = len(data) - (len(self._data) - self.offset) - self.stored += len(data) - - if len(self._data) <= self.stored: - self.read = self._read - - def read(self, number=None, step=1): - """Read the ring Buffer. Number can be positive or negative. - Positive values will give the latest information, negative values will - give the newest added information from the buffer. (in normal order) - - Before the buffer is filled once: This returns just None - """ - return np.array([]) - - def _read(self, number=None, step=1): - """Read the ring Buffer. Number can be positive or negative. - Positive values will give the latest information, negative values will - give the newest added information from the buffer. (in normal order) - """ - if number == None: - number = len(self._data) // step - - number *= step - assert abs(number) <= len(self._data), \ - 'Number to read*step must be smaller then length' - - if number < 0: - if abs(number) <= self.offset: - return self._data[self.offset + number:self.offset:step] - - spam = (self.offset - 1) % step - - return np.concatenate( - (self._data[step - spam - 1 + self.offset + number::step], - self._data[spam:self.offset:step])) - - if number - (len(self._data) - self.offset) > 0: - spam = ((self.offset + number) - self.offset - 1) % step - return np.concatenate( - (self._data[self.offset:self.offset + number:step], - self._data[spam:number - - (len(self._data) - self.offset):step])) - - return self._data[self.offset:self.offset + number:step].copy() diff --git a/plugins/camera_sensor/camera_sensor.py b/plugins/camera_sensor/camera_sensor.py deleted file mode 100644 index 6509a88..0000000 --- a/plugins/camera_sensor/camera_sensor.py +++ /dev/null @@ -1,308 +0,0 @@ -#!/usr/bin/env python -#Copyright (c) 2011, 2012 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 gst -import gtk -from fcntl import ioctl -import os -from time import time - -from gettext import gettext as _ - -from plugins.camera_sensor.tacamera import Camera -from plugins.camera_sensor.v4l2 import v4l2_control, V4L2_CID_AUTOGAIN, \ - VIDIOC_G_CTRL, VIDIOC_S_CTRL - -from plugins.plugin import Plugin - -from TurtleArt.tapalette import make_palette -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 - - -class Camera_sensor(Plugin): - - def __init__(self, parent): - ''' Make sure there is a camera device ''' - self._parent = parent - self._status = False - self._ag_control = None - self.devices = [] - self.cameras = [] - - if os.path.exists('/dev/video0'): - self.devices.append('/dev/video0') - if os.path.exists('/dev/video1'): - self.devices.append('/dev/video1') - if len(self.devices) > 0: - self._status = True - else: - self._status = False - - def setup(self): - ''' Set up the palettes ''' - sensors_palette = make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_( - 'Palette of sensor blocks'), - position=6) - media_palette = make_palette('media', - colors=["#A0FF00", "#80A000"], - help_string=_('Palette of media objects'), - 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 - - SKIN_PATHS.append('plugins/camera_sensor/images') - - if self._status: - sensors_palette.add_block('luminance', - style='box-style', - label=_('brightness'), - help_string=_( - '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)) - - # Depreciated block - sensors_palette.add_block('read_camera', - hidden=True, - style='box-style', - label=_('brightness'), - help_string=_( - 'Average RGB color from camera \ -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']()) - - media_palette.add_block('camera', - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) - if len(self.devices) > 1: - media_palette.add_block('camera1', - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) - else: - media_palette.add_block('camera1', - hidden=True, - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) - - else: # No camera, so blocks should do nothing - sensors_palette.add_block('luminance', - hidden=True, - style='box-style', - label=_('brightness'), - help_string=\ - _('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)) - - # Depreciated block - sensors_palette.add_block('read_camera', - hidden=True, - style='box-style', - label=_('brightness'), - help_string=_( - 'Average RGB color from camera \ -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']()) - - media_palette.add_block('camera', - hidden=True, - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) - - media_palette.add_block('camera1', - hidden=True, - style='box-style-media', - label=' ', - default='CAMERA', - help_string=_('camera output'), - content_block=True) - - NO_IMPORT.append('camera') - BLOCKS_WITH_SKIN.append('camera') - NO_IMPORT.append('camera1') - BLOCKS_WITH_SKIN.append('camera1') - MEDIA_SHAPES.append('camerasmall') - MEDIA_SHAPES.append('cameraoff') - MEDIA_SHAPES.append('camera1small') - MEDIA_SHAPES.append('camera1off') - - def start(self): - ''' Initialize the camera if there is an camera block in use ''' - if len(self._parent.block_list.get_similar_blocks('block', - ['camera', 'camera1', 'read_camera', 'luminance'])) > 0: - if self._status and len(self.cameras) == 0: - for device in self.devices: - self.cameras.append(Camera(device)) - - def quit(self): - ''' This gets called when the activity quits ''' - self._reset_the_camera() - - def stop(self): - ''' This gets called by the stop button ''' - self._reset_the_camera() - - def clear(self): - ''' This gets called by the clean button and erase button ''' - self._reset_the_camera() - - def _reset_the_camera(self): - if self._status and len(self.cameras) > 0: - for i, camera in enumerate(self.cameras): - camera.stop_camera_input() - self._set_autogain(1, camera=i) # enable AUTOGAIN - - def _status_report(self): - debug_output('Reporting camera status: %s' % (str(self._status)), - self._parent.running_sugar) - return self._status - - # Block primitives used in talogo - - def prim_take_picture0(self): - self._take_picture(camera=0) - - def prim_take_picture1(self): - self._take_picture(camera=1) - - def _take_picture(self, camera=0): - ''' method called by media block ''' - self._set_autogain(1, camera) # enable AUTOGAIN - self._get_pixbuf_from_camera(camera) - self._parent.lc.pixbuf = self.cameras[camera].pixbuf - - def prim_read_camera(self, luminance_only=False, camera=0): - """ Read average pixel from camera and push b, g, r to the stack """ - self.luminance_only = luminance_only - if not self._status: - if self.luminance_only: - return -1 - else: - self._parent.lc.heap.append(-1) - self._parent.lc.heap.append(-1) - self._parent.lc.heap.append(-1) - 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 - else: - self._parent.lc.heap.append(self.b) - self._parent.lc.heap.append(self.g) - self._parent.lc.heap.append(self.r) - - def calc_luminance(self, camera=0): - array = self.cameras[camera].pixbuf.get_pixels() - width = self.cameras[camera].pixbuf.get_width() - height = self.cameras[camera].pixbuf.get_height() - - if array is not None: - length = int(len(array) / 3) - if length != width * height: - debug_output('array length != width x height (%d != %dx%d)' % \ - (length, width, height), - self._parent.running_sugar) - - # Average the 100 pixels in the center of the screen - r, g, b = 0, 0, 0 - row_offset = int((height / 2 - 5) * width * 3) - column_offset = int(width / 2 - 5) * 3 - for y in range(10): - i = row_offset + column_offset - for x in range(10): - r += ord(array[i]) - i += 1 - g += ord(array[i]) - i += 1 - b += ord(array[i]) - i += 1 - row_offset += width * 3 - if self.luminance_only: - self.luminance = int((r * 0.3 + g * 0.6 + b * 0.1) / 100) - else: - self.r = int(r / 100) - self.g = int(g / 100) - self.b = int(b / 100) - else: - if self.luminance_only: - self.luminance = -1 - else: - self.r = -1 - self.g = -1 - self.b = -1 - - 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: - return - try: - video_capture_device = open(self.devices[camera], 'rw') - except: - video_capture_device = None - debug_output('video capture device not available', - self._parent.running_sugar) - return - self._ag_control = v4l2_control(V4L2_CID_AUTOGAIN) - try: - ioctl(video_capture_device, VIDIOC_G_CTRL, self._ag_control) - self._ag_control.value = state - ioctl(video_capture_device, VIDIOC_S_CTRL, self._ag_control) - except: - pass - video_capture_device.close() - - def _get_pixbuf_from_camera(self, camera): - ''' Regardless of how we get it, we want to return a pixbuf ''' - self._parent.lc.pixbuf = None - if self._status: - self.cameras[camera].start_camera_input() diff --git a/plugins/camera_sensor/icons/sensoroff.svg b/plugins/camera_sensor/icons/sensoroff.svg deleted file mode 100644 index 0a16670..0000000 --- a/plugins/camera_sensor/icons/sensoroff.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/camera_sensor/icons/sensoron.svg b/plugins/camera_sensor/icons/sensoron.svg deleted file mode 100644 index d756860..0000000 --- a/plugins/camera_sensor/icons/sensoron.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/plugins/camera_sensor/images/camera1off.svg b/plugins/camera_sensor/images/camera1off.svg deleted file mode 100644 index 2abf8d2..0000000 --- a/plugins/camera_sensor/images/camera1off.svg +++ /dev/null @@ -1,66 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/camera_sensor/images/camera1small.svg b/plugins/camera_sensor/images/camera1small.svg deleted file mode 100644 index 4d7f756..0000000 --- a/plugins/camera_sensor/images/camera1small.svg +++ /dev/null @@ -1,68 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/camera_sensor/images/cameraoff.svg b/plugins/camera_sensor/images/cameraoff.svg deleted file mode 100644 index 54d9c86..0000000 --- a/plugins/camera_sensor/images/cameraoff.svg +++ /dev/null @@ -1,15 +0,0 @@ - - -]> - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/camera_sensor/images/camerasmall.svg b/plugins/camera_sensor/images/camerasmall.svg deleted file mode 100644 index 690e940..0000000 --- a/plugins/camera_sensor/images/camerasmall.svg +++ /dev/null @@ -1,51 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - \ No newline at end of file diff --git a/plugins/camera_sensor/tacamera.py b/plugins/camera_sensor/tacamera.py deleted file mode 100644 index fc0804d..0000000 --- a/plugins/camera_sensor/tacamera.py +++ /dev/null @@ -1,69 +0,0 @@ -# -*- coding: utf-8 -*- -#Copyright (c) 2010, Walter Bender -#Copyright (c) 2010, Tony Forster - -#Permission is hereby granted, free of charge, to any person obtaining a copy -#of this software and associated documentation files (the "Software"), to deal -#in the Software without restriction, including without limitation the rights -#to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -#copies of the Software, and to permit persons to whom the Software is -#furnished to do so, subject to the following conditions: - -#The above copyright notice and this permission notice shall be included in -#all copies or substantial portions of the Software. - -#THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -#IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -#FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -#AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -#LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -#OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -#THE SOFTWARE. - -import gst, time -import gobject - -from TurtleArt.tautils import debug_output - - -class Camera(): - ''' Sets up a pipe from the camera to a pixbuf and emits a signal - when the image is ready. ''' - - def __init__(self, device='/dev/video0'): - ''' Prepare camera pipeline to pixbuf and signal watch ''' - self.pipe = gst.Pipeline('pipeline') - v4l2src = gst.element_factory_make('v4l2src', None) - v4l2src.props.device = device - self.pipe.add(v4l2src) - ffmpegcolorspace = gst.element_factory_make('ffmpegcolorspace', None) - self.pipe.add(ffmpegcolorspace) - gdkpixbufsink = gst.element_factory_make('gdkpixbufsink', None) - self.pipe.add(gdkpixbufsink) - gst.element_link_many(v4l2src, ffmpegcolorspace, gdkpixbufsink) - if self.pipe is not None: - self.bus = self.pipe.get_bus() - self.bus.add_signal_watch() - self.bus.connect('message', self._on_message) - status = True - else: - status = False - - def _on_message(self, bus, message): - ''' We get a message if a pixbuf is available ''' - if message.structure is not None: - if message.structure.get_name() == 'pixbuf': - self.pixbuf = message.structure['pixbuf'] - self.image_ready = True - - def start_camera_input(self): - ''' Start grabbing ''' - self.pixbuf = None - self.image_ready = False - self.pipe.set_state(gst.STATE_PLAYING) - while not self.image_ready: - self.bus.poll(gst.MESSAGE_ANY, -1) - - def stop_camera_input(self): - ''' Stop grabbing ''' - self.pipe.set_state(gst.STATE_NULL) diff --git a/plugins/camera_sensor/v4l2.py b/plugins/camera_sensor/v4l2.py deleted file mode 100644 index 9c052fd..0000000 --- a/plugins/camera_sensor/v4l2.py +++ /dev/null @@ -1,1914 +0,0 @@ -# Python bindings for the v4l2 userspace api - -# Copyright (C) 1999-2009 the contributors - -# 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. - -# Alternatively you can redistribute this file under the terms of the -# BSD license as stated below: - -# Redistribution and use in source and binary forms, with or without -# modification, are permitted provided that the following conditions -# are met: -# 1. Redistributions of source code must retain the above copyright -# notice, this list of conditions and the following disclaimer. -# 2. Redistributions in binary form must reproduce the above copyright -# notice, this list of conditions and the following disclaimer in -# the documentation and/or other materials provided with the -# distribution. -# 3. The names of its contributors may not be used to endorse or promote -# products derived from this software without specific prior written -# permission. - -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR -# A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT -# OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, -# SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED -# TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR -# PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF -# LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING -# NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS -# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - -""" -Python bindings for the v4l2 userspace api in Linux 2.6.34 -""" - -# see linux/videodev2.h - -import ctypes - - -_IOC_NRBITS = 8 -_IOC_TYPEBITS = 8 -_IOC_SIZEBITS = 14 -_IOC_DIRBITS = 2 - -_IOC_NRSHIFT = 0 -_IOC_TYPESHIFT = _IOC_NRSHIFT + _IOC_NRBITS -_IOC_SIZESHIFT = _IOC_TYPESHIFT + _IOC_TYPEBITS -_IOC_DIRSHIFT = _IOC_SIZESHIFT + _IOC_SIZEBITS - -_IOC_NONE = 0 -_IOC_WRITE = 1 -_IOC_READ = 2 - - -def _IOC(dir_, type_, nr, size): - return ( - ctypes.c_int32(dir_ << _IOC_DIRSHIFT).value | - ctypes.c_int32(ord(type_) << _IOC_TYPESHIFT).value | - ctypes.c_int32(nr << _IOC_NRSHIFT).value | - ctypes.c_int32(size << _IOC_SIZESHIFT).value) - - -def _IOC_TYPECHECK(t): - return ctypes.sizeof(t) - - -def _IO(type_, nr): - return _IOC(_IOC_NONE, type_, nr, 0) - - -def _IOW(type_, nr, size): - return _IOC(_IOC_WRITE, type_, nr, _IOC_TYPECHECK(size)) - - -def _IOR(type_, nr, size): - return _IOC(_IOC_READ, type_, nr, _IOC_TYPECHECK(size)) - - -def _IOWR(type_, nr, size): - return _IOC(_IOC_READ | _IOC_WRITE, type_, nr, _IOC_TYPECHECK(size)) - - -# -# type alias -# - -enum = ctypes.c_uint -c_int = ctypes.c_int - - -# -# time -# - -class timeval(ctypes.Structure): - _fields_ = [ - ('secs', ctypes.c_long), - ('usecs', ctypes.c_long), - ] - - -# -# v4l2 -# - - -VIDEO_MAX_FRAME = 32 - - -VID_TYPE_CAPTURE = 1 -VID_TYPE_TUNER = 2 -VID_TYPE_TELETEXT = 4 -VID_TYPE_OVERLAY = 8 -VID_TYPE_CHROMAKEY = 16 -VID_TYPE_CLIPPING = 32 -VID_TYPE_FRAMERAM = 64 -VID_TYPE_SCALES = 128 -VID_TYPE_MONOCHROME = 256 -VID_TYPE_SUBCAPTURE = 512 -VID_TYPE_MPEG_DECODER = 1024 -VID_TYPE_MPEG_ENCODER = 2048 -VID_TYPE_MJPEG_DECODER = 4096 -VID_TYPE_MJPEG_ENCODER = 8192 - - -def v4l2_fourcc(a, b, c, d): - return ord(a) | (ord(b) << 8) | (ord(c) << 16) | (ord(d) << 24) - - -v4l2_field = enum -( - V4L2_FIELD_ANY, - V4L2_FIELD_NONE, - V4L2_FIELD_TOP, - V4L2_FIELD_BOTTOM, - V4L2_FIELD_INTERLACED, - V4L2_FIELD_SEQ_TB, - V4L2_FIELD_SEQ_BT, - V4L2_FIELD_ALTERNATE, - V4L2_FIELD_INTERLACED_TB, - V4L2_FIELD_INTERLACED_BT, -) = range(10) - - -def V4L2_FIELD_HAS_TOP(field): - return ( - field == V4L2_FIELD_TOP or - field == V4L2_FIELD_INTERLACED or - field == V4L2_FIELD_INTERLACED_TB or - field == V4L2_FIELD_INTERLACED_BT or - field == V4L2_FIELD_SEQ_TB or - field == V4L2_FIELD_SEQ_BT) - - -def V4L2_FIELD_HAS_BOTTOM(field): - return ( - field == V4L2_FIELD_BOTTOM or - field == V4L2_FIELD_INTERLACED or - field == V4L2_FIELD_INTERLACED_TB or - field == V4L2_FIELD_INTERLACED_BT or - field == V4L2_FIELD_SEQ_TB or - field == V4L2_FIELD_SEQ_BT) - - -def V4L2_FIELD_HAS_BOTH(field): - return ( - field == V4L2_FIELD_INTERLACED or - field == V4L2_FIELD_INTERLACED_TB or - field == V4L2_FIELD_INTERLACED_BT or - field == V4L2_FIELD_SEQ_TB or - field == V4L2_FIELD_SEQ_BT) - - -v4l2_buf_type = enum -( - V4L2_BUF_TYPE_VIDEO_CAPTURE, - V4L2_BUF_TYPE_VIDEO_OUTPUT, - V4L2_BUF_TYPE_VIDEO_OVERLAY, - V4L2_BUF_TYPE_VBI_CAPTURE, - V4L2_BUF_TYPE_VBI_OUTPUT, - V4L2_BUF_TYPE_SLICED_VBI_CAPTURE, - V4L2_BUF_TYPE_SLICED_VBI_OUTPUT, - V4L2_BUF_TYPE_VIDEO_OUTPUT_OVERLAY, - V4L2_BUF_TYPE_PRIVATE, -) = range(1, 9) + [0x80] - - -v4l2_ctrl_type = enum -( - V4L2_CTRL_TYPE_INTEGER, - V4L2_CTRL_TYPE_BOOLEAN, - V4L2_CTRL_TYPE_MENU, - V4L2_CTRL_TYPE_BUTTON, - V4L2_CTRL_TYPE_INTEGER64, - V4L2_CTRL_TYPE_CTRL_CLASS, - V4L2_CTRL_TYPE_STRING, -) = range(1, 8) - - -v4l2_tuner_type = enum -( - V4L2_TUNER_RADIO, - V4L2_TUNER_ANALOG_TV, - V4L2_TUNER_DIGITAL_TV, -) = range(1, 4) - - -v4l2_memory = enum -( - V4L2_MEMORY_MMAP, - V4L2_MEMORY_USERPTR, - V4L2_MEMORY_OVERLAY, -) = range(1, 4) - - -v4l2_colorspace = enum -( - V4L2_COLORSPACE_SMPTE170M, - V4L2_COLORSPACE_SMPTE240M, - V4L2_COLORSPACE_REC709, - V4L2_COLORSPACE_BT878, - V4L2_COLORSPACE_470_SYSTEM_M, - V4L2_COLORSPACE_470_SYSTEM_BG, - V4L2_COLORSPACE_JPEG, - V4L2_COLORSPACE_SRGB, -) = range(1, 9) - - -v4l2_priority = enum -( - V4L2_PRIORITY_UNSET, - V4L2_PRIORITY_BACKGROUND, - V4L2_PRIORITY_INTERACTIVE, - V4L2_PRIORITY_RECORD, - V4L2_PRIORITY_DEFAULT, -) = range(0, 4) + [2] - - -class v4l2_rect(ctypes.Structure): - _fields_ = [ - ('left', ctypes.c_int32), - ('top', ctypes.c_int32), - ('width', ctypes.c_int32), - ('height', ctypes.c_int32), - ] - - -class v4l2_fract(ctypes.Structure): - _fields_ = [ - ('numerator', ctypes.c_uint32), - ('denominator', ctypes.c_uint32), - ] - - -# -# Driver capabilities -# - -class v4l2_capability(ctypes.Structure): - _fields_ = [ - ('driver', ctypes.c_char * 16), - ('card', ctypes.c_char * 32), - ('bus_info', ctypes.c_char * 32), - ('version', ctypes.c_uint32), - ('capabilities', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -# -# Values for 'capabilities' field -# - -V4L2_CAP_VIDEO_CAPTURE = 0x00000001 -V4L2_CAP_VIDEO_OUTPUT = 0x00000002 -V4L2_CAP_VIDEO_OVERLAY = 0x00000004 -V4L2_CAP_VBI_CAPTURE = 0x00000010 -V4L2_CAP_VBI_OUTPUT = 0x00000020 -V4L2_CAP_SLICED_VBI_CAPTURE = 0x00000040 -V4L2_CAP_SLICED_VBI_OUTPUT = 0x00000080 -V4L2_CAP_RDS_CAPTURE = 0x00000100 -V4L2_CAP_VIDEO_OUTPUT_OVERLAY = 0x00000200 -V4L2_CAP_HW_FREQ_SEEK = 0x00000400 -V4L2_CAP_RDS_OUTPUT = 0x00000800 - -V4L2_CAP_TUNER = 0x00010000 -V4L2_CAP_AUDIO = 0x00020000 -V4L2_CAP_RADIO = 0x00040000 -V4L2_CAP_MODULATOR = 0x00080000 - -V4L2_CAP_READWRITE = 0x01000000 -V4L2_CAP_ASYNCIO = 0x02000000 -V4L2_CAP_STREAMING = 0x04000000 - - -# -# Video image format -# - -class v4l2_pix_format(ctypes.Structure): - _fields_ = [ - ('width', ctypes.c_uint32), - ('height', ctypes.c_uint32), - ('pixelformat', ctypes.c_uint32), - ('field', v4l2_field), - ('bytesperline', ctypes.c_uint32), - ('sizeimage', ctypes.c_uint32), - ('colorspace', v4l2_colorspace), - ('priv', ctypes.c_uint32), - ] - -# RGB formats -V4L2_PIX_FMT_RGB332 = v4l2_fourcc('R', 'G', 'B', '1') -V4L2_PIX_FMT_RGB444 = v4l2_fourcc('R', '4', '4', '4') -V4L2_PIX_FMT_RGB555 = v4l2_fourcc('R', 'G', 'B', 'O') -V4L2_PIX_FMT_RGB565 = v4l2_fourcc('R', 'G', 'B', 'P') -V4L2_PIX_FMT_RGB555X = v4l2_fourcc('R', 'G', 'B', 'Q') -V4L2_PIX_FMT_RGB565X = v4l2_fourcc('R', 'G', 'B', 'R') -V4L2_PIX_FMT_BGR24 = v4l2_fourcc('B', 'G', 'R', '3') -V4L2_PIX_FMT_RGB24 = v4l2_fourcc('R', 'G', 'B', '3') -V4L2_PIX_FMT_BGR32 = v4l2_fourcc('B', 'G', 'R', '4') -V4L2_PIX_FMT_RGB32 = v4l2_fourcc('R', 'G', 'B', '4') - -# Grey formats -V4L2_PIX_FMT_GREY = v4l2_fourcc('G', 'R', 'E', 'Y') -V4L2_PIX_FMT_Y10 = v4l2_fourcc('Y', '1', '0', ' ') -V4L2_PIX_FMT_Y16 = v4l2_fourcc('Y', '1', '6', ' ') - -# Palette formats -V4L2_PIX_FMT_PAL8 = v4l2_fourcc('P', 'A', 'L', '8') - -# Luminance+Chrominance formats -V4L2_PIX_FMT_YVU410 = v4l2_fourcc('Y', 'V', 'U', '9') -V4L2_PIX_FMT_YVU420 = v4l2_fourcc('Y', 'V', '1', '2') -V4L2_PIX_FMT_YUYV = v4l2_fourcc('Y', 'U', 'Y', 'V') -V4L2_PIX_FMT_YYUV = v4l2_fourcc('Y', 'Y', 'U', 'V') -V4L2_PIX_FMT_YVYU = v4l2_fourcc('Y', 'V', 'Y', 'U') -V4L2_PIX_FMT_UYVY = v4l2_fourcc('U', 'Y', 'V', 'Y') -V4L2_PIX_FMT_VYUY = v4l2_fourcc('V', 'Y', 'U', 'Y') -V4L2_PIX_FMT_YUV422P = v4l2_fourcc('4', '2', '2', 'P') -V4L2_PIX_FMT_YUV411P = v4l2_fourcc('4', '1', '1', 'P') -V4L2_PIX_FMT_Y41P = v4l2_fourcc('Y', '4', '1', 'P') -V4L2_PIX_FMT_YUV444 = v4l2_fourcc('Y', '4', '4', '4') -V4L2_PIX_FMT_YUV555 = v4l2_fourcc('Y', 'U', 'V', 'O') -V4L2_PIX_FMT_YUV565 = v4l2_fourcc('Y', 'U', 'V', 'P') -V4L2_PIX_FMT_YUV32 = v4l2_fourcc('Y', 'U', 'V', '4') -V4L2_PIX_FMT_YUV410 = v4l2_fourcc('Y', 'U', 'V', '9') -V4L2_PIX_FMT_YUV420 = v4l2_fourcc('Y', 'U', '1', '2') -V4L2_PIX_FMT_HI240 = v4l2_fourcc('H', 'I', '2', '4') -V4L2_PIX_FMT_HM12 = v4l2_fourcc('H', 'M', '1', '2') - -# two planes -- one Y, one Cr + Cb interleaved -V4L2_PIX_FMT_NV12 = v4l2_fourcc('N', 'V', '1', '2') -V4L2_PIX_FMT_NV21 = v4l2_fourcc('N', 'V', '2', '1') -V4L2_PIX_FMT_NV16 = v4l2_fourcc('N', 'V', '1', '6') -V4L2_PIX_FMT_NV61 = v4l2_fourcc('N', 'V', '6', '1') - -# Bayer formats - see http://www.siliconimaging.com/RGB%20Bayer.htm -V4L2_PIX_FMT_SBGGR8 = v4l2_fourcc('B', 'A', '8', '1') -V4L2_PIX_FMT_SGBRG8 = v4l2_fourcc('G', 'B', 'R', 'G') -V4L2_PIX_FMT_SGRBG8 = v4l2_fourcc('G', 'R', 'B', 'G') -V4L2_PIX_FMT_SRGGB8 = v4l2_fourcc('R', 'G', 'G', 'B') -V4L2_PIX_FMT_SBGGR10 = v4l2_fourcc('B', 'G', '1', '0') -V4L2_PIX_FMT_SGBRG10 = v4l2_fourcc('G', 'B', '1', '0') -V4L2_PIX_FMT_SGRBG10 = v4l2_fourcc('B', 'A', '1', '0') -V4L2_PIX_FMT_SRGGB10 = v4l2_fourcc('R', 'G', '1', '0') -V4L2_PIX_FMT_SGRBG10DPCM8 = v4l2_fourcc('B', 'D', '1', '0') -V4L2_PIX_FMT_SBGGR16 = v4l2_fourcc('B', 'Y', 'R', '2') - -# compressed formats -V4L2_PIX_FMT_MJPEG = v4l2_fourcc('M', 'J', 'P', 'G') -V4L2_PIX_FMT_JPEG = v4l2_fourcc('J', 'P', 'E', 'G') -V4L2_PIX_FMT_DV = v4l2_fourcc('d', 'v', 's', 'd') -V4L2_PIX_FMT_MPEG = v4l2_fourcc('M', 'P', 'E', 'G') - -# Vendor-specific formats -V4L2_PIX_FMT_CPIA1 = v4l2_fourcc('C', 'P', 'I', 'A') -V4L2_PIX_FMT_WNVA = v4l2_fourcc('W', 'N', 'V', 'A') -V4L2_PIX_FMT_SN9C10X = v4l2_fourcc('S', '9', '1', '0') -V4L2_PIX_FMT_SN9C20X_I420 = v4l2_fourcc('S', '9', '2', '0') -V4L2_PIX_FMT_PWC1 = v4l2_fourcc('P', 'W', 'C', '1') -V4L2_PIX_FMT_PWC2 = v4l2_fourcc('P', 'W', 'C', '2') -V4L2_PIX_FMT_ET61X251 = v4l2_fourcc('E', '6', '2', '5') -V4L2_PIX_FMT_SPCA501 = v4l2_fourcc('S', '5', '0', '1') -V4L2_PIX_FMT_SPCA505 = v4l2_fourcc('S', '5', '0', '5') -V4L2_PIX_FMT_SPCA508 = v4l2_fourcc('S', '5', '0', '8') -V4L2_PIX_FMT_SPCA561 = v4l2_fourcc('S', '5', '6', '1') -V4L2_PIX_FMT_PAC207 = v4l2_fourcc('P', '2', '0', '7') -V4L2_PIX_FMT_MR97310A = v4l2_fourcc('M', '3', '1', '0') -V4L2_PIX_FMT_SN9C2028 = v4l2_fourcc('S', 'O', 'N', 'X') -V4L2_PIX_FMT_SQ905C = v4l2_fourcc('9', '0', '5', 'C') -V4L2_PIX_FMT_PJPG = v4l2_fourcc('P', 'J', 'P', 'G') -V4L2_PIX_FMT_OV511 = v4l2_fourcc('O', '5', '1', '1') -V4L2_PIX_FMT_OV518 = v4l2_fourcc('O', '5', '1', '8') -V4L2_PIX_FMT_STV0680 = v4l2_fourcc('S', '6', '8', '0') - - -# -# Format enumeration -# - -class v4l2_fmtdesc(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('type', ctypes.c_int), - ('flags', ctypes.c_uint32), - ('description', ctypes.c_char * 32), - ('pixelformat', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - -V4L2_FMT_FLAG_COMPRESSED = 0x0001 -V4L2_FMT_FLAG_EMULATED = 0x0002 - - -# -# Experimental frame size and frame rate enumeration -# - -v4l2_frmsizetypes = enum -( - V4L2_FRMSIZE_TYPE_DISCRETE, - V4L2_FRMSIZE_TYPE_CONTINUOUS, - V4L2_FRMSIZE_TYPE_STEPWISE, -) = range(1, 4) - - -class v4l2_frmsize_discrete(ctypes.Structure): - _fields_ = [ - ('width', ctypes.c_uint32), - ('height', ctypes.c_uint32), - ] - - -class v4l2_frmsize_stepwise(ctypes.Structure): - _fields_ = [ - ('min_width', ctypes.c_uint32), - ('min_height', ctypes.c_uint32), - ('step_width', ctypes.c_uint32), - ('min_height', ctypes.c_uint32), - ('max_height', ctypes.c_uint32), - ('step_height', ctypes.c_uint32), - ] - - -class v4l2_frmsizeenum(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('discrete', v4l2_frmsize_discrete), - ('stepwise', v4l2_frmsize_stepwise), - ] - - _fields_ = [ - ('index', ctypes.c_uint32), - ('pixel_format', ctypes.c_uint32), - ('type', ctypes.c_uint32), - ('_u', _u), - ('reserved', ctypes.c_uint32 * 2) - ] - - _anonymous_ = ('_u',) - - -# -# Frame rate enumeration -# - -v4l2_frmivaltypes = enum -( - V4L2_FRMIVAL_TYPE_DISCRETE, - V4L2_FRMIVAL_TYPE_CONTINUOUS, - V4L2_FRMIVAL_TYPE_STEPWISE, -) = range(1, 4) - - -class v4l2_frmival_stepwise(ctypes.Structure): - _fields_ = [ - ('min', v4l2_fract), - ('max', v4l2_fract), - ('step', v4l2_fract), - ] - - -class v4l2_frmivalenum(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('discrete', v4l2_fract), - ('stepwise', v4l2_frmival_stepwise), - ] - - _fields_ = [ - ('index', ctypes.c_uint32), - ('pixel_format', ctypes.c_uint32), - ('width', ctypes.c_uint32), - ('height', ctypes.c_uint32), - ('type', ctypes.c_uint32), - ('_u', _u), - ('reserved', ctypes.c_uint32 * 2), - ] - - _anonymous_ = ('_u',) - - -# -# Timecode -# - -class v4l2_timecode(ctypes.Structure): - _fields_ = [ - ('type', ctypes.c_uint32), - ('flags', ctypes.c_uint32), - ('frames', ctypes.c_uint8), - ('seconds', ctypes.c_uint8), - ('minutes', ctypes.c_uint8), - ('hours', ctypes.c_uint8), - ('userbits', ctypes.c_uint8 * 4), - ] - - -V4L2_TC_TYPE_24FPS = 1 -V4L2_TC_TYPE_25FPS = 2 -V4L2_TC_TYPE_30FPS = 3 -V4L2_TC_TYPE_50FPS = 4 -V4L2_TC_TYPE_60FPS = 5 - -V4L2_TC_FLAG_DROPFRAME = 0x0001 -V4L2_TC_FLAG_COLORFRAME = 0x0002 -V4L2_TC_USERBITS_field = 0x000C -V4L2_TC_USERBITS_USERDEFINED = 0x0000 -V4L2_TC_USERBITS_8BITCHARS = 0x0008 - - -class v4l2_jpegcompression(ctypes.Structure): - _fields_ = [ - ('quality', ctypes.c_int), - ('APPn', ctypes.c_int), - ('APP_len', ctypes.c_int), - ('APP_data', ctypes.c_char * 60), - ('COM_len', ctypes.c_int), - ('COM_data', ctypes.c_char * 60), - ('jpeg_markers', ctypes.c_uint32), - ] - - -V4L2_JPEG_MARKER_DHT = 1 << 3 -V4L2_JPEG_MARKER_DQT = 1 << 4 -V4L2_JPEG_MARKER_DRI = 1 << 5 -V4L2_JPEG_MARKER_COM = 1 << 6 -V4L2_JPEG_MARKER_APP = 1 << 7 - - -# -# Memory-mapping buffers -# - -class v4l2_requestbuffers(ctypes.Structure): - _fields_ = [ - ('count', ctypes.c_uint32), - ('type', v4l2_buf_type), - ('memory', v4l2_memory), - ('reserved', ctypes.c_uint32 * 2), - ] - - -class v4l2_buffer(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('offset', ctypes.c_uint32), - ('userptr', ctypes.c_ulong), - ] - - _fields_ = [ - ('index', ctypes.c_uint32), - ('type', v4l2_buf_type), - ('bytesused', ctypes.c_uint32), - ('flags', ctypes.c_uint32), - ('field', v4l2_field), - ('timestamp', timeval), - ('timecode', v4l2_timecode), - ('sequence', ctypes.c_uint32), - ('memory', v4l2_memory), - ('m', _u), - ('length', ctypes.c_uint32), - ('input', ctypes.c_uint32), - ('reserved', ctypes.c_uint32), - ] - - -V4L2_BUF_FLAG_MAPPED = 0x0001 -V4L2_BUF_FLAG_QUEUED = 0x0002 -V4L2_BUF_FLAG_DONE = 0x0004 -V4L2_BUF_FLAG_KEYFRAME = 0x0008 -V4L2_BUF_FLAG_PFRAME = 0x0010 -V4L2_BUF_FLAG_BFRAME = 0x0020 -V4L2_BUF_FLAG_TIMECODE = 0x0100 -V4L2_BUF_FLAG_INPUT = 0x0200 - - -# -# Overlay preview -# - -class v4l2_framebuffer(ctypes.Structure): - _fields_ = [ - ('capability', ctypes.c_uint32), - ('flags', ctypes.c_uint32), - ('base', ctypes.c_void_p), - ('fmt', v4l2_pix_format), - ] - -V4L2_FBUF_CAP_EXTERNOVERLAY = 0x0001 -V4L2_FBUF_CAP_CHROMAKEY = 0x0002 -V4L2_FBUF_CAP_LIST_CLIPPING = 0x0004 -V4L2_FBUF_CAP_BITMAP_CLIPPING = 0x0008 -V4L2_FBUF_CAP_LOCAL_ALPHA = 0x0010 -V4L2_FBUF_CAP_GLOBAL_ALPHA = 0x0020 -V4L2_FBUF_CAP_LOCAL_INV_ALPHA = 0x0040 -V4L2_FBUF_CAP_SRC_CHROMAKEY = 0x0080 - -V4L2_FBUF_FLAG_PRIMARY = 0x0001 -V4L2_FBUF_FLAG_OVERLAY = 0x0002 -V4L2_FBUF_FLAG_CHROMAKEY = 0x0004 -V4L2_FBUF_FLAG_LOCAL_ALPHA = 0x0008 -V4L2_FBUF_FLAG_GLOBAL_ALPHA = 0x0010 -V4L2_FBUF_FLAG_LOCAL_INV_ALPHA = 0x0020 -V4L2_FBUF_FLAG_SRC_CHROMAKEY = 0x0040 - - -class v4l2_clip(ctypes.Structure): - pass -v4l2_clip._fields_ = [ - ('c', v4l2_rect), - ('next', ctypes.POINTER(v4l2_clip)), -] - - -class v4l2_window(ctypes.Structure): - _fields_ = [ - ('w', v4l2_rect), - ('field', v4l2_field), - ('chromakey', ctypes.c_uint32), - ('clips', ctypes.POINTER(v4l2_clip)), - ('clipcount', ctypes.c_uint32), - ('bitmap', ctypes.c_void_p), - ('global_alpha', ctypes.c_uint8), - ] - - -# -# Capture parameters -# - -class v4l2_captureparm(ctypes.Structure): - _fields_ = [ - ('capability', ctypes.c_uint32), - ('capturemode', ctypes.c_uint32), - ('timeperframe', v4l2_fract), - ('extendedmode', ctypes.c_uint32), - ('readbuffers', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -V4L2_MODE_HIGHQUALITY = 0x0001 -V4L2_CAP_TIMEPERFRAME = 0x1000 - - -class v4l2_outputparm(ctypes.Structure): - _fields_ = [ - ('capability', ctypes.c_uint32), - ('outputmode', ctypes.c_uint32), - ('timeperframe', v4l2_fract), - ('extendedmode', ctypes.c_uint32), - ('writebuffers', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -# -# Input image cropping -# - -class v4l2_cropcap(ctypes.Structure): - _fields_ = [ - ('type', v4l2_buf_type), - ('bounds', v4l2_rect), - ('defrect', v4l2_rect), - ('pixelaspect', v4l2_fract), - ] - - -class v4l2_crop(ctypes.Structure): - _fields_ = [ - ('type', ctypes.c_int), - ('c', v4l2_rect), - ] - - -# -# Analog video standard -# - -v4l2_std_id = ctypes.c_uint64 - - -V4L2_STD_PAL_B = 0x00000001 -V4L2_STD_PAL_B1 = 0x00000002 -V4L2_STD_PAL_G = 0x00000004 -V4L2_STD_PAL_H = 0x00000008 -V4L2_STD_PAL_I = 0x00000010 -V4L2_STD_PAL_D = 0x00000020 -V4L2_STD_PAL_D1 = 0x00000040 -V4L2_STD_PAL_K = 0x00000080 - -V4L2_STD_PAL_M = 0x00000100 -V4L2_STD_PAL_N = 0x00000200 -V4L2_STD_PAL_Nc = 0x00000400 -V4L2_STD_PAL_60 = 0x00000800 - -V4L2_STD_NTSC_M = 0x00001000 -V4L2_STD_NTSC_M_JP = 0x00002000 -V4L2_STD_NTSC_443 = 0x00004000 -V4L2_STD_NTSC_M_KR = 0x00008000 - -V4L2_STD_SECAM_B = 0x00010000 -V4L2_STD_SECAM_D = 0x00020000 -V4L2_STD_SECAM_G = 0x00040000 -V4L2_STD_SECAM_H = 0x00080000 -V4L2_STD_SECAM_K = 0x00100000 -V4L2_STD_SECAM_K1 = 0x00200000 -V4L2_STD_SECAM_L = 0x00400000 -V4L2_STD_SECAM_LC = 0x00800000 - -V4L2_STD_ATSC_8_VSB = 0x01000000 -V4L2_STD_ATSC_16_VSB = 0x02000000 - - -# some common needed stuff -V4L2_STD_PAL_BG = (V4L2_STD_PAL_B | V4L2_STD_PAL_B1 | V4L2_STD_PAL_G) -V4L2_STD_PAL_DK = (V4L2_STD_PAL_D | V4L2_STD_PAL_D1 | V4L2_STD_PAL_K) -V4L2_STD_PAL = (V4L2_STD_PAL_BG | V4L2_STD_PAL_DK | V4L2_STD_PAL_H | V4L2_STD_PAL_I) -V4L2_STD_NTSC = (V4L2_STD_NTSC_M | V4L2_STD_NTSC_M_JP | V4L2_STD_NTSC_M_KR) -V4L2_STD_SECAM_DK = (V4L2_STD_SECAM_D | V4L2_STD_SECAM_K | V4L2_STD_SECAM_K1) -V4L2_STD_SECAM = (V4L2_STD_SECAM_B | V4L2_STD_SECAM_G | V4L2_STD_SECAM_H | V4L2_STD_SECAM_DK | V4L2_STD_SECAM_L | V4L2_STD_SECAM_LC) - -V4L2_STD_525_60 = (V4L2_STD_PAL_M | V4L2_STD_PAL_60 | V4L2_STD_NTSC | V4L2_STD_NTSC_443) -V4L2_STD_625_50 = (V4L2_STD_PAL | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | V4L2_STD_SECAM) -V4L2_STD_ATSC = (V4L2_STD_ATSC_8_VSB | V4L2_STD_ATSC_16_VSB) - -V4L2_STD_UNKNOWN = 0 -V4L2_STD_ALL = (V4L2_STD_525_60 | V4L2_STD_625_50) - -# some merged standards -V4L2_STD_MN = (V4L2_STD_PAL_M | V4L2_STD_PAL_N | V4L2_STD_PAL_Nc | V4L2_STD_NTSC) -V4L2_STD_B = (V4L2_STD_PAL_B | V4L2_STD_PAL_B1 | V4L2_STD_SECAM_B) -V4L2_STD_GH = (V4L2_STD_PAL_G | V4L2_STD_PAL_H|V4L2_STD_SECAM_G | V4L2_STD_SECAM_H) -V4L2_STD_DK = (V4L2_STD_PAL_DK | V4L2_STD_SECAM_DK) - - -class v4l2_standard(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('id', v4l2_std_id), - ('name', ctypes.c_char * 24), - ('frameperiod', v4l2_fract), - ('framelines', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -# -# Video timings dv preset -# - -class v4l2_dv_preset(ctypes.Structure): - _fields_ = [ - ('preset', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4) - ] - - -# -# DV preset enumeration -# - -class v4l2_dv_enum_preset(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('preset', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('width', ctypes.c_uint32), - ('height', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - -# -# DV preset values -# - -V4L2_DV_INVALID = 0 -V4L2_DV_480P59_94 = 1 -V4L2_DV_576P50 = 2 -V4L2_DV_720P24 = 3 -V4L2_DV_720P25 = 4 -V4L2_DV_720P30 = 5 -V4L2_DV_720P50 = 6 -V4L2_DV_720P59_94 = 7 -V4L2_DV_720P60 = 8 -V4L2_DV_1080I29_97 = 9 -V4L2_DV_1080I30 = 10 -V4L2_DV_1080I25 = 11 -V4L2_DV_1080I50 = 12 -V4L2_DV_1080I60 = 13 -V4L2_DV_1080P24 = 14 -V4L2_DV_1080P25 = 15 -V4L2_DV_1080P30 = 16 -V4L2_DV_1080P50 = 17 -V4L2_DV_1080P60 = 18 - - -# -# DV BT timings -# - -class v4l2_bt_timings(ctypes.Structure): - _fields_ = [ - ('width', ctypes.c_uint32), - ('height', ctypes.c_uint32), - ('interlaced', ctypes.c_uint32), - ('polarities', ctypes.c_uint32), - ('pixelclock', ctypes.c_uint64), - ('hfrontporch', ctypes.c_uint32), - ('hsync', ctypes.c_uint32), - ('hbackporch', ctypes.c_uint32), - ('vfrontporch', ctypes.c_uint32), - ('vsync', ctypes.c_uint32), - ('vbackporch', ctypes.c_uint32), - ('il_vfrontporch', ctypes.c_uint32), - ('il_vsync', ctypes.c_uint32), - ('il_vbackporch', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 16), - ] - - _pack_ = True - -# Interlaced or progressive format -V4L2_DV_PROGRESSIVE = 0 -V4L2_DV_INTERLACED = 1 - -# Polarities. If bit is not set, it is assumed to be negative polarity -V4L2_DV_VSYNC_POS_POL = 0x00000001 -V4L2_DV_HSYNC_POS_POL = 0x00000002 - - -class v4l2_dv_timings(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('bt', v4l2_bt_timings), - ('reserved', ctypes.c_uint32 * 32), - ] - - _fields_ = [ - ('type', ctypes.c_uint32), - ('_u', _u), - ] - - _anonymous_ = ('_u',) - _pack_ = True - - -# Values for the type field -V4L2_DV_BT_656_1120 = 0 - - -# -# Video inputs -# - -class v4l2_input(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('type', ctypes.c_uint32), - ('audioset', ctypes.c_uint32), - ('tuner', ctypes.c_uint32), - ('std', v4l2_std_id), - ('status', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -V4L2_INPUT_TYPE_TUNER = 1 -V4L2_INPUT_TYPE_CAMERA = 2 - -V4L2_IN_ST_NO_POWER = 0x00000001 -V4L2_IN_ST_NO_SIGNAL = 0x00000002 -V4L2_IN_ST_NO_COLOR = 0x00000004 - -V4L2_IN_ST_HFLIP = 0x00000010 -V4L2_IN_ST_VFLIP = 0x00000020 - -V4L2_IN_ST_NO_H_LOCK = 0x00000100 -V4L2_IN_ST_COLOR_KILL = 0x00000200 - -V4L2_IN_ST_NO_SYNC = 0x00010000 -V4L2_IN_ST_NO_EQU = 0x00020000 -V4L2_IN_ST_NO_CARRIER = 0x00040000 - -V4L2_IN_ST_MACROVISION = 0x01000000 -V4L2_IN_ST_NO_ACCESS = 0x02000000 -V4L2_IN_ST_VTR = 0x04000000 - -V4L2_IN_CAP_PRESETS = 0x00000001 -V4L2_IN_CAP_CUSTOM_TIMINGS = 0x00000002 -V4L2_IN_CAP_STD = 0x00000004 - -# -# Video outputs -# - -class v4l2_output(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('type', ctypes.c_uint32), - ('audioset', ctypes.c_uint32), - ('modulator', ctypes.c_uint32), - ('std', v4l2_std_id), - ('reserved', ctypes.c_uint32 * 4), - ] - - -V4L2_OUTPUT_TYPE_MODULATOR = 1 -V4L2_OUTPUT_TYPE_ANALOG = 2 -V4L2_OUTPUT_TYPE_ANALOGVGAOVERLAY = 3 - -V4L2_OUT_CAP_PRESETS = 0x00000001 -V4L2_OUT_CAP_CUSTOM_TIMINGS = 0x00000002 -V4L2_OUT_CAP_STD = 0x00000004 - -# -# Controls -# - -class v4l2_control(ctypes.Structure): - _fields_ = [ - ('id', ctypes.c_uint32), - ('value', ctypes.c_int32), - ] - - -class v4l2_ext_control(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('value', ctypes.c_int32), - ('value64', ctypes.c_int64), - ('reserved', ctypes.c_void_p), - ] - - _fields_ = [ - ('id', ctypes.c_uint32), - ('reserved2', ctypes.c_uint32 * 2), - ('_u', _u) - ] - - _anonymous_ = ('_u',) - _pack_ = True - - -class v4l2_ext_controls(ctypes.Structure): - _fields_ = [ - ('ctrl_class', ctypes.c_uint32), - ('count', ctypes.c_uint32), - ('error_idx', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ('controls', ctypes.POINTER(v4l2_ext_control)), - ] - - -V4L2_CTRL_CLASS_USER = 0x00980000 -V4L2_CTRL_CLASS_MPEG = 0x00990000 -V4L2_CTRL_CLASS_CAMERA = 0x009a0000 -V4L2_CTRL_CLASS_FM_TX = 0x009b0000 - - -def V4L2_CTRL_ID_MASK(): - return 0x0fffffff - - -def V4L2_CTRL_ID2CLASS(id_): - return id_ & 0x0fff0000 # unsigned long - - -def V4L2_CTRL_DRIVER_PRIV(id_): - return (id_ & 0xffff) >= 0x1000 - - -class v4l2_queryctrl(ctypes.Structure): - _fields_ = [ - ('id', ctypes.c_uint32), - ('type', v4l2_ctrl_type), - ('name', ctypes.c_char * 32), - ('minimum', ctypes.c_int32), - ('maximum', ctypes.c_int32), - ('step', ctypes.c_int32), - ('default', ctypes.c_int32), - ('flags', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -class v4l2_querymenu(ctypes.Structure): - _fields_ = [ - ('id', ctypes.c_uint32), - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('reserved', ctypes.c_uint32), - ] - - -V4L2_CTRL_FLAG_DISABLED = 0x0001 -V4L2_CTRL_FLAG_GRABBED = 0x0002 -V4L2_CTRL_FLAG_READ_ONLY = 0x0004 -V4L2_CTRL_FLAG_UPDATE = 0x0008 -V4L2_CTRL_FLAG_INACTIVE = 0x0010 -V4L2_CTRL_FLAG_SLIDER = 0x0020 -V4L2_CTRL_FLAG_WRITE_ONLY = 0x0040 - -V4L2_CTRL_FLAG_NEXT_CTRL = 0x80000000 - -V4L2_CID_BASE = V4L2_CTRL_CLASS_USER | 0x900 -V4L2_CID_USER_BASE = V4L2_CID_BASE -V4L2_CID_PRIVATE_BASE = 0x08000000 - -V4L2_CID_USER_CLASS = V4L2_CTRL_CLASS_USER | 1 -V4L2_CID_BRIGHTNESS = V4L2_CID_BASE + 0 -V4L2_CID_CONTRAST = V4L2_CID_BASE + 1 -V4L2_CID_SATURATION = V4L2_CID_BASE + 2 -V4L2_CID_HUE = V4L2_CID_BASE + 3 -V4L2_CID_AUDIO_VOLUME = V4L2_CID_BASE + 5 -V4L2_CID_AUDIO_BALANCE = V4L2_CID_BASE + 6 -V4L2_CID_AUDIO_BASS = V4L2_CID_BASE + 7 -V4L2_CID_AUDIO_TREBLE = V4L2_CID_BASE + 8 -V4L2_CID_AUDIO_MUTE = V4L2_CID_BASE + 9 -V4L2_CID_AUDIO_LOUDNESS = V4L2_CID_BASE + 10 -V4L2_CID_BLACK_LEVEL = V4L2_CID_BASE + 11 # Deprecated -V4L2_CID_AUTO_WHITE_BALANCE = V4L2_CID_BASE + 12 -V4L2_CID_DO_WHITE_BALANCE = V4L2_CID_BASE + 13 -V4L2_CID_RED_BALANCE = V4L2_CID_BASE + 14 -V4L2_CID_BLUE_BALANCE = V4L2_CID_BASE + 15 -V4L2_CID_GAMMA = V4L2_CID_BASE + 16 -V4L2_CID_WHITENESS = V4L2_CID_GAMMA # Deprecated -V4L2_CID_EXPOSURE = V4L2_CID_BASE + 17 -V4L2_CID_AUTOGAIN = V4L2_CID_BASE + 18 -V4L2_CID_GAIN = V4L2_CID_BASE + 19 -V4L2_CID_HFLIP = V4L2_CID_BASE + 20 -V4L2_CID_VFLIP = V4L2_CID_BASE + 21 - -# Deprecated; use V4L2_CID_PAN_RESET and V4L2_CID_TILT_RESET -V4L2_CID_HCENTER = V4L2_CID_BASE + 22 -V4L2_CID_VCENTER = V4L2_CID_BASE + 23 - -V4L2_CID_POWER_LINE_FREQUENCY = V4L2_CID_BASE + 24 - -v4l2_power_line_frequency = enum -( - V4L2_CID_POWER_LINE_FREQUENCY_DISABLED, - V4L2_CID_POWER_LINE_FREQUENCY_50HZ, - V4L2_CID_POWER_LINE_FREQUENCY_60HZ, -) = range(3) - -V4L2_CID_HUE_AUTO = V4L2_CID_BASE + 25 -V4L2_CID_WHITE_BALANCE_TEMPERATURE = V4L2_CID_BASE + 26 -V4L2_CID_SHARPNESS = V4L2_CID_BASE + 27 -V4L2_CID_BACKLIGHT_COMPENSATION = V4L2_CID_BASE + 28 -V4L2_CID_CHROMA_AGC = V4L2_CID_BASE + 29 -V4L2_CID_COLOR_KILLER = V4L2_CID_BASE + 30 -V4L2_CID_COLORFX = V4L2_CID_BASE + 31 - -v4l2_colorfx = enum -( - V4L2_COLORFX_NONE, - V4L2_COLORFX_BW, - V4L2_COLORFX_SEPIA, -) = range(3) - -V4L2_CID_AUTOBRIGHTNESS = V4L2_CID_BASE + 32 -V4L2_CID_BAND_STOP_FILTER = V4L2_CID_BASE + 33 - -V4L2_CID_ROTATE = V4L2_CID_BASE + 34 -V4L2_CID_BG_COLOR = V4L2_CID_BASE + 35 -V4L2_CID_LASTP1 = V4L2_CID_BASE + 36 - -V4L2_CID_MPEG_BASE = V4L2_CTRL_CLASS_MPEG | 0x900 -V4L2_CID_MPEG_CLASS = V4L2_CTRL_CLASS_MPEG | 1 - -# MPEG streams -V4L2_CID_MPEG_STREAM_TYPE = V4L2_CID_MPEG_BASE + 0 - -v4l2_mpeg_stream_type = enum -( - V4L2_MPEG_STREAM_TYPE_MPEG2_PS, - V4L2_MPEG_STREAM_TYPE_MPEG2_TS, - V4L2_MPEG_STREAM_TYPE_MPEG1_SS, - V4L2_MPEG_STREAM_TYPE_MPEG2_DVD, - V4L2_MPEG_STREAM_TYPE_MPEG1_VCD, - V4L2_MPEG_STREAM_TYPE_MPEG2_SVCD, -) = range(6) - -V4L2_CID_MPEG_STREAM_PID_PMT = V4L2_CID_MPEG_BASE + 1 -V4L2_CID_MPEG_STREAM_PID_AUDIO = V4L2_CID_MPEG_BASE + 2 -V4L2_CID_MPEG_STREAM_PID_VIDEO = V4L2_CID_MPEG_BASE + 3 -V4L2_CID_MPEG_STREAM_PID_PCR = V4L2_CID_MPEG_BASE + 4 -V4L2_CID_MPEG_STREAM_PES_ID_AUDIO = V4L2_CID_MPEG_BASE + 5 -V4L2_CID_MPEG_STREAM_PES_ID_VIDEO = V4L2_CID_MPEG_BASE + 6 -V4L2_CID_MPEG_STREAM_VBI_FMT = V4L2_CID_MPEG_BASE + 7 - -v4l2_mpeg_stream_vbi_fmt = enum -( - V4L2_MPEG_STREAM_VBI_FMT_NONE, - V4L2_MPEG_STREAM_VBI_FMT_IVTV, -) = range(2) - -V4L2_CID_MPEG_AUDIO_SAMPLING_FREQ = V4L2_CID_MPEG_BASE + 100 - -v4l2_mpeg_audio_sampling_freq = enum -( - V4L2_MPEG_AUDIO_SAMPLING_FREQ_44100, - V4L2_MPEG_AUDIO_SAMPLING_FREQ_48000, - V4L2_MPEG_AUDIO_SAMPLING_FREQ_32000, -) = range(3) - -V4L2_CID_MPEG_AUDIO_ENCODING = V4L2_CID_MPEG_BASE + 101 - -v4l2_mpeg_audio_encoding = enum -( - V4L2_MPEG_AUDIO_ENCODING_LAYER_1, - V4L2_MPEG_AUDIO_ENCODING_LAYER_2, - V4L2_MPEG_AUDIO_ENCODING_LAYER_3, - V4L2_MPEG_AUDIO_ENCODING_AAC, - V4L2_MPEG_AUDIO_ENCODING_AC3, -) = range(5) - -V4L2_CID_MPEG_AUDIO_L1_BITRATE = V4L2_CID_MPEG_BASE + 102 - -v4l2_mpeg_audio_l1_bitrate = enum -( - V4L2_MPEG_AUDIO_L1_BITRATE_32K, - V4L2_MPEG_AUDIO_L1_BITRATE_64K, - V4L2_MPEG_AUDIO_L1_BITRATE_96K, - V4L2_MPEG_AUDIO_L1_BITRATE_128K, - V4L2_MPEG_AUDIO_L1_BITRATE_160K, - V4L2_MPEG_AUDIO_L1_BITRATE_192K, - V4L2_MPEG_AUDIO_L1_BITRATE_224K, - V4L2_MPEG_AUDIO_L1_BITRATE_256K, - V4L2_MPEG_AUDIO_L1_BITRATE_288K, - V4L2_MPEG_AUDIO_L1_BITRATE_320K, - V4L2_MPEG_AUDIO_L1_BITRATE_352K, - V4L2_MPEG_AUDIO_L1_BITRATE_384K, - V4L2_MPEG_AUDIO_L1_BITRATE_416K, - V4L2_MPEG_AUDIO_L1_BITRATE_448K, -) = range(14) - -V4L2_CID_MPEG_AUDIO_L2_BITRATE = V4L2_CID_MPEG_BASE + 103 - -v4l2_mpeg_audio_l2_bitrate = enum -( - V4L2_MPEG_AUDIO_L2_BITRATE_32K, - V4L2_MPEG_AUDIO_L2_BITRATE_48K, - V4L2_MPEG_AUDIO_L2_BITRATE_56K, - V4L2_MPEG_AUDIO_L2_BITRATE_64K, - V4L2_MPEG_AUDIO_L2_BITRATE_80K, - V4L2_MPEG_AUDIO_L2_BITRATE_96K, - V4L2_MPEG_AUDIO_L2_BITRATE_112K, - V4L2_MPEG_AUDIO_L2_BITRATE_128K, - V4L2_MPEG_AUDIO_L2_BITRATE_160K, - V4L2_MPEG_AUDIO_L2_BITRATE_192K, - V4L2_MPEG_AUDIO_L2_BITRATE_224K, - V4L2_MPEG_AUDIO_L2_BITRATE_256K, - V4L2_MPEG_AUDIO_L2_BITRATE_320K, - V4L2_MPEG_AUDIO_L2_BITRATE_384K, -) = range(14) - -V4L2_CID_MPEG_AUDIO_L3_BITRATE = V4L2_CID_MPEG_BASE + 104 - -v4l2_mpeg_audio_l3_bitrate = enum -( - V4L2_MPEG_AUDIO_L3_BITRATE_32K, - V4L2_MPEG_AUDIO_L3_BITRATE_40K, - V4L2_MPEG_AUDIO_L3_BITRATE_48K, - V4L2_MPEG_AUDIO_L3_BITRATE_56K, - V4L2_MPEG_AUDIO_L3_BITRATE_64K, - V4L2_MPEG_AUDIO_L3_BITRATE_80K, - V4L2_MPEG_AUDIO_L3_BITRATE_96K, - V4L2_MPEG_AUDIO_L3_BITRATE_112K, - V4L2_MPEG_AUDIO_L3_BITRATE_128K, - V4L2_MPEG_AUDIO_L3_BITRATE_160K, - V4L2_MPEG_AUDIO_L3_BITRATE_192K, - V4L2_MPEG_AUDIO_L3_BITRATE_224K, - V4L2_MPEG_AUDIO_L3_BITRATE_256K, - V4L2_MPEG_AUDIO_L3_BITRATE_320K, -) = range(14) - -V4L2_CID_MPEG_AUDIO_MODE = V4L2_CID_MPEG_BASE + 105 - -v4l2_mpeg_audio_mode = enum -( - V4L2_MPEG_AUDIO_MODE_STEREO, - V4L2_MPEG_AUDIO_MODE_JOINT_STEREO, - V4L2_MPEG_AUDIO_MODE_DUAL, - V4L2_MPEG_AUDIO_MODE_MONO, -) = range(4) - -V4L2_CID_MPEG_AUDIO_MODE_EXTENSION = V4L2_CID_MPEG_BASE + 106 - -v4l2_mpeg_audio_mode_extension = enum -( - V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_4, - V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_8, - V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_12, - V4L2_MPEG_AUDIO_MODE_EXTENSION_BOUND_16, -) = range(4) - -V4L2_CID_MPEG_AUDIO_EMPHASIS = V4L2_CID_MPEG_BASE + 107 - -v4l2_mpeg_audio_emphasis = enum -( - V4L2_MPEG_AUDIO_EMPHASIS_NONE, - V4L2_MPEG_AUDIO_EMPHASIS_50_DIV_15_uS, - V4L2_MPEG_AUDIO_EMPHASIS_CCITT_J17, -) = range(3) - -V4L2_CID_MPEG_AUDIO_CRC = V4L2_CID_MPEG_BASE + 108 - -v4l2_mpeg_audio_crc = enum -( - V4L2_MPEG_AUDIO_CRC_NONE, - V4L2_MPEG_AUDIO_CRC_CRC16, -) = range(2) - -V4L2_CID_MPEG_AUDIO_MUTE = V4L2_CID_MPEG_BASE + 109 -V4L2_CID_MPEG_AUDIO_AAC_BITRATE = V4L2_CID_MPEG_BASE + 110 -V4L2_CID_MPEG_AUDIO_AC3_BITRATE = V4L2_CID_MPEG_BASE + 111 - -v4l2_mpeg_audio_ac3_bitrate = enum -( - V4L2_MPEG_AUDIO_AC3_BITRATE_32K, - V4L2_MPEG_AUDIO_AC3_BITRATE_40K, - V4L2_MPEG_AUDIO_AC3_BITRATE_48K, - V4L2_MPEG_AUDIO_AC3_BITRATE_56K, - V4L2_MPEG_AUDIO_AC3_BITRATE_64K, - V4L2_MPEG_AUDIO_AC3_BITRATE_80K, - V4L2_MPEG_AUDIO_AC3_BITRATE_96K, - V4L2_MPEG_AUDIO_AC3_BITRATE_112K, - V4L2_MPEG_AUDIO_AC3_BITRATE_128K, - V4L2_MPEG_AUDIO_AC3_BITRATE_160K, - V4L2_MPEG_AUDIO_AC3_BITRATE_192K, - V4L2_MPEG_AUDIO_AC3_BITRATE_224K, - V4L2_MPEG_AUDIO_AC3_BITRATE_256K, - V4L2_MPEG_AUDIO_AC3_BITRATE_320K, - V4L2_MPEG_AUDIO_AC3_BITRATE_384K, - V4L2_MPEG_AUDIO_AC3_BITRATE_448K, - V4L2_MPEG_AUDIO_AC3_BITRATE_512K, - V4L2_MPEG_AUDIO_AC3_BITRATE_576K, - V4L2_MPEG_AUDIO_AC3_BITRATE_640K, -) = range(19) - -V4L2_CID_MPEG_VIDEO_ENCODING = V4L2_CID_MPEG_BASE + 200 - -v4l2_mpeg_video_encoding = enum -( - V4L2_MPEG_VIDEO_ENCODING_MPEG_1, - V4L2_MPEG_VIDEO_ENCODING_MPEG_2, - V4L2_MPEG_VIDEO_ENCODING_MPEG_4_AVC, -) = range(3) - -V4L2_CID_MPEG_VIDEO_ASPECT = V4L2_CID_MPEG_BASE + 201 - -v4l2_mpeg_video_aspect = enum -( - V4L2_MPEG_VIDEO_ASPECT_1x1, - V4L2_MPEG_VIDEO_ASPECT_4x3, - V4L2_MPEG_VIDEO_ASPECT_16x9, - V4L2_MPEG_VIDEO_ASPECT_221x100, -) = range(4) - -V4L2_CID_MPEG_VIDEO_B_FRAMES = V4L2_CID_MPEG_BASE + 202 -V4L2_CID_MPEG_VIDEO_GOP_SIZE = V4L2_CID_MPEG_BASE + 203 -V4L2_CID_MPEG_VIDEO_GOP_CLOSURE = V4L2_CID_MPEG_BASE + 204 -V4L2_CID_MPEG_VIDEO_PULLDOWN = V4L2_CID_MPEG_BASE + 205 -V4L2_CID_MPEG_VIDEO_BITRATE_MODE = V4L2_CID_MPEG_BASE + 206 - -v4l2_mpeg_video_bitrate_mode = enum -( - V4L2_MPEG_VIDEO_BITRATE_MODE_VBR, - V4L2_MPEG_VIDEO_BITRATE_MODE_CBR, -) = range(2) - -V4L2_CID_MPEG_VIDEO_BITRATE = V4L2_CID_MPEG_BASE + 207 -V4L2_CID_MPEG_VIDEO_BITRATE_PEAK = V4L2_CID_MPEG_BASE + 208 -V4L2_CID_MPEG_VIDEO_TEMPORAL_DECIMATION = V4L2_CID_MPEG_BASE + 209 -V4L2_CID_MPEG_VIDEO_MUTE = V4L2_CID_MPEG_BASE + 210 -V4L2_CID_MPEG_VIDEO_MUTE_YUV = V4L2_CID_MPEG_BASE + 211 - -V4L2_CID_MPEG_CX2341X_BASE = V4L2_CTRL_CLASS_MPEG | 0x1000 -V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE = V4L2_CID_MPEG_CX2341X_BASE + 0 - -v4l2_mpeg_cx2341x_video_spatial_filter_mode = enum -( - V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_MANUAL, - V4L2_MPEG_CX2341X_VIDEO_SPATIAL_FILTER_MODE_AUTO, -) = range(2) - -V4L2_CID_MPEG_CX2341X_VIDEO_SPATIAL_FILTER = V4L2_CID_MPEG_CX2341X_BASE + 1 -V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE = V4L2_CID_MPEG_CX2341X_BASE + 2 - -v4l2_mpeg_cx2341x_video_luma_spatial_filter_type = enum -( - V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_OFF, - V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_HOR, - V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_1D_VERT, - V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_HV_SEPARABLE, - V4L2_MPEG_CX2341X_VIDEO_LUMA_SPATIAL_FILTER_TYPE_2D_SYM_NON_SEPARABLE, -) = range(5) - -V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE = V4L2_CID_MPEG_CX2341X_BASE + 3 - -v4l2_mpeg_cx2341x_video_chroma_spatial_filter_type = enum -( - V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_OFF, - V4L2_MPEG_CX2341X_VIDEO_CHROMA_SPATIAL_FILTER_TYPE_1D_HOR, -) = range(2) - -V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE = V4L2_CID_MPEG_CX2341X_BASE + 4 - -v4l2_mpeg_cx2341x_video_temporal_filter_mode = enum -( - V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_MANUAL, - V4L2_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER_MODE_AUTO, -) = range(2) - -V4L2_CID_MPEG_CX2341X_VIDEO_TEMPORAL_FILTER = V4L2_CID_MPEG_CX2341X_BASE + 5 -V4L2_CID_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE = V4L2_CID_MPEG_CX2341X_BASE + 6 - -v4l2_mpeg_cx2341x_video_median_filter_type = enum -( - V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_OFF, - V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR, - V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_VERT, - V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_HOR_VERT, - V4L2_MPEG_CX2341X_VIDEO_MEDIAN_FILTER_TYPE_DIAG, -) = range(5) - -V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_BOTTOM = V4L2_CID_MPEG_CX2341X_BASE + 7 -V4L2_CID_MPEG_CX2341X_VIDEO_LUMA_MEDIAN_FILTER_TOP = V4L2_CID_MPEG_CX2341X_BASE + 8 -V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_BOTTOM = V4L2_CID_MPEG_CX2341X_BASE + 9 -V4L2_CID_MPEG_CX2341X_VIDEO_CHROMA_MEDIAN_FILTER_TOP = V4L2_CID_MPEG_CX2341X_BASE + 10 -V4L2_CID_MPEG_CX2341X_STREAM_INSERT_NAV_PACKETS = V4L2_CID_MPEG_CX2341X_BASE + 11 - -V4L2_CID_CAMERA_CLASS_BASE = V4L2_CTRL_CLASS_CAMERA | 0x900 -V4L2_CID_CAMERA_CLASS = V4L2_CTRL_CLASS_CAMERA | 1 - -V4L2_CID_EXPOSURE_AUTO = V4L2_CID_CAMERA_CLASS_BASE + 1 - -v4l2_exposure_auto_type = enum -( - V4L2_EXPOSURE_AUTO, - V4L2_EXPOSURE_MANUAL, - V4L2_EXPOSURE_SHUTTER_PRIORITY, - V4L2_EXPOSURE_APERTURE_PRIORITY, -) = range(4) - -V4L2_CID_EXPOSURE_ABSOLUTE = V4L2_CID_CAMERA_CLASS_BASE + 2 -V4L2_CID_EXPOSURE_AUTO_PRIORITY = V4L2_CID_CAMERA_CLASS_BASE + 3 - -V4L2_CID_PAN_RELATIVE = V4L2_CID_CAMERA_CLASS_BASE + 4 -V4L2_CID_TILT_RELATIVE = V4L2_CID_CAMERA_CLASS_BASE + 5 -V4L2_CID_PAN_RESET = V4L2_CID_CAMERA_CLASS_BASE + 6 -V4L2_CID_TILT_RESET = V4L2_CID_CAMERA_CLASS_BASE + 7 - -V4L2_CID_PAN_ABSOLUTE = V4L2_CID_CAMERA_CLASS_BASE + 8 -V4L2_CID_TILT_ABSOLUTE = V4L2_CID_CAMERA_CLASS_BASE + 9 - -V4L2_CID_FOCUS_ABSOLUTE = V4L2_CID_CAMERA_CLASS_BASE + 10 -V4L2_CID_FOCUS_RELATIVE = V4L2_CID_CAMERA_CLASS_BASE + 11 -V4L2_CID_FOCUS_AUTO = V4L2_CID_CAMERA_CLASS_BASE + 12 - -V4L2_CID_ZOOM_ABSOLUTE = V4L2_CID_CAMERA_CLASS_BASE + 13 -V4L2_CID_ZOOM_RELATIVE = V4L2_CID_CAMERA_CLASS_BASE + 14 -V4L2_CID_ZOOM_CONTINUOUS = V4L2_CID_CAMERA_CLASS_BASE + 15 - -V4L2_CID_PRIVACY = V4L2_CID_CAMERA_CLASS_BASE + 16 - -V4L2_CID_FM_TX_CLASS_BASE = V4L2_CTRL_CLASS_FM_TX | 0x900 -V4L2_CID_FM_TX_CLASS = V4L2_CTRL_CLASS_FM_TX | 1 - -V4L2_CID_RDS_TX_DEVIATION = V4L2_CID_FM_TX_CLASS_BASE + 1 -V4L2_CID_RDS_TX_PI = V4L2_CID_FM_TX_CLASS_BASE + 2 -V4L2_CID_RDS_TX_PTY = V4L2_CID_FM_TX_CLASS_BASE + 3 -V4L2_CID_RDS_TX_PS_NAME = V4L2_CID_FM_TX_CLASS_BASE + 5 -V4L2_CID_RDS_TX_RADIO_TEXT = V4L2_CID_FM_TX_CLASS_BASE + 6 - -V4L2_CID_AUDIO_LIMITER_ENABLED = V4L2_CID_FM_TX_CLASS_BASE + 64 -V4L2_CID_AUDIO_LIMITER_RELEASE_TIME = V4L2_CID_FM_TX_CLASS_BASE + 65 -V4L2_CID_AUDIO_LIMITER_DEVIATION = V4L2_CID_FM_TX_CLASS_BASE + 66 - -V4L2_CID_AUDIO_COMPRESSION_ENABLED = V4L2_CID_FM_TX_CLASS_BASE + 80 -V4L2_CID_AUDIO_COMPRESSION_GAIN = V4L2_CID_FM_TX_CLASS_BASE + 81 -V4L2_CID_AUDIO_COMPRESSION_THRESHOLD = V4L2_CID_FM_TX_CLASS_BASE + 82 -V4L2_CID_AUDIO_COMPRESSION_ATTACK_TIME = V4L2_CID_FM_TX_CLASS_BASE + 83 -V4L2_CID_AUDIO_COMPRESSION_RELEASE_TIME = V4L2_CID_FM_TX_CLASS_BASE + 84 - -V4L2_CID_PILOT_TONE_ENABLED = V4L2_CID_FM_TX_CLASS_BASE + 96 -V4L2_CID_PILOT_TONE_DEVIATION = V4L2_CID_FM_TX_CLASS_BASE + 97 -V4L2_CID_PILOT_TONE_FREQUENCY = V4L2_CID_FM_TX_CLASS_BASE + 98 - -V4L2_CID_TUNE_PREEMPHASIS = V4L2_CID_FM_TX_CLASS_BASE + 112 - -v4l2_preemphasis = enum -( - V4L2_PREEMPHASIS_DISABLED, - V4L2_PREEMPHASIS_50_uS, - V4L2_PREEMPHASIS_75_uS, -) = range(3) - -V4L2_CID_TUNE_POWER_LEVEL = V4L2_CID_FM_TX_CLASS_BASE + 113 -V4L2_CID_TUNE_ANTENNA_CAPACITOR = V4L2_CID_FM_TX_CLASS_BASE + 114 - - -# -# Tuning -# - -class v4l2_tuner(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('type', v4l2_tuner_type), - ('capability', ctypes.c_uint32), - ('rangelow', ctypes.c_uint32), - ('rangehigh', ctypes.c_uint32), - ('rxsubchans', ctypes.c_uint32), - ('audmode', ctypes.c_uint32), - ('signal', ctypes.c_int32), - ('afc', ctypes.c_int32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -class v4l2_modulator(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('capability', ctypes.c_uint32), - ('rangelow', ctypes.c_uint32), - ('rangehigh', ctypes.c_uint32), - ('txsubchans', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ] - - -V4L2_TUNER_CAP_LOW = 0x0001 -V4L2_TUNER_CAP_NORM = 0x0002 -V4L2_TUNER_CAP_STEREO = 0x0010 -V4L2_TUNER_CAP_LANG2 = 0x0020 -V4L2_TUNER_CAP_SAP = 0x0020 -V4L2_TUNER_CAP_LANG1 = 0x0040 -V4L2_TUNER_CAP_RDS = 0x0080 - -V4L2_TUNER_SUB_MONO = 0x0001 -V4L2_TUNER_SUB_STEREO = 0x0002 -V4L2_TUNER_SUB_LANG2 = 0x0004 -V4L2_TUNER_SUB_SAP = 0x0004 -V4L2_TUNER_SUB_LANG1 = 0x0008 -V4L2_TUNER_SUB_RDS = 0x0010 - -V4L2_TUNER_MODE_MONO = 0x0000 -V4L2_TUNER_MODE_STEREO = 0x0001 -V4L2_TUNER_MODE_LANG2 = 0x0002 -V4L2_TUNER_MODE_SAP = 0x0002 -V4L2_TUNER_MODE_LANG1 = 0x0003 -V4L2_TUNER_MODE_LANG1_LANG2 = 0x0004 - - -class v4l2_frequency(ctypes.Structure): - _fields_ = [ - ('tuner', ctypes.c_uint32), - ('type', v4l2_tuner_type), - ('frequency', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 8), - ] - - -class v4l2_hw_freq_seek(ctypes.Structure): - _fields_ = [ - ('tuner', ctypes.c_uint32), - ('type', v4l2_tuner_type), - ('seek_upward', ctypes.c_uint32), - ('wrap_around', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 8), - ] - - -# -# RDS -# - -class v4l2_rds_data(ctypes.Structure): - _fields_ = [ - ('lsb', ctypes.c_char), - ('msb', ctypes.c_char), - ('block', ctypes.c_char), - ] - - _pack_ = True - - -V4L2_RDS_BLOCK_MSK = 0x7 -V4L2_RDS_BLOCK_A = 0 -V4L2_RDS_BLOCK_B = 1 -V4L2_RDS_BLOCK_C = 2 -V4L2_RDS_BLOCK_D = 3 -V4L2_RDS_BLOCK_C_ALT = 4 -V4L2_RDS_BLOCK_INVALID = 7 - -V4L2_RDS_BLOCK_CORRECTED = 0x40 -V4L2_RDS_BLOCK_ERROR = 0x80 - - -# -# Audio -# - -class v4l2_audio(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('capability', ctypes.c_uint32), - ('mode', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -V4L2_AUDCAP_STEREO = 0x00001 -V4L2_AUDCAP_AVL = 0x00002 - -V4L2_AUDMODE_AVL = 0x00001 - - -class v4l2_audioout(ctypes.Structure): - _fields_ = [ - ('index', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ('capability', ctypes.c_uint32), - ('mode', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -# -# Mpeg services (experimental) -# - -V4L2_ENC_IDX_FRAME_I = 0 -V4L2_ENC_IDX_FRAME_P = 1 -V4L2_ENC_IDX_FRAME_B = 2 -V4L2_ENC_IDX_FRAME_MASK = 0xf - - -class v4l2_enc_idx_entry(ctypes.Structure): - _fields_ = [ - ('offset', ctypes.c_uint64), - ('pts', ctypes.c_uint64), - ('length', ctypes.c_uint32), - ('flags', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -V4L2_ENC_IDX_ENTRIES = 64 - - -class v4l2_enc_idx(ctypes.Structure): - _fields_ = [ - ('entries', ctypes.c_uint32), - ('entries_cap', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 4), - ('entry', v4l2_enc_idx_entry * V4L2_ENC_IDX_ENTRIES), - ] - - -V4L2_ENC_CMD_START = 0 -V4L2_ENC_CMD_STOP = 1 -V4L2_ENC_CMD_PAUSE = 2 -V4L2_ENC_CMD_RESUME = 3 - -V4L2_ENC_CMD_STOP_AT_GOP_END = 1 << 0 - - -class v4l2_encoder_cmd(ctypes.Structure): - class _u(ctypes.Union): - class _s(ctypes.Structure): - _fields_ = [ - ('data', ctypes.c_uint32 * 8), - ] - - _fields_ = [ - ('raw', _s), - ] - - _fields_ = [ - ('cmd', ctypes.c_uint32), - ('flags', ctypes.c_uint32), - ('_u', _u), - ] - - _anonymous_ = ('_u',) - - -# -# Data services (VBI) -# - -class v4l2_vbi_format(ctypes.Structure): - _fields_ = [ - ('sampling_rate', ctypes.c_uint32), - ('offset', ctypes.c_uint32), - ('samples_per_line', ctypes.c_uint32), - ('sample_format', ctypes.c_uint32), - ('start', ctypes.c_int32 * 2), - ('count', ctypes.c_uint32 * 2), - ('flags', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -V4L2_VBI_UNSYNC = 1 << 0 -V4L2_VBI_INTERLACED = 1 << 1 - - -class v4l2_sliced_vbi_format(ctypes.Structure): - _fields_ = [ - ('service_set', ctypes.c_uint16), - ('service_lines', ctypes.c_uint16 * 2 * 24), - ('io_size', ctypes.c_uint32), - ('reserved', ctypes.c_uint32 * 2), - ] - - -V4L2_SLICED_TELETEXT_B = 0x0001 -V4L2_SLICED_VPS = 0x0400 -V4L2_SLICED_CAPTION_525 = 0x1000 -V4L2_SLICED_WSS_625 = 0x4000 -V4L2_SLICED_VBI_525 = V4L2_SLICED_CAPTION_525 -V4L2_SLICED_VBI_625 = ( - V4L2_SLICED_TELETEXT_B | V4L2_SLICED_VPS | V4L2_SLICED_WSS_625) - - -class v4l2_sliced_vbi_cap(ctypes.Structure): - _fields_ = [ - ('service_set', ctypes.c_uint16), - ('service_lines', ctypes.c_uint16 * 2 * 24), - ('type', v4l2_buf_type), - ('reserved', ctypes.c_uint32 * 3), - ] - - -class v4l2_sliced_vbi_data(ctypes.Structure): - _fields_ = [ - ('id', ctypes.c_uint32), - ('field', ctypes.c_uint32), - ('line', ctypes.c_uint32), - ('reserved', ctypes.c_uint32), - ('data', ctypes.c_char * 48), - ] - - -# -# Sliced VBI data inserted into MPEG Streams -# - - -V4L2_MPEG_VBI_IVTV_TELETEXT_B = 1 -V4L2_MPEG_VBI_IVTV_CAPTION_525 = 4 -V4L2_MPEG_VBI_IVTV_WSS_625 = 5 -V4L2_MPEG_VBI_IVTV_VPS = 7 - - -class v4l2_mpeg_vbi_itv0_line(ctypes.Structure): - _fields_ = [ - ('id', ctypes.c_char), - ('data', ctypes.c_char * 42), - ] - - _pack_ = True - - -class v4l2_mpeg_vbi_itv0(ctypes.Structure): - _fields_ = [ - ('linemask', ctypes.c_uint32 * 2), # how to define __le32 in ctypes? - ('line', v4l2_mpeg_vbi_itv0_line * 35), - ] - - _pack_ = True - - -class v4l2_mpeg_vbi_ITV0(ctypes.Structure): - _fields_ = [ - ('line', v4l2_mpeg_vbi_itv0_line * 36), - ] - - _pack_ = True - - -V4L2_MPEG_VBI_IVTV_MAGIC0 = "itv0" -V4L2_MPEG_VBI_IVTV_MAGIC1 = "ITV0" - - -class v4l2_mpeg_vbi_fmt_ivtv(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('itv0', v4l2_mpeg_vbi_itv0), - ('ITV0', v4l2_mpeg_vbi_ITV0), - ] - - _fields_ = [ - ('magic', ctypes.c_char * 4), - ('_u', _u) - ] - - _anonymous_ = ('_u',) - _pack_ = True - - -# -# Aggregate structures -# - -class v4l2_format(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('pix', v4l2_pix_format), - ('win', v4l2_window), - ('vbi', v4l2_vbi_format), - ('sliced', v4l2_sliced_vbi_format), - ('raw_data', ctypes.c_char * 200), - ] - - _fields_ = [ - ('type', v4l2_buf_type), - ('fmt', _u), - ] - - -class v4l2_streamparm(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('capture', v4l2_captureparm), - ('output', v4l2_outputparm), - ('raw_data', ctypes.c_char * 200), - ] - - _fields_ = [ - ('type', v4l2_buf_type), - ('parm', _u) - ] - - -# -# Advanced debugging -# - -V4L2_CHIP_MATCH_HOST = 0 -V4L2_CHIP_MATCH_I2C_DRIVER = 1 -V4L2_CHIP_MATCH_I2C_ADDR = 2 -V4L2_CHIP_MATCH_AC97 = 3 - - -class v4l2_dbg_match(ctypes.Structure): - class _u(ctypes.Union): - _fields_ = [ - ('addr', ctypes.c_uint32), - ('name', ctypes.c_char * 32), - ] - - _fields_ = [ - ('type', ctypes.c_uint32), - ('_u', _u), - ] - - _anonymous_ = ('_u',) - _pack_ = True - - -class v4l2_dbg_register(ctypes.Structure): - _fields_ = [ - ('match', v4l2_dbg_match), - ('size', ctypes.c_uint32), - ('reg', ctypes.c_uint64), - ('val', ctypes.c_uint64), - ] - - _pack_ = True - - -class v4l2_dbg_chip_ident(ctypes.Structure): - _fields_ = [ - ('match', v4l2_dbg_match), - ('ident', ctypes.c_uint32), - ('revision', ctypes.c_uint32), - ] - - _pack_ = True - - -# -# ioctl codes for video devices -# - -VIDIOC_QUERYCAP = _IOR('V', 0, v4l2_capability) -VIDIOC_RESERVED = _IO('V', 1) -VIDIOC_ENUM_FMT = _IOWR('V', 2, v4l2_fmtdesc) -VIDIOC_G_FMT = _IOWR('V', 4, v4l2_format) -VIDIOC_S_FMT = _IOWR('V', 5, v4l2_format) -VIDIOC_REQBUFS = _IOWR('V', 8, v4l2_requestbuffers) -VIDIOC_QUERYBUF = _IOWR('V', 9, v4l2_buffer) -VIDIOC_G_FBUF = _IOR('V', 10, v4l2_framebuffer) -VIDIOC_S_FBUF = _IOW('V', 11, v4l2_framebuffer) -VIDIOC_OVERLAY = _IOW('V', 14, ctypes.c_int) -VIDIOC_QBUF = _IOWR('V', 15, v4l2_buffer) -VIDIOC_DQBUF = _IOWR('V', 17, v4l2_buffer) -VIDIOC_STREAMON = _IOW('V', 18, ctypes.c_int) -VIDIOC_STREAMOFF = _IOW('V', 19, ctypes.c_int) -VIDIOC_G_PARM = _IOWR('V', 21, v4l2_streamparm) -VIDIOC_S_PARM = _IOWR('V', 22, v4l2_streamparm) -VIDIOC_G_STD = _IOR('V', 23, v4l2_std_id) -VIDIOC_S_STD = _IOW('V', 24, v4l2_std_id) -VIDIOC_ENUMSTD = _IOWR('V', 25, v4l2_standard) -VIDIOC_ENUMINPUT = _IOWR('V', 26, v4l2_input) -VIDIOC_G_CTRL = _IOWR('V', 27, v4l2_control) -VIDIOC_S_CTRL = _IOWR('V', 28, v4l2_control) -VIDIOC_G_TUNER = _IOWR('V', 29, v4l2_tuner) -VIDIOC_S_TUNER = _IOW('V', 30, v4l2_tuner) -VIDIOC_G_AUDIO = _IOR('V', 33, v4l2_audio) -VIDIOC_S_AUDIO = _IOW('V', 34, v4l2_audio) -VIDIOC_QUERYCTRL = _IOWR('V', 36, v4l2_queryctrl) -VIDIOC_QUERYMENU = _IOWR('V', 37, v4l2_querymenu) -VIDIOC_G_INPUT = _IOR('V', 38, ctypes.c_int) -VIDIOC_S_INPUT = _IOWR('V', 39, ctypes.c_int) -VIDIOC_G_OUTPUT = _IOR('V', 46, ctypes.c_int) -VIDIOC_S_OUTPUT = _IOWR('V', 47, ctypes.c_int) -VIDIOC_ENUMOUTPUT = _IOWR('V', 48, v4l2_output) -VIDIOC_G_AUDOUT = _IOR('V', 49, v4l2_audioout) -VIDIOC_S_AUDOUT = _IOW('V', 50, v4l2_audioout) -VIDIOC_G_MODULATOR = _IOWR('V', 54, v4l2_modulator) -VIDIOC_S_MODULATOR = _IOW('V', 55, v4l2_modulator) -VIDIOC_G_FREQUENCY = _IOWR('V', 56, v4l2_frequency) -VIDIOC_S_FREQUENCY = _IOW('V', 57, v4l2_frequency) -VIDIOC_CROPCAP = _IOWR('V', 58, v4l2_cropcap) -VIDIOC_G_CROP = _IOWR('V', 59, v4l2_crop) -VIDIOC_S_CROP = _IOW('V', 60, v4l2_crop) -VIDIOC_G_JPEGCOMP = _IOR('V', 61, v4l2_jpegcompression) -VIDIOC_S_JPEGCOMP = _IOW('V', 62, v4l2_jpegcompression) -VIDIOC_QUERYSTD = _IOR('V', 63, v4l2_std_id) -VIDIOC_TRY_FMT = _IOWR('V', 64, v4l2_format) -VIDIOC_ENUMAUDIO = _IOWR('V', 65, v4l2_audio) -VIDIOC_ENUMAUDOUT = _IOWR('V', 66, v4l2_audioout) -VIDIOC_G_PRIORITY = _IOR('V', 67, v4l2_priority) -VIDIOC_S_PRIORITY = _IOW('V', 68, v4l2_priority) -VIDIOC_G_SLICED_VBI_CAP = _IOWR('V', 69, v4l2_sliced_vbi_cap) -VIDIOC_LOG_STATUS = _IO('V', 70) -VIDIOC_G_EXT_CTRLS = _IOWR('V', 71, v4l2_ext_controls) -VIDIOC_S_EXT_CTRLS = _IOWR('V', 72, v4l2_ext_controls) -VIDIOC_TRY_EXT_CTRLS = _IOWR('V', 73, v4l2_ext_controls) - -VIDIOC_ENUM_FRAMESIZES = _IOWR('V', 74, v4l2_frmsizeenum) -VIDIOC_ENUM_FRAMEINTERVALS = _IOWR('V', 75, v4l2_frmivalenum) -VIDIOC_G_ENC_INDEX = _IOR('V', 76, v4l2_enc_idx) -VIDIOC_ENCODER_CMD = _IOWR('V', 77, v4l2_encoder_cmd) -VIDIOC_TRY_ENCODER_CMD = _IOWR('V', 78, v4l2_encoder_cmd) - -VIDIOC_DBG_S_REGISTER = _IOW('V', 79, v4l2_dbg_register) -VIDIOC_DBG_G_REGISTER = _IOWR('V', 80, v4l2_dbg_register) - -VIDIOC_DBG_G_CHIP_IDENT = _IOWR('V', 81, v4l2_dbg_chip_ident) - -VIDIOC_S_HW_FREQ_SEEK = _IOW('V', 82, v4l2_hw_freq_seek) -VIDIOC_ENUM_DV_PRESETS = _IOWR('V', 83, v4l2_dv_enum_preset) -VIDIOC_S_DV_PRESET = _IOWR('V', 84, v4l2_dv_preset) -VIDIOC_G_DV_PRESET = _IOWR('V', 85, v4l2_dv_preset) -VIDIOC_QUERY_DV_PRESET = _IOR('V', 86, v4l2_dv_preset) -VIDIOC_S_DV_TIMINGS = _IOWR('V', 87, v4l2_dv_timings) -VIDIOC_G_DV_TIMINGS = _IOWR('V', 88, v4l2_dv_timings) - -VIDIOC_OVERLAY_OLD = _IOWR('V', 14, ctypes.c_int) -VIDIOC_S_PARM_OLD = _IOW('V', 22, v4l2_streamparm) -VIDIOC_S_CTRL_OLD = _IOW('V', 28, v4l2_control) -VIDIOC_G_AUDIO_OLD = _IOWR('V', 33, v4l2_audio) -VIDIOC_G_AUDOUT_OLD = _IOWR('V', 49, v4l2_audioout) -VIDIOC_CROPCAP_OLD = _IOR('V', 58, v4l2_cropcap) - -BASE_VIDIOC_PRIVATE = 192 diff --git a/plugins/light_sensor/icons/sensoroff.svg b/plugins/light_sensor/icons/sensoroff.svg deleted file mode 100644 index 0a16670..0000000 --- a/plugins/light_sensor/icons/sensoroff.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/light_sensor/icons/sensoron.svg b/plugins/light_sensor/icons/sensoron.svg deleted file mode 100644 index d756860..0000000 --- a/plugins/light_sensor/icons/sensoron.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/plugins/light_sensor/light_sensor.py b/plugins/light_sensor/light_sensor.py deleted file mode 100644 index bd5655e..0000000 --- a/plugins/light_sensor/light_sensor.py +++ /dev/null @@ -1,87 +0,0 @@ -#!/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.talogo import primitive_dictionary -from TurtleArt.tautils import debug_output - -import logging -_logger = logging.getLogger('turtleart-activity light-sensor plugin') - - -LIGHT_SENSOR_DEVICE = '/sys/devices/platform/olpc-ols.0/level' - - -class Light_sensor(Plugin): - - def __init__(self, parent): - self._parent = parent - if os.path.exists(LIGHT_SENSOR_DEVICE): - self._status = True - else: - self._status = False - self.running_sugar = self._parent.running_sugar - - def setup(self): - # set up light-sensor specific blocks - palette = make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks'), - position=6) - - primitive_dictionary['lightsensor'] = self.prim_lightsensor - if self._status: - palette.add_block('lightsensor', - style='box-style', - label=_('brightness'), - help_string=\ - _('light level detected by light sensor'), - prim_name='lightsensor') - else: - palette.add_block('lightsensor', - style='box-style', - label=_('brightness'), - help_string=\ - _('light level detected by light sensor'), - hidden=True, - prim_name='lightsensor') - - self._parent.lc.def_prim( - 'lightsensor', 0, - lambda self: primitive_dictionary['lightsensor']()) - - def _status_report(self): - debug_output('Reporting light-sensor status: %s' % (str(self._status))) - return self._status - - # Block primitives used in talogo - - def prim_lightsensor(self): - ''' push accelerometer xyz to stack ''' - if not self._status: - return -1 - else: - fh = open(LIGHT_SENSOR_DEVICE) - string = fh.read() - fh.close() - return float(string) diff --git a/plugins/rfid/device.py b/plugins/rfid/device.py deleted file mode 100644 index 04a82b2..0000000 --- a/plugins/rfid/device.py +++ /dev/null @@ -1,61 +0,0 @@ -import gobject - -class RFIDDevice(gobject.GObject): - """ - Ancestor class for every supported device. - The main class for the device driver must be called "RFIDReader". - """ - # signal "tag-read" has to be emitted when a tag has been read. - # The handler must receive the ISO-11784 hex value of the tag. - # signal "disconnected" has to be emitted when the device is - # unplugged or an error has been detected. - __gsignals__ = { - 'tag-read': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_STRING,)), - 'disconnected': (gobject.SIGNAL_RUN_LAST, gobject.TYPE_NONE, - (gobject.TYPE_STRING,)) - } - def __init__(self): - """ - Initializer. Subclasses must call this method. - """ - self.__gobject_init__() - - def get_present(self): - """ - This method must detect if the device is present, returning True if so, - or False otherwise. - """ - raise NotImplementedError - - def get_version(self): - """ - Returns a descriptive text of the device. - """ - raise NotImplementedError - - def do_connect(self): - """ - Connects to the device. - Must return True if successfull, False otherwise. - """ - raise NotImplementedError - - def do_disconnect(self): - """ - Disconnects from the device. - """ - raise NotImplementedError - - def read_tag(self): - """ - Returns the 64 bit data in hex format of the last read tag. - """ - raise NotImplementedError - - def write_tag(self, hex_val): - """ - Could be implemented if the device is capable of writing tags. - Receives the hex value (according to ISO 11784) to be written. - Returns True if successfull or False if something went wrong. - """ diff --git a/plugins/rfid/icons/sensoroff.svg b/plugins/rfid/icons/sensoroff.svg deleted file mode 100644 index 0a16670..0000000 --- a/plugins/rfid/icons/sensoroff.svg +++ /dev/null @@ -1,79 +0,0 @@ - - - -image/svg+xml - - - - - - - - - - - - - - \ No newline at end of file diff --git a/plugins/rfid/icons/sensoron.svg b/plugins/rfid/icons/sensoron.svg deleted file mode 100644 index d756860..0000000 --- a/plugins/rfid/icons/sensoron.svg +++ /dev/null @@ -1,63 +0,0 @@ - - - -image/svg+xml \ No newline at end of file diff --git a/plugins/rfid/rfid.py b/plugins/rfid/rfid.py deleted file mode 100644 index de96a1f..0000000 --- a/plugins/rfid/rfid.py +++ /dev/null @@ -1,151 +0,0 @@ -#!/usr/bin/env python -#Copyright (C) 2010,11 Emiliano Pastorino -#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 dbus -from dbus.mainloop.glib import DBusGMainLoop -from gettext import gettext as _ - -from plugins.rfid.rfidutils import strhex2bin, strbin2dec, find_device -from plugins.plugin import Plugin - -from TurtleArt.tapalette import make_palette -from TurtleArt.talogo import primitive_dictionary -from TurtleArt.tautils import debug_output - -import logging -_logger = logging.getLogger('turtleart-activity RFID plugin') - -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]' - - -class Rfid(Plugin): - - def __init__(self, parent): - self._parent = parent - self._status = False - - """ - 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) - - self._status = True - - def setup(self): - # set up RFID-specific blocks - primitive_dictionary['rfid'] = self.prim_read_rfid - palette = make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks'), - position=6) - - if self._status: - palette.add_block('rfid', - style='box-style', - label=_('RFID'), - help_string=_('read value from RFID device'), - value_block=True, - prim_name='rfid') - else: - palette.add_block('rfid', - hidden=True, - style='box-style', - label=_('RFID'), - help_string=_('read value from RFID device'), - value_block=True, - prim_name='rfid') - - self._parent.lc.def_prim( - 'rfid', 0, lambda self: primitive_dictionary['rfid']()) - - def _status_report(self): - debug_output('Reporting RFID status: %s' % (str(self._status))) - return self._status - - 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 - self.tw.lc.update_label_value('rfid', self.rfid_idn) - - # Block primitives used in talogo - - def prim_read_rfid(self): - if self._status: - return self.rfid_idn - else: - return '0' diff --git a/plugins/rfid/rfidrweusb.py b/plugins/rfid/rfidrweusb.py deleted file mode 100644 index bd12631..0000000 --- a/plugins/rfid/rfidrweusb.py +++ /dev/null @@ -1,200 +0,0 @@ -from device import RFIDDevice -from serial import Serial -import dbus -from dbus.mainloop.glib import DBusGMainLoop -import gobject -from time import sleep -import utils - -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]' - -VERSIONS = ['301'] - -class RFIDReader(RFIDDevice): - """ - RFIDRW-E-W interface. - """ - - def __init__(self): - - RFIDDevice.__init__(self) - self.last_tag = "" - self.tags = [] - self.ser = Serial() - self.device = '' - self.device_path = '' - self._connected = False - - loop = DBusGMainLoop() - self.bus = dbus.SystemBus(mainloop=loop) - hmgr_iface = dbus.Interface(self.bus.get_object(HAL_SERVICE, - HAL_MGR_PATH), HAL_MGR_IFACE) - - hmgr_iface.connect_to_signal('DeviceRemoved', self._device_removed_cb) - - def get_present(self): - """ - Checks if RFID-RW-USB device is present. - Returns True if so, False otherwise. - """ - hmgr_if = dbus.Interface(self.bus.get_object(HAL_SERVICE, HAL_MGR_PATH), - HAL_MGR_IFACE) - serialusb_devices = set(hmgr_if.FindDeviceStringMatch('serial.type', - 'usb')) & set(hmgr_if.FindDeviceStringMatch( - 'info.subsystem', 'tty')) - for i in serialusb_devices: - serialusb_if = dbus.Interface(self.bus.get_object(HAL_SERVICE, i), - HAL_DEV_IFACE) - if serialusb_if.PropertyExists('info.parent'): - parent_udi = str(serialusb_if.GetProperty('info.parent')) - parent = dbus.Interface(self.bus.get_object(HAL_SERVICE, - parent_udi), HAL_DEV_IFACE) - if parent.PropertyExists('info.linux.driver') and \ - str(parent.GetProperty('info.linux.driver')) == 'ftdi_sio': - device = str(serialusb_if.GetProperty('linux.device_file')) - ser = Serial(device, 9600, timeout=0.1) - ser.read(100) - ser.write('v') - ser.write('e') - ser.write('r') - ser.write('\x0D') - resp = ser.read(4) - if resp[0:-1] in VERSIONS: - self.device = device - self.device_path = i - return True - return False - - def do_connect(self): - """ - Connects to the device. - Returns True if successfull, False otherwise. - """ - retval = False - if self.get_present(): - try: - self.ser = Serial(self.device, 9600, timeout=0.1) - self._connected = True - if self._select_animal_tag: - #gobject.idle_add(self._loop) - gobject.timeout_add(1000, self._loop) - retval = True - except: - self._connected = False - return retval - - def do_disconnect(self): - """ - Disconnect from the device. - """ - self.ser.close() - self._connected = False - - def read_tag(self): - """ - Returns the last read value. - """ - return self.last_tag - - def _select_animal_tag(self): - """ - Sends the "Select Tag 2" (animal tag) command to the device. - """ - self.ser.read(100) - self.ser.write('s') - self.ser.write('t') - self.ser.write('2') - self.ser.write('\x0d') - resp = self.ser.read(3)[0:-1] - if resp == 'OK': - return True - return False - - def get_version(self): - """ - Sends the version command to the device and returns - a string with the device version. - """ - #self.ser.flushInput() - ver = "???" - self.ser.read(100) - self.ser.write('v') - self.ser.write('e') - self.ser.write('r') - self.ser.write('\x0d') - resp = self.ser.read(4)[0:-1] - if resp in VERSIONS: - return "RFIDRW-E-USB " + resp - return ver - - def _device_removed_cb(self, path): - """ - Called when a device is removed. - Checks if the removed device is itself and emits the "disconnected" - signal if so. - """ - if path == self.device_path: - self.device_path = '' - self.ser.close() - self._connected = False - self.tags = [] - self.emit("disconnected","RFID-RW-USB") - - def _loop(self): - """ - Threaded loop for reading data from the device. - """ - if not self._connected: - return False - - self.ser.read(100) - self.ser.write('r') - self.ser.write('a') - self.ser.write('t') - self.ser.write('\x0d') - resp = self.ser.read(33)[0:-1].split('_') - if resp.__len__() is not 6 or resp in self.tags: - return True - - self.tags.append(resp) - anbit_bin = utils.dec2bin(int(resp[2])) - reserved_bin = '00000000000000' - databit_bin = utils.dec2bin(int(resp[3])) - country_bin = utils.dec2bin(int(resp[0])) - while country_bin.__len__() < 10: - country_bin = '0' + country_bin - id_bin = utils.dec2bin(int(resp[1])) - while id_bin.__len__() < 10: - id_bin = '0' + id_bin - - tag_bin = anbit_bin + reserved_bin + databit_bin + country_bin + id_bin - data = utils.bin2hex(tag_bin) - self.emit("tag-read", data) - self.last_tag = data - #sleep(1) - return True - -# Testing -#if __name__ == '__main__': -# def handler(device, idhex): -# """ -# Handler for "tag-read" signal. -# Prints the tag id. -# """ -# print "ID: ", idhex -# -# dev = RFIDReader() -# if dev.get_present(): -# print "SIPI!" -# dev.do_connect() -# dev.connect('tag-read', handler) -# else: -# print "Not connected" -# -# mloop = gobject.MainLoop() -# mloop.run() diff --git a/plugins/rfid/rfidutils.py b/plugins/rfid/rfidutils.py deleted file mode 100644 index 4e02619..0000000 --- a/plugins/rfid/rfidutils.py +++ /dev/null @@ -1,123 +0,0 @@ -# utils.py - Helper functions for tis2000.py -# Copyright (C) 2010 Emiliano Pastorino -# -# 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 3 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, see . - -import os -import logging - -def find_device(): - """ - Search for devices. - Return a device instance or None. - """ - device = None - for i in os.listdir(os.path.join('.', 'plugins/rfid')): - if not os.path.isdir(os.path.join('.', 'plugins/rfid', i)): - try: - _tempmod = __import__('rfid.%s'%i.split('.')[0], globals(), - locals(), ['RFIDReader'], -1) - devtemp = _tempmod.RFIDReader() - if devtemp.get_present() == True: - device = devtemp - except Exception, e: - # logging.error("FIND_DEVICE: %s: %s"%(i, e)) - pass - if device is None: - logging.debug("No RFID device found") - return device - - -def strhex2bin(strhex): - """ - Convert a string representing an hex value into a - string representing the same value in binary format. - """ - dic = { '0':"0000", - '1':"0001", - '2':"0010", - '3':"0011", - '4':"0100", - '5':"0101", - '6':"0110", - '7':"0111", - '8':"1000", - '9':"1001", - 'A':"1010", - 'B':"1011", - 'C':"1100", - 'D':"1101", - 'E':"1110", - 'F':"1111" - } - binstr = "" - for i in strhex: - binstr = binstr + dic[i.upper()] - return binstr - -def strbin2dec(strbin): - """ - Convert a string representing a binary value into a - string representing the same value in decimal format. - """ - strdec = "0" - for i in range(1, strbin.__len__()+1): - strdec = str(int(strdec)+int(strbin[-i])*int(pow(2, i-1))) - return strdec - -def dec2bin(ndec): - """ - Convert a decimal number into a string representing - the same value in binary format. - """ - if ndec < 1: - return "0" - binary = [] - while ndec != 0: - binary.append(ndec%2) - ndec = ndec/2 - strbin = "" - binary.reverse() - for i in binary: - strbin = strbin+str(i) - return strbin - -def bin2hex(strbin): - """ - Convert a string representing a binary number into a string - representing the same value in hexadecimal format. - """ - dic = { "0000":"0", - "0001":"1", - "0010":"2", - "0011":"3", - "0100":"4", - "0101":"5", - "0110":"6", - "0111":"7", - "1000":"8", - "1001":"9", - "1010":"A", - "1011":"B", - "1100":"C", - "1101":"D", - "1110":"E", - "1111":"F" - } - while strbin.__len__()%4 != 0: - strbin = '0' + strbin - strh = "" - for i in range(0, strbin.__len__()/4): - strh = strh + dic[str(strbin[i*4:i*4+4])] - return strh diff --git a/plugins/rfid/serial/__init__.py b/plugins/rfid/serial/__init__.py deleted file mode 100644 index 681ad5c..0000000 --- a/plugins/rfid/serial/__init__.py +++ /dev/null @@ -1,25 +0,0 @@ -#!/usr/bin/env python -#portable serial port access with python -#this is a wrapper module for different platform implementations -# -# (C)2001-2002 Chris Liechti -# this is distributed under a free software license, see license.txt - -VERSION = '2.4' - -import sys - -if sys.platform == 'cli': - from serialcli import * -else: - import os - #chose an implementation, depending on os - if os.name == 'nt': #sys.platform == 'win32': - from serialwin32 import * - elif os.name == 'posix': - from serialposix import * - elif os.name == 'java': - from serialjava import * - else: - raise Exception("Sorry: no implementation for your platform ('%s') available" % os.name) - diff --git a/plugins/rfid/serial/serialposix.py b/plugins/rfid/serial/serialposix.py deleted file mode 100644 index 174e2f7..0000000 --- a/plugins/rfid/serial/serialposix.py +++ /dev/null @@ -1,492 +0,0 @@ -#!/usr/bin/env python -# Python Serial Port Extension for Win32, Linux, BSD, Jython -# module for serial IO for POSIX compatible systems, like Linux -# see __init__.py -# -# (C) 2001-2008 Chris Liechti -# this is distributed under a free software license, see license.txt -# -# parts based on code from Grant B. Edwards : -# ftp://ftp.visi.com/users/grante/python/PosixSerial.py -# references: http://www.easysw.com/~mike/serial/serial.html - -import sys, os, fcntl, termios, struct, select, errno -from serialutil import * - -#Do check the Python version as some constants have moved. -if (sys.hexversion < 0x020100f0): - import TERMIOS -else: - TERMIOS = termios - -if (sys.hexversion < 0x020200f0): - import FCNTL -else: - FCNTL = fcntl - -#try to detect the os so that a device can be selected... -plat = sys.platform.lower() - -if plat[:5] == 'linux': #Linux (confirmed) - def device(port): - return '/dev/ttyS%d' % port - -elif plat == 'cygwin': #cywin/win32 (confirmed) - def device(port): - return '/dev/com%d' % (port + 1) - -elif plat == 'openbsd3': #BSD (confirmed) - def device(port): - return '/dev/ttyp%d' % port - -elif plat[:3] == 'bsd' or \ - plat[:7] == 'freebsd' or \ - plat[:7] == 'openbsd' or \ - plat[:6] == 'darwin': #BSD (confirmed for freebsd4: cuaa%d) - def device(port): - return '/dev/cuad%d' % port - -elif plat[:6] == 'netbsd': #NetBSD 1.6 testing by Erk - def device(port): - return '/dev/dty%02d' % port - -elif plat[:4] == 'irix': #IRIX (partialy tested) - def device(port): - return '/dev/ttyf%d' % (port+1) #XXX different device names depending on flow control - -elif plat[:2] == 'hp': #HP-UX (not tested) - def device(port): - return '/dev/tty%dp0' % (port+1) - -elif plat[:5] == 'sunos': #Solaris/SunOS (confirmed) - def device(port): - return '/dev/tty%c' % (ord('a')+port) - -elif plat[:3] == 'aix': #aix - def device(port): - return '/dev/tty%d' % (port) - -else: - #platform detection has failed... - print """don't know how to number ttys on this system. -! Use an explicit path (eg /dev/ttyS1) or send this information to -! the author of this module: - -sys.platform = %r -os.name = %r -serialposix.py version = %s - -also add the device name of the serial port and where the -counting starts for the first serial port. -e.g. 'first serial port: /dev/ttyS0' -and with a bit luck you can get this module running... -""" % (sys.platform, os.name, VERSION) - #no exception, just continue with a brave attempt to build a device name - #even if the device name is not correct for the platform it has chances - #to work using a string with the real device name as port paramter. - def device(portum): - return '/dev/ttyS%d' % portnum - #~ raise Exception, "this module does not run on this platform, sorry." - -#whats up with "aix", "beos", .... -#they should work, just need to know the device names. - - -#load some constants for later use. -#try to use values from TERMIOS, use defaults from linux otherwise -TIOCMGET = hasattr(TERMIOS, 'TIOCMGET') and TERMIOS.TIOCMGET or 0x5415 -TIOCMBIS = hasattr(TERMIOS, 'TIOCMBIS') and TERMIOS.TIOCMBIS or 0x5416 -TIOCMBIC = hasattr(TERMIOS, 'TIOCMBIC') and TERMIOS.TIOCMBIC or 0x5417 -TIOCMSET = hasattr(TERMIOS, 'TIOCMSET') and TERMIOS.TIOCMSET or 0x5418 - -#TIOCM_LE = hasattr(TERMIOS, 'TIOCM_LE') and TERMIOS.TIOCM_LE or 0x001 -TIOCM_DTR = hasattr(TERMIOS, 'TIOCM_DTR') and TERMIOS.TIOCM_DTR or 0x002 -TIOCM_RTS = hasattr(TERMIOS, 'TIOCM_RTS') and TERMIOS.TIOCM_RTS or 0x004 -#TIOCM_ST = hasattr(TERMIOS, 'TIOCM_ST') and TERMIOS.TIOCM_ST or 0x008 -#TIOCM_SR = hasattr(TERMIOS, 'TIOCM_SR') and TERMIOS.TIOCM_SR or 0x010 - -TIOCM_CTS = hasattr(TERMIOS, 'TIOCM_CTS') and TERMIOS.TIOCM_CTS or 0x020 -TIOCM_CAR = hasattr(TERMIOS, 'TIOCM_CAR') and TERMIOS.TIOCM_CAR or 0x040 -TIOCM_RNG = hasattr(TERMIOS, 'TIOCM_RNG') and TERMIOS.TIOCM_RNG or 0x080 -TIOCM_DSR = hasattr(TERMIOS, 'TIOCM_DSR') and TERMIOS.TIOCM_DSR or 0x100 -TIOCM_CD = hasattr(TERMIOS, 'TIOCM_CD') and TERMIOS.TIOCM_CD or TIOCM_CAR -TIOCM_RI = hasattr(TERMIOS, 'TIOCM_RI') and TERMIOS.TIOCM_RI or TIOCM_RNG -#TIOCM_OUT1 = hasattr(TERMIOS, 'TIOCM_OUT1') and TERMIOS.TIOCM_OUT1 or 0x2000 -#TIOCM_OUT2 = hasattr(TERMIOS, 'TIOCM_OUT2') and TERMIOS.TIOCM_OUT2 or 0x4000 -TIOCINQ = hasattr(TERMIOS, 'FIONREAD') and TERMIOS.FIONREAD or 0x541B - -TIOCM_zero_str = struct.pack('I', 0) -TIOCM_RTS_str = struct.pack('I', TIOCM_RTS) -TIOCM_DTR_str = struct.pack('I', TIOCM_DTR) - -TIOCSBRK = hasattr(TERMIOS, 'TIOCSBRK') and TERMIOS.TIOCSBRK or 0x5427 -TIOCCBRK = hasattr(TERMIOS, 'TIOCCBRK') and TERMIOS.TIOCCBRK or 0x5428 - -ASYNC_SPD_MASK = 0x1030 -ASYNC_SPD_CUST = 0x0030 - -baudrate_constants = { - 0: 0000000, # hang up - 50: 0000001, - 75: 0000002, - 110: 0000003, - 134: 0000004, - 150: 0000005, - 200: 0000006, - 300: 0000007, - 600: 0000010, - 1200: 0000011, - 1800: 0000012, - 2400: 0000013, - 4800: 0000014, - 9600: 0000015, - 19200: 0000016, - 38400: 0000017, - 57600: 0010001, - 115200: 0010002, - 230400: 0010003, - 460800: 0010004, - 500000: 0010005, - 576000: 0010006, - 921600: 0010007, - 1000000: 0010010, - 1152000: 0010011, - 1500000: 0010012, - 2000000: 0010013, - 2500000: 0010014, - 3000000: 0010015, - 3500000: 0010016, - 4000000: 0010017 -} - - -class Serial(SerialBase): - """Serial port class POSIX implementation. Serial port configuration is - done with termios and fcntl. Runs on Linux and many other Un*x like - systems.""" - - def open(self): - """Open port with current settings. This may throw a SerialException - if the port cannot be opened.""" - if self._port is None: - raise SerialException("Port must be configured before it can be used.") - self.fd = None - #open - try: - self.fd = os.open(self.portstr, os.O_RDWR|os.O_NOCTTY|os.O_NONBLOCK) - except Exception, msg: - self.fd = None - raise SerialException("could not open port %s: %s" % (self._port, msg)) - #~ fcntl.fcntl(self.fd, FCNTL.F_SETFL, 0) #set blocking - - try: - self._reconfigurePort() - except: - os.close(self.fd) - self.fd = None - else: - self._isOpen = True - #~ self.flushInput() - - - def _reconfigurePort(self): - """Set communication parameters on opened port.""" - if self.fd is None: - raise SerialException("Can only operate on a valid port handle") - custom_baud = None - - vmin = vtime = 0 #timeout is done via select - if self._interCharTimeout is not None: - vmin = 1 - vtime = int(self._interCharTimeout * 10) - try: - iflag, oflag, cflag, lflag, ispeed, ospeed, cc = termios.tcgetattr(self.fd) - except termios.error, msg: #if a port is nonexistent but has a /dev file, it'll fail here - raise SerialException("Could not configure port: %s" % msg) - #set up raw mode / no echo / binary - cflag |= (TERMIOS.CLOCAL|TERMIOS.CREAD) - lflag &= ~(TERMIOS.ICANON|TERMIOS.ECHO|TERMIOS.ECHOE|TERMIOS.ECHOK|TERMIOS.ECHONL| - TERMIOS.ISIG|TERMIOS.IEXTEN) #|TERMIOS.ECHOPRT - for flag in ('ECHOCTL', 'ECHOKE'): #netbsd workaround for Erk - if hasattr(TERMIOS, flag): - lflag &= ~getattr(TERMIOS, flag) - - oflag &= ~(TERMIOS.OPOST) - iflag &= ~(TERMIOS.INLCR|TERMIOS.IGNCR|TERMIOS.ICRNL|TERMIOS.IGNBRK) - if hasattr(TERMIOS, 'IUCLC'): - iflag &= ~TERMIOS.IUCLC - if hasattr(TERMIOS, 'PARMRK'): - iflag &= ~TERMIOS.PARMRK - - #setup baudrate - try: - ispeed = ospeed = getattr(TERMIOS,'B%s' % (self._baudrate)) - except AttributeError: - try: - ispeed = ospeed = baudrate_constants[self._baudrate] - except KeyError: - #~ raise ValueError('Invalid baud rate: %r' % self._baudrate) - # may need custom baud rate, it isnt in our list. - ispeed = ospeed = getattr(TERMIOS, 'B38400') - custom_baud = int(self._baudrate) # store for later - - #setup char len - cflag &= ~TERMIOS.CSIZE - if self._bytesize == 8: - cflag |= TERMIOS.CS8 - elif self._bytesize == 7: - cflag |= TERMIOS.CS7 - elif self._bytesize == 6: - cflag |= TERMIOS.CS6 - elif self._bytesize == 5: - cflag |= TERMIOS.CS5 - else: - raise ValueError('Invalid char len: %r' % self._bytesize) - #setup stopbits - if self._stopbits == STOPBITS_ONE: - cflag &= ~(TERMIOS.CSTOPB) - elif self._stopbits == STOPBITS_TWO: - cflag |= (TERMIOS.CSTOPB) - else: - raise ValueError('Invalid stopit specification: %r' % self._stopbits) - #setup parity - iflag &= ~(TERMIOS.INPCK|TERMIOS.ISTRIP) - if self._parity == PARITY_NONE: - cflag &= ~(TERMIOS.PARENB|TERMIOS.PARODD) - elif self._parity == PARITY_EVEN: - cflag &= ~(TERMIOS.PARODD) - cflag |= (TERMIOS.PARENB) - elif self._parity == PARITY_ODD: - cflag |= (TERMIOS.PARENB|TERMIOS.PARODD) - else: - raise ValueError('Invalid parity: %r' % self._parity) - #setup flow control - #xonxoff - if hasattr(TERMIOS, 'IXANY'): - if self._xonxoff: - iflag |= (TERMIOS.IXON|TERMIOS.IXOFF) #|TERMIOS.IXANY) - else: - iflag &= ~(TERMIOS.IXON|TERMIOS.IXOFF|TERMIOS.IXANY) - else: - if self._xonxoff: - iflag |= (TERMIOS.IXON|TERMIOS.IXOFF) - else: - iflag &= ~(TERMIOS.IXON|TERMIOS.IXOFF) - #rtscts - if hasattr(TERMIOS, 'CRTSCTS'): - if self._rtscts: - cflag |= (TERMIOS.CRTSCTS) - else: - cflag &= ~(TERMIOS.CRTSCTS) - elif hasattr(TERMIOS, 'CNEW_RTSCTS'): #try it with alternate constant name - if self._rtscts: - cflag |= (TERMIOS.CNEW_RTSCTS) - else: - cflag &= ~(TERMIOS.CNEW_RTSCTS) - #XXX should there be a warning if setting up rtscts (and xonxoff etc) fails?? - - #buffer - #vmin "minimal number of characters to be read. = for non blocking" - if vmin < 0 or vmin > 255: - raise ValueError('Invalid vmin: %r ' % vmin) - cc[TERMIOS.VMIN] = vmin - #vtime - if vtime < 0 or vtime > 255: - raise ValueError('Invalid vtime: %r' % vtime) - cc[TERMIOS.VTIME] = vtime - #activate settings - termios.tcsetattr(self.fd, TERMIOS.TCSANOW, [iflag, oflag, cflag, lflag, ispeed, ospeed, cc]) - - # apply custom baud rate, if any - if custom_baud is not None: - import array - buf = array.array('i', [0] * 32) - - # get serial_struct - FCNTL.ioctl(self.fd, TERMIOS.TIOCGSERIAL, buf) - - # set custom divisor - buf[6] = buf[7] / custom_baud - - # update flags - buf[4] &= ~ASYNC_SPD_MASK - buf[4] |= ASYNC_SPD_CUST - - # set serial_struct - try: - res = FCNTL.ioctl(self.fd, TERMIOS.TIOCSSERIAL, buf) - except IOError: - raise ValueError('Failed to set custom baud rate: %r' % self._baudrate) - - def close(self): - """Close port""" - if self._isOpen: - if self.fd is not None: - os.close(self.fd) - self.fd = None - self._isOpen = False - - def makeDeviceName(self, port): - return device(port) - - # - - - - - - - - - - - - - - - - - - - - - - - - - - def inWaiting(self): - """Return the number of characters currently in the input buffer.""" - #~ s = fcntl.ioctl(self.fd, TERMIOS.FIONREAD, TIOCM_zero_str) - s = fcntl.ioctl(self.fd, TIOCINQ, TIOCM_zero_str) - return struct.unpack('I',s)[0] - - def read(self, size=1): - """Read size bytes from the serial port. If a timeout is set it may - return less characters as requested. With no timeout it will block - until the requested number of bytes is read.""" - if self.fd is None: raise portNotOpenError - read = '' - inp = None - if size > 0: - while len(read) < size: - #print "\tread(): size",size, "have", len(read) #debug - ready,_,_ = select.select([self.fd],[],[], self._timeout) - if not ready: - break #timeout - buf = os.read(self.fd, size-len(read)) - read = read + buf - if (self._timeout >= 0 or self._interCharTimeout > 0) and not buf: - break #early abort on timeout - return read - - def write(self, data): - """Output the given string over the serial port.""" - if self.fd is None: raise portNotOpenError - if not isinstance(data, str): - raise TypeError('expected str, got %s' % type(data)) - t = len(data) - d = data - while t > 0: - try: - if self._writeTimeout is not None and self._writeTimeout > 0: - _,ready,_ = select.select([],[self.fd],[], self._writeTimeout) - if not ready: - raise writeTimeoutError - n = os.write(self.fd, d) - if self._writeTimeout is not None and self._writeTimeout > 0: - _,ready,_ = select.select([],[self.fd],[], self._writeTimeout) - if not ready: - raise writeTimeoutError - d = d[n:] - t = t - n - except OSError,v: - if v.errno != errno.EAGAIN: - raise - - def flush(self): - """Flush of file like objects. In this case, wait until all data - is written.""" - self.drainOutput() - - def flushInput(self): - """Clear input buffer, discarding all that is in the buffer.""" - if self.fd is None: - raise portNotOpenError - termios.tcflush(self.fd, TERMIOS.TCIFLUSH) - - def flushOutput(self): - """Clear output buffer, aborting the current output and - discarding all that is in the buffer.""" - if self.fd is None: - raise portNotOpenError - termios.tcflush(self.fd, TERMIOS.TCOFLUSH) - - def sendBreak(self, duration=0.25): - """Send break condition. Timed, returns to idle state after given duration.""" - if self.fd is None: - raise portNotOpenError - termios.tcsendbreak(self.fd, int(duration/0.25)) - - def setBreak(self, level=1): - """Set break: Controls TXD. When active, to transmitting is possible.""" - if self.fd is None: raise portNotOpenError - if level: - fcntl.ioctl(self.fd, TIOCSBRK) - else: - fcntl.ioctl(self.fd, TIOCCBRK) - - def setRTS(self, level=1): - """Set terminal status line: Request To Send""" - if self.fd is None: raise portNotOpenError - if level: - fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_RTS_str) - else: - fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_RTS_str) - - def setDTR(self, level=1): - """Set terminal status line: Data Terminal Ready""" - if self.fd is None: raise portNotOpenError - if level: - fcntl.ioctl(self.fd, TIOCMBIS, TIOCM_DTR_str) - else: - fcntl.ioctl(self.fd, TIOCMBIC, TIOCM_DTR_str) - - def getCTS(self): - """Read terminal status line: Clear To Send""" - if self.fd is None: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_CTS != 0 - - def getDSR(self): - """Read terminal status line: Data Set Ready""" - if self.fd is None: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_DSR != 0 - - def getRI(self): - """Read terminal status line: Ring Indicator""" - if self.fd is None: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_RI != 0 - - def getCD(self): - """Read terminal status line: Carrier Detect""" - if self.fd is None: raise portNotOpenError - s = fcntl.ioctl(self.fd, TIOCMGET, TIOCM_zero_str) - return struct.unpack('I',s)[0] & TIOCM_CD != 0 - - # - - platform specific - - - - - - def drainOutput(self): - """internal - not portable!""" - if self.fd is None: raise portNotOpenError - termios.tcdrain(self.fd) - - def nonblocking(self): - """internal - not portable!""" - if self.fd is None: - raise portNotOpenError - fcntl.fcntl(self.fd, FCNTL.F_SETFL, FCNTL.O_NONBLOCK) - - def fileno(self): - """For easier of the serial port instance with select. - WARNING: this function is not portable to different platforms!""" - if self.fd is None: raise portNotOpenError - return self.fd - -if __name__ == '__main__': - s = Serial(0, - baudrate=19200, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_EVEN, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=3, #set a timeout value, None for waiting forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - ) - s.setRTS(1) - s.setDTR(1) - s.flushInput() - s.flushOutput() - s.write('hello') - print repr(s.read(5)) - print s.inWaiting() - del s - diff --git a/plugins/rfid/serial/serialutil.py b/plugins/rfid/serial/serialutil.py deleted file mode 100644 index fd466f2..0000000 --- a/plugins/rfid/serial/serialutil.py +++ /dev/null @@ -1,400 +0,0 @@ -#! python -# Python Serial Port Extension for Win32, Linux, BSD, Jython -# see __init__.py -# -# (C) 2001-2008 Chris Liechti -# this is distributed under a free software license, see license.txt - -PARITY_NONE, PARITY_EVEN, PARITY_ODD, PARITY_MARK, PARITY_SPACE = 'N', 'E', 'O', 'M', 'S' -STOPBITS_ONE, STOPBITS_TWO = (1, 2) -FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS = (5,6,7,8) - -PARITY_NAMES = { - PARITY_NONE: 'None', - PARITY_EVEN: 'Even', - PARITY_ODD: 'Odd', - PARITY_MARK: 'Mark', - PARITY_SPACE:'Space', -} - -XON = chr(17) -XOFF = chr(19) - -#Python < 2.2.3 compatibility -try: - True -except: - True = 1 - False = not True - -class SerialException(Exception): - """Base class for serial port related exceptions.""" - -portNotOpenError = SerialException('Port not open') - -class SerialTimeoutException(SerialException): - """Write timeouts give an exception""" - -writeTimeoutError = SerialTimeoutException("Write timeout") - -class FileLike(object): - """An abstract file like class. - - This class implements readline and readlines based on read and - writelines based on write. - This class is used to provide the above functions for to Serial - port objects. - - Note that when the serial port was opened with _NO_ timeout that - readline blocks until it sees a newline (or the specified size is - reached) and that readlines would never return and therefore - refuses to work (it raises an exception in this case)! - """ - - def read(self, size): raise NotImplementedError - def write(self, s): raise NotImplementedError - - def readline(self, size=None, eol='\n'): - """read a line which is terminated with end-of-line (eol) character - ('\n' by default) or until timeout""" - line = '' - while 1: - c = self.read(1) - if c: - line += c #not very efficient but lines are usually not that long - if c == eol: - break - if size is not None and len(line) >= size: - break - else: - break - return line - - def readlines(self, sizehint=None, eol='\n'): - """read a list of lines, until timeout - sizehint is ignored""" - if self.timeout is None: - raise ValueError, "Serial port MUST have enabled timeout for this function!" - lines = [] - while 1: - line = self.readline(eol=eol) - if line: - lines.append(line) - if line[-1] != eol: #was the line received with a timeout? - break - else: - break - return lines - - def xreadlines(self, sizehint=None): - """just call readlines - here for compatibility""" - return self.readlines() - - def writelines(self, sequence): - for line in sequence: - self.write(line) - - def flush(self): - """flush of file like objects""" - pass - - # iterator for e.g. "for line in Serial(0): ..." usage - def next(self): - line = self.readline() - if not line: raise StopIteration - return line - - def __iter__(self): - return self - - -class SerialBase(FileLike): - """Serial port base class. Provides __init__ function and properties to - get/set port settings.""" - - #default values, may be overriden in subclasses that do not support all values - BAUDRATES = (50,75,110,134,150,200,300,600,1200,1800,2400,4800,9600, - 19200,38400,57600,115200,230400,460800,500000,576000,921600, - 1000000,1152000,1500000,2000000,2500000,3000000,3500000,4000000) - BYTESIZES = (FIVEBITS, SIXBITS, SEVENBITS, EIGHTBITS) - PARITIES = (PARITY_NONE, PARITY_EVEN, PARITY_ODD) - STOPBITS = (STOPBITS_ONE, STOPBITS_TWO) - - def __init__(self, - port = None, #number of device, numbering starts at - #zero. if everything fails, the user - #can specify a device string, note - #that this isn't portable anymore - #port will be opened if one is specified - baudrate=9600, #baudrate - bytesize=EIGHTBITS, #number of databits - parity=PARITY_NONE, #enable parity checking - stopbits=STOPBITS_ONE, #number of stopbits - timeout=None, #set a timeout value, None to wait forever - xonxoff=0, #enable software flow control - rtscts=0, #enable RTS/CTS flow control - writeTimeout=None, #set a timeout for writes - dsrdtr=None, #None: use rtscts setting, dsrdtr override if true or false - interCharTimeout=None #Inter-character timeout, None to disable - ): - """Initialize comm port object. If a port is given, then the port will be - opened immediately. Otherwise a Serial port object in closed state - is returned.""" - - self._isOpen = False - self._port = None #correct value is assigned below trough properties - self._baudrate = None #correct value is assigned below trough properties - self._bytesize = None #correct value is assigned below trough properties - self._parity = None #correct value is assigned below trough properties - self._stopbits = None #correct value is assigned below trough properties - self._timeout = None #correct value is assigned below trough properties - self._writeTimeout = None #correct value is assigned below trough properties - self._xonxoff = None #correct value is assigned below trough properties - self._rtscts = None #correct value is assigned below trough properties - self._dsrdtr = None #correct value is assigned below trough properties - self._interCharTimeout = None #correct value is assigned below trough properties - - #assign values using get/set methods using the properties feature - self.port = port - self.baudrate = baudrate - self.bytesize = bytesize - self.parity = parity - self.stopbits = stopbits - self.timeout = timeout - self.writeTimeout = writeTimeout - self.xonxoff = xonxoff - self.rtscts = rtscts - self.dsrdtr = dsrdtr - self.interCharTimeout = interCharTimeout - - if port is not None: - self.open() - - def isOpen(self): - """Check if the port is opened.""" - return self._isOpen - - # - - - - - - - - - - - - - - - - - - - - - - - - - - #TODO: these are not realy needed as the is the BAUDRATES etc attribute... - #maybe i remove them before the final release... - - def getSupportedBaudrates(self): - return [(str(b), b) for b in self.BAUDRATES] - - def getSupportedByteSizes(self): - return [(str(b), b) for b in self.BYTESIZES] - - def getSupportedStopbits(self): - return [(str(b), b) for b in self.STOPBITS] - - def getSupportedParities(self): - return [(PARITY_NAMES[b], b) for b in self.PARITIES] - - # - - - - - - - - - - - - - - - - - - - - - - - - - - def setPort(self, port): - """Change the port. The attribute portstr is set to a string that - contains the name of the port.""" - - was_open = self._isOpen - if was_open: self.close() - if port is not None: - if type(port) in [type(''), type(u'')]: #strings are taken directly - self.portstr = port - else: - self.portstr = self.makeDeviceName(port) - else: - self.portstr = None - self._port = port - if was_open: self.open() - - def getPort(self): - """Get the current port setting. The value that was passed on init or using - setPort() is passed back. See also the attribute portstr which contains - the name of the port as a string.""" - return self._port - - port = property(getPort, setPort, doc="Port setting") - - - def setBaudrate(self, baudrate): - """Change baudrate. It raises a ValueError if the port is open and the - baudrate is not possible. If the port is closed, then tha value is - accepted and the exception is raised when the port is opened.""" - #~ if baudrate not in self.BAUDRATES: raise ValueError("Not a valid baudrate: %r" % baudrate) - try: - self._baudrate = int(baudrate) - except TypeError: - raise ValueError("Not a valid baudrate: %r" % (baudrate,)) - else: - if self._isOpen: self._reconfigurePort() - - def getBaudrate(self): - """Get the current baudrate setting.""" - return self._baudrate - - baudrate = property(getBaudrate, setBaudrate, doc="Baudrate setting") - - - def setByteSize(self, bytesize): - """Change byte size.""" - if bytesize not in self.BYTESIZES: raise ValueError("Not a valid byte size: %r" % (bytesize,)) - self._bytesize = bytesize - if self._isOpen: self._reconfigurePort() - - def getByteSize(self): - """Get the current byte size setting.""" - return self._bytesize - - bytesize = property(getByteSize, setByteSize, doc="Byte size setting") - - - def setParity(self, parity): - """Change parity setting.""" - if parity not in self.PARITIES: raise ValueError("Not a valid parity: %r" % (parity,)) - self._parity = parity - if self._isOpen: self._reconfigurePort() - - def getParity(self): - """Get the current parity setting.""" - return self._parity - - parity = property(getParity, setParity, doc="Parity setting") - - - def setStopbits(self, stopbits): - """Change stopbits size.""" - if stopbits not in self.STOPBITS: raise ValueError("Not a valid stopbit size: %r" % (stopbits,)) - self._stopbits = stopbits - if self._isOpen: self._reconfigurePort() - - def getStopbits(self): - """Get the current stopbits setting.""" - return self._stopbits - - stopbits = property(getStopbits, setStopbits, doc="Stopbits setting") - - - def setTimeout(self, timeout): - """Change timeout setting.""" - if timeout is not None: - if timeout < 0: raise ValueError("Not a valid timeout: %r" % (timeout,)) - try: - timeout + 1 #test if it's a number, will throw a TypeError if not... - except TypeError: - raise ValueError("Not a valid timeout: %r" % (timeout,)) - - self._timeout = timeout - if self._isOpen: self._reconfigurePort() - - def getTimeout(self): - """Get the current timeout setting.""" - return self._timeout - - timeout = property(getTimeout, setTimeout, doc="Timeout setting for read()") - - - def setWriteTimeout(self, timeout): - """Change timeout setting.""" - if timeout is not None: - if timeout < 0: raise ValueError("Not a valid timeout: %r" % (timeout,)) - try: - timeout + 1 #test if it's a number, will throw a TypeError if not... - except TypeError: - raise ValueError("Not a valid timeout: %r" % timeout) - - self._writeTimeout = timeout - if self._isOpen: self._reconfigurePort() - - def getWriteTimeout(self): - """Get the current timeout setting.""" - return self._writeTimeout - - writeTimeout = property(getWriteTimeout, setWriteTimeout, doc="Timeout setting for write()") - - - def setXonXoff(self, xonxoff): - """Change XonXoff setting.""" - self._xonxoff = xonxoff - if self._isOpen: self._reconfigurePort() - - def getXonXoff(self): - """Get the current XonXoff setting.""" - return self._xonxoff - - xonxoff = property(getXonXoff, setXonXoff, doc="Xon/Xoff setting") - - def setRtsCts(self, rtscts): - """Change RtsCts flow control setting.""" - self._rtscts = rtscts - if self._isOpen: self._reconfigurePort() - - def getRtsCts(self): - """Get the current RtsCts flow control setting.""" - return self._rtscts - - rtscts = property(getRtsCts, setRtsCts, doc="RTS/CTS flow control setting") - - def setDsrDtr(self, dsrdtr=None): - """Change DsrDtr flow control setting.""" - if dsrdtr is None: - #if not set, keep backwards compatibility and follow rtscts setting - self._dsrdtr = self._rtscts - else: - #if defined independently, follow its value - self._dsrdtr = dsrdtr - if self._isOpen: self._reconfigurePort() - - def getDsrDtr(self): - """Get the current DsrDtr flow control setting.""" - return self._dsrdtr - - dsrdtr = property(getDsrDtr, setDsrDtr, "DSR/DTR flow control setting") - - def setInterCharTimeout(self, interCharTimeout): - """Change inter-character timeout setting.""" - if interCharTimeout is not None: - if interCharTimeout < 0: raise ValueError("Not a valid timeout: %r" % interCharTimeout) - try: - interCharTimeout + 1 #test if it's a number, will throw a TypeError if not... - except TypeError: - raise ValueError("Not a valid timeout: %r" % interCharTimeout) - - self._interCharTimeout = interCharTimeout - if self._isOpen: self._reconfigurePort() - - def getInterCharTimeout(self): - """Get the current inter-character timeout setting.""" - return self._interCharTimeout - - interCharTimeout = property(getInterCharTimeout, setInterCharTimeout, doc="Inter-character timeout setting for read()") - - - # - - - - - - - - - - - - - - - - - - - - - - - - - - def __repr__(self): - """String representation of the current port settings and its state.""" - return "%s(port=%r, baudrate=%r, bytesize=%r, parity=%r, stopbits=%r, timeout=%r, xonxoff=%r, rtscts=%r, dsrdtr=%r)" % ( - self.__class__.__name__, - id(self), - self._isOpen, - self.portstr, - self.baudrate, - self.bytesize, - self.parity, - self.stopbits, - self.timeout, - self.xonxoff, - self.rtscts, - self.dsrdtr, - ) - -if __name__ == '__main__': - s = SerialBase() - print s.portstr - print s.getSupportedBaudrates() - print s.getSupportedByteSizes() - print s.getSupportedParities() - print s.getSupportedStopbits() - print s diff --git a/plugins/rfid/tis2000.py b/plugins/rfid/tis2000.py deleted file mode 100644 index 91d1991..0000000 --- a/plugins/rfid/tis2000.py +++ /dev/null @@ -1,252 +0,0 @@ -from device import RFIDDevice -from serial import Serial -import dbus -from dbus.mainloop.glib import DBusGMainLoop -import gobject -import re -from time import sleep - -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]' - -STATE_WAITING = 0 -STATE_WAITING2 = 1 -STATE_READING = 2 - -class RFIDReader(RFIDDevice): - """ - TIS-2000 interface. - """ - - def __init__(self): - - RFIDDevice.__init__(self) - self.last_tag = "" - self.ser = Serial() - self.device = '' - self.device_path = '' - self._connected = False - self._state = STATE_WAITING - - loop = DBusGMainLoop() - self.bus = dbus.SystemBus(mainloop=loop) - hmgr_iface = dbus.Interface(self.bus.get_object(HAL_SERVICE, - HAL_MGR_PATH), HAL_MGR_IFACE) - - hmgr_iface.connect_to_signal('DeviceRemoved', self._device_removed_cb) - - def get_present(self): - """ - Checks if TI-S2000 device is present. - Returns True if so, False otherwise. - """ - hmgr_if = dbus.Interface(self.bus.get_object(HAL_SERVICE, HAL_MGR_PATH), - HAL_MGR_IFACE) - tiusb_devices = set(hmgr_if.FindDeviceStringMatch('serial.type', - 'usb')) & set(hmgr_if.FindDeviceStringMatch( - 'info.product', 'TUSB3410 Microcontroller')) - for i in tiusb_devices: - tiusb_if = dbus.Interface(self.bus.get_object(HAL_SERVICE, i), - HAL_DEV_IFACE) - if tiusb_if.PropertyExists('linux.device_file'): - self.device = str(tiusb_if.GetProperty('linux.device_file')) - self.device_path = i - return True - return False - - def do_connect(self): - """ - Connects to the device. - Returns True if successfull, False otherwise. - """ - retval = False - if self.get_present(): - try: - self.ser = Serial(self.device, 9600, timeout=0.1) - self._connected = True - self._escape() - self._clear() - self._format() - gobject.idle_add(self._loop) - retval = True - except: - self._connected = False - return retval - - def do_disconnect(self): - """ - Disconnect from the device. - """ - self.ser.close() - self._connected = False - - def read_tag(self): - """ - Returns the last read value. - """ - return self.last_tag - - def write_tag(self, hexval): - """ - Usage: write_tag(hexval) - - Writes the hexadecimal string "hexval" into the tag. - Returns True if successfull, False otherwise. - """ - #self.ser.flushInput() - reg = re.compile('([^0-9A-F]+)') - if not (hexval.__len__() == 16 and reg.findall(hexval) == []): - return False - self.ser.read(100) - self.ser.write('P') - for i in hexval: - self.ser.write(i) - sleep(1) - resp = self.ser.read(64) - resp = resp.split()[0] - if resp == "P0": - return True - else: - return False - - def _escape(self): - """ - Sends the scape command to the TIS-2000 device. - """ - try: - #self.ser.flushInput() - self.ser.read(100) - self.ser.write('\x1B') - resp = self.ser.read() - if resp == 'E': - return True - else: - return False - except: - return False - - def _format(self): - """ - Sends the format command to the TIS-2000 device. - """ - try: - #self.ser.flushInput() - self.ser.read(100) - self.ser.write('F') - resp = self.ser.read() - if resp == 'F': - return True - else: - return False - except: - return False - - def _clear(self): - """ - Sends the clear command to the TIS-2000 device. - """ - try: - #self.ser.flushInput() - self.ser.read(100) - self.ser.write('C') - resp = self.ser.read() - if resp == 'C': - return True - else: - return False - except: - return False - - def get_version(self): - """ - Sends the version command to the TIS-2000 device and returns - a string with the device version. - """ - #self.ser.flushInput() - self.ser.read(100) - self.ser.write('V') - version = [] - tver = "" - while 1: - resp = self.ser.read() - if resp == '\x0A' or resp == '': - break - if resp != '\n' and resp != '\r': - version.append(resp) - for i in version: - tver = tver + i - if tver != "": - return tver - return "Unknown" - - def _device_removed_cb(self, path): - """ - Called when a device is removed. - Checks if the removed device is itself and emits the "disconnected" - signal if so. - """ - if path == self.device_path: - self.device_path = '' - self.ser.close() - self._connected = False - self.emit("disconnected","TIS-2000") - - def _loop(self): - """ - Threaded loop for reading data sent from the TIS-2000. - """ - if not self._connected: - return False - - if self._state is STATE_WAITING: - data = self.ser.read() - if data in ['W', 'R']: - self._state = STATE_WAITING2 - return True - - elif self._state is STATE_WAITING2: - data = self.ser.read() - if data.isspace(): - self._state = STATE_READING - else: - self._clear() - self._state = STATE_WAITING - return True - - elif self._state is STATE_READING: - data = self.ser.read(16) - if data.__len__() < 16: - self._clear() - self._state = STATE_WAITING - else: - reg = re.compile('([^0-9A-F]+)') - if reg.findall(data) == []: - self.emit("tag-read", data) - self.last_tag = data - self._clear() - self._state = STATE_WAITING - return True - return True - -# Testing -#if __name__ == '__main__': -# def handler(device, idhex): -# """ -# Handler for "tag-read" signal. -# Prints the tag id. -# """ -# print "ID: ", idhex -# -# dev = RFIDReader() -# if dev.get_present(): -# dev.do_connect() -# dev.connect('tag-read', handler) -# else: -# print "Not connected" -# -# mloop = gobject.MainLoop() -# mloop.run() diff --git a/plugins/rfid/utils.py b/plugins/rfid/utils.py deleted file mode 100644 index 94e5540..0000000 --- a/plugins/rfid/utils.py +++ /dev/null @@ -1,98 +0,0 @@ -# utils.py - Helper functions for tis2000.py -# Copyright (C) 2010 Emiliano Pastorino -# -# 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 3 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, see . - -def strhex2bin(strhex): - """ - Convert a string representing an hex value into a - string representing the same value in binary format. - """ - dic = { '0':"0000", - '1':"0001", - '2':"0010", - '3':"0011", - '4':"0100", - '5':"0101", - '6':"0110", - '7':"0111", - '8':"1000", - '9':"1001", - 'A':"1010", - 'B':"1011", - 'C':"1100", - 'D':"1101", - 'E':"1110", - 'F':"1111" - } - binstr = "" - for i in strhex: - binstr = binstr + dic[i.upper()] - return binstr - -def strbin2dec(strbin): - """ - Convert a string representing a binary value into a - string representing the same value in decimal format. - """ - strdec = "0" - for i in range(1, strbin.__len__()+1): - strdec = str(int(strdec)+int(strbin[-i])*int(pow(2, i-1))) - return strdec - -def dec2bin(ndec): - """ - Convert a decimal number into a string representing - the same value in binary format. - """ - if ndec < 1: - return "0" - binary = [] - while ndec != 0: - binary.append(ndec%2) - ndec = ndec/2 - strbin = "" - binary.reverse() - for i in binary: - strbin = strbin+str(i) - return strbin - -def bin2hex(strbin): - """ - Convert a string representing a binary number into a string - representing the same value in hexadecimal format. - """ - dic = { "0000":"0", - "0001":"1", - "0010":"2", - "0011":"3", - "0100":"4", - "0101":"5", - "0110":"6", - "0111":"7", - "1000":"8", - "1001":"9", - "1010":"A", - "1011":"B", - "1100":"C", - "1101":"D", - "1110":"E", - "1111":"F" - } - while strbin.__len__()%4 != 0: - strbin = '0' + strbin - strh = "" - for i in range(0, strbin.__len__()/4): - strh = strh + dic[str(strbin[i*4:i*4+4])] - return strh diff --git a/plugins/turtle_blocks_extras/turtle_blocks_extras.py b/plugins/turtle_blocks_extras/turtle_blocks_extras.py index 36d98e2..132848a 100644 --- a/plugins/turtle_blocks_extras/turtle_blocks_extras.py +++ b/plugins/turtle_blocks_extras/turtle_blocks_extras.py @@ -92,6 +92,7 @@ class Turtle_blocks_extras(Plugin): # internally expanded macro palette.add_block('while', + hidden=True, style='clamp-style-boolean', label=_('while'), prim_name='while', @@ -102,6 +103,7 @@ boolean operators from Numbers palette')) # internally expanded macro palette.add_block('until', + hidden=True, style='clamp-style-boolean', label=_('until'), prim_name='until', @@ -112,6 +114,7 @@ boolean operators from Numbers palette')) primitive_dictionary['clamp'] = self._prim_clamp palette.add_block('sandwichclamp', + hidden=True, style='clamp-style-collapsible', label=' ', special_name=_('top'), @@ -121,12 +124,12 @@ boolean operators from Numbers palette')) def _media_palette(self): - palette = make_palette('media', - colors=["#A0FF00", "#80A000"], - help_string=_('Palette of media objects'), - position=7) + palette = make_palette('flow', + colors=["#FFC000", "#A08000"], + help_string=_('Palette of flow operators')) palette.add_block('journal', + hidden=True, style='box-style-media', label=' ', default='None', @@ -139,6 +142,7 @@ boolean operators from Numbers palette')) MEDIA_SHAPES.append('journalon') palette.add_block('audio', + hidden=True, style='box-style-media', label=' ', special_name=_('audio'), @@ -151,6 +155,7 @@ boolean operators from Numbers palette')) MEDIA_SHAPES.append('audioon') palette.add_block('video', + hidden=True, style='box-style-media', label=' ', special_name=_('video'), @@ -163,6 +168,7 @@ boolean operators from Numbers palette')) MEDIA_SHAPES.append('videoon') palette.add_block('description', + hidden=True, style='box-style-media', label=' ', special_name=_('description'), @@ -175,6 +181,7 @@ boolean operators from Numbers palette')) MEDIA_SHAPES.append('descriptionon') palette.add_block('string', + hidden=True, style='box-style', label=_('text'), default=_('text'), @@ -183,6 +190,7 @@ boolean operators from Numbers palette')) primitive_dictionary['show'] = self._prim_show palette.add_block('show', + hidden=True, style='basic-style-1arg', label=_('show'), default=_('text'), @@ -226,6 +234,7 @@ Journal')) primitive_dictionary['setscale'] = self._prim_setscale palette.add_block('setscale', + hidden=True, style='basic-style-1arg', label=_('set scale'), prim_name='setscale', @@ -238,6 +247,7 @@ Journal')) primitive_dictionary['savepix'] = self._prim_save_picture palette.add_block('savepix', + hidden=True, style='basic-style-1arg', label=_('save picture'), prim_name='savepix', @@ -249,6 +259,7 @@ Journal')) primitive_dictionary['savesvg'] = self._prim_save_svg palette.add_block('savesvg', + hidden=True, style='basic-style-1arg', label=_('save SVG'), prim_name='savesvg', @@ -259,6 +270,7 @@ in the Sugar Journal')) lambda self, x: primitive_dictionary['savesvg'](x)) palette.add_block('scale', + hidden=True, style='box-style', label=_('scale'), prim_name='scale', @@ -268,6 +280,7 @@ in the Sugar Journal')) self.tw.lc.def_prim('scale', 0, lambda self: self.tw.lc.scale) palette.add_block('mediawait', + hidden=True, style='basic-style-extended-vertical', label=_('media wait'), prim_name='mediawait', @@ -276,6 +289,7 @@ complete')) self.tw.lc.def_prim('mediawait', 0, self.tw.lc.media_wait, True) palette.add_block('mediastop', + hidden=True, style='basic-style-extended-vertical', label=_('media stop'), prim_name='mediastop', @@ -283,6 +297,7 @@ complete')) self.tw.lc.def_prim('mediastop', 0, self.tw.lc.media_stop, True) palette.add_block('mediapause', + hidden=True, style='basic-style-extended-vertical', label=_('media pause'), prim_name='mediapause', @@ -290,6 +305,7 @@ complete')) self.tw.lc.def_prim('mediapause', 0, self.tw.lc.media_pause, True) palette.add_block('mediaplay', + hidden=True, style='basic-style-extended-vertical', label=_('media resume'), prim_name='mediaplay', @@ -298,6 +314,7 @@ complete')) primitive_dictionary['speak'] = self._prim_speak palette.add_block('speak', + hidden=True, style='basic-style-1arg', label=_('speak'), prim_name='speak', @@ -308,6 +325,7 @@ complete')) primitive_dictionary['sinewave'] = self._prim_sinewave palette.add_block('sinewave', + hidden=True, style='basic-style-3arg', # TRANS: pitch, duration, amplitude label=[_('sinewave') + '\n\n', _('pitch'), @@ -322,10 +340,9 @@ amplitude, and duration (in seconds)')) def _sensor_palette(self): - palette = make_palette('sensor', - colors=["#FF6060", "#A06060"], - help_string=_('Palette of sensor blocks'), - position=6) + palette = make_palette('flow', + colors=["#FFC000", "#A08000"], + help_string=_('Palette of flow operators')) primitive_dictionary['mousebutton'] = self._prim_mouse_button palette.add_block('mousebutton', @@ -341,6 +358,7 @@ pressed')) primitive_dictionary['mousebutton2'] = self._prim_mouse_button_bool palette.add_block('mousebutton2', + hidden=True, style='boolean-block-style', label=_('button down'), prim_name='mousebutton2', @@ -352,6 +370,7 @@ pressed')) primitive_dictionary['mousebutton2']()) palette.add_block('mousex', + hidden=True, style='box-style', label=_('mouse x'), prim_name='mousex', @@ -362,6 +381,7 @@ pressed')) self.tw.mouse_x - (self.tw.canvas.width / 2)) palette.add_block('mousey', + hidden=True, style='box-style', label=_('mouse y'), prim_name='mousey', @@ -373,6 +393,7 @@ pressed')) primitive_dictionary['kbinput'] = self._prim_kbinput palette.add_block('kbinput', + hidden=True, style='basic-style-extended-vertical', label=_('query keyboard'), prim_name='kbinput', @@ -382,6 +403,7 @@ stored in keyboard block)')) lambda self: primitive_dictionary['kbinput']()) palette.add_block('keyboard', + hidden=True, style='box-style', label=_('keyboard'), prim_name='keyboard', @@ -418,6 +440,7 @@ block as number')) primitive_dictionary['readpixel'] = self._prim_readpixel palette.add_block('readpixel', + hidden=True, style='basic-style-extended-vertical', label=_('read pixel'), prim_name='readpixel', @@ -429,6 +452,7 @@ to the stack')) primitive_dictionary['see'] = self._prim_see palette.add_block('see', + hidden=True, style='box-style', label=_('turtle sees'), prim_name='see', @@ -452,11 +476,11 @@ program started')) palette = make_palette('extras', colors=["#FF0000", "#A00000"], - help_string=_('Palette of extra options'), - position=8) + help_string=_('Palette of extra options')) primitive_dictionary['push'] = self._prim_push palette.add_block('push', + hidden=True, style='basic-style-1arg', #TRANS: push adds a new item to the program stack label=_('push'), @@ -471,6 +495,7 @@ last-out heap)')) primitive_dictionary['printheap'] = self._prim_printheap palette.add_block('printheap', + hidden=True, style='basic-style-extended-vertical', label=_('show heap'), prim_name='printheap', @@ -484,6 +509,7 @@ end\n') primitive_dictionary['clearheap'] = self._prim_emptyheap palette.add_block('clearheap', + hidden=True, style='basic-style-extended-vertical', label=_('empty heap'), prim_name='clearheap', @@ -497,6 +523,7 @@ end\n') primitive_dictionary['pop'] = self._prim_pop palette.add_block('pop', + hidden=True, style='box-style', #TRANS: pop removes a new item from the program stack label=_('pop'), @@ -523,6 +550,7 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n') primitive_dictionary['isheapempty2'] = self._prim_is_heap_empty_bool palette.add_block('isheapempty2', + hidden=True, style='boolean-block-style', label=_('empty heap?'), prim_name='isheapempty2', @@ -534,6 +562,7 @@ make "tmp first :taheap\nmake "taheap butfirst :taheap\noutput :tmp\nend\n') primitive_dictionary['print'] = self._prim_print palette.add_block('comment', + hidden=True, style='basic-style-1arg', label=_('comment'), prim_name='comment', @@ -558,6 +587,7 @@ bottom of the screen')) primitive_dictionary['chr'] = self._prim_chr palette.add_block('chr', + hidden=True, style='number-style-1arg', label='chr', prim_name='chr', @@ -567,6 +597,7 @@ bottom of the screen')) primitive_dictionary['int'] = self._prim_int palette.add_block('int', + hidden=True, style='number-style-1arg', label='int', prim_name='int', @@ -576,6 +607,7 @@ bottom of the screen')) primitive_dictionary['myfunction'] = self._prim_myfunction palette.add_block('myfunc1arg', + hidden=True, style='number-style-var-arg', label=[_('Python'), 'f(x)', 'x'], prim_name='myfunction', @@ -617,6 +649,7 @@ advanced multi-variable math equations, e.g., sin(x+y+z)')) primitive_dictionary['userdefined'] = self._prim_myblock palette.add_block('userdefined', + hidden=True, style='basic-style-var-arg', label=' ', prim_name='userdefined', @@ -685,6 +718,7 @@ module found in the Journal')) lambda self: self.tw.set_polar(True)) palette.add_block('addturtle', + hidden=True, style='basic-style-1arg', label=_('turtle'), prim_name='turtle', @@ -697,6 +731,7 @@ module found in the Journal')) primitive_dictionary['activeturtle'] = self._prim_active_turtle palette.add_block('activeturtle', + hidden=True, style='box-style', #TRANS: pop removes a new item from the program stack label=_('active turtle'), @@ -721,6 +756,7 @@ module found in the Journal')) # macro palette.add_block('reskin', + hidden=True, style='basic-style-1arg', label=_('turtle shell'), help_string=_("put a custom 'shell' on the turtle")) @@ -735,6 +771,7 @@ module found in the Journal')) primitive_dictionary['loadblock'] = self._prim_load_block palette.add_block('loadblock', + hidden=True, style='basic-style-var-arg', label=_('load'), prim_name='loadblock', @@ -745,8 +782,8 @@ module found in the Journal')) primitive_dictionary['loadblock'](x)) palette.add_block('loadblock2arg', - style='basic-style-var-arg', hidden=True, + style='basic-style-var-arg', label=_('load'), prim_name='loadblock2', string_or_number=True, @@ -757,8 +794,8 @@ module found in the Journal')) primitive_dictionary['loadblock']([x, y])) palette.add_block('loadblock3arg', - style='basic-style-var-arg', hidden=True, + style='basic-style-var-arg', label=_('load'), string_or_number=True, prim_name='loadblock3', @@ -770,6 +807,7 @@ module found in the Journal')) primitive_dictionary['loadpalette'] = self._prim_load_palette palette.add_block('loadpalette', + hidden=True, style='basic-style-1arg', string_or_number=True, label=_('palette'), @@ -782,14 +820,13 @@ module found in the Journal')) def _portfolio_palette(self): - palette = make_palette('portfolio', - colors=["#0606FF", "#0606A0"], - help_string=_('Palette of presentation \ -templates'), - position=9) + palette = make_palette('extras', + colors=["#FF0000", "#A00000"], + help_string=_('Palette of extra options')) primitive_dictionary['hideblocks'] = self._prim_hideblocks palette.add_block('hideblocks', + hidden=True, style='basic-style-extended-vertical', label=_('hide blocks'), prim_name='hideblocks', @@ -799,6 +836,7 @@ templates'), primitive_dictionary['showblocks'] = self._prim_showblocks palette.add_block('showblocks', + hidden=True, style='basic-style-extended-vertical', label=_('show blocks'), prim_name='showblocks', @@ -807,6 +845,7 @@ templates'), lambda self: primitive_dictionary['showblocks']()) palette.add_block('fullscreen', + hidden=True, style='basic-style-extended-vertical', label=_('Fullscreen').lower(), prim_name='fullscreen', @@ -829,6 +868,7 @@ templates'), # macros palette.add_block('picturelist', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: list of \ @@ -836,6 +876,7 @@ bullets')) MEDIA_SHAPES.append('list') palette.add_block('picture1x1a', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: select \ @@ -843,6 +884,7 @@ Journal object (no description)')) MEDIA_SHAPES.append('1x1a') palette.add_block('picture1x1', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: select \ @@ -850,6 +892,7 @@ Journal object (with description)')) MEDIA_SHAPES.append('1x1') palette.add_block('picture2x2', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: select four \ @@ -857,6 +900,7 @@ Journal objects')) MEDIA_SHAPES.append('2x2') palette.add_block('picture2x1', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: select two \ @@ -864,6 +908,7 @@ Journal objects')) MEDIA_SHAPES.append('2x1') palette.add_block('picture1x2', + hidden=True, style='basic-style-extended', label=' ', help_string=_('presentation template: select two \ @@ -872,6 +917,7 @@ Journal objects')) # Display-dependent constants palette.add_block('leftpos', + hidden=True, style='box-style', label=_('left'), prim_name='lpos', @@ -880,6 +926,7 @@ Journal objects')) self.tw.lc.def_prim('lpos', 0, lambda self: CONSTANTS['leftpos']) palette.add_block('bottompos', + hidden=True, style='box-style', label=_('bottom'), prim_name='bpos', @@ -888,6 +935,7 @@ Journal objects')) self.tw.lc.def_prim('bpos', 0, lambda self: CONSTANTS['bottompos']) palette.add_block('width', + hidden=True, style='box-style', label=_('width'), prim_name='hres', @@ -896,6 +944,7 @@ Journal objects')) self.tw.lc.def_prim('hres', 0, lambda self: CONSTANTS['width']) palette.add_block('rightpos', + hidden=True, style='box-style', label=_('right'), prim_name='rpos', @@ -904,6 +953,7 @@ Journal objects')) self.tw.lc.def_prim('rpos', 0, lambda self: CONSTANTS['rightpos']) palette.add_block('toppos', + hidden=True, style='box-style', label=_('top'), prim_name='tpos', @@ -912,6 +962,7 @@ Journal objects')) self.tw.lc.def_prim('tpos', 0, lambda self: CONSTANTS['toppos']) palette.add_block('height', + hidden=True, style='box-style', label=_('height'), prim_name='vres', diff --git a/turtleblocks.py b/turtleblocks.py index 9de66b4..338f2c3 100755 --- a/turtleblocks.py +++ b/turtleblocks.py @@ -424,6 +424,15 @@ return %s(self)" % (p, P, P) turtle_menu = MenuBuilder.make_sub_menu(menu, _('Turtle')) menu = gtk.Menu() + self._level = 0 + self._levels = self._get_levels() + self._custom_filepath = None + for i in range(40): + MenuBuilder.make_menu_item(menu, _('Challenge') + ' ' + str(i + 1), + self._do_level_cb, i) + turtle_menu = MenuBuilder.make_sub_menu(menu, _('Challenges')) + + menu = gtk.Menu() MenuBuilder.make_menu_item(menu, _('About...'), self._do_about_cb) help_menu = MenuBuilder.make_sub_menu(menu, _('Help')) @@ -648,6 +657,68 @@ Would you like to save before quitting?')) self.win.get_window().set_cursor(gtk.gdk.Cursor(gtk.gdk.HAND1)) self.tw.deleting_blocks = True + + def restore_challenge(self): + ''' Restore the current challange after a clear screen ''' + if self._custom_filepath is None: + self._load_level() + else: + self._load_level(custom=True) + + def _load_level(self, custom=False): + self.tw.canvas.clearscreen() + if custom: + self.tw.canvas.setxy(0, 0, pendown=False) + self.tw.lc.insert_image(center=True, + filepath=self._custom_filepath, + resize=True, offset=False) + else: + self.tw.canvas.setxy(int(-gtk.gdk.screen_width() / 2), 0, + pendown=False) + self.tw.lc.insert_image(center=False, resize=False, + filepath=os.path.join( + self._get_execution_dir(), 'images', + 'turtle-a.png')) + # Slight offset to account for stroke width + if self._level + 1 in self.offsets: + xoffset = self.offsets[self._level + 1][0] + yoffset = self.offsets[self._level + 1][1] + else: + xoffset = 0 + yoffset = 0 + self.tw.canvas.setxy(-2.5 + xoffset, -2.5 + yoffset, pendown=False) + self.tw.lc.insert_image(center=False, + filepath=os.path.join( + self._get_execution_dir(), 'challenges', + self._levels[self._level] + '.svg'), resize=False, + offset=True) + self.tw.canvas.setxy(0, 0, pendown=False) + + def _do_level_cb(self, widget, level): + ''' Callback to resize blocks. ''' + self._level = level + self._load_level() + + def _get_levels(self): + ''' Look for level files in lessons directory. ''' + level_files = [] + + for i in range(40): + level_files.append('confusion-%d' % (i+1)) + + self.offsets = {} + offset_fd = open(os.path.join(self._get_execution_dir(), 'challenges', + 'offsets')) + for line in offset_fd: + try: + idx, offsets = line.strip('\n').split(':') + xoffset, yoffset = offsets.split(',') + self.offsets[int(idx)] = (int(xoffset), int(yoffset)) + except ValueError: + pass + offset_fd.close() + return level_files + def _do_copy_cb(self, button): ''' Callback for copy button. ''' self.tw.saving_blocks = False -- cgit v0.9.1