Kaynağa Gözat

add UI freeze when USB cable is connected.

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@443 bbd45198-f89e-11dd-88c7-29a3b14d5316
bernard.xiong 15 yıl önce
ebeveyn
işleme
35e90a5004

+ 5 - 0
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)
     {

+ 1 - 0
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

+ 55 - 1
bsp/stm32_radio/player_ui.c

@@ -3,6 +3,7 @@
 #include <rtgui/rtgui_system.h>
 
 #include <rtgui/widgets/view.h>
+#include <rtgui/widgets/label.h>
 #include <rtgui/widgets/list_view.h>
 #include <rtgui/widgets/workbench.h>
 #include <rtgui/widgets/filelist_view.h>
@@ -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));
+}
+

+ 1 - 0
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);