Ejemplo n.º 1
0
static void
cc_process_volume_usage(struct hid_appcol *ha, struct hid_report *hr, int value)
{
	struct hid_interface *hi;
	struct hid_field *hf;
	int i, flags, total;
	struct hid_key keycodes[MAX_KEYCODE];
	uint16_t key;

	/*
	 * HUG_VOLUME has Usage Type LC (linear control). Usually it has
	 * value range [-Min, Max]. Positive value n increments the volume
	 * by n. Negative value -n decrements the volumn by n. To fit in
	 * our key press/release model, HUG_VOLUME is simulated by
	 * pressing/releasing HUG_VOLUME_UP or HUG_VLOLUME_DOWN n times.
	 */

	hi = hid_appcol_get_parser_private(ha);
	assert(hi != NULL);

	/* Do nothing if value is 0. */
	if (value == 0)
		return;

	/* The keyboard driver needs to know the total number of keys. */
	total = 0;
	hf = NULL;
	while ((hf = hid_report_get_next_field(hr, hf, HID_INPUT)) != NULL) {
		flags = hid_field_get_flags(hf);
		if (flags & HIO_CONST)
			continue;
		for (i = 0; i < hf->hf_count; i++)
			total++;
	}
	if (total >= MAX_KEYCODE)
		return;

	if (value < 0)
		key = HUG_VOLUME_DOWN;
	else
		key = HUG_VOLUME_UP;
	value = abs(value);

	memset(keycodes, 0, sizeof(keycodes));
	for (i = 0; i < value; i++) {
		/* Key press. */
		keycodes[0].code = key;
		keycodes[0].up = HUP_CONSUMER;
		kbd_input(ha, 0, keycodes, total);
		if (verbose > 1)
			PRINT1("hid codes: 0x%02X (HUG_VOLUME)\n",
			    keycodes[0].code);
		/* Key release. */
		keycodes[0].code = 0;
		kbd_input(ha, 0, keycodes, total);
		if (verbose > 1)
			PRINT1("hid codes: none (HUG_VOLUME)\n");
	}
}
Ejemplo n.º 2
0
static bool create_dir(void)
{
    char dirname[MAX_PATH];
    char *cwd;
    int rc;
    int pathlen;

    cwd = getcwd(NULL, 0);
    memset(dirname, 0, sizeof dirname);

    snprintf(dirname, sizeof dirname, "%s/", cwd[1] ? cwd : "");

    pathlen = strlen(dirname);
    rc = kbd_input(dirname + pathlen, (sizeof dirname)-pathlen);
    if (rc < 0)
        return false;

    rc = mkdir(dirname);
    if (rc < 0) {
        cond_talk_ids_fq(LANG_CREATE_DIR, LANG_FAILED);
        splashf(HZ, (unsigned char *)"%s %s", str(LANG_CREATE_DIR),
                                              str(LANG_FAILED));
    } else {
        onplay_result = ONPLAY_RELOAD_DIR;
    }

    return true;
}
Ejemplo n.º 3
0
void
cc_recv(struct hid_appcol *ha, struct hid_report *hr)
{
	struct hid_interface *hi;
	struct hid_field *hf;
	struct hid_key keycodes[MAX_KEYCODE];
	unsigned int usage, up;
	int i, value, cnt, flags, total;

	hi = hid_appcol_get_parser_private(ha);
	assert(hi != NULL);

	total = 0;
	cnt = 0;
	memset(keycodes, 0, sizeof(keycodes));

	hf = NULL;
	while ((hf = hid_report_get_next_field(hr, hf, HID_INPUT)) != NULL) {
		flags = hid_field_get_flags(hf);
		if (flags & HIO_CONST)
			continue;
		for (i = 0; i < hf->hf_count; i++) {
			up = hid_field_get_usage_page(hf);
			hid_field_get_usage_value(hf, i, &usage, &value);
			if (total >= MAX_KEYCODE)
				continue;
			total++;
			if (up == HUP_CONSUMER &&
			    HID_USAGE(usage) == HUG_VOLUME && value) {
				cc_process_volume_usage(ha, hr, value);
				continue;
			}
			if (value) {
				if (cnt >= MAX_KEYCODE)
					continue;
				keycodes[cnt].code = HID_USAGE(usage);
				keycodes[cnt].up = up;
				cnt++;
			}
		}
	}

	if (total > 0 && verbose > 1) {
		PRINT1("hid codes: ");
		if (cnt == 0)
			printf("none");
		for (i = 0; i < cnt; i++)
			printf("0x%02X ", keycodes[i].code);
		putchar('\n');
	}

	kbd_input(ha, 0, keycodes, total);
}
Ejemplo n.º 4
0
bool settings_save_config(int options)
{
    char filename[MAX_PATH];
    char *folder, *namebase;
    switch (options)
    {
        case SETTINGS_SAVE_THEME:
            folder = THEME_DIR;
            namebase = "theme";
            break;
#ifdef HAVE_RECORDING
        case SETTINGS_SAVE_RECPRESETS:
            folder = RECPRESETS_DIR;
            namebase = "recording";
            break;
#endif
#if CONFIG_CODEC == SWCODEC
        case SETTINGS_SAVE_EQPRESET:
            folder = EQS_DIR;
            namebase = "eq";
            break;
#endif
        case SETTINGS_SAVE_SOUND:
            folder = ROCKBOX_DIR;
            namebase = "sound";
            break;
        default:
            folder = ROCKBOX_DIR;
            namebase = "config";
            break;
    }
    create_numbered_filename(filename, folder, namebase, ".cfg", 2
                             IF_CNFN_NUM_(, NULL));

    /* allow user to modify filename */
    while (true) {
        if (!kbd_input(filename, sizeof filename)) {
            break;
        }
        else {
            return false;
        }
    }

    if (settings_write_config(filename, options))
        splash(HZ, ID2P(LANG_SETTINGS_SAVED));
    else
        splash(HZ, ID2P(LANG_FAILED));
    return true;
}
bool catalog_add_to_a_playlist(const char* sel, int sel_attr,
                               bool new_playlist, char *m3u8name)
{
    int result;
    char playlist[MAX_PATH];
    if (in_add_to_playlist)
        return false;

    if (initialize_catalog() == -1)
        return false;

    if (new_playlist)
    {
        size_t len;
        if (m3u8name == NULL)
        {
            /*If sel is a folder, we prefill the text field with its name*/
            const char *name = strrchr(sel, '/');
            snprintf(playlist, MAX_PATH, "%s/%s.m3u8",
                     playlist_dir,
                     (name!=NULL && (sel_attr & ATTR_DIRECTORY))?name+1:"");
        }
        else
            strcpy(playlist, m3u8name);

        len = strlen(playlist);

        if(len > 4 && !strcasecmp(&playlist[len-4], ".m3u"))
            strcat(playlist, "8");
        else if(len <= 5 || strcasecmp(&playlist[len-5], ".m3u8"))
            strcat(playlist, ".m3u8");
        
        if (kbd_input(playlist, MAX_PATH))
            return false;
    }
    else
    {
        in_add_to_playlist = true;
        result = display_playlists(playlist, false);
        in_add_to_playlist = false;

        if (result == -1)
            return false;
    }

    if (add_to_playlist(playlist, new_playlist, sel, sel_attr) == 0)
        return true;
    else
        return false;
}
Ejemplo n.º 6
0
static bool rename_file(void)
{
    char newname[MAX_PATH];
    char* ptr = strrchr(selected_file, '/') + 1;
    int pathlen = (ptr - selected_file);
    strlcpy(newname, selected_file, sizeof(newname));
    if (!kbd_input(newname + pathlen, (sizeof newname)-pathlen)) {
        if (!strlen(newname + pathlen) ||
            (rename(selected_file, newname) < 0)) {
            cond_talk_ids_fq(LANG_RENAME, LANG_FAILED);
            splashf(HZ*2, "%s %s", str(LANG_RENAME), str(LANG_FAILED));
        }
        else
            onplay_result = ONPLAY_RELOAD_DIR;
    }

    return false;
}
Ejemplo n.º 7
0
static int autoresume_nexttrack_callback(int action,
                                         const struct menu_item_ex *this_item)
{
    (void)this_item;
    static int oldval = 0;
    switch (action)
    {
        case ACTION_ENTER_MENUITEM:
            oldval = global_settings.autoresume_automatic;
            break;
        case ACTION_EXIT_MENUITEM:
            if (global_settings.autoresume_automatic == AUTORESUME_NEXTTRACK_CUSTOM
                && kbd_input ((char*) &global_settings.autoresume_paths,
                              MAX_PATHNAME+1) < 0)
            {
                global_settings.autoresume_automatic = oldval;
            }
    }
    return action;
}
Ejemplo n.º 8
0
bool create_playlist(void)
{
    char filename[MAX_PATH];

    if (tc.currdir[1])
        snprintf(filename, sizeof filename, "%s.m3u8", tc.currdir);
    else
        snprintf(filename, sizeof filename, "%s/all.m3u8",
                catalog_get_directory());
        
    
    if (kbd_input(filename, MAX_PATH))
        return false;
    splashf(0, "%s %s", str(LANG_CREATING), filename);

    trigger_cpu_boost();
    catalog_add_to_a_playlist(tc.currdir, ATTR_DIRECTORY, true, filename);
    cancel_cpu_boost();

    return true;
}
bool search_playlist(void)
{
    char search_str[32] = "";
    bool ret = false, exit = false;
    int i, playlist_count;
    int found_indicies[MAX_PLAYLIST_ENTRIES];
    int found_indicies_count = 0, last_found_count = -1;
    int button;
    struct gui_synclist playlist_lists;
    struct playlist_track_info track;

    if (!playlist_viewer_init(&viewer, 0, false))
        return ret;
    if (kbd_input(search_str, sizeof(search_str)) < 0)
        return ret;
    lcd_clear_display();
    playlist_count = playlist_amount_ex(viewer.playlist);

    cpu_boost(true);

    for (i = 0; i < playlist_count &&
        found_indicies_count < MAX_PLAYLIST_ENTRIES; i++)
    {
        if (found_indicies_count != last_found_count)
        {
            splashf(0, str(LANG_PLAYLIST_SEARCH_MSG), found_indicies_count,
                       str(LANG_OFF_ABORT));
            last_found_count = found_indicies_count;
        }

        if (action_userabort(TIMEOUT_NOBLOCK))
            break;

        playlist_get_track_info(viewer.playlist, i, &track);

        if (strcasestr(track.filename,search_str))
            found_indicies[found_indicies_count++] = track.index;

        yield();
    }

    cpu_boost(false);

    if (!found_indicies_count)
    {
        return ret;
    }
    backlight_on();

    gui_synclist_init(&playlist_lists, playlist_search_callback_name,
                      found_indicies, false, 1, NULL);
    gui_synclist_set_title(&playlist_lists, str(LANG_SEARCH_RESULTS), NOICON);
    gui_synclist_set_icon_callback(&playlist_lists, NULL);
    gui_synclist_set_nb_items(&playlist_lists, found_indicies_count);
    gui_synclist_select_item(&playlist_lists, 0);
    gui_synclist_draw(&playlist_lists);
    while (!exit)
    {
        if (list_do_action(CONTEXT_LIST, HZ/4,
                           &playlist_lists, &button, LIST_WRAP_UNLESS_HELD))
            continue;
        switch (button)
        {
            case ACTION_STD_CANCEL:
                exit = true;
                break;

            case ACTION_STD_OK:
            {
                int sel = gui_synclist_get_sel_pos(&playlist_lists);
                playlist_start(found_indicies[sel], 0);
                exit = 1;
            }
                break;

            default:
                if (default_event_handler(button) == SYS_USB_CONNECTED)
                {
                    ret = true;
                    exit = true;
                }
                break;
        }
    }
    return ret;
}