提交 a4ce0520 编写于 作者: wuyangyong's avatar wuyangyong

update radio_list_update by inkfish

git-svn-id: https://rt-thread.googlecode.com/svn/trunk@510 bbd45198-f89e-11dd-88c7-29a3b14d5316
上级 bfc473eb
...@@ -23,36 +23,38 @@ ...@@ -23,36 +23,38 @@
#define RADIO_FN "/radio.pls" #define RADIO_FN "/radio.pls"
const static char *time_bg_xpm[] = { const static char *time_bg_xpm[] =
"48 20 7 1", {
". c #007DC6", "48 20 7 1",
"+ c #0079C6", ". c #007DC6",
"@ c #0079BD", "+ c #0079C6",
"# c #0075BD", "@ c #0079BD",
"$ c #0071BD", "# c #0075BD",
"% c #0071B5", "$ c #0071BD",
"& c #006DB5", "% c #0071B5",
"................................................", "& c #006DB5",
"................................................", "................................................",
"................................................", "................................................",
"................................................", "................................................",
"................................................", "................................................",
"++++++++++++++++++++++++++++++++++++++++++++++++", "................................................",
"++++++++++++++++++++++++++++++++++++++++++++++++", "++++++++++++++++++++++++++++++++++++++++++++++++",
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", "++++++++++++++++++++++++++++++++++++++++++++++++",
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"################################################", "@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@",
"################################################", "################################################",
"################################################", "################################################",
"################################################", "################################################",
"$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$", "################################################",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", "$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$$",
"%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&", "%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%",
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&", "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&", "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"}; "&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&",
"&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&"
};
static struct rtgui_view* home_view; static struct rtgui_view* home_view;
static struct rtgui_list_view* function_view; static struct rtgui_list_view* function_view;
...@@ -70,98 +72,106 @@ void player_play_url(const char* url); ...@@ -70,98 +72,106 @@ void player_play_url(const char* url);
static void info_timer_timeout(rtgui_timer_t* timer, void* parameter) static void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
rtgui_color_t saved; rtgui_color_t saved;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view)); dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
if (dc == RT_NULL) return ; if (dc == RT_NULL) return ;
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)); saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255); RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(206, 231, 255);
rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212) / tinfo.duration, 75); rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212) / tinfo.duration, 75);
if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226) if ((player_mode == PLAYER_PLAY_RADIO) && ((tinfo.position * 212 + 14)/tinfo.duration) < 226)
{ {
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212) / tinfo.duration, 226, 75); rtgui_dc_draw_hline(dc, 14 + (tinfo.position * 212) / tinfo.duration, 226, 75);
} }
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
if (player_mode == PLAYER_PLAY_FILE) if (player_mode == PLAYER_PLAY_FILE)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
char line[32]; char line[32];
play_time++; play_time++;
rt_snprintf(line, sizeof(line), "%3d:%02d", play_time / 60, play_time % 60); rt_snprintf(line, sizeof(line), "%3d:%02d", play_time / 60, play_time % 60);
rect.x1 = 172; rect.y1 = 39; rect.x1 = 172;
rect.x2 = 220; rect.y2 = 59; rect.y1 = 39;
rtgui_image_blit(time_bg_image, dc, &rect); rect.x2 = 220;
rtgui_dc_draw_text(dc, line, &rect); rect.y2 = 59;
} rtgui_image_blit(time_bg_image, dc, &rect);
rtgui_dc_draw_text(dc, line, &rect);
}
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
static void player_update_tag_info(struct rtgui_dc* dc) static void player_update_tag_info(struct rtgui_dc* dc)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
char line[32]; char line[32];
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *background; rtgui_image_t *background;
saved = rtgui_dc_get_color(dc); saved = rtgui_dc_get_color(dc);
rtgui_dc_set_color(dc, black); rtgui_dc_set_color(dc, black);
rect.x1 = 0; rect.y1 = 0; rect.x1 = 0;
rect.x2 = 240; rect.y2 = 65; rect.y1 = 0;
/* draw background */ rect.x2 = 240;
rect.y2 = 65;
/* draw background */
background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE); background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
if (background != RT_NULL) if (background != RT_NULL)
{ {
rtgui_image_blit(background, dc, &rect); rtgui_image_blit(background, dc, &rect);
rtgui_image_destroy(background); rtgui_image_destroy(background);
background = RT_NULL; background = RT_NULL;
} }
else else
{ {
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
} }
/* draw playing information */ /* draw playing information */
rect.x1 = 28; rect.y1 = 12; rect.x1 = 28;
rect.x2 = 220; rect.y2 = rect.y1 + 16; rect.y1 = 12;
if (player_mode == PLAYER_STOP) rect.x2 = 220;
{ rect.y2 = rect.y1 + 16;
rt_snprintf(line, sizeof(line), "网络收音机"); if (player_mode == PLAYER_STOP)
rtgui_dc_draw_text(dc, line, &rect); {
} rt_snprintf(line, sizeof(line), "网络收音机");
else rtgui_dc_draw_text(dc, line, &rect);
rtgui_dc_draw_text(dc, tinfo.title, &rect); }
else
rect.x1 = 28; rect.y1 = 39; rtgui_dc_draw_text(dc, tinfo.title, &rect);
rect.x2 = 220; rect.y2 = 59;
if (player_mode == PLAYER_STOP) rect.x1 = 28;
{ rect.y1 = 39;
rt_snprintf(line, sizeof(line), "radio.rt-thread.org"); rect.x2 = 220;
rtgui_dc_draw_text(dc, line, &rect); rect.y2 = 59;
} if (player_mode == PLAYER_STOP)
else {
rtgui_dc_draw_text(dc, tinfo.artist, &rect); rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
rtgui_dc_draw_text(dc, line, &rect);
if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE) }
{ else
play_time = 0; rtgui_dc_draw_text(dc, tinfo.artist, &rect);
if ((tinfo.duration != 0) && player_mode == PLAYER_PLAY_FILE)
{
play_time = 0;
rect.x1 = 172; rect.x1 = 172;
rt_snprintf(line, sizeof(line), " 0:00"); rt_snprintf(line, sizeof(line), " 0:00");
rtgui_dc_draw_text(dc, line, &rect); rtgui_dc_draw_text(dc, line, &rect);
} }
rtgui_dc_set_color(dc, saved); rtgui_dc_set_color(dc, saved);
} }
static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size) static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
...@@ -173,12 +183,12 @@ static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size) ...@@ -173,12 +183,12 @@ static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
if (length > 0) if (length > 0)
{ {
pos = strstr(line, "\r\n"); pos = strstr(line, "\r\n");
if (pos == RT_NULL) if (pos == RT_NULL)
{ {
pos = strstr(line, "\n"); pos = strstr(line, "\n");
next = pos ++; next = pos ++;
} }
else next = pos + 2; else next = pos + 2;
if (pos != RT_NULL) if (pos != RT_NULL)
{ {
...@@ -197,81 +207,90 @@ static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size) ...@@ -197,81 +207,90 @@ static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
static void function_play_radio(void* parameter) static void function_play_radio(void* parameter)
{ {
struct station_list* list; struct station_list* list;
struct station_item* item; struct station_item* item;
list = station_list_create(RADIO_FN); list = station_list_create(RADIO_FN);
if (list != RT_NULL) if (list != RT_NULL)
{ {
item = station_list_select(list, workbench); item = station_list_select(list, workbench);
if (item != RT_NULL) if (item != RT_NULL)
{ {
player_play_url(item->url); player_play_url(item->url);
} }
station_list_destroy(list); station_list_destroy(list);
} }
} }
static void function_radio_list_update(void* parameter) static void function_radio_list_update(void* parameter)
{ {
extern void update_radio_list_req(void); extern void update_radio_list_req(void);
extern void update_radio_thread(void* parameter); extern void update_radio_thread(void* parameter);
extern rt_mq_t update_radio_mq; extern rt_mq_t update_radio_mq;
rt_thread_t update_radio_list_thread; rt_thread_t update_radio_list_thread;
rtgui_view_t *view;
if(update_radio_mq == RT_NULL) extern rtgui_view_t* update_radio_list_view_create(rtgui_workbench_t* workbench);
{
update_radio_mq = rt_mq_create("updateRadioList", sizeof(struct player_request), if(update_radio_mq == RT_NULL)
1, RT_IPC_FLAG_FIFO); {
RT_ASSERT(update_radio_mq != RT_NULL); update_radio_mq = rt_mq_create("updateRadioList", sizeof(struct player_request),
1, RT_IPC_FLAG_FIFO);
update_radio_list_thread = rt_thread_create("update_bg", update_radio_thread, RT_NULL, RT_ASSERT(update_radio_mq != RT_NULL);
1024 ,20, 5);
update_radio_list_thread = rt_thread_create("update_bg", update_radio_thread, RT_NULL,
if (update_radio_list_thread == RT_NULL) rt_kprintf("updateRadioList thread init failed\n"); 1024 ,20, 5);
else
{ if (update_radio_list_thread == RT_NULL) rt_kprintf("updateRadioList thread init failed\n");
rt_thread_startup(update_radio_list_thread); else
update_radio_list_req(); {
} rt_thread_startup(update_radio_list_thread);
} update_radio_list_req();
return; }
}
view = update_radio_list_view_create(workbench);
if (view != RT_NULL)
{
rtgui_view_show(view, RT_FALSE);
}
return;
} }
static void function_filelist(void* parameter) static void function_filelist(void* parameter)
{ {
rtgui_rect_t rect; rtgui_rect_t rect;
rtgui_filelist_view_t *view; rtgui_filelist_view_t *view;
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect); view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL) if (view != RT_NULL)
{ {
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK) if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
{ {
char fn[64]; char fn[64];
/* get open file */ /* get open file */
rt_snprintf(fn, 64, "%s/%s", view->current_directory, rt_snprintf(fn, 64, "%s/%s", view->current_directory,
view->items[view->current_item].name); view->items[view->current_item].name);
if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL || if (strstr(view->items[view->current_item].name , ".mp3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".MP3") != RT_NULL || strstr(view->items[view->current_item].name , ".MP3") != RT_NULL ||
strstr(view->items[view->current_item].name , ".wav") != RT_NULL || strstr(view->items[view->current_item].name , ".wav") != RT_NULL ||
strstr(view->items[view->current_item].name , ".WAV") != RT_NULL) strstr(view->items[view->current_item].name , ".WAV") != RT_NULL)
{ {
/* clear old play list */ /* clear old play list */
play_list_clear(); play_list_clear();
play_list_append(fn); play_list_append(fn);
player_mode = PLAYER_PLAY_FILE; player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_STOP; next_step = PLAYER_STEP_STOP;
player_play_file(play_list_start()); player_play_file(play_list_start());
} }
else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL || else if (strstr(view->items[view->current_item].name , ".m3u") != RT_NULL ||
strstr(view->items[view->current_item].name , ".M3U") != RT_NULL) strstr(view->items[view->current_item].name , ".M3U") != RT_NULL)
{ {
/* read all of music filename to a list */ /* read all of music filename to a list */
int fd; int fd;
...@@ -283,194 +302,197 @@ static void function_filelist(void* parameter) ...@@ -283,194 +302,197 @@ static void function_filelist(void* parameter)
rt_uint32_t length; rt_uint32_t length;
length = read_line(fd, line, sizeof(line)); length = read_line(fd, line, sizeof(line));
/* clear old play list */ /* clear old play list */
play_list_clear(); play_list_clear();
do do
{ {
length = read_line(fd, line, sizeof(line)); length = read_line(fd, line, sizeof(line));
if (length > 0) if (length > 0)
{ {
if (strstr(line, "http:") != RT_NULL) if (strstr(line, "http:") != RT_NULL)
{ {
play_list_append(line); play_list_append(line);
} }
else if (line[0] != '/') else if (line[0] != '/')
{ {
rt_snprintf(fn, sizeof(fn), "%s/%s", view->current_directory, line); rt_snprintf(fn, sizeof(fn), "%s/%s", view->current_directory, line);
play_list_append(fn); play_list_append(fn);
} }
else play_list_append(line); else play_list_append(line);
} }
} while (length > 0); }
while (length > 0);
close(fd); close(fd);
if (play_list_items() > 0) if (play_list_items() > 0)
{ {
player_mode = PLAYER_PLAY_FILE; player_mode = PLAYER_PLAY_FILE;
next_step = PLAYER_STEP_NEXT; next_step = PLAYER_STEP_NEXT;
player_play_file(play_list_start()); player_play_file(play_list_start());
} }
} }
} }
} }
/* destroy view */ /* destroy view */
rtgui_filelist_view_destroy(view); rtgui_filelist_view_destroy(view);
} }
return; return;
} }
static void function_device(void* parameter) static void function_device(void* parameter)
{ {
rtgui_view_t *view; rtgui_view_t *view;
extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench); extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench);
view = device_view_create(workbench); view = device_view_create(workbench);
if (view != RT_NULL) if (view != RT_NULL)
{ {
rtgui_view_show(view, RT_FALSE); rtgui_view_show(view, RT_FALSE);
} }
return; return;
} }
static void function_player(void* parameter) static void function_player(void* parameter)
{ {
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
return; return;
} }
static void function_show_picure(void* parameter) static void function_show_picure(void* parameter)
{ {
rtgui_view_t *view; rtgui_view_t *view;
view = picture_view_create(workbench); view = picture_view_create(workbench);
if (view != RT_NULL) if (view != RT_NULL)
{ {
rtgui_view_show(view, RT_TRUE); rtgui_view_show(view, RT_TRUE);
rtgui_view_destroy(view); rtgui_view_destroy(view);
} }
return; return;
} }
void function_action(void* parameter) void function_action(void* parameter)
{ {
rt_kprintf("item action!\n"); rt_kprintf("item action!\n");
return; return;
} }
void function_cable(void* parameter) void function_cable(void* parameter)
{ {
extern void USB_cable(void); extern void USB_cable(void);
USB_cable(); USB_cable();
} }
const struct rtgui_list_item function_list[] = const struct rtgui_list_item function_list[] =
{ {
{"选择电台", RT_NULL, function_play_radio, RT_NULL}, {"选择电台", RT_NULL, function_play_radio, RT_NULL},
{"更新电台", RT_NULL, function_radio_list_update, RT_NULL}, {"更新电台", RT_NULL, function_radio_list_update, RT_NULL},
{"播放文件", RT_NULL, function_filelist, RT_NULL}, {"播放文件", RT_NULL, function_filelist, RT_NULL},
{"浏览图片", RT_NULL, function_show_picure, RT_NULL}, {"浏览图片", RT_NULL, function_show_picure, RT_NULL},
{"设备信息", RT_NULL, function_device, RT_NULL}, {"设备信息", RT_NULL, function_device, RT_NULL},
{"选项设置", RT_NULL, function_action, RT_NULL}, {"选项设置", RT_NULL, function_action, RT_NULL},
{"USB 联机", RT_NULL, function_cable, RT_NULL}, {"USB 联机", RT_NULL, function_cable, RT_NULL},
{"返回播放器", RT_NULL, function_player, RT_NULL}, {"返回播放器", RT_NULL, function_player, RT_NULL},
}; };
void player_set_position(rt_uint32_t position) void player_set_position(rt_uint32_t position)
{ {
if (player_mode != PLAYER_PLAY_RADIO) if (player_mode != PLAYER_PLAY_RADIO)
{ {
tinfo.position = position / (tinfo.bit_rate / 8); tinfo.position = position / (tinfo.bit_rate / 8);
} }
else else
{ {
tinfo.position = position; tinfo.position = position;
} }
} }
void player_set_title(const char* title) void player_set_title(const char* title)
{ {
strncpy(tinfo.title, title, 40); strncpy(tinfo.title, title, 40);
} }
void player_set_buffer_status(rt_bool_t buffering) void player_set_buffer_status(rt_bool_t buffering)
{ {
if (buffering == RT_TRUE) if (buffering == RT_TRUE)
strncpy(tinfo.artist, "缓冲中...", 40); strncpy(tinfo.artist, "缓冲中...", 40);
else else
strncpy(tinfo.artist, "播放中...", 40); strncpy(tinfo.artist, "播放中...", 40);
} }
enum PLAYER_MODE player_get_mode() enum PLAYER_MODE player_get_mode()
{ {
return player_mode; return player_mode;
} }
void player_play_file(const char* fn) void player_play_file(const char* fn)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
rtgui_color_t saved; rtgui_color_t saved;
rt_bool_t is_mp3; rt_bool_t is_mp3;
is_mp3 = RT_FALSE; is_mp3 = RT_FALSE;
if (strstr(fn, ".mp3") != RT_NULL || if (strstr(fn, ".mp3") != RT_NULL ||
strstr(fn, ".MP3") != RT_NULL) strstr(fn, ".MP3") != RT_NULL)
is_mp3 = RT_TRUE; is_mp3 = RT_TRUE;
else if (strstr(fn, ".wav") != RT_NULL || else if (strstr(fn, ".wav") != RT_NULL ||
strstr(fn, ".wav") != RT_NULL) strstr(fn, ".wav") != RT_NULL)
is_mp3 = RT_FALSE; is_mp3 = RT_FALSE;
else return; /* not supported audio format */ else return; /* not supported audio format */
if (is_mp3 == RT_TRUE) if (is_mp3 == RT_TRUE)
{ {
/* get music tag information */ /* get music tag information */
mp3_get_info(fn, &tinfo); mp3_get_info(fn, &tinfo);
if (tinfo.title[0] == '\0') if (tinfo.title[0] == '\0')
rt_snprintf(tinfo.title, sizeof(tinfo.title), "<未知名音乐>"); rt_snprintf(tinfo.title, sizeof(tinfo.title), "<未知名音乐>");
} }
else else
{ {
/* wav file */ /* wav file */
rt_snprintf(tinfo.title, sizeof(tinfo.title), "<未知名音乐>"); rt_snprintf(tinfo.title, sizeof(tinfo.title), "<未知名音乐>");
rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav音乐>"); rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav音乐>");
tinfo.duration = 0; tinfo.duration = 0;
} }
/* set player mode */ /* set player mode */
player_mode = PLAYER_PLAY_FILE; player_mode = PLAYER_PLAY_FILE;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view)); dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
if (dc != RT_NULL) if (dc != RT_NULL)
{ {
rtgui_rect_t play_rect; rtgui_rect_t play_rect;
rtgui_image_t *button; rtgui_image_t *button;
/* update tag information */ /* update tag information */
player_update_tag_info(dc); player_update_tag_info(dc);
/* reset progress bar */ /* reset progress bar */
saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)); saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14, 226, 75); rtgui_dc_draw_hline(dc, 14, 226, 75);
RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved; RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
/* update play button */ /* update play button */
button = rtgui_image_create_from_mem("hdc", button = rtgui_image_create_from_mem("hdc",
play_hdh, sizeof(play_hdh), RT_FALSE); play_hdh, sizeof(play_hdh), RT_FALSE);
play_rect.x1 = 32; play_rect.y1 = 92; play_rect.x1 = 32;
play_rect.x2 = 61; play_rect.y2 = 114; play_rect.y1 = 92;
play_rect.x2 = 61;
play_rect.y2 = 114;
rtgui_image_blit(button, dc, &play_rect); rtgui_image_blit(button, dc, &play_rect);
rtgui_image_destroy(button); rtgui_image_destroy(button);
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
...@@ -479,35 +501,37 @@ void player_play_file(const char* fn) ...@@ -479,35 +501,37 @@ void player_play_file(const char* fn)
void player_play_url(const char* url) void player_play_url(const char* url)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
/* set music tag information */ /* set music tag information */
strncpy(tinfo.title, "网络电台", 40); strncpy(tinfo.title, "网络电台", 40);
player_set_buffer_status(RT_TRUE); player_set_buffer_status(RT_TRUE);
tinfo.duration = 320 * 1024; /* 320 k */ tinfo.duration = 320 * 1024; /* 320 k */
/* set player mode */ /* set player mode */
player_mode = PLAYER_PLAY_RADIO; player_mode = PLAYER_PLAY_RADIO;
dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view)); dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
if (dc != RT_NULL) if (dc != RT_NULL)
{ {
rtgui_rect_t play_rect; rtgui_rect_t play_rect;
rtgui_image_t *button; rtgui_image_t *button;
/* update tag information */ /* update tag information */
player_update_tag_info(dc); player_update_tag_info(dc);
/* update play button */ /* update play button */
button = rtgui_image_create_from_mem("hdc", button = rtgui_image_create_from_mem("hdc",
play_hdh, sizeof(play_hdh), RT_FALSE); play_hdh, sizeof(play_hdh), RT_FALSE);
play_rect.x1 = 32; play_rect.y1 = 92; play_rect.x1 = 32;
play_rect.x2 = 61; play_rect.y2 = 114; play_rect.y1 = 92;
play_rect.x2 = 61;
play_rect.y2 = 114;
rtgui_image_blit(button, dc, &play_rect); rtgui_image_blit(button, dc, &play_rect);
rtgui_image_destroy(button); rtgui_image_destroy(button);
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
...@@ -516,306 +540,324 @@ void player_play_url(const char* url) ...@@ -516,306 +540,324 @@ void player_play_url(const char* url)
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event) static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{ {
if (event->type == RTGUI_EVENT_PAINT) if (event->type == RTGUI_EVENT_PAINT)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
struct rtgui_rect rect; struct rtgui_rect rect;
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *background; rtgui_image_t *background;
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE; if (dc == RT_NULL) return RT_FALSE;
rtgui_widget_get_rect(widget, &rect); rtgui_widget_get_rect(widget, &rect);
saved = RTGUI_WIDGET_FOREGROUND(widget); saved = RTGUI_WIDGET_FOREGROUND(widget);
/* draw background */ /* draw background */
background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE); background = rtgui_image_create_from_file("hdc", "/resource/bg.hdc", RT_FALSE);
if (background != RT_NULL) if (background != RT_NULL)
{ {
rtgui_image_t *play; rtgui_image_t *play;
rtgui_rect_t play_rect; rtgui_rect_t play_rect;
rtgui_image_blit(background, dc, &rect); rtgui_image_blit(background, dc, &rect);
rtgui_image_destroy(background); rtgui_image_destroy(background);
background = RT_NULL; background = RT_NULL;
if (player_mode == PLAYER_STOP) if (player_mode == PLAYER_STOP)
play = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE); play = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE);
else else
play = rtgui_image_create_from_mem("hdc", play_hdh, sizeof(play_hdh), RT_FALSE); play = rtgui_image_create_from_mem("hdc", play_hdh, sizeof(play_hdh), RT_FALSE);
play_rect.x1 = 32; play_rect.y1 = 92; play_rect.x1 = 32;
play_rect.x2 = 61; play_rect.y2 = 114; play_rect.y1 = 92;
play_rect.x2 = 61;
play_rect.y2 = 114;
rtgui_image_blit(play, dc, &play_rect); rtgui_image_blit(play, dc, &play_rect);
rtgui_image_destroy(play); rtgui_image_destroy(play);
} }
else else
{ {
rtgui_dc_fill_rect(dc, &rect); rtgui_dc_fill_rect(dc, &rect);
} }
/* draw playing information */ /* draw playing information */
rtgui_dc_set_color(dc, black); rtgui_dc_set_color(dc, black);
{ {
char line[32]; char line[32];
rect.x1 = 28; rect.y1 = 12; rect.x1 = 28;
rect.x2 = 220; rect.y2 = rect.y1 + 16; rect.y1 = 12;
if (player_mode == PLAYER_STOP) rect.x2 = 220;
{ rect.y2 = rect.y1 + 16;
rt_snprintf(line, sizeof(line), "网络收音机"); if (player_mode == PLAYER_STOP)
rtgui_dc_draw_text(dc, line, &rect); {
} rt_snprintf(line, sizeof(line), "网络收音机");
else rtgui_dc_draw_text(dc, line, &rect);
rtgui_dc_draw_text(dc, tinfo.title, &rect); }
else
rect.x1 = 28; rect.y1 = 39; rtgui_dc_draw_text(dc, tinfo.title, &rect);
rect.x2 = 170; rect.y2 = 59;
if (player_mode == PLAYER_STOP) rect.x1 = 28;
{ rect.y1 = 39;
rect.x2 = 220; rect.x2 = 170;
rt_snprintf(line, sizeof(line), "radio.rt-thread.org"); rect.y2 = 59;
rtgui_dc_draw_text(dc, line, &rect); if (player_mode == PLAYER_STOP)
} {
else rect.x2 = 220;
rtgui_dc_draw_text(dc, tinfo.artist, &rect); rt_snprintf(line, sizeof(line), "radio.rt-thread.org");
rtgui_dc_draw_text(dc, line, &rect);
if ((tinfo.duration != 0) && (player_mode == PLAYER_PLAY_FILE)) }
{ else
rt_uint32_t t = player_mode == PLAYER_STOP ? tinfo.duration : play_time; rtgui_dc_draw_text(dc, tinfo.artist, &rect);
rect.x1 = 172; rect.x2 = 220; if ((tinfo.duration != 0) && (player_mode == PLAYER_PLAY_FILE))
rt_snprintf(line, sizeof(line), "%3d:%02d", t / 60, t % 60); {
rtgui_dc_draw_text(dc, line, &rect); rt_uint32_t t = player_mode == PLAYER_STOP ? tinfo.duration : play_time;
}
rect.x1 = 172;
rect.x2 = 220;
rt_snprintf(line, sizeof(line), "%3d:%02d", t / 60, t % 60);
rtgui_dc_draw_text(dc, line, &rect);
}
} }
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14, 226, 75); rtgui_dc_draw_hline(dc, 14, 226, 75);
RTGUI_WIDGET_FOREGROUND(widget) = saved; RTGUI_WIDGET_FOREGROUND(widget) = saved;
if (player_mode == PLAYER_PLAY_FILE) if (player_mode == PLAYER_PLAY_FILE)
{ {
char line[32]; char line[32];
rt_uint32_t index; rt_uint32_t index;
struct play_item* item; struct play_item* item;
rect.x1 = 20; rect.y1 = 150; rect.x1 = 20;
rect.x2 = 170; rect.y2 = 168; rect.y1 = 150;
for (index = 0; index < play_list_items() && index < 8; index ++) rect.x2 = 170;
{ rect.y2 = 168;
item = play_list_item(index); for (index = 0; index < play_list_items() && index < 8; index ++)
rtgui_dc_draw_text(dc, item->title, &rect); {
item = play_list_item(index);
rect.x1 = 172; rect.x2 = 220; rtgui_dc_draw_text(dc, item->title, &rect);
rt_snprintf(line, sizeof(line), "%3d:%02d", item->duration / 60, item->duration % 60);
rtgui_dc_draw_text(dc, line, &rect); rect.x1 = 172;
rect.x2 = 220;
/* move to next item */ rt_snprintf(line, sizeof(line), "%3d:%02d", item->duration / 60, item->duration % 60);
rect.x1 = 20; rect.x2 = 170; rtgui_dc_draw_text(dc, line, &rect);
rect.y1 += 18; rect.y2 += 18;
} /* move to next item */
} rect.x1 = 20;
rtgui_dc_end_drawing(dc); rect.x2 = 170;
rect.y1 += 18;
return RT_FALSE; rect.y2 += 18;
} }
else if (event->type == RTGUI_EVENT_KBD) }
{ rtgui_dc_end_drawing(dc);
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN) return RT_FALSE;
{ }
switch (ekbd->key) else if (event->type == RTGUI_EVENT_KBD)
{ {
case RTGUIK_RIGHT: struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN)
{
switch (ekbd->key)
{
case RTGUIK_RIGHT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0) if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{ {
player_stop_req(); player_stop_req();
next_step = PLAYER_STEP_NEXT; next_step = PLAYER_STEP_NEXT;
} }
break; break;
case RTGUIK_LEFT: case RTGUIK_LEFT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0) if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{ {
player_stop_req(); player_stop_req();
next_step = PLAYER_STEP_PREV; next_step = PLAYER_STEP_PREV;
} }
break; break;
case RTGUIK_RETURN: case RTGUIK_RETURN:
if (player_is_playing() == RT_TRUE) if (player_is_playing() == RT_TRUE)
{ {
player_stop_req(); player_stop_req();
next_step = PLAYER_STEP_STOP; next_step = PLAYER_STEP_STOP;
} }
else else
{ {
if ((player_mode == PLAYER_STOP) && (play_list_items() > 0)) if ((player_mode == PLAYER_STOP) && (play_list_items() > 0))
{ {
next_step = PLAYER_STEP_NEXT; next_step = PLAYER_STEP_NEXT;
player_play_file(play_list_current_item()); player_play_file(play_list_current_item());
} }
} }
break; break;
case RTGUIK_DOWN: case RTGUIK_DOWN:
rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE); rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
break; break;
} }
} }
return RT_FALSE; return RT_FALSE;
} }
else if (event->type == RTGUI_EVENT_COMMAND) else if (event->type == RTGUI_EVENT_COMMAND)
{ {
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event; struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
switch (ecmd->command_id) switch (ecmd->command_id)
{ {
case PLAYER_REQUEST_PLAY_SINGLE_FILE: case PLAYER_REQUEST_PLAY_SINGLE_FILE:
case PLAYER_REQUEST_PLAY_LIST: case PLAYER_REQUEST_PLAY_LIST:
rtgui_timer_start(info_timer); rtgui_timer_start(info_timer);
break; break;
case PLAYER_REQUEST_STOP: case PLAYER_REQUEST_STOP:
{ {
rtgui_timer_stop(info_timer); rtgui_timer_stop(info_timer);
switch (next_step) switch (next_step)
{ {
case PLAYER_STEP_STOP: case PLAYER_STEP_STOP:
// #define TEST_MODE // #define TEST_MODE
#ifdef TEST_MODE #ifdef TEST_MODE
player_play_file(play_list_start()); player_play_file(play_list_start());
next_step = PLAYER_STEP_STOP; next_step = PLAYER_STEP_STOP;
#else #else
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *button; rtgui_image_t *button;
rtgui_rect_t play_rect; rtgui_rect_t play_rect;
player_mode = PLAYER_STOP; player_mode = PLAYER_STOP;
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE; if (dc == RT_NULL) return RT_FALSE;
player_update_tag_info(dc); player_update_tag_info(dc);
saved = RTGUI_WIDGET_FOREGROUND(widget); saved = RTGUI_WIDGET_FOREGROUND(widget);
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14, 226, 75); rtgui_dc_draw_hline(dc, 14, 226, 75);
/* update play button */ /* update play button */
button = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE); button = rtgui_image_create_from_mem("hdc", stop_hdh, sizeof(stop_hdh), RT_FALSE);
play_rect.x1 = 32; play_rect.y1 = 92; play_rect.x1 = 32;
play_rect.x2 = 61; play_rect.y2 = 114; play_rect.y1 = 92;
rtgui_image_blit(button, dc, &play_rect); play_rect.x2 = 61;
rtgui_image_destroy(button); play_rect.y2 = 114;
rtgui_image_blit(button, dc, &play_rect);
rtgui_image_destroy(button);
RTGUI_WIDGET_FOREGROUND(widget) = saved; RTGUI_WIDGET_FOREGROUND(widget) = saved;
rtgui_dc_end_drawing(dc); rtgui_dc_end_drawing(dc);
} }
#endif #endif
break; break;
case PLAYER_STEP_NEXT: case PLAYER_STEP_NEXT:
if (play_list_is_end() == RT_TRUE) if (play_list_is_end() == RT_TRUE)
{ {
struct rtgui_dc* dc; struct rtgui_dc* dc;
rtgui_color_t saved; rtgui_color_t saved;
rtgui_image_t *button; rtgui_image_t *button;
rtgui_rect_t play_rect; rtgui_rect_t play_rect;
/* set stat */ /* set stat */
next_step = PLAYER_STEP_STOP; next_step = PLAYER_STEP_STOP;
player_mode = PLAYER_STOP; player_mode = PLAYER_STOP;
/* update UI */ /* update UI */
dc = rtgui_dc_begin_drawing(widget); dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE; if (dc == RT_NULL) return RT_FALSE;
player_update_tag_info(dc); player_update_tag_info(dc);
saved = RTGUI_WIDGET_FOREGROUND(widget); saved = RTGUI_WIDGET_FOREGROUND(widget);
RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16); RTGUI_WIDGET_FOREGROUND(widget) = RTGUI_RGB(82, 199, 16);
rtgui_dc_draw_hline(dc, 14, 226, 75); rtgui_dc_draw_hline(dc, 14, 226, 75);
/* update play button */ /* update play button */
button = rtgui_image_create_from_mem("hdc", button = rtgui_image_create_from_mem("hdc",
stop_hdh, sizeof(stop_hdh), RT_FALSE); stop_hdh, sizeof(stop_hdh), RT_FALSE);
play_rect.x1 = 32; play_rect.y1 = 92; play_rect.x1 = 32;
play_rect.x2 = 61; play_rect.y2 = 114; play_rect.y1 = 92;
rtgui_image_blit(button, dc, &play_rect); play_rect.x2 = 61;
rtgui_image_destroy(button); play_rect.y2 = 114;
rtgui_image_blit(button, dc, &play_rect);
RTGUI_WIDGET_FOREGROUND(widget) = saved; rtgui_image_destroy(button);
rtgui_dc_end_drawing(dc);
} RTGUI_WIDGET_FOREGROUND(widget) = saved;
else rtgui_dc_end_drawing(dc);
{ }
player_play_file(play_list_next()); else
next_step = PLAYER_STEP_NEXT; {
} player_play_file(play_list_next());
break; next_step = PLAYER_STEP_NEXT;
}
case PLAYER_STEP_PREV: break;
player_play_file(play_list_prev());
next_step = PLAYER_STEP_NEXT; case PLAYER_STEP_PREV:
break; player_play_file(play_list_prev());
}; next_step = PLAYER_STEP_NEXT;
} break;
break; };
}
case PLAYER_REQUEST_FREEZE: break;
{
/* stop play */ case PLAYER_REQUEST_FREEZE:
if (player_is_playing() == RT_TRUE) {
{ /* stop play */
player_stop_req(); if (player_is_playing() == RT_TRUE)
next_step = PLAYER_STEP_STOP; {
} player_stop_req();
next_step = PLAYER_STEP_STOP;
/* delay some tick */ }
rt_thread_delay(50);
/* delay some tick */
/* show a modal view */ rt_thread_delay(50);
{
rtgui_view_t *view; /* show a modal view */
rtgui_label_t *label; {
rtgui_rect_t rect = {0, 0, 150, 150}, container_rect; rtgui_view_t *view;
rtgui_label_t *label;
rtgui_graphic_driver_get_default_rect(&container_rect); rtgui_rect_t rect = {0, 0, 150, 150}, container_rect;
/* set centre */
rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); rtgui_graphic_driver_get_default_rect(&container_rect);
view = rtgui_view_create("USB"); /* set centre */
rtgui_workbench_add_view(workbench, view); rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
view = rtgui_view_create("USB");
/* set container to window rect */ rtgui_workbench_add_view(workbench, view);
container_rect = rect;
/* set container to window rect */
rect.x1 = 0; rect.y1 = 0; container_rect = rect;
rect.x2 = 120; rect.y2 = 20;
label = rtgui_label_create("USB 联机中..."); rect.x1 = 0;
rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL); rect.y1 = 0;
rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); rect.x2 = 120;
rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label)); rect.y2 = 20;
label = rtgui_label_create("USB 联机中...");
rtgui_view_show(view, RT_TRUE); rtgui_rect_moveto_align(&container_rect, &rect, RTGUI_ALIGN_CENTER_HORIZONTAL | RTGUI_ALIGN_CENTER_VERTICAL);
/* never reach hear */ rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect);
} rtgui_container_add_child(RTGUI_CONTAINER(view), RTGUI_WIDGET(label));
}
default: rtgui_view_show(view, RT_TRUE);
break; /* never reach hear */
} }
}
return RT_FALSE; default:
} break;
}
return rtgui_view_event_handler(widget, event);
return RT_FALSE;
}
return rtgui_view_event_handler(widget, event);
} }
rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event) rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *event)
...@@ -824,7 +866,7 @@ rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t * ...@@ -824,7 +866,7 @@ rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *
{ {
struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event; 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)) && !RTGUI_WORKBENCH_IS_MODAL_MODE(workbench))
{ {
/* active home view */ /* active home view */
if (workbench->current_view != home_view) if (workbench->current_view != home_view)
...@@ -840,44 +882,44 @@ rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t * ...@@ -840,44 +882,44 @@ rt_bool_t player_workbench_event_handler(rtgui_widget_t *widget, rtgui_event_t *
static void player_entry(void* parameter) static void player_entry(void* parameter)
{ {
rt_mq_t mq; rt_mq_t mq;
rtgui_rect_t rect; rtgui_rect_t rect;
mq = rt_mq_create("ply_ui", 256, 4, RT_IPC_FLAG_FIFO); mq = rt_mq_create("ply_ui", 256, 4, RT_IPC_FLAG_FIFO);
rtgui_thread_register(rt_thread_self(), mq); rtgui_thread_register(rt_thread_self(), mq);
/* create information timer */ /* create information timer */
info_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, info_timer_timeout, RT_NULL); info_timer = rtgui_timer_create(RT_TICK_PER_SECOND, RT_TIMER_FLAG_PERIODIC, info_timer_timeout, RT_NULL);
time_bg_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t *) time_bg_xpm, sizeof(time_bg_xpm), RT_TRUE); time_bg_image = rtgui_image_create_from_mem("xpm", (rt_uint8_t *) time_bg_xpm, sizeof(time_bg_xpm), RT_TRUE);
workbench = rtgui_workbench_create("main", "workbench"); workbench = rtgui_workbench_create("main", "workbench");
if (workbench == RT_NULL) return; if (workbench == RT_NULL) return;
rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), player_workbench_event_handler); rtgui_widget_set_event_handler(RTGUI_WIDGET(workbench), player_workbench_event_handler);
/* add home view */ /* add home view */
home_view = rtgui_view_create("Home"); home_view = rtgui_view_create("Home");
rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler); rtgui_widget_set_event_handler(RTGUI_WIDGET(home_view), home_view_event_handler);
rtgui_workbench_add_view(workbench, home_view); rtgui_workbench_add_view(workbench, home_view);
/* this view can be focused */ /* this view can be focused */
RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE; RTGUI_WIDGET(home_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* set widget focus */ /* set widget focus */
rtgui_widget_focus(RTGUI_WIDGET(home_view)); rtgui_widget_focus(RTGUI_WIDGET(home_view));
rtgui_view_show(home_view, RT_FALSE); rtgui_view_show(home_view, RT_FALSE);
/* add function view */ /* add function view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect); rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
function_view = rtgui_list_view_create(function_list, function_view = rtgui_list_view_create(function_list,
sizeof(function_list)/sizeof(struct rtgui_list_item), sizeof(function_list)/sizeof(struct rtgui_list_item),
&rect); &rect);
rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view)); rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));
rtgui_workbench_event_loop(workbench); rtgui_workbench_event_loop(workbench);
rtgui_thread_deregister(rt_thread_self()); rtgui_thread_deregister(rt_thread_self());
rt_mq_delete(mq); rt_mq_delete(mq);
} }
void player_notify_play(void) void player_notify_play(void)
...@@ -902,18 +944,18 @@ void player_notify_stop() ...@@ -902,18 +944,18 @@ void player_notify_stop()
void player_ui_init() void player_ui_init()
{ {
player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL, player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL,
0x800, 25, 5); 0x800, 25, 5);
if (player_ui_tid != RT_NULL) if (player_ui_tid != RT_NULL)
rt_thread_startup(player_ui_tid); rt_thread_startup(player_ui_tid);
} }
void player_ui_freeze() void player_ui_freeze()
{ {
struct rtgui_event_command ecmd; struct rtgui_event_command ecmd;
/* check whether UI starts. */ /* check whether UI starts. */
if (home_view == RT_NULL || workbench == RT_NULL) return; if (home_view == RT_NULL || workbench == RT_NULL) return;
RTGUI_EVENT_COMMAND_INIT(&ecmd); RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.type = RTGUI_CMD_USER_INT; ecmd.type = RTGUI_CMD_USER_INT;
......
#include <rtgui/rtgui.h>
#include <rtgui/rtgui_system.h>
#include <stdio.h>
#include <stdlib.h>
#include <rtgui/widgets/view.h>
#include <rtgui/widgets/workbench.h>
#include <stm32f10x.h> #include <stm32f10x.h>
#include <rtthread.h> #include <rtthread.h>
#include <dfs_posix.h> #include <dfs_posix.h>
...@@ -20,8 +28,16 @@ extern int http_resolve_address(struct sockaddr_in *server, const char * url, ch ...@@ -20,8 +28,16 @@ extern int http_resolve_address(struct sockaddr_in *server, const char * url, ch
const char _radio_list_update_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nConnection: close\r\n\r\n"; const char _radio_list_update_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nConnection: close\r\n\r\n";
rt_mq_t update_radio_mq = RT_NULL; rt_mq_t update_radio_mq = RT_NULL;
static struct rtgui_view* update_radio_list_view = RT_NULL;
typedef enum
{
UPDATE_RAIDO_LIST_PROC,
UPDATE_RADIO_LIST_CONNECT_FAILED,
UPDATE_RADIO_LIST_SUCCEED,
} UPDATE_RADIO_LIST_STATE;
static UPDATE_RADIO_LIST_STATE update_radio_list_state;
int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_addr, const char* url) int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_addr, const char* url)
{ {
...@@ -39,6 +55,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -39,6 +55,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
peer_handle = connect( socket_handle, (struct sockaddr *) server, sizeof(*server)); peer_handle = connect( socket_handle, (struct sockaddr *) server, sizeof(*server));
if ( peer_handle < 0 ) if ( peer_handle < 0 )
{ {
closesocket(socket_handle);
rt_kprintf( "RLUS: CONNECT FAILED %i\n", peer_handle ); rt_kprintf( "RLUS: CONNECT FAILED %i\n", peer_handle );
return -1; return -1;
} }
...@@ -66,8 +83,11 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -66,8 +83,11 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
rc = http_read_line(peer_handle, mimeBuffer, 100); rc = http_read_line(peer_handle, mimeBuffer, 100);
rt_kprintf(">>%s", mimeBuffer); rt_kprintf(">>%s", mimeBuffer);
if ( rc < 0 ) return rc; if ( rc < 0 )
{
closesocket(peer_handle);
return rc;
}
// End of headers is a blank line. exit. // End of headers is a blank line. exit.
if (rc == 0) break; if (rc == 0) break;
if ((rc == 2) && (mimeBuffer[0] == '\r')) break; if ((rc == 2) && (mimeBuffer[0] == '\r')) break;
...@@ -78,6 +98,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -78,6 +98,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
if(rc) if(rc)
{ {
rt_kprintf("HTTP: status code = %d!\n", rc); rt_kprintf("HTTP: status code = %d!\n", rc);
closesocket(peer_handle);
return -rc; return -rc;
} }
} }
...@@ -88,6 +109,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -88,6 +109,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
if (strstr(mimeBuffer, "text/plain") == RT_NULL) if (strstr(mimeBuffer, "text/plain") == RT_NULL)
{ {
rt_kprintf("radio list update content is not text/plain.\n"); rt_kprintf("radio list update content is not text/plain.\n");
closesocket(peer_handle);
return -1; return -1;
} }
} }
...@@ -98,6 +120,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -98,6 +120,7 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
if (strstr(mimeBuffer, "text/plain") == RT_NULL) if (strstr(mimeBuffer, "text/plain") == RT_NULL)
{ {
rt_kprintf("radio list update content is not text/plain.\n"); rt_kprintf("radio list update content is not text/plain.\n");
closesocket(peer_handle);
return -1; return -1;
} }
} }
...@@ -105,9 +128,10 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a ...@@ -105,9 +128,10 @@ int radio_list_update_servicer_connect(struct sockaddr_in* server, char* host_a
return peer_handle; return peer_handle;
} }
int radio_list_update_servicer_session_open(char* url) int radio_list_update_servicer_session_open(char* url)
{ {
int peer_handle = 0; int peer_handle = -1;
struct sockaddr_in server; struct sockaddr_in server;
char *request, host_addr[32]; char *request, host_addr[32];
...@@ -124,7 +148,7 @@ int radio_list_update_servicer_session_open(char* url) ...@@ -124,7 +148,7 @@ int radio_list_update_servicer_session_open(char* url)
return peer_handle; return peer_handle;
} }
void update_radio_list(char* url) int update_radio_list(char* url)
{ {
char *buf = NULL; char *buf = NULL;
int peer_handle = 0; int peer_handle = 0;
...@@ -135,13 +159,13 @@ void update_radio_list(char* url) ...@@ -135,13 +159,13 @@ void update_radio_list(char* url)
if(peer_handle < 0) if(peer_handle < 0)
{ {
return; return -1;
} }
fd = open(RADIO_FN, O_WRONLY | O_CREAT | O_TRUNC, 0); fd = open(RADIO_FN, O_WRONLY | O_CREAT | O_TRUNC, 0);
if(fd < 0) if(fd < 0)
{ {
return; return -1;
} }
buf = rt_malloc (512); buf = rt_malloc (512);
while ( 1 ) while ( 1 )
...@@ -160,11 +184,13 @@ void update_radio_list(char* url) ...@@ -160,11 +184,13 @@ void update_radio_list(char* url)
} }
rt_free(buf); rt_free(buf);
closesocket(peer_handle);
if(close(fd) == 0) if(close(fd) == 0)
{ {
rt_kprintf("Update radio list succeed \r\n"); rt_kprintf("Update radio list succeed \r\n");
} }
return 0;
} }
void update_radio_list_req(void) void update_radio_list_req(void)
...@@ -174,6 +200,7 @@ void update_radio_list_req(void) ...@@ -174,6 +200,7 @@ void update_radio_list_req(void)
extern rt_mq_t player_thread_mq; extern rt_mq_t player_thread_mq;
char* ch = RT_NULL; char* ch = RT_NULL;
update_radio_list_state = UPDATE_RAIDO_LIST_PROC;
request.type = PLAYER_REQUEST_UPDATE_RADIO_LIST; request.type = PLAYER_REQUEST_UPDATE_RADIO_LIST;
ch = strncpy(request.fn, RADIO_LIST_UPDATE_URL, strlen(RADIO_LIST_UPDATE_URL)); ch = strncpy(request.fn, RADIO_LIST_UPDATE_URL, strlen(RADIO_LIST_UPDATE_URL));
...@@ -187,6 +214,8 @@ void update_radio_thread(void* parameter) ...@@ -187,6 +214,8 @@ void update_radio_thread(void* parameter)
rt_err_t result; rt_err_t result;
struct player_request request; struct player_request request;
rt_thread_t update_radio_list_thread; rt_thread_t update_radio_list_thread;
while(1) while(1)
{ {
/* get request from message queue */ /* get request from message queue */
...@@ -196,11 +225,25 @@ void update_radio_thread(void* parameter) ...@@ -196,11 +225,25 @@ void update_radio_thread(void* parameter)
{ {
switch (request.type) switch (request.type)
{ {
case PLAYER_REQUEST_UPDATE_RADIO_LIST: case PLAYER_REQUEST_UPDATE_RADIO_LIST:
if ((strstr(request.fn, "http://") == request.fn || if ((strstr(request.fn, "http://") == request.fn ||
(strstr(request.fn, "HTTP://") == request.fn ))) (strstr(request.fn, "HTTP://") == request.fn )))
{ {
update_radio_list(request.fn); struct rtgui_event_command ecmd;
if(update_radio_list(request.fn)==0)
{
update_radio_list_state = UPDATE_RADIO_LIST_SUCCEED;
}
else
{
update_radio_list_state = UPDATE_RADIO_LIST_CONNECT_FAILED;
}
RTGUI_EVENT_COMMAND_INIT(&ecmd);
ecmd.type = RTGUI_EVENT_PAINT;
ecmd.command_id = PLAYER_REQUEST_UPDATE_RADIO_LIST;
rtgui_thread_send(rt_thread_find("ply_ui"), &ecmd.parent, sizeof(ecmd));
} }
break; break;
} }
...@@ -212,3 +255,114 @@ void update_radio_thread(void* parameter) ...@@ -212,3 +255,114 @@ void update_radio_thread(void* parameter)
} }
} }
void drawing_update_state_info(struct rtgui_widget* widget)
{
char* line;
struct rtgui_dc* dc;
struct rtgui_rect rect;
line = rtgui_malloc(256);
if (line == RT_NULL) return ;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL)
{
rt_free(line);
return;
}
rtgui_widget_get_rect(widget, &rect);
/* fill background */
rtgui_dc_fill_rect(dc, &rect);
rect.y2 = rect.y1 + 18;
switch(update_radio_list_state)
{
case UPDATE_RAIDO_LIST_PROC:
sprintf(line, "正在更新电台列表......");
break ;
case UPDATE_RADIO_LIST_CONNECT_FAILED:
sprintf(line, "更新电台列表失败,请返回");
break;
case UPDATE_RADIO_LIST_SUCCEED:
sprintf(line, "更新电台列表成功,请返回");
break;
}
rtgui_dc_draw_text(dc, line, &rect);
rtgui_dc_end_drawing(dc);
rtgui_free(line);
}
static rt_bool_t update_radio_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
switch (event->type)
{
case RTGUI_EVENT_COMMAND:
{
struct rtgui_event_command* ecmd = (struct rtgui_event_command*)event;
switch(ecmd->type)
{
case RTGUI_EVENT_PAINT:
drawing_update_state_info(widget);
return RT_FALSE;
}
return RT_FALSE;
}
case RTGUI_EVENT_PAINT:
{
drawing_update_state_info(widget);
return RT_FALSE;
}
case RTGUI_EVENT_KBD:
{
struct rtgui_event_kbd* ekbd;
ekbd = (struct rtgui_event_kbd*)event;
if (ekbd->type == RTGUI_KEYDOWN && ekbd->key == RTGUIK_RETURN)
{
rtgui_workbench_t* workbench;
workbench = RTGUI_WORKBENCH(RTGUI_WIDGET(update_radio_list_view)->parent);
rtgui_workbench_remove_view(workbench, update_radio_list_view);
rtgui_view_destroy(update_radio_list_view);
update_radio_list_view = RT_NULL;
}
}
return RT_FALSE;
}
/* use parent event handler */
return rtgui_view_event_handler(widget, event);
}
rtgui_view_t *update_radio_list_view_create(rtgui_workbench_t* workbench)
{
if (update_radio_list_view != RT_NULL)
{
rtgui_view_show(update_radio_list_view, RT_FALSE);
}
else
{
/* create a view */
update_radio_list_view = rtgui_view_create("update radio list Info");
/* set view event handler */
rtgui_widget_set_event_handler(RTGUI_WIDGET(update_radio_list_view), update_radio_list_view_event_handler);
/* this view can be focused */
RTGUI_WIDGET(update_radio_list_view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
/* add view to workbench */
rtgui_workbench_add_view(workbench, update_radio_list_view);
}
return update_radio_list_view;
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册