Subversion Repositories freemyipod

Rev

Rev 838 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
828 theseven 1
//
2
//
3
//    Copyright 2011 TheSeven
4
//
5
//
6
//    This file is part of emCORE.
7
//
8
//    emCORE is free software: you can redistribute it and/or
9
//    modify it under the terms of the GNU General Public License as
10
//    published by the Free Software Foundation, either version 2 of the
11
//    License, or (at your option) any later version.
12
//
13
//    emCORE is distributed in the hope that it will be useful,
14
//    but WITHOUT ANY WARRANTY; without even the implied warranty of
15
//    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16
//    See the GNU General Public License for more details.
17
//
18
//    You should have received a copy of the GNU General Public License along
19
//    with emCORE.  If not, see <http://www.gnu.org/licenses/>.
20
//
21
//
22
 
23
 
24
#include "emcoreapp.h"
25
#include "libui.h"
26
#include "mainchooser.h"
27
#include "toolchooser.h"
28
#include "settings.h"
29
#include "util.h"
30
#include "main.h"
31
#include "boot.h"
32
 
33
 
34
static bool mainchooser_preblit(struct chooser_data* data)
35
{
36
    char buf[4];
37
    struct chooser_action_handler_wheel_data* adata;
38
    adata = (struct chooser_action_handler_wheel_data*)(data->actionhandlerdata);
39
    if (adata->timeout_remaining != TIMEOUT_BLOCK)
40
    {
41
        snprintf(buf, sizeof(buf), "%3d", adata->timeout_remaining / 1000000);
42
        rendertext(framebuf, 155, 121, 176, 0xffffcccc, 0, buf);
43
    }
44
    update_display(data);
45
    return false;
46
}
47
 
48
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_powerdown =
49
{
50
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
51
                          LIBUI_POINT(44, 44)),
52
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 0)),
53
                                   LIBUI_POINT(44, 44)),
54
    .text = "Power off",
55
    .text_color = 0xffffcccc,
56
    .render = NULL
57
};
58
 
59
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_crapple =
60
{
61
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 44)),
62
                          LIBUI_POINT(44, 44)),
63
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 44)),
64
                                   LIBUI_POINT(44, 44)),
65
    .text = "Original firmware",
66
    .text_color = 0xffffcccc,
67
    .render = NULL
68
};
69
 
70
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_rockbox =
71
{
72
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 88)),
73
                          LIBUI_POINT(44, 44)),
74
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 88)),
75
                                   LIBUI_POINT(44, 44)),
76
    .text = "Rockbox",
77
    .text_color = 0xffffcccc,
78
    .render = NULL
79
};
80
 
81
struct chooser_renderer_iconflow_itemdata mainchooser_rparams_diskmode =
82
{
83
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 132)),
84
                          LIBUI_POINT(44, 44)),
85
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 132)),
86
                                   LIBUI_POINT(44, 44)),
87
    .text = "Disk mode",
88
    .text_color = 0xffffcccc,
89
    .render = NULL
90
};
91
 
92
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_console =
93
{
94
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 176)),
95
                          LIBUI_POINT(44, 44)),
96
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 176)),
97
                                   LIBUI_POINT(44, 44)),
98
    .text = "emCORE console",
99
    .text_color = 0xffffcccc,
100
    .render = NULL
101
};
102
 
103
static struct chooser_renderer_iconflow_itemdata mainchooser_rparams_toolchooser =
104
{
105
    .icon = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 220)),
106
                          LIBUI_POINT(44, 44)),
107
    .icon_selected = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 44), LIBUI_POINT(0, 220)),
108
                                   LIBUI_POINT(44, 44)),
109
    .text = "Tools",
110
    .text_color = 0xffffcccc,
111
    .render = NULL
112
};
113
 
114
static struct chooser_renderer_iconflow_params mainchooser_rparams =
115
{
116
    .version = CHOOSER_RENDERER_ICONFLOW_PARAMS_VERSION,
117
    .copy_dest = LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
118
    .copy_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
119
                              LIBUI_POINT(176, 132)),
120
    .bg_dest = LIBUI_LOCATION_NULL,
121
    .bg_src = LIBUI_SURFACE_NULL,
122
    .bg_opacity = 0,
123
    .fill_dest = LIBUI_SURFACE_NULL,
124
    .fill_color = 0,
125
    .viewport = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 16)),
126
                              LIBUI_POINT(176, 72)),
127
    .text_pos = LIBUI_POINT(88, 118),
128
    .blit_dest = LIBUI_POINT(0, 0),
129
    .blit_src = LIBUI_SURFACE(LIBUI_LOCATION(LIBUI_BUFFER(NULL, 176), LIBUI_POINT(0, 0)),
130
                              LIBUI_POINT(176, 132)),
131
    .smoothness = 500000,
132
    .startposition = -3,
133
    .iconsinview = 4,
134
    .preblit = mainchooser_preblit,
135
    .postblit = NULL
136
};
137
 
138
static struct chooser_action_handler_wheel_params mainchooser_aparams =
139
{
140
    .version = CHOOSER_ACTION_HANDLER_WHEEL_PARAMS_VERSION,
141
    .stepsperitem = 512,
142
    .eventfilter = NULL,
143
    .timeout_initial = 0,
144
    .timeout_idle = 0,
145
    .timeout_item = CHOOSER_ACTION_HANDLER_WHEEL_TIMEOUT_ITEM_NULL,
146
    .tick_force_redraw = true,
147
    .buttoncount = 3,
148
    .buttonmap =
149
    {
150
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_SELECT,
151
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_NEXT,
152
        CHOOSER_ACTION_HANDLER_WHEEL_ACTION_PREV
153
    }
154
};
155
 
156
static struct chooser_info mainchooser =
157
{
158
    .version = CHOOSER_INFO_VERSION,
159
    .actionhandler = NULL,
160
    .actionhandlerparams = &mainchooser_aparams,
161
    .renderer = NULL,
162
    .rendererparams = &mainchooser_rparams,
163
    .userparams = NULL,
164
    .tickinterval = 990000,
165
    .itemcount = 6,
166
    .defaultitem = 0,
167
    .items =
168
    {
169
        {
170
            .user = run_powerdown,
171
            .actionparams = NULL,
172
            .renderparams = &mainchooser_rparams_powerdown
173
        },
174
        {
175
            .user = run_crapple,
176
            .actionparams = NULL,
177
            .renderparams = &mainchooser_rparams_crapple
178
        },
179
        {
180
            .user = run_rockbox,
181
            .actionparams = NULL,
182
            .renderparams = &mainchooser_rparams_rockbox
183
        },
184
        {
185
            .user = run_diskmode,
186
            .actionparams = NULL,
187
            .renderparams = &mainchooser_rparams_diskmode
188
        },
189
        {
190
            .user = NULL,
191
            .actionparams = NULL,
192
            .renderparams = &mainchooser_rparams_console
193
        },
194
        {
195
            .user = run_toolchooser,
196
            .actionparams = NULL,
197
            .renderparams = &mainchooser_rparams_toolchooser
198
        }
199
    }
200
};
201
 
202
void run_mainchooser(void** firmware, void** app, int* size)
203
{
204
    while (!*firmware && !*app)
205
    {
206
        const struct chooser_item* result = ui->chooser_run(&mainchooser);
207
        if (!result)
208
            switch(settings.timeout_item)
209
            {
210
                case 0:
211
                    run_powerdown(firmware, app, size);
212
                    break;
213
 
214
                case 1:
215
                    run_crapple(firmware, app, size);
216
                    break;
217
 
218
                case 2:
219
                    run_rockbox(firmware, app, size);
220
                    break;
221
 
222
                case 3:
223
                    run_diskmode(firmware, app, size);
224
                    break;
225
 
226
                case 4:
227
                    run_umsboot(firmware, app, size);
228
                    break;
229
 
230
                case 5:
231
                    return;
232
            }
233
        if (!result->user) return;
234
        void (*selected_function)(void** firmware, void** app, int* size);
235
        selected_function = (void(*)(void** firmware, void** app, int* size))(result->user);
236
        selected_function(firmware, app, size);
237
    }
238
}
239
 
240
void mainchooser_init()
241
{
242
    mainchooser.actionhandler = ui->chooser_action_handler_wheel;
243
    mainchooser.renderer = ui->chooser_renderer_iconflow;
244
    mainchooser_rparams.copy_dest.buf.addr = framebuf;
245
    mainchooser_rparams.copy_src.loc.buf.addr = bg;
246
    mainchooser_rparams.viewport.loc.buf.addr = framebuf;
247
    mainchooser_rparams.blit_src.loc.buf.addr = framebuf;
248
    mainchooser_rparams_powerdown.icon.loc.buf.addr = icons;
249
    mainchooser_rparams_powerdown.icon_selected.loc.buf.addr = icons;
250
    mainchooser_rparams_crapple.icon.loc.buf.addr = icons;
251
    mainchooser_rparams_crapple.icon_selected.loc.buf.addr = icons;
252
    mainchooser_rparams_rockbox.icon.loc.buf.addr = icons;
253
    mainchooser_rparams_rockbox.icon_selected.loc.buf.addr = icons;
254
    mainchooser_rparams_console.icon.loc.buf.addr = icons;
255
    mainchooser_rparams_console.icon_selected.loc.buf.addr = icons;
256
    mainchooser_rparams_diskmode.icon.loc.buf.addr = icons;
257
    mainchooser_rparams_diskmode.icon_selected.loc.buf.addr = icons;
258
    mainchooser_rparams_toolchooser.icon.loc.buf.addr = icons;
259
    mainchooser_rparams_toolchooser.icon_selected.loc.buf.addr = icons;
260
}
261
 
262
void mainchooser_apply_settings()
263
{
264
    mainchooser.defaultitem = settings.default_item;
265
    if (settings.timeout_initial < SETTINGS_TIMEOUT_CUTOFF)
266
        mainchooser_aparams.timeout_initial = TIMEOUT_BLOCK;
267
    else mainchooser_aparams.timeout_initial = settings.timeout_initial + 500000;
268
    if (settings.timeout_idle < SETTINGS_TIMEOUT_CUTOFF)
269
        mainchooser_aparams.timeout_idle = TIMEOUT_BLOCK;
270
    else mainchooser_aparams.timeout_idle = settings.timeout_idle + 500000;
271
}