1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
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 ****************************************************************************/
26 #ifdef HAVE_REMOTE_LCD
27 #include "lcd-remote.h"
31 #if defined(HAVE_USBSTACK)
34 #include "usb_keymaps.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"
47 #ifdef HAVE_REMOTE_LCD
48 #include "bitmaps/remote_usblogo.h"
51 #if (CONFIG_STORAGE & STORAGE_MMC)
62 static int handle_usb_events(void)
64 #if (CONFIG_STORAGE & STORAGE_MMC)
66 #endif /* STORAGE_MMC */
68 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
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
)
87 button
= button_get_w_tmo(HZ
/2);
88 /* hid emits the event in get_action */
89 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
94 case SYS_USB_DISCONNECTED
:
95 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
97 case SYS_CHARGER_DISCONNECTED
:
98 /*reset rockbox battery runtime*/
99 global_status
.runtime
= 0;
105 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
106 if(TIME_AFTER(current_tick
,next_update
))
109 led(mmc_usb_active(HZ
));
111 next_update
=current_tick
+HZ
/2;
113 #endif /* STORAGE_MMC */
118 #endif /* SIMULATOR */
120 #define MODE_NAME_LEN 32
122 struct usb_screen_vps_t
124 struct viewport parent
;
125 #ifdef HAVE_LCD_BITMAP
126 struct viewport logo
;
127 #ifdef USB_ENABLE_HID
128 struct viewport title
;
133 #ifdef HAVE_LCD_BITMAP
134 static void usb_screen_fix_viewports(struct screen
*screen
,
135 struct usb_screen_vps_t
*usb_screen_vps
)
138 int logo_width
, logo_height
;
139 struct viewport
*parent
= &usb_screen_vps
->parent
;
140 struct viewport
*logo
= &usb_screen_vps
->logo
;
142 #ifdef HAVE_REMOTE_LCD
143 if (screen
->screen_type
== SCREEN_REMOTE
)
145 logo_width
= BMPWIDTH_remote_usblogo
;
146 logo_height
= BMPHEIGHT_remote_usblogo
;
151 logo_width
= BMPWIDTH_usblogo
;
152 logo_height
= BMPHEIGHT_usblogo
;
155 viewport_set_defaults(parent
, screen
->screen_type
);
156 disable
= (parent
->width
< logo_width
|| parent
->height
< logo_height
);
157 viewportmanager_theme_enable(screen
->screen_type
, !disable
, parent
);
158 screen
->clear_display();
159 screen
->stop_scroll();
162 logo
->x
= parent
->x
+ parent
->width
- logo_width
;
163 logo
->y
= parent
->y
+ (parent
->height
- logo_height
) / 2;
164 logo
->width
= logo_width
;
165 logo
->height
= logo_height
;
167 #ifdef USB_ENABLE_HID
170 struct viewport
*title
= &usb_screen_vps
->title
;
171 int char_height
= font_get(parent
->font
)->height
;
173 title
->y
= logo
->y
+ logo
->height
+ char_height
;
174 title
->height
= char_height
;
175 /* try to fit logo and title to parent */
176 if (parent
->y
+ parent
->height
< title
->y
+ title
->height
)
179 title
->y
= parent
->y
+ logo
->height
;
186 static void usb_screens_draw(struct usb_screen_vps_t
*usb_screen_vps_ar
)
191 struct screen
*screen
= &screens
[i
];
193 struct usb_screen_vps_t
*usb_screen_vps
= &usb_screen_vps_ar
[i
];
194 struct viewport
*parent
= &usb_screen_vps
->parent
;
195 #ifdef HAVE_LCD_BITMAP
196 struct viewport
*logo
= &usb_screen_vps
->logo
;
199 screen
->set_viewport(parent
);
200 screen
->clear_viewport();
201 screen
->backlight_on();
203 #ifdef HAVE_LCD_BITMAP
204 screen
->set_viewport(logo
);
205 #ifdef HAVE_REMOTE_LCD
206 if (i
== SCREEN_REMOTE
)
208 screen
->bitmap(remote_usblogo
, 0, 0, logo
->width
,
214 screen
->transparent_bitmap(usblogo
, 0, 0, logo
->width
,
216 #ifdef USB_ENABLE_HID
219 char modestring
[100];
220 screen
->set_viewport(&usb_screen_vps
->title
);
221 usb_screen_vps
->title
.flags
|= VP_FLAG_ALIGN_CENTER
;
222 snprintf(modestring
, sizeof(modestring
), "%s: %s",
223 str(LANG_USB_KEYPAD_MODE
),
224 str(keypad_mode_name_get()));
225 screen
->puts_scroll(0, 0, modestring
);
227 #endif /* USB_ENABLE_HID */
229 screen
->set_viewport(parent
);
231 #else /* HAVE_LCD_BITMAP */
232 screen
->double_height(false);
233 screen
->puts_scroll(0, 0, "[USB Mode]");
234 status_set_param(false);
235 status_set_audio(false);
236 status_set_usb(true);
237 #endif /* HAVE_LCD_BITMAP */
239 screen
->set_viewport(NULL
);
240 screen
->update_viewport();
244 void gui_usb_screen_run(void)
247 struct usb_screen_vps_t usb_screen_vps_ar
[NB_SCREENS
];
248 #if defined HAVE_TOUCHSCREEN
249 enum touchscreen_mode old_mode
= touchscreen_get_mode();
251 /* TODO: Paint buttons on screens OR switch to point mode and use
252 * touchscreen as a touchpad to move the host's mouse cursor */
253 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
257 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
260 #ifdef USB_ENABLE_HID
261 usb_hid
= global_settings
.usb_hid
;
262 usb_keypad_mode
= global_settings
.usb_keypad_mode
;
265 /* The font system leaves the .fnt fd's open, so we need for force close them all */
266 #ifdef HAVE_LCD_BITMAP
268 #ifdef HAVE_REMOTE_LCD
269 font_load_remoteui(NULL
);
271 skin_font_init(); /* unload all the skin fonts */
275 struct screen
*screen
= &screens
[i
];
277 screen
->set_viewport(NULL
);
278 #ifdef HAVE_LCD_CHARCELLS
279 /* Quick fix. Viewports should really be enabled proper for charcell */
280 viewport_set_defaults(&usb_screen_vps_ar
[i
].parent
, i
);
282 usb_screen_fix_viewports(screen
, &usb_screen_vps_ar
[i
]);
288 usb_screens_draw(usb_screen_vps_ar
);
290 if (button_get_w_tmo(HZ
/2))
292 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
294 if (handle_usb_events())
296 #endif /* SIMULATOR */
301 const struct viewport
* vp
= NULL
;
303 #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
304 vp
= usb_hid
? &usb_screen_vps_ar
[i
].title
: NULL
;
305 #elif !defined(HAVE_LCD_BITMAP)
306 vp
= &usb_screen_vps_ar
[i
].parent
;
309 screens
[i
].scroll_stop(vp
);
311 #ifdef USB_ENABLE_HID
312 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
314 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
319 #ifdef HAVE_TOUCHSCREEN
320 touchscreen_set_mode(old_mode
);
323 #ifdef HAVE_LCD_CHARCELLS
324 status_set_usb(false);
325 #endif /* HAVE_LCD_CHARCELLS */
326 #ifdef HAVE_LCD_BITMAP
327 /* Not pretty, reload all settings so fonts are loaded again correctly */
328 settings_apply(true);
329 settings_apply_skins();
334 screens
[i
].backlight_on();
335 viewportmanager_theme_undo(i
, false);