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(bool early_usb
)
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
;
267 /* The font system leaves the .fnt fd's open, so we need for force close them all */
268 #ifdef HAVE_LCD_BITMAP
270 #ifdef HAVE_REMOTE_LCD
271 font_load_remoteui(NULL
);
273 skin_font_init(); /* unload all the skin fonts */
279 struct screen
*screen
= &screens
[i
];
281 screen
->set_viewport(NULL
);
282 #ifdef HAVE_LCD_CHARCELLS
283 /* Quick fix. Viewports should really be enabled proper for charcell */
284 viewport_set_defaults(&usb_screen_vps_ar
[i
].parent
, i
);
286 usb_screen_fix_viewports(screen
, &usb_screen_vps_ar
[i
]);
292 usb_screens_draw(usb_screen_vps_ar
);
294 if (button_get_w_tmo(HZ
/2))
296 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
298 if (handle_usb_events())
300 #endif /* SIMULATOR */
305 const struct viewport
* vp
= NULL
;
307 #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
308 vp
= usb_hid
? &usb_screen_vps_ar
[i
].title
: NULL
;
309 #elif !defined(HAVE_LCD_BITMAP)
310 vp
= &usb_screen_vps_ar
[i
].parent
;
313 screens
[i
].scroll_stop(vp
);
315 #ifdef USB_ENABLE_HID
316 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
318 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
323 #ifdef HAVE_TOUCHSCREEN
324 touchscreen_set_mode(old_mode
);
327 #ifdef HAVE_LCD_CHARCELLS
328 status_set_usb(false);
329 #endif /* HAVE_LCD_CHARCELLS */
330 #ifdef HAVE_LCD_BITMAP
333 /* Not pretty, reload all settings so fonts are loaded again correctly */
334 settings_apply(true);
335 settings_apply_skins();
341 screens
[i
].backlight_on();
342 viewportmanager_theme_undo(i
, false);