summaryrefslogtreecommitdiffstats
path: root/apps/radio/radio_skin.c
blob: 2e329230f7be8fb2efe85ffd462df11becdbfbe6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
/***************************************************************************
 *             __________               __   ___.
 *   Open      \______   \ ____   ____ |  | _\_ |__   _______  ___
 *   Source     |       _//  _ \_/ ___\|  |/ /| __ \ /  _ \  \/  /
 *   Jukebox    |    |   (  <_> )  \___|    < | \_\ (  <_> > <  <
 *   Firmware   |____|_  /\____/ \___  >__|_ \|___  /\____/__/\_ \
 *                     \/            \/     \/    \/            \/
 * $Id$
 *
 * Copyright (C) 2010 Jonathan Gordon
 *
 * 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 software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
 * KIND, either express or implied.
 *
 ****************************************************************************/


#include "config.h"
#include <stdio.h>
#include <stdbool.h>
#include <stdlib.h>
#include "skin_engine/skin_engine.h"
#include "settings.h"
#include "radio.h"
#include "tuner.h"
#include "action.h"
#include "appevents.h"
#include "statusbar-skinned.h"
#include "option_select.h"
#ifdef HAVE_TOUCHSCREEN
#include "sound.h"
#include "misc.h"
#endif


char* default_radio_skin(enum screen_type screen)
{
    (void)screen;
    static char default_fms[] = 
        "%s%?Ti<%Ti. |>%?Tn<%Tn|%Tf>\n"
        "%Sx(Station:) %tf MHz\n"
        "%?St(force fm mono)<%Sx(Force Mono)|%?ts<%Sx(Stereo)|%Sx(Mono)>>\n"
        "%Sx(Mode:) %?tm<%Sx(Scan)|%Sx(Preset)>\n"
#ifdef HAVE_RADIO_RSSI
        "%Sx(Signal strength:) %tr dBuV\n"
#endif
#if CONFIG_CODEC != SWCODEC && !defined(SIMULATOR)
        "%?Rr<%Sx(Time:) %Rh:%Rn:%Rs|%?St(prerecording time)<%pm|%Sx(Prerecord Time) %Rs>>\n"
#endif
        "%pb\n"
#ifdef HAVE_RDS_CAP
        "\n%s%ty\n"
        "%s%tz\n"
#endif
        ;
    return default_fms;
}

void fms_fix_displays(enum fms_exiting toggle_state)
{
    int i;
    FOR_NB_SCREENS(i)
    {
        struct wps_data *data = skin_get_gwps(FM_SCREEN, i)->data;
        if (toggle_state == FMS_ENTER)
        {
            viewportmanager_theme_enable(i, skin_has_sbs(i, data), NULL);  
#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
            skin_backdrop_show(data->backdrop_id);
#endif
            screens[i].clear_display();
            /* force statusbar/skin update since we just cleared the whole screen */
            send_event(GUI_EVENT_ACTIONUPDATE, (void*)1);
        }
        else
        {
            screens[i].stop_scroll();
#if LCD_DEPTH > 1 || defined(HAVE_REMOTE_LCD) && LCD_REMOTE_DEPTH > 1
            skin_backdrop_show(sb_get_backdrop(i));
#endif
            viewportmanager_theme_undo(i, skin_has_sbs(i, data));
        }
#ifdef HAVE_TOUCHSCREEN
        if (i==SCREEN_MAIN && !data->touchregions)
            touchscreen_set_mode(toggle_state == FMS_ENTER ? 
                                 TOUCHSCREEN_BUTTON : global_settings.touch_mode);
#endif
    }
}
        

int fms_do_button_loop(bool update_screen)
{
    int button = skin_wait_for_action(FM_SCREEN, CONTEXT_FM, 
                                      update_screen ? TIMEOUT_NOBLOCK : HZ/5);
#ifdef HAVE_TOUCHSCREEN
    struct touchregion *region;
    int offset;
    if (button == ACTION_TOUCHSCREEN)
        button = skin_get_touchaction(skin_get_gwps(FM_SCREEN, SCREEN_MAIN)->data,
                                      &offset, &region);
    switch (button)
    {
        case ACTION_WPS_STOP:
            return ACTION_FM_STOP;
        case ACTION_STD_CANCEL:
            return ACTION_FM_EXIT;
        case ACTION_WPS_VOLUP:
            return ACTION_SETTINGS_INC;
        case ACTION_WPS_VOLDOWN:
            return ACTION_SETTINGS_DEC;
        case ACTION_WPS_PLAY:
            return ACTION_FM_PLAY;
        case ACTION_STD_MENU:
            return ACTION_FM_MENU;
        case WPS_TOUCHREGION_SCROLLBAR:
            /* TODO */
            break;
        case ACTION_SETTINGS_INC:
        case ACTION_SETTINGS_DEC:
        {
            const struct settings_list *setting = region->data;
            option_select_next_val(setting, button == ACTION_SETTINGS_DEC, true);
        }
        return ACTION_REDRAW;
        case ACTION_TOUCH_MUTE:
        {
            const int min_vol = sound_min(SOUND_VOLUME);
            if (global_settings.volume == min_vol)
                global_settings.volume = region->value;
            else
            {
                region->value = global_settings.volume;
                global_settings.volume = min_vol;
            }
            setvol();
        }
        return ACTION_REDRAW;
    }   
#endif
    return button;
}

struct gui_wps *fms_get(enum screen_type screen)
{
    return skin_get_gwps(FM_SCREEN, screen);
}