Exemplo n.º 1
0
static int selection_to_val(const struct settings_list *setting, int selection)
{
    int min = 0, max = 0, step = 1;
    if (((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING) ||
          ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING))
        return selection;
    else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)
    {
        const struct table_setting *info = setting->table_setting;
        if (setting->flags&F_ALLOW_ARBITRARY_VALS && 
            table_setting_array_position != -1    &&
            (selection >= table_setting_array_position))
        {
            if (selection == table_setting_array_position)
                return table_setting_oldval;
            return info->values[selection-1];
        }
        else
            return info->values[selection];
    }
    else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
    {
        int setting_id = setting->sound_setting->setting;
#ifndef ASCENDING_INT_SETTINGS
        step = sound_steps(setting_id);
        max = sound_max(setting_id);
        min = sound_min(setting_id);
#else
        step = -sound_steps(setting_id);
        min = sound_max(setting_id);
        max = sound_min(setting_id);
#endif
    }
    else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
    {
        const struct int_setting *info = setting->int_setting;
#ifndef ASCENDING_INT_SETTINGS
        min = info->min;
        max = info->max;
        step = info->step;
#else
        max = info->min;
        min = info->max;
        step = -info->step;
#endif
    }
    return max- (selection * step);
}
Exemplo n.º 2
0
static int volume_limit_callback(int action,const struct menu_item_ex *this_item)
{
    (void)this_item;

    static struct int_setting volume_limit_int_setting;
    volume_limit_int_setting.option_callback = NULL;
    volume_limit_int_setting.unit = UNIT_DB;
    volume_limit_int_setting.min = sound_min(SOUND_VOLUME);
    volume_limit_int_setting.max = sound_max(SOUND_VOLUME);
    volume_limit_int_setting.step = sound_steps(SOUND_VOLUME);
    volume_limit_int_setting.formatter = NULL;
    volume_limit_int_setting.get_talk_id = get_dec_talkid;

    struct settings_list setting;
    setting.flags = F_BANFROMQS|F_INT_SETTING|F_T_INT|F_NO_WRAP;
    setting.lang_id = LANG_VOLUME_LIMIT;
    setting.default_val.int_ = sound_max(SOUND_VOLUME);
    setting.int_setting = &volume_limit_int_setting;

    switch (action)
    {
        case ACTION_ENTER_MENUITEM:
            setting.setting = &global_settings.volume_limit;
            option_screen(&setting, NULL, false, ID2P(LANG_VOLUME_LIMIT));
        case ACTION_EXIT_MENUITEM: /* on exit */
            setvol();
            break;
    }
    return action;
}
Exemplo n.º 3
0
static void val_to_selection(const struct settings_list *setting, int oldvalue,
                             int *nb_items, int *selected,
                             void (**function)(int))
{
    int var_type = setting->flags&F_T_MASK;
    /* set the number of items and current selection */
    if (var_type == F_T_INT || var_type == F_T_UINT)
    {
        if (setting->flags&F_CHOICE_SETTING)
        {
            *nb_items = setting->choice_setting->count;
            *selected = oldvalue;
            *function = setting->choice_setting->option_callback;
        }
        else if (setting->flags&F_TABLE_SETTING)
        {
            const struct table_setting *info = setting->table_setting;
            int i;
            *nb_items = info->count;
            *selected = -1;
            table_setting_array_position = -1;
            for (i=0;*selected==-1 && i<*nb_items;i++)
            {
                if (setting->flags&F_ALLOW_ARBITRARY_VALS &&
                    (oldvalue < info->values[i]))
                {
                    table_setting_oldval = oldvalue;
                    table_setting_array_position = i;
                    *selected = i;
                    (*nb_items)++;
                }
                else if (oldvalue == info->values[i])
                    *selected = i;
            }
            *function = info->option_callback;
        }
        else if (setting->flags&F_T_SOUND)
        {
            int setting_id = setting->sound_setting->setting;
            int steps = sound_steps(setting_id);
            int min = sound_min(setting_id);
            int max = sound_max(setting_id);
            *nb_items = (max-min)/steps + 1;
#ifndef ASCENDING_INT_SETTINGS
            *selected = (max - oldvalue) / steps;
#else
            *selected = (oldvalue - min) / steps;
#endif
            *function = sound_get_fn(setting_id);
        }
        else
        {
            const struct int_setting *info = setting->int_setting;
            int min, max, step;
            max = info->max;
            min = info->min;
            step = info->step;
            *nb_items = (max-min)/step + 1;
#ifndef ASCENDING_INT_SETTINGS
            *selected = (max - oldvalue) / step;
#else
            *selected = (oldvalue - min) / step;
#endif
            *function = info->option_callback;
        }
    }
    else if (var_type == F_T_BOOL)
    {
        *selected = oldvalue;
        *nb_items = 2;
        boolfunction = setting->bool_setting->option_callback;
        if (boolfunction)
            *function = bool_funcwrapper;
    }
}
Exemplo n.º 4
0
   /* only the quickscreen and recording trigger needs this */
void option_select_next_val(const struct settings_list *setting,
                            bool previous, bool apply)
{
    int val = 0;
    int *value = setting->setting;
    if ((setting->flags & F_BOOL_SETTING) == F_BOOL_SETTING)
    {
        *(bool*)value = !*(bool*)value;
        if (apply && setting->bool_setting->option_callback)
            setting->bool_setting->option_callback(*(bool*)value);
        return;
    }
    else if ((setting->flags & F_INT_SETTING) == F_INT_SETTING)
    {
        struct int_setting *info = (struct int_setting *)setting->int_setting;
        bool neg_step = (info->step < 0);
        if (!previous)
        {
            val = *value + info->step;
            if (neg_step ? (val < info->max) : (val > info->max))
                val = info->min;
        }
        else
        {
            val = *value - info->step;
            if (neg_step ? (val > info->min) : (val < info->min))
                val = info->max;
        }
        *value = val;
        if (apply && info->option_callback)
            info->option_callback(val);
    }
    else if ((setting->flags & F_T_SOUND) == F_T_SOUND)
    {
        int setting_id = setting->sound_setting->setting;
        int steps = sound_steps(setting_id);
        int min = sound_min(setting_id);
        int max = sound_max(setting_id);
        if (!previous)
        {
            val = *value + steps;
            if (val >= max)
                val = min;
        }
        else
        {
            val = *value - steps;
            if (val < min)
                val = max;
        }
        *value = val;
    }
    else if ((setting->flags & F_CHOICE_SETTING) == F_CHOICE_SETTING)
    {
        struct choice_setting *info = (struct choice_setting *)setting->choice_setting;
        val = *value + 1;
        if (!previous)
        {
            val = *value + 1;
            if (val >= info->count)
                val = 0;
        }
        else
        {
            val = *value - 1;
            if (val < 0)
                val = info->count-1;
        }
        *value = val;
        if (apply && info->option_callback)
            info->option_callback(val);
    }
    else if ((setting->flags & F_TABLE_SETTING) == F_TABLE_SETTING)
    {
        const struct table_setting *tbl_info = setting->table_setting;
        int i, add;
        add = previous?tbl_info->count-1:1;
        for (i=0; i<tbl_info->count;i++)
        {
            if ((*value == tbl_info->values[i]) ||
                  (settings->flags&F_ALLOW_ARBITRARY_VALS &&
                    *value < tbl_info->values[i]))
            {
                val = tbl_info->values[(i+add)%tbl_info->count];
                break;
            }
        }
        *value = val;
    }
}
Exemplo n.º 5
0
bool set_sound(const char* string,
               int* variable,
               int setting)
{
    bool done = false;
    bool changed = true;
    int min, max;
    int val;
    int numdec;
    int integer;
    int dec;
    const char* unit;
    char str[32];
    int talkunit = UNIT_INT;
    int steps;
    int button;

    unit = sound_unit(setting);
    numdec = sound_numdecimals(setting);
    steps = sound_steps(setting);
    min = sound_min(setting);
    max = sound_max(setting);
    if (*unit == 'd') /* crude reconstruction */
        talkunit = UNIT_DB;
    else if (*unit == '%')
        talkunit = UNIT_PERCENT;
    else if (*unit == 'H')
         talkunit = UNIT_HERTZ;
    
#ifdef HAVE_LCD_BITMAP
    if(global_settings.statusbar)
        lcd_setmargins(0, STATUSBAR_HEIGHT);
    else
        lcd_setmargins(0, 0);
#endif
    lcd_clear_display();
    lcd_puts_scroll(0,0,string);

    while (!done) {
        if (changed) {
            val = sound_val2phys(setting, *variable);
            if(numdec)
            {
                integer = val / (10 * numdec);
                dec = val % (10 * numdec);
                snprintf(str,sizeof str, fmt[numdec], integer, dec, unit);
            }
            else
            {
                snprintf(str,sizeof str,"%d %s  ", val, unit);
            }
            if (global_settings.talk_menu)
                talk_value(val, talkunit, false); /* speak it */
        }
        lcd_puts(0,1,str);
        status_draw(true);
        lcd_update();

        changed = false;
        button = button_get_w_tmo(HZ/2);
        switch( button ) {
            case SETTINGS_INC:
            case SETTINGS_INC | BUTTON_REPEAT:
                (*variable)+=steps;
                if(*variable > max )
                    *variable = max;
                changed = true;
                break;

            case SETTINGS_DEC:
            case SETTINGS_DEC | BUTTON_REPEAT:
                (*variable)-=steps;
                if(*variable < min )
                    *variable = min;
                changed = true;
                break;

            case SETTINGS_OK:
            case SETTINGS_CANCEL:
#ifdef SETTINGS_OK2
            case SETTINGS_OK2:
#endif
#ifdef SETTINGS_CANCEL2
            case SETTINGS_CANCEL2:
#endif
                done = true;
                break;

            default:
                if(default_event_handler(button) == SYS_USB_CONNECTED)
                    return true;
                break;
        }
        if (changed)
            sound_set(setting, *variable);
    }
    lcd_stop_scroll();
    return false;
}