From 35e90a50040831d3ad918ad61614a78f668a1d97 Mon Sep 17 00:00:00 2001 From: "bernard.xiong" Date: Wed, 24 Feb 2010 16:05:37 +0000 Subject: [PATCH] add UI freeze when USB cable is connected. git-svn-id: https://rt-thread.googlecode.com/svn/trunk@443 bbd45198-f89e-11dd-88c7-29a3b14d5316 --- .../Libraries/Mass_Storage/src/usb_main.c | 5 ++ bsp/stm32_radio/player_bg.h | 1 + bsp/stm32_radio/player_ui.c | 56 ++++++++++++++++++- bsp/stm32_radio/player_ui.h | 1 + 4 files changed, 62 insertions(+), 1 deletion(-) diff --git a/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c b/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c index 81a079dc4f..ca975458b0 100644 --- a/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c +++ b/bsp/stm32_radio/Libraries/Mass_Storage/src/usb_main.c @@ -16,6 +16,7 @@ extern rt_device_t dev_spi_flash; extern unsigned long test_unit_ready_last; void msc_thread_entry(void *parameter) { + extern void player_ui_freeze(void); unsigned long test_unit_ready_start = rt_tick_get(); test_unit_ready_last = test_unit_ready_start; @@ -25,6 +26,10 @@ void msc_thread_entry(void *parameter) rt_thread_delay( RT_TICK_PER_SECOND ); } + + /* freeze player UI */ + player_ui_freeze(); + /* wait remove */ while(1) { diff --git a/bsp/stm32_radio/player_bg.h b/bsp/stm32_radio/player_bg.h index 715fcba86a..e5efd51a06 100644 --- a/bsp/stm32_radio/player_bg.h +++ b/bsp/stm32_radio/player_bg.h @@ -8,6 +8,7 @@ enum PLAYER_REQUEST_TYPE PLAYER_REQUEST_PLAY_SINGLE_FILE, PLAYER_REQUEST_PLAY_LIST, PLAYER_REQUEST_STOP, + PLAYER_REQUEST_FREEZE, }; struct player_request diff --git a/bsp/stm32_radio/player_ui.c b/bsp/stm32_radio/player_ui.c index 8f9a3e789c..a8029d5d45 100644 --- a/bsp/stm32_radio/player_ui.c +++ b/bsp/stm32_radio/player_ui.c @@ -3,6 +3,7 @@ #include #include +#include #include #include #include @@ -742,6 +743,44 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg } break; + case PLAYER_REQUEST_FREEZE: + { + /* stop play */ + if (player_is_playing() == RT_TRUE) + { + player_stop_req(); + next_step = PLAYER_STEP_STOP; + } + + /* delay some tick */ + rt_thread_delay(50); + + /* show a modal view */ + { + rtgui_view_t *view; + rtgui_label_t *label; + rtgui_rect_t rect = {0, 0, 150, 150}, container_rect; + + rtgui_graphic_driver_get_default_rect(&container_rect); + /* set centre */ + rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); + view = rtgui_view_create("USB"); + rtgui_workbench_add_view(workbench, view); + + /* set container to window rect */ + container_rect = rect; + + rect.x1 = 0; rect.y1 = 0; + rect.x2 = 120; rect.y2 = 20; + label = rtgui_label_create("USB Áª»úÖÐ..."); + rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); + rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); + rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); + + rtgui_view_show(view, RT_TRUE); + /* never reach hear */ + } + } default: break; } @@ -757,7 +796,8 @@ rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t * if (event->type == RTGUI_EVENT_KBD) { struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; - if ((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME) + if (((ekbd->type == RTGUI_KEYUP) && ekbd->key == RTGUIK_HOME) + && !RTGUI_WORKBENCH_IS_MODAL_MODE(workbench)) { /* active home view */ if (workbench->current_view != home_view) @@ -841,3 +881,17 @@ void player_ui_init() rt_thread_startup(player_ui_tid); } +void player_ui_freeze() +{ + struct rtgui_event_command ecmd; + + /* check whether UI starts. */ + if (home_view == RT_NULL || workbench == RT_NULL) return; + + RTGUI_EVENT_COMMAND_INIT(&ecmd); + ecmd.type = RTGUI_CMD_USER_INT; + ecmd.command_id = PLAYER_REQUEST_FREEZE; + + rtgui_thread_send(player_ui_tid, &ecmd.parent, sizeof(ecmd)); +} + diff --git a/bsp/stm32_radio/player_ui.h b/bsp/stm32_radio/player_ui.h index 4e657fc873..27ff3e6ed2 100644 --- a/bsp/stm32_radio/player_ui.h +++ b/bsp/stm32_radio/player_ui.h @@ -39,6 +39,7 @@ enum PLAYER_STEP /* init player ui */ void player_ui_init(void); +void player_ui_freeze(void); /* notification function, which invoked by player background thread */ void player_notify_play(void); -- GitLab