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 ****************************************************************************/
24 #ifdef HAVE_REMOTE_LCD
25 #include "lcd-remote.h"
29 #if defined(HAVE_USBSTACK)
32 #include "usb_keymaps.h"
38 #include "appevents.h"
39 #include "usb_screen.h"
41 #ifdef HAVE_LCD_BITMAP
42 #include "bitmaps/usblogo.h"
45 #ifdef HAVE_REMOTE_LCD
46 #include "bitmaps/remote_usblogo.h"
49 #if (CONFIG_STORAGE & STORAGE_MMC)
60 static int handle_usb_events(void)
62 #if (CONFIG_STORAGE & STORAGE_MMC)
64 #endif /* STORAGE_MMC */
66 /* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
73 button
= get_hid_usb_action();
75 /* On mode change, we need to refresh the screen */
76 if (button
== ACTION_USB_HID_MODE_SWITCH_NEXT
||
77 button
== ACTION_USB_HID_MODE_SWITCH_PREV
)
85 button
= button_get_w_tmo(HZ
/2);
86 /* hid emits the event in get_action */
87 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
92 case SYS_USB_DISCONNECTED
:
93 usb_acknowledge(SYS_USB_DISCONNECTED_ACK
);
95 case SYS_CHARGER_DISCONNECTED
:
96 /*reset rockbox battery runtime*/
97 global_status
.runtime
= 0;
103 #if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
104 if(TIME_AFTER(current_tick
,next_update
))
107 led(mmc_usb_active(HZ
));
109 next_update
=current_tick
+HZ
/2;
111 #endif /* STORAGE_MMC */
116 #endif /* SIMULATOR */
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
;
131 #ifdef HAVE_LCD_BITMAP
132 static void usb_screen_fix_viewports(struct screen
*screen
,
133 struct usb_screen_vps_t
*usb_screen_vps
)
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
;
149 logo_width
= BMPWIDTH_usblogo
;
150 logo_height
= BMPHEIGHT_usblogo
;
153 viewport_set_defaults(parent
, screen
->screen_type
);
154 disable
= (parent
->width
< logo_width
|| parent
->height
< logo_height
);
155 viewportmanager_theme_enable(screen
->screen_type
, !disable
, parent
);
158 logo
->x
= parent
->x
+ parent
->width
- logo_width
;
159 logo
->y
= parent
->y
+ (parent
->height
- logo_height
) / 2;
160 logo
->width
= logo_width
;
161 logo
->height
= logo_height
;
163 #ifdef USB_ENABLE_HID
166 struct viewport
*title
= &usb_screen_vps
->title
;
167 int char_height
= font_get(parent
->font
)->height
;
169 title
->y
= logo
->y
+ logo
->height
+ char_height
;
170 title
->height
= char_height
;
171 /* try to fit logo and title to parent */
172 if (parent
->y
+ parent
->height
< title
->y
+ title
->height
)
175 title
->y
= parent
->y
+ logo
->height
;
182 static void usb_screens_draw(struct usb_screen_vps_t
*usb_screen_vps_ar
)
187 struct screen
*screen
= &screens
[i
];
189 struct usb_screen_vps_t
*usb_screen_vps
= &usb_screen_vps_ar
[i
];
190 struct viewport
*parent
= &usb_screen_vps
->parent
;
191 #ifdef HAVE_LCD_BITMAP
192 struct viewport
*logo
= &usb_screen_vps
->logo
;
195 screen
->set_viewport(parent
);
196 screen
->clear_viewport();
197 screen
->backlight_on();
199 #ifdef HAVE_LCD_BITMAP
200 screen
->set_viewport(logo
);
201 #ifdef HAVE_REMOTE_LCD
202 if (i
== SCREEN_REMOTE
)
204 screen
->bitmap(remote_usblogo
, 0, 0, logo
->width
,
210 screen
->transparent_bitmap(usblogo
, 0, 0, logo
->width
,
212 #ifdef USB_ENABLE_HID
215 char modestring
[100];
216 screen
->set_viewport(&usb_screen_vps
->title
);
217 usb_screen_vps
->title
.flags
|= VP_FLAG_ALIGN_CENTER
;
218 snprintf(modestring
, sizeof(modestring
), "%s: %s",
219 str(LANG_USB_KEYPAD_MODE
),
220 str(keypad_mode_name_get()));
221 screen
->puts_scroll(0, 0, modestring
);
223 #endif /* USB_ENABLE_HID */
225 screen
->set_viewport(parent
);
227 #else /* HAVE_LCD_BITMAP */
228 screen
->double_height(false);
229 screen
->puts_scroll(0, 0, "[USB Mode]");
230 status_set_param(false);
231 status_set_audio(false);
232 status_set_usb(true);
233 #endif /* HAVE_LCD_BITMAP */
235 screen
->set_viewport(NULL
);
236 screen
->update_viewport();
240 void gui_usb_screen_run(void)
243 struct usb_screen_vps_t usb_screen_vps_ar
[NB_SCREENS
];
244 #if defined HAVE_TOUCHSCREEN
245 enum touchscreen_mode old_mode
= touchscreen_get_mode();
247 /* TODO: Paint buttons on screens OR switch to point mode and use
248 * touchscreen as a touchpad to move the host's mouse cursor */
249 touchscreen_set_mode(TOUCHSCREEN_BUTTON
);
253 usb_acknowledge(SYS_USB_CONNECTED_ACK
);
256 #ifdef USB_ENABLE_HID
257 usb_hid
= global_settings
.usb_hid
;
258 usb_keypad_mode
= global_settings
.usb_keypad_mode
;
263 struct screen
*screen
= &screens
[i
];
265 screen
->set_viewport(NULL
);
266 #ifdef HAVE_LCD_BITMAP
267 usb_screen_fix_viewports(screen
, &usb_screen_vps_ar
[i
]);
273 usb_screens_draw(usb_screen_vps_ar
);
275 if (button_get_w_tmo(HZ
/2))
277 send_event(GUI_EVENT_ACTIONUPDATE
, NULL
);
279 if (handle_usb_events())
281 #endif /* SIMULATOR */
286 const struct viewport
* vp
= NULL
;
288 #if defined(HAVE_LCD_BITMAP) && defined(USB_ENABLE_HID)
289 vp
= usb_hid
? &usb_screen_vps_ar
[i
].title
: NULL
;
290 #elif !defined(HAVE_LCD_BITMAP)
291 vp
= &usb_screen_vps_ar
[i
].parent
;
294 screens
[i
].scroll_stop(vp
);
296 #ifdef USB_ENABLE_HID
297 if (global_settings
.usb_keypad_mode
!= usb_keypad_mode
)
299 global_settings
.usb_keypad_mode
= usb_keypad_mode
;
304 #ifdef HAVE_TOUCHSCREEN
305 touchscreen_set_mode(old_mode
);
308 #ifdef HAVE_LCD_CHARCELLS
309 status_set_usb(false);
310 #endif /* HAVE_LCD_CHARCELLS */
313 screens
[i
].backlight_on();
314 viewportmanager_theme_undo(i
, false);