futile attempt to keep the ondioSP rombox working. This will almost certainly be...
[maemo-rb.git] / apps / gui / usb_screen.c
blobac31708718f29a2e28f8eb3d4d78dee4c7f84a05
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 "action.h"
23 #include "font.h"
24 #ifdef HAVE_REMOTE_LCD
25 #include "lcd-remote.h"
26 #endif
27 #include "lang.h"
28 #include "usb.h"
29 #if defined(HAVE_USBSTACK)
30 #include "usb_core.h"
31 #ifdef USB_ENABLE_HID
32 #include "usb_keymaps.h"
33 #endif
34 #endif
35 #include "settings.h"
36 #include "led.h"
37 #include "appevents.h"
38 #include "usb_screen.h"
40 #ifdef HAVE_LCD_BITMAP
41 #include "bitmaps/usblogo.h"
42 #endif
44 #ifdef HAVE_REMOTE_LCD
45 #include "bitmaps/remote_usblogo.h"
46 #endif
48 #if (CONFIG_STORAGE & STORAGE_MMC)
49 #include "ata_mmc.h"
50 #endif
52 #ifdef USB_ENABLE_HID
53 int usb_keypad_mode;
54 static bool usb_hid;
55 #endif
57 #ifndef SIMULATOR
59 static int handle_usb_events(void)
61 #if (CONFIG_STORAGE & STORAGE_MMC)
62 int next_update=0;
63 #endif /* STORAGE_MMC */
65 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
66 while(1)
68 int button;
69 #ifdef USB_ENABLE_HID
70 if (usb_hid)
72 button = get_hid_usb_action();
74 /* On mode change, we need to refresh the screen */
75 if (button == ACTION_USB_HID_MODE_SWITCH_NEXT ||
76 button == ACTION_USB_HID_MODE_SWITCH_PREV)
78 break;
81 else
82 #endif
84 button = button_get_w_tmo(HZ/2);
85 /* hid emits the event in get_action */
86 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
89 switch(button)
91 case SYS_USB_DISCONNECTED:
92 usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
93 return 1;
94 case SYS_TIMEOUT:
95 break;
98 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
99 if(TIME_AFTER(current_tick,next_update))
101 if(usb_inserted()) {
102 led(mmc_usb_active(HZ));
104 next_update=current_tick+HZ/2;
106 #endif /* STORAGE_MMC */
109 return 0;
111 #endif
113 #ifdef USB_NONE
114 void gui_usb_screen_run(void)
117 #else
118 #define MODE_NAME_LEN 32
120 struct usb_screen_vps_t
122 struct viewport parent;
123 #ifdef HAVE_LCD_BITMAP
124 struct viewport logo;
125 #ifdef USB_ENABLE_HID
126 struct viewport title;
127 #endif
128 #endif
131 #ifdef HAVE_LCD_BITMAP
132 static bool usb_screen_fix_viewports(struct screen *screen,
133 struct usb_screen_vps_t *usb_screen_vps)
135 bool theme_needs_undo = false;
136 int logo_width, logo_height;
137 struct viewport *parent = &usb_screen_vps->parent;
138 struct viewport *logo = &usb_screen_vps->logo;
140 #ifdef HAVE_REMOTE_LCD
141 if (screen->screen_type == SCREEN_REMOTE)
143 logo_width = BMPWIDTH_remote_usblogo;
144 logo_height = BMPHEIGHT_remote_usblogo;
146 else
147 #endif
149 logo_width = BMPWIDTH_usblogo;
150 logo_height = BMPHEIGHT_usblogo;
153 viewport_set_defaults(parent, screen->screen_type);
154 if (parent->width < logo_width || parent->height < logo_height)
156 theme_needs_undo = true;
157 viewportmanager_theme_enable(screen->screen_type, false, parent);
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
182 return theme_needs_undo;
184 #endif
186 static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar)
188 int i;
189 lcd_clear_display();
190 #ifdef HAVE_LCD_REMOTE
191 lcd_remote_clear_display();
192 #endif
194 FOR_NB_SCREENS(i)
196 struct screen *screen = &screens[i];
198 struct usb_screen_vps_t *usb_screen_vps = &usb_screen_vps_ar[i];
199 struct viewport *parent = &usb_screen_vps->parent;
200 #ifdef HAVE_LCD_BITMAP
201 struct viewport *logo = &usb_screen_vps->logo;
202 #endif
204 screen->set_viewport(parent);
205 #if LCD_DEPTH > 1
206 screen->backdrop_show(BACKDROP_MAIN);
207 #endif
208 screen->backlight_on();
209 screen->clear_viewport();
211 #ifdef HAVE_LCD_BITMAP
212 screen->set_viewport(logo);
213 #ifdef HAVE_REMOTE_LCD
214 if (i == SCREEN_REMOTE)
216 screen->bitmap(remote_usblogo, 0, 0, logo->width,
217 logo->height);
219 else
220 #endif
222 screen->transparent_bitmap(usblogo, 0, 0, logo->width,
223 logo->height);
224 #ifdef USB_ENABLE_HID
225 if (usb_hid)
227 screen->set_viewport(&usb_screen_vps->title);
228 usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER;
229 screen->puts_scroll(0, 0, str(keypad_mode_name_get()));
231 #endif /* USB_ENABLE_HID */
233 screen->set_viewport(parent);
235 #else /* HAVE_LCD_BITMAP */
236 screen->double_height(false);
237 screen->puts_scroll(0, 0, "[USB Mode]");
238 status_set_param(false);
239 status_set_audio(false);
240 status_set_usb(true);
241 #endif /* HAVE_LCD_BITMAP */
243 screen->update_viewport();
244 screen->set_viewport(NULL);
248 void gui_usb_screen_run(void)
250 int i;
251 bool screen_theme_needs_undo[NB_SCREENS];
252 struct usb_screen_vps_t usb_screen_vps_ar[NB_SCREENS];
253 #if defined HAVE_TOUCHSCREEN
254 enum touchscreen_mode old_mode = touchscreen_get_mode();
256 /* TODO: Paint buttons on screens OR switch to point mode and use
257 * touchscreen as a touchpad to move the host's mouse cursor */
258 touchscreen_set_mode(TOUCHSCREEN_BUTTON);
259 #endif
261 #ifndef SIMULATOR
262 usb_acknowledge(SYS_USB_CONNECTED_ACK);
263 #endif
265 #ifdef USB_ENABLE_HID
266 usb_hid = global_settings.usb_hid;
267 usb_keypad_mode = global_settings.usb_keypad_mode;
268 #endif
270 FOR_NB_SCREENS(i)
272 struct screen *screen = &screens[i];
274 screen->set_viewport(NULL);
275 #ifdef HAVE_LCD_BITMAP
276 screen_theme_needs_undo[i] = usb_screen_fix_viewports(screen, &usb_screen_vps_ar[i]);
277 #endif
280 while (1)
282 usb_screens_draw(usb_screen_vps_ar);
283 #ifdef SIMULATOR
284 if (button_get_w_tmo(HZ/2))
285 break;
286 send_event(GUI_EVENT_ACTIONUPDATE, NULL);
287 #else
288 if (handle_usb_events())
289 break;
290 #endif /* SIMULATOR */
293 FOR_NB_SCREENS(i)
295 const struct viewport* vp = NULL;
297 #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
298 vp = usb_hid ? &usb_screen_vps_ar[i].title : NULL;
299 #elif !defined(HAVE_LCD_BITMAP)
300 vp = &usb_screen_vps_ar[i].parent;
301 #endif
302 if (vp)
303 screens[i].scroll_stop(vp);
305 #ifdef USB_ENABLE_HID
306 if (global_settings.usb_keypad_mode != usb_keypad_mode)
308 global_settings.usb_keypad_mode = usb_keypad_mode;
309 settings_save();
311 #endif
313 #ifdef HAVE_TOUCHSCREEN
314 touchscreen_set_mode(old_mode);
315 #endif
317 #ifdef HAVE_LCD_CHARCELLS
318 status_set_usb(false);
319 #endif /* HAVE_LCD_CHARCELLS */
320 FOR_NB_SCREENS(i)
322 screens[i].backlight_on();
323 if(screen_theme_needs_undo[i])
325 viewportmanager_theme_undo(i, false);
330 #endif /* !defined(USB_NONE) */