예제 #1
0
void sort_balls(void) {
    start_spinner();
    
    while (!side_button()) {
        msleep(50);
        camera_update(); camera_update();
        if (get_object_count(kCameraChannelOrange) > 0 && get_object_confidence(kCameraChannelOrange, 0) >= 0.95 && get_object_area(kCameraChannelOrange, 0) > 500) {
            stop_spinner();
            set_servo_position(kServoPortSorter, kServoPositionSorterOrange);
            msleep(200);
            set_servo_position(kServoPortSorter, kServoPositionSorterCenter);
            msleep(200);
            start_spinner();
        } else if (get_object_count(kCameraChannelGreen) > 0  && get_object_confidence(kCameraChannelGreen, 0) >= 0.95 && get_object_area(kCameraChannelGreen, 0) > 500) {
            stop_spinner();
            set_servo_position(kServoPortSorter, kServoPositionSorterGreen);
            msleep(200);
            set_servo_position(kServoPortSorter, kServoPositionSorterCenter);
            msleep(200);
            start_spinner();
        }
    }
    
    alloff();
}
예제 #2
0
/* Search the documentation pages for the string 'text', building the index
  if necessary */
void
i7_search_window_search_documentation(I7SearchWindow *self)
{
	GError *err;

	if(doc_index == NULL) { /* documentation index hasn't been built yet */
		GFile *doc_file = i7_app_get_data_file_va(i7_app_get(), "Documentation", NULL);

		GFileEnumerator *docdir;
		if((docdir = g_file_enumerate_children(doc_file, "standard::*", G_FILE_QUERY_INFO_NONE, NULL, &err)) == NULL) {
			IO_ERROR_DIALOG(GTK_WINDOW(self), doc_file, err, _("opening documentation directory"));
			g_object_unref(doc_file);
			return;
		}

		start_spinner(self);

		GFileInfo *info;
		while((info = g_file_enumerator_next_file(docdir, NULL, &err)) != NULL) {
			const char *basename = g_file_info_get_name(info);
			const char *displayname = g_file_info_get_display_name(info);

			if(!g_str_has_suffix(basename, ".html") ||
			   (!g_str_has_prefix(basename, "doc") && !g_str_has_prefix(basename, "Rdoc")))
				continue;

			char *label = g_strdup_printf(_("Please be patient, indexing %s..."), displayname);
			gtk_label_set_text(GTK_LABEL(self->search_text), label);
			g_free(label);

			while(gtk_events_pending())
				gtk_main_iteration();

			GFile *file = g_file_get_child(doc_file, basename);
			GSList *doctexts = html_to_ascii(file, g_str_has_prefix(basename, "R"));
			g_object_unref(file);
			if(doctexts != NULL) {
				GSList *iter;
				/* Append the entries to the documentation index and search them
				right now while we're at it */
				for(iter = doctexts; iter != NULL; iter = g_slist_next(iter)) {
					doc_index = g_list_prepend(doc_index, iter->data);
					search_documentation(iter->data, self);
				}
				g_slist_free(doctexts);
			}
		}
		g_object_unref(doc_file);

		stop_spinner(self);
		update_label(self);
	} else {
		start_spinner(self);
		g_list_foreach(doc_index, (GFunc)search_documentation, self);
		stop_spinner(self);
	}
	return;
}
예제 #3
0
/* Search the project file for the string 'text' */
void
i7_search_window_search_project(I7SearchWindow *self)
{
	I7_SEARCH_WINDOW_USE_PRIVATE(self, priv);
	GtkTreeIter result;
	GtkTextIter search_from, match_start, match_end;
	GtkTextBuffer *buffer = GTK_TEXT_BUFFER(i7_document_get_buffer(priv->document));
	gtk_text_buffer_get_start_iter(buffer, &search_from);

	start_spinner(self);

	while(find_no_wrap(&search_from, priv->text, TRUE,
		GTK_SOURCE_SEARCH_TEXT_ONLY | (priv->ignore_case? GTK_SOURCE_SEARCH_CASE_INSENSITIVE : 0),
		priv->algorithm, &match_start, &match_end))
	{
		while(gtk_events_pending())
			gtk_main_iteration();

		search_from = match_end;

		/* Get the line number (counted from 0) */
		guint lineno = gtk_text_iter_get_line(&match_start) + 1;

		gchar *context = extract_context(buffer, &match_start, &match_end);

		/* Make a sort string */
		gchar *sort = g_strdup_printf("%04i", lineno);
		/* Put the full path to the project in */
		GFile *file = i7_document_get_file(priv->document);

		gtk_list_store_append(priv->results, &result);
		gtk_list_store_set(priv->results, &result,
			I7_RESULT_CONTEXT_COLUMN, context,
			I7_RESULT_SORT_STRING_COLUMN, sort,
			I7_RESULT_FILE_COLUMN, file,
			I7_RESULT_RESULT_TYPE_COLUMN, I7_RESULT_TYPE_PROJECT,
			I7_RESULT_LINE_NUMBER_COLUMN, lineno,
			-1);
		g_free(context);
		g_free(sort);
		g_object_unref(file);
	}

	stop_spinner(self);
}
예제 #4
0
static void
extension_search_result(GFile *parent, GFileInfo *info, gpointer unused, I7SearchWindow *self)
{
	I7_SEARCH_WINDOW_USE_PRIVATE(self, priv);
	GError *err = NULL;
	const char *basename = g_file_info_get_name(info);
	GFile *file = g_file_get_child(parent, basename);
	char *contents;
	GtkTextBuffer *buffer;
	GtkTreeIter result;
	GtkTextIter search_from, match_start, match_end;

	if(!g_file_load_contents(file, NULL, &contents, NULL, NULL, &err)) {
		char *author_display_name = file_get_display_name(parent);
		const char *ext_display_name = g_file_info_get_display_name(info);

		error_dialog_file_operation(GTK_WINDOW(self), file, err, I7_FILE_ERROR_OTHER,
		  /* TRANSLATORS: Error opening EXTENSION_NAME by AUTHOR_NAME */
		  _("Error opening extension '%s' by '%s':"), author_display_name, ext_display_name);

		g_free(author_display_name);
		g_object_unref(file);
		return;
	}

	buffer = GTK_TEXT_BUFFER(gtk_source_buffer_new(NULL));
	gtk_text_buffer_set_text(buffer, contents, -1);
	g_free(contents);

	gtk_text_buffer_get_start_iter(buffer, &search_from);

	start_spinner(self);

	while(find_no_wrap(&search_from, priv->text, TRUE,
		GTK_SOURCE_SEARCH_TEXT_ONLY | (priv->ignore_case? GTK_SOURCE_SEARCH_CASE_INSENSITIVE : 0),
		priv->algorithm, &match_start, &match_end))
	{
		unsigned lineno;
		char *sort, *context;

		while(gtk_events_pending())
			gtk_main_iteration();

		search_from = match_end;

		/* Get the line number (counted from 0) */
		lineno = gtk_text_iter_get_line(&match_start) + 1;

		context = extract_context(buffer, &match_start, &match_end);

		/* Make a sort string */
		sort = g_strdup_printf("%s %04i", basename, lineno);

		gtk_list_store_append(priv->results, &result);
		gtk_list_store_set(priv->results, &result,
			I7_RESULT_CONTEXT_COLUMN, context,
			I7_RESULT_SORT_STRING_COLUMN, sort,
			I7_RESULT_FILE_COLUMN, file,
			I7_RESULT_RESULT_TYPE_COLUMN, I7_RESULT_TYPE_EXTENSION,
			I7_RESULT_LINE_NUMBER_COLUMN, lineno,
			-1);

		g_free(context);
		g_free(sort);
	}

	stop_spinner(self);

	g_object_unref(buffer);
	g_object_unref(file);
}