2009-10-19 21:19:30 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
2010-01-03 14:28:09 +00:00
|
|
|
* $Id$
|
2009-10-19 21:19:30 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2002 Björn Stenberg
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2010-05-06 22:22:47 +00:00
|
|
|
#include <stdio.h>
|
2010-05-06 21:37:03 +00:00
|
|
|
#include <stdbool.h>
|
2009-10-19 21:19:30 +00:00
|
|
|
#include "action.h"
|
2009-11-10 13:40:50 +00:00
|
|
|
#include "font.h"
|
2009-10-19 21:19:30 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
#include "lcd-remote.h"
|
|
|
|
#endif
|
|
|
|
#include "lang.h"
|
|
|
|
#include "usb.h"
|
|
|
|
#if defined(HAVE_USBSTACK)
|
|
|
|
#include "usb_core.h"
|
|
|
|
#ifdef USB_ENABLE_HID
|
|
|
|
#include "usb_keymaps.h"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#include "settings.h"
|
2009-10-19 21:59:19 +00:00
|
|
|
#include "led.h"
|
2009-10-19 21:19:30 +00:00
|
|
|
#include "appevents.h"
|
2009-12-20 16:28:15 +00:00
|
|
|
#include "usb_screen.h"
|
2011-09-28 01:02:48 +00:00
|
|
|
#include "skin_engine/skin_engine.h"
|
2012-07-17 18:55:14 +00:00
|
|
|
#include "playlist.h"
|
2014-01-15 23:26:45 +00:00
|
|
|
#include "misc.h"
|
2023-02-14 19:10:38 +00:00
|
|
|
#include "icons.h"
|
2009-10-19 21:19:30 +00:00
|
|
|
|
|
|
|
#include "bitmaps/usblogo.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
#include "bitmaps/remote_usblogo.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-19 21:44:38 +00:00
|
|
|
#if (CONFIG_STORAGE & STORAGE_MMC)
|
|
|
|
#include "ata_mmc.h"
|
|
|
|
#endif
|
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
#ifdef USB_ENABLE_HID
|
|
|
|
int usb_keypad_mode;
|
2009-10-23 13:29:19 +00:00
|
|
|
static bool usb_hid;
|
2009-10-19 21:19:30 +00:00
|
|
|
#endif
|
|
|
|
|
2009-10-20 17:30:42 +00:00
|
|
|
#ifndef SIMULATOR
|
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
static int handle_usb_events(void)
|
|
|
|
{
|
|
|
|
#if (CONFIG_STORAGE & STORAGE_MMC)
|
|
|
|
int next_update=0;
|
|
|
|
#endif /* STORAGE_MMC */
|
|
|
|
|
|
|
|
/* Don't return until we get SYS_USB_DISCONNECTED or SYS_TIMEOUT */
|
|
|
|
while(1)
|
|
|
|
{
|
|
|
|
int button;
|
|
|
|
#ifdef USB_ENABLE_HID
|
2009-10-23 13:29:19 +00:00
|
|
|
if (usb_hid)
|
2009-10-19 21:19:30 +00:00
|
|
|
{
|
|
|
|
button = get_hid_usb_action();
|
|
|
|
|
|
|
|
/* On mode change, we need to refresh the screen */
|
|
|
|
if (button == ACTION_USB_HID_MODE_SWITCH_NEXT ||
|
|
|
|
button == ACTION_USB_HID_MODE_SWITCH_PREV)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
button = button_get_w_tmo(HZ/2);
|
|
|
|
/* hid emits the event in get_action */
|
|
|
|
send_event(GUI_EVENT_ACTIONUPDATE, NULL);
|
|
|
|
}
|
|
|
|
|
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
case SYS_USB_DISCONNECTED:
|
|
|
|
return 1;
|
2010-02-27 22:47:49 +00:00
|
|
|
case SYS_CHARGER_DISCONNECTED:
|
2016-03-30 22:25:24 +00:00
|
|
|
reset_runtime();
|
2010-02-27 22:47:49 +00:00
|
|
|
break;
|
2009-10-19 21:19:30 +00:00
|
|
|
case SYS_TIMEOUT:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
#if (CONFIG_STORAGE & STORAGE_MMC) /* USB-MMC bridge can report activity */
|
|
|
|
if(TIME_AFTER(current_tick,next_update))
|
|
|
|
{
|
|
|
|
if(usb_inserted()) {
|
|
|
|
led(mmc_usb_active(HZ));
|
|
|
|
}
|
|
|
|
next_update=current_tick+HZ/2;
|
|
|
|
}
|
|
|
|
#endif /* STORAGE_MMC */
|
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
2010-03-08 23:43:11 +00:00
|
|
|
#endif /* SIMULATOR */
|
2009-10-19 21:19:30 +00:00
|
|
|
|
|
|
|
#define MODE_NAME_LEN 32
|
|
|
|
|
|
|
|
struct usb_screen_vps_t
|
|
|
|
{
|
|
|
|
struct viewport parent;
|
|
|
|
struct viewport logo;
|
|
|
|
#ifdef USB_ENABLE_HID
|
|
|
|
struct viewport title;
|
|
|
|
#endif
|
|
|
|
};
|
|
|
|
|
2010-01-29 07:52:13 +00:00
|
|
|
static void usb_screen_fix_viewports(struct screen *screen,
|
2009-11-10 20:13:24 +00:00
|
|
|
struct usb_screen_vps_t *usb_screen_vps)
|
2009-10-19 21:19:30 +00:00
|
|
|
{
|
|
|
|
int logo_width, logo_height;
|
|
|
|
struct viewport *parent = &usb_screen_vps->parent;
|
|
|
|
struct viewport *logo = &usb_screen_vps->logo;
|
|
|
|
|
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
if (screen->screen_type == SCREEN_REMOTE)
|
|
|
|
{
|
2014-01-15 23:28:18 +00:00
|
|
|
logo_width = BMPWIDTH_remote_usblogo;
|
|
|
|
logo_height = BMPHEIGHT_remote_usblogo;
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|
|
|
|
else
|
|
|
|
#endif
|
|
|
|
{
|
|
|
|
logo_width = BMPWIDTH_usblogo;
|
|
|
|
logo_height = BMPHEIGHT_usblogo;
|
|
|
|
}
|
|
|
|
|
2014-01-15 12:37:58 +00:00
|
|
|
viewportmanager_theme_enable(screen->screen_type, true, parent);
|
2009-11-10 20:13:24 +00:00
|
|
|
|
2014-01-15 23:28:18 +00:00
|
|
|
if (logo_width > parent->width)
|
|
|
|
logo_width = parent->width;
|
|
|
|
if (logo_height > parent->height)
|
|
|
|
logo_height = parent->height;
|
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
*logo = *parent;
|
2009-11-10 13:40:50 +00:00
|
|
|
logo->x = parent->x + parent->width - logo_width;
|
2023-02-14 19:10:38 +00:00
|
|
|
#ifdef HAVE_LCD_SPLIT
|
|
|
|
switch (statusbar_position(screen))
|
|
|
|
{
|
|
|
|
/* start beyond split */
|
|
|
|
case STATUSBAR_OFF:
|
|
|
|
logo->y = parent->y + LCD_SPLIT_POS;
|
|
|
|
break;
|
|
|
|
case STATUSBAR_TOP:
|
|
|
|
logo->y = parent->y + LCD_SPLIT_POS - STATUSBAR_HEIGHT;
|
|
|
|
break;
|
|
|
|
/* start at the top for maximum space */
|
|
|
|
default:
|
|
|
|
logo->y = parent->y;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
#else
|
2009-11-10 13:40:50 +00:00
|
|
|
logo->y = parent->y + (parent->height - logo_height) / 2;
|
2023-02-14 19:10:38 +00:00
|
|
|
#endif
|
2009-10-19 21:19:30 +00:00
|
|
|
logo->width = logo_width;
|
|
|
|
logo->height = logo_height;
|
|
|
|
|
|
|
|
#ifdef USB_ENABLE_HID
|
2009-10-23 13:29:19 +00:00
|
|
|
if (usb_hid)
|
|
|
|
{
|
|
|
|
struct viewport *title = &usb_screen_vps->title;
|
2009-11-10 13:40:50 +00:00
|
|
|
int char_height = font_get(parent->font)->height;
|
2009-10-23 13:29:19 +00:00
|
|
|
*title = *parent;
|
|
|
|
title->y = logo->y + logo->height + char_height;
|
2009-11-10 13:40:50 +00:00
|
|
|
title->height = char_height;
|
|
|
|
/* try to fit logo and title to parent */
|
|
|
|
if (parent->y + parent->height < title->y + title->height)
|
|
|
|
{
|
|
|
|
logo->y = parent->y;
|
|
|
|
title->y = parent->y + logo->height;
|
|
|
|
}
|
2009-10-23 13:29:19 +00:00
|
|
|
}
|
2009-10-19 21:19:30 +00:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2009-11-10 20:13:24 +00:00
|
|
|
static void usb_screens_draw(struct usb_screen_vps_t *usb_screen_vps_ar)
|
2009-10-19 21:19:30 +00:00
|
|
|
{
|
2020-10-07 06:01:35 +00:00
|
|
|
struct viewport *last_vp;
|
2011-11-13 15:37:16 +00:00
|
|
|
static const struct bitmap* logos[NB_SCREENS] = {
|
|
|
|
&bm_usblogo,
|
2011-11-13 15:44:27 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
2011-11-13 15:37:16 +00:00
|
|
|
&bm_remote_usblogo,
|
|
|
|
#endif
|
|
|
|
};
|
2011-11-13 15:44:27 +00:00
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
struct screen *screen = &screens[i];
|
|
|
|
|
|
|
|
struct usb_screen_vps_t *usb_screen_vps = &usb_screen_vps_ar[i];
|
|
|
|
struct viewport *parent = &usb_screen_vps->parent;
|
|
|
|
struct viewport *logo = &usb_screen_vps->logo;
|
|
|
|
|
2020-10-07 06:01:35 +00:00
|
|
|
last_vp = screen->set_viewport(parent);
|
2009-10-19 21:19:30 +00:00
|
|
|
screen->clear_viewport();
|
2010-01-29 07:52:13 +00:00
|
|
|
screen->backlight_on();
|
2009-10-19 21:19:30 +00:00
|
|
|
|
|
|
|
screen->set_viewport(logo);
|
2011-11-13 15:37:16 +00:00
|
|
|
screen->bmp(logos[i], 0, 0);
|
|
|
|
if (i == SCREEN_MAIN)
|
2009-10-19 21:19:30 +00:00
|
|
|
{
|
|
|
|
#ifdef USB_ENABLE_HID
|
2009-10-23 13:29:19 +00:00
|
|
|
if (usb_hid)
|
|
|
|
{
|
2010-03-12 17:32:24 +00:00
|
|
|
char modestring[100];
|
2009-10-23 13:29:19 +00:00
|
|
|
screen->set_viewport(&usb_screen_vps->title);
|
|
|
|
usb_screen_vps->title.flags |= VP_FLAG_ALIGN_CENTER;
|
2010-03-12 17:32:24 +00:00
|
|
|
snprintf(modestring, sizeof(modestring), "%s: %s",
|
|
|
|
str(LANG_USB_KEYPAD_MODE),
|
|
|
|
str(keypad_mode_name_get()));
|
|
|
|
screen->puts_scroll(0, 0, modestring);
|
2009-10-23 13:29:19 +00:00
|
|
|
}
|
2009-10-19 21:19:30 +00:00
|
|
|
#endif /* USB_ENABLE_HID */
|
|
|
|
}
|
|
|
|
screen->set_viewport(parent);
|
|
|
|
|
2020-10-07 06:01:35 +00:00
|
|
|
screen->set_viewport(last_vp);
|
2010-01-29 07:52:13 +00:00
|
|
|
screen->update_viewport();
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2010-10-10 13:17:39 +00:00
|
|
|
void gui_usb_screen_run(bool early_usb)
|
2009-10-19 21:19:30 +00:00
|
|
|
{
|
2014-01-15 23:44:06 +00:00
|
|
|
(void) early_usb;
|
2009-10-19 21:19:30 +00:00
|
|
|
struct usb_screen_vps_t usb_screen_vps_ar[NB_SCREENS];
|
|
|
|
#if defined HAVE_TOUCHSCREEN
|
|
|
|
enum touchscreen_mode old_mode = touchscreen_get_mode();
|
|
|
|
|
|
|
|
/* TODO: Paint buttons on screens OR switch to point mode and use
|
|
|
|
* touchscreen as a touchpad to move the host's mouse cursor */
|
|
|
|
touchscreen_set_mode(TOUCHSCREEN_BUTTON);
|
|
|
|
#endif
|
|
|
|
|
2014-01-15 23:26:45 +00:00
|
|
|
push_current_activity(ACTIVITY_USBSCREEN);
|
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
#ifdef USB_ENABLE_HID
|
2009-10-23 13:29:19 +00:00
|
|
|
usb_hid = global_settings.usb_hid;
|
2009-10-19 21:19:30 +00:00
|
|
|
usb_keypad_mode = global_settings.usb_keypad_mode;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
struct screen *screen = &screens[i];
|
2014-03-18 11:24:44 +00:00
|
|
|
/* we might be coming from anywhere, and the originating screen
|
|
|
|
* can't be practically expected to cleanup the UI because
|
|
|
|
* we're invoked via default_event_handler(), therefore we make a
|
|
|
|
* generic cleanup here */
|
2009-10-19 21:19:30 +00:00
|
|
|
screen->set_viewport(NULL);
|
2014-03-18 11:24:44 +00:00
|
|
|
screen->scroll_stop();
|
2010-01-29 07:52:13 +00:00
|
|
|
usb_screen_fix_viewports(screen, &usb_screen_vps_ar[i]);
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|
|
|
|
|
2014-01-15 12:37:58 +00:00
|
|
|
/* update the UI before disabling fonts, this maximizes the propability
|
|
|
|
* that font cache lookups succeed during USB */
|
|
|
|
send_event(GUI_EVENT_ACTIONUPDATE, NULL);
|
|
|
|
if(!early_usb)
|
|
|
|
{
|
|
|
|
/* The font system leaves the .fnt fd's open, so we need for force close them all */
|
|
|
|
font_disable_all();
|
|
|
|
}
|
|
|
|
|
2011-12-06 00:58:01 +00:00
|
|
|
usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
while (1)
|
|
|
|
{
|
2009-11-10 20:13:24 +00:00
|
|
|
usb_screens_draw(usb_screen_vps_ar);
|
2009-10-19 21:19:30 +00:00
|
|
|
#ifdef SIMULATOR
|
|
|
|
if (button_get_w_tmo(HZ/2))
|
|
|
|
break;
|
|
|
|
send_event(GUI_EVENT_ACTIONUPDATE, NULL);
|
|
|
|
#else
|
|
|
|
if (handle_usb_events())
|
|
|
|
break;
|
|
|
|
#endif /* SIMULATOR */
|
|
|
|
}
|
|
|
|
|
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
const struct viewport* vp = NULL;
|
|
|
|
|
2020-07-17 14:31:31 +00:00
|
|
|
#if defined(USB_ENABLE_HID)
|
2009-10-23 13:29:19 +00:00
|
|
|
vp = usb_hid ? &usb_screen_vps_ar[i].title : NULL;
|
2009-10-19 21:19:30 +00:00
|
|
|
#endif
|
|
|
|
if (vp)
|
2013-04-03 14:33:23 +00:00
|
|
|
screens[i].scroll_stop_viewport(vp);
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|
|
|
|
#ifdef USB_ENABLE_HID
|
|
|
|
if (global_settings.usb_keypad_mode != usb_keypad_mode)
|
|
|
|
{
|
|
|
|
global_settings.usb_keypad_mode = usb_keypad_mode;
|
|
|
|
settings_save();
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
|
|
|
touchscreen_set_mode(old_mode);
|
|
|
|
#endif
|
|
|
|
|
2010-10-10 13:17:39 +00:00
|
|
|
if(!early_usb)
|
|
|
|
{
|
2014-01-15 12:37:58 +00:00
|
|
|
font_enable_all();
|
2010-10-10 13:17:39 +00:00
|
|
|
/* Not pretty, reload all settings so fonts are loaded again correctly */
|
|
|
|
settings_apply(true);
|
2012-07-17 18:55:14 +00:00
|
|
|
/* Reload playlist */
|
|
|
|
playlist_resume();
|
2010-10-10 13:17:39 +00:00
|
|
|
}
|
2010-06-21 20:19:30 +00:00
|
|
|
|
2009-10-19 21:19:30 +00:00
|
|
|
FOR_NB_SCREENS(i)
|
|
|
|
{
|
|
|
|
screens[i].backlight_on();
|
2010-01-29 07:52:13 +00:00
|
|
|
viewportmanager_theme_undo(i, false);
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|
2009-11-10 20:13:24 +00:00
|
|
|
|
2022-12-14 08:06:04 +00:00
|
|
|
pop_current_activity();
|
2009-10-19 21:19:30 +00:00
|
|
|
}
|