Add missing cabbiev2 800x480 backdrop
[maemo-rb.git] / apps / gui / usb_screen.c
blob66b7094760f6ac62dbce47afe59c712b73f311ec
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Björn Stenberg
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
22 #include <stdio.h>
23 #include <stdbool.h>
24 #include "action.h"
25 #include "font.h"
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
28 #endif
29 #include "lang.h"
30 #include "usb.h"
31 #if defined(HAVE_USBSTACK)
32 #include "usb_core.h"
33 #ifdef USB_ENABLE_HID
34 #include "usb_keymaps.h"
35 #endif
36 #endif
37 #include "settings.h"
38 #include "led.h"
39 #include "appevents.h"
40 #include "usb_screen.h"
42 #ifdef HAVE_LCD_BITMAP
43 #include "bitmaps/usblogo.h"
44 #include "skin_engine/skin_fonts.h"
45 #endif
47 #ifdef HAVE_REMOTE_LCD
48 #include "bitmaps/remote_usblogo.h"
49 #endif
51 #if (CONFIG_STORAGE & STORAGE_MMC)
52 #include "ata_mmc.h"
53 #endif
55 #ifdef USB_ENABLE_HID
56 int usb_keypad_mode;
57 static bool usb_hid;
58 #endif
60 #ifndef SIMULATOR
62 static int handle_usb_events(void)
64 #if (CONFIG_STORAGE & STORAGE_MMC)
65 int next_update=0;
66 #endif /* STORAGE_MMC */
68 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
69 while(1)
71 int button;
72 #ifdef USB_ENABLE_HID
73 if (usb_hid)
75 button = get_hid_usb_action();
77 /* On mode change, we need to refresh the screen */
78 if (button == ACTION_USB_HID_MODE_SWITCH_NEXT ||
79 button == ACTION_USB_HID_MODE_SWITCH_PREV)
81 break;
84 else
85 #endif
87 button = button_get_w_tmo(HZ/2);
88 /* hid emits the event in get_action */
89 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
92 switch(button)
94 case SYS_USB_DISCONNECTED:
95 return 1;
96 case SYS_CHARGER_DISCONNECTED:
97 /*reset rockbox battery runtime*/
98 global_status.runtime = 0;
99 break;
100 case SYS_TIMEOUT:
101 break;
104 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
105 if(TIME_AFTER(current_tick,next_update))
107 if(usb_inserted()) {
108 led(mmc_usb_active(HZ));
110 next_update=current_tick+HZ/2;
112 #endif /* STORAGE_MMC */
115 return 0;
117 #endif /* SIMULATOR */
119 #define MODE_NAME_LEN 32
121 struct usb_screen_vps_t
123 struct viewport parent;
124 #ifdef HAVE_LCD_BITMAP
125 struct viewport logo;
126 #ifdef USB_ENABLE_HID
127 struct viewport title;
128 #endif
129 #endif
132 #ifdef HAVE_LCD_BITMAP
133 static void usb_screen_fix_viewports(struct screen *screen,
134 struct usb_screen_vps_t *usb_screen_vps)
136 bool disable = true;
137 int logo_width, logo_height;
138 struct viewport *parent = &usb_screen_vps->parent;
139 struct viewport *logo = &usb_screen_vps->logo;
141 #ifdef HAVE_REMOTE_LCD
142 if (screen->screen_type == SCREEN_REMOTE)
144 logo_width = BMPWIDTH_remote_usblogo;
145 logo_height = BMPHEIGHT_remote_usblogo;
147 else
148 #endif
150 logo_width = BMPWIDTH_usblogo;
151 logo_height = BMPHEIGHT_usblogo;
154 viewport_set_defaults(parent, screen->screen_type);
155 disable = (parent->width < logo_width || parent->height < logo_height);
156 viewportmanager_theme_enable(screen->screen_type, !disable, parent);
157 screen->clear_display();
158 screen->stop_scroll();
160 *logo = *parent;
161 logo->x = parent->x + parent->width - logo_width;
162 logo->y = parent->y + (parent->height - logo_height) / 2;
163 logo->width = logo_width;
164 logo->height = logo_height;
166 #ifdef USB_ENABLE_HID
167 if (usb_hid)
169 struct viewport *title = &usb_screen_vps->title;
170 int char_height = font_get(parent->font)->height;
171 *title = *parent;
172 title->y = logo->y + logo->height + char_height;
173 title->height = char_height;
174 /* try to fit logo and title to parent */
175 if (parent->y + parent->height < title->y + title->height)
177 logo->y = parent->y;
178 title->y = parent->y + logo->height;
181 #endif
183 #endif
185 static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar)
187 int i;
188 FOR_NB_SCREENS(i)
190 struct screen *screen = &screens[i];
192 struct usb_screen_vps_t *usb_screen_vps = &usb_screen_vps_ar[i];
193 struct viewport *parent = &usb_screen_vps->parent;
194 #ifdef HAVE_LCD_BITMAP
195 struct viewport *logo = &usb_screen_vps->logo;
196 #endif
198 screen->set_viewport(parent);
199 screen->clear_viewport();
200 screen->backlight_on();
202 #ifdef HAVE_LCD_BITMAP
203 screen->set_viewport(logo);
204 #ifdef HAVE_REMOTE_LCD
205 if (i == SCREEN_REMOTE)
207 screen->bitmap(remote_usblogo, 0, 0, logo->width,
208 logo->height);
210 else
211 #endif
213 screen->transparent_bitmap(usblogo, 0, 0, logo->width,
214 logo->height);
215 #ifdef USB_ENABLE_HID
216 if (usb_hid)
218 char modestring[100];
219 screen->set_viewport(&usb_screen_vps->title);
220 usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER;
221 snprintf(modestring, sizeof(modestring), "%s: %s",
222 str(LANG_USB_KEYPAD_MODE),
223 str(keypad_mode_name_get()));
224 screen->puts_scroll(0, 0, modestring);
226 #endif /* USB_ENABLE_HID */
228 screen->set_viewport(parent);
230 #else /* HAVE_LCD_BITMAP */
231 screen->double_height(false);
232 screen->puts_scroll(0, 0, "[USB Mode]");
233 status_set_param(false);
234 status_set_audio(false);
235 status_set_usb(true);
236 #endif /* HAVE_LCD_BITMAP */
238 screen->set_viewport(NULL);
239 screen->update_viewport();
243 void gui_usb_screen_run(bool early_usb)
245 int i;
246 struct usb_screen_vps_t usb_screen_vps_ar[NB_SCREENS];
247 #if defined HAVE_TOUCHSCREEN
248 enum touchscreen_mode old_mode = touchscreen_get_mode();
250 /* TODO: Paint buttons on screens OR switch to point mode and use
251 * touchscreen as a touchpad to move the host's mouse cursor */
252 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
253 #endif
255 #ifndef SIMULATOR
256 usb_acknowledge(SYS_USB_CONNECTED_ACK);
257 #endif
259 #ifdef USB_ENABLE_HID
260 usb_hid = global_settings.usb_hid;
261 usb_keypad_mode = global_settings.usb_keypad_mode;
262 #endif
264 if(!early_usb)
266 /* The font system leaves the .fnt fd's open, so we need for force close them all */
267 #ifdef HAVE_LCD_BITMAP
268 font_reset(NULL);
269 #ifdef HAVE_REMOTE_LCD
270 font_load_remoteui(NULL);
271 #endif
272 skin_font_init(); /* unload all the skin fonts */
273 #endif
276 FOR_NB_SCREENS(i)
278 struct screen *screen = &screens[i];
280 screen->set_viewport(NULL);
281 #ifdef HAVE_LCD_CHARCELLS
282 /* Quick fix. Viewports should really be enabled proper for charcell */
283 viewport_set_defaults(&usb_screen_vps_ar[i].parent, i);
284 #else
285 usb_screen_fix_viewports(screen, &usb_screen_vps_ar[i]);
286 #endif
289 while (1)
291 usb_screens_draw(usb_screen_vps_ar);
292 #ifdef SIMULATOR
293 if (button_get_w_tmo(HZ/2))
294 break;
295 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
296 #else
297 if (handle_usb_events())
298 break;
299 #endif /* SIMULATOR */
302 FOR_NB_SCREENS(i)
304 const struct viewport* vp = NULL;
306 #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
307 vp = usb_hid ? &usb_screen_vps_ar[i].title : NULL;
308 #elif !defined(HAVE_LCD_BITMAP)
309 vp = &usb_screen_vps_ar[i].parent;
310 #endif
311 if (vp)
312 screens[i].scroll_stop(vp);
314 #ifdef USB_ENABLE_HID
315 if (global_settings.usb_keypad_mode != usb_keypad_mode)
317 global_settings.usb_keypad_mode = usb_keypad_mode;
318 settings_save();
320 #endif
322 #ifdef HAVE_TOUCHSCREEN
323 touchscreen_set_mode(old_mode);
324 #endif
326 #ifdef HAVE_LCD_CHARCELLS
327 status_set_usb(false);
328 #endif /* HAVE_LCD_CHARCELLS */
329 #ifdef HAVE_LCD_BITMAP
330 if(!early_usb)
332 /* Not pretty, reload all settings so fonts are loaded again correctly */
333 settings_apply(true);
334 settings_apply_skins();
336 #endif
338 FOR_NB_SCREENS(i)
340 screens[i].backlight_on();
341 viewportmanager_theme_undo(i, false);