summaryrefslogtreecommitdiff
path: root/bsp
diff options
context:
space:
mode:
authorbernard.xiong <[email protected]>2010-02-17 23:56:49 +0000
committerbernard.xiong <[email protected]>2010-02-17 23:56:49 +0000
commit860d1ddfd4a069c75ee66eea09f07b6b61b997be (patch)
tree2e612efb2f8b0ea98483e6c25123fdd06bafd231 /bsp
parent332d0d00e2c94807546bba4bcb3c7b07ab8cdede (diff)
add radio station selection; remove list and filelist view implementation in STM32 radio; remove warning of RTGUI.
git-svn-id: https://rt-thread.googlecode.com/svn/trunk@419 bbd45198-f89e-11dd-88c7-29a3b14d5316
Diffstat (limited to 'bsp')
-rw-r--r--bsp/stm32_radio/device_info.c2
-rw-r--r--bsp/stm32_radio/dm9000.c2
-rw-r--r--bsp/stm32_radio/filelist.c676
-rw-r--r--bsp/stm32_radio/filelist.h55
-rw-r--r--bsp/stm32_radio/http.c70
-rw-r--r--bsp/stm32_radio/listview.c245
-rw-r--r--bsp/stm32_radio/listview.h53
-rw-r--r--bsp/stm32_radio/mp3.c14
-rw-r--r--bsp/stm32_radio/mp3.h12
-rw-r--r--bsp/stm32_radio/netbuffer.c3
-rw-r--r--bsp/stm32_radio/play_list.c2
-rw-r--r--bsp/stm32_radio/player_bg.c14
-rw-r--r--bsp/stm32_radio/player_bg.h14
-rw-r--r--bsp/stm32_radio/player_ui.c382
-rw-r--r--bsp/stm32_radio/player_ui.h5
-rw-r--r--bsp/stm32_radio/project.Uv27
-rw-r--r--bsp/stm32_radio/rtconfig.h2
-rw-r--r--bsp/stm32_radio/station_list.c219
-rw-r--r--bsp/stm32_radio/station_list.h31
-rw-r--r--bsp/stm32_radio/workbench.c95
20 files changed, 509 insertions, 1394 deletions
diff --git a/bsp/stm32_radio/device_info.c b/bsp/stm32_radio/device_info.c
index c32d59430d..495df65bbd 100644
--- a/bsp/stm32_radio/device_info.c
+++ b/bsp/stm32_radio/device_info.c
@@ -117,7 +117,7 @@ static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_ev
};
/* check device index */
- if (dev_index < 0 || dev_index > 4) dev_index = 3;
+ if (dev_index > 4) dev_index = 3;
/* draw each information */
sprintf(line, "�豸: %s %s",
diff --git a/bsp/stm32_radio/dm9000.c b/bsp/stm32_radio/dm9000.c
index a5ae054b01..fb26bf1910 100644
--- a/bsp/stm32_radio/dm9000.c
+++ b/bsp/stm32_radio/dm9000.c
@@ -503,7 +503,7 @@ struct pbuf *rt_dm9000_rx(rt_device_t dev)
{
rt_uint16_t dummy;
- DM9000_TRACE("dm9000 rx: no pbuf\n");
+ rt_kprintf("dm9000 rx: no pbuf\n");
/* no pbuf, discard data from DM9000 */
data = &dummy;
diff --git a/bsp/stm32_radio/filelist.c b/bsp/stm32_radio/filelist.c
deleted file mode 100644
index 8c2aed8b5a..0000000000
--- a/bsp/stm32_radio/filelist.c
+++ /dev/null
@@ -1,676 +0,0 @@
-#include <rtgui/rtgui_object.h>
-#include <rtgui/rtgui_system.h>
-#include <rtgui/rtgui_theme.h>
-
-#include <rtgui/list.h>
-#include <rtgui/image.h>
-#include <rtgui/widgets/view.h>
-#include <rtgui/widgets/workbench.h>
-
-#include "filelist.h"
-#include <dfs_posix.h>
-#include <string.h>
-
-#define FILELIST_MARGIN 5
-#ifdef _WIN32
-#define PATH_SEPARATOR '\\'
-#define stat _stat
-#else
-#define PATH_SEPARATOR '/'
-#endif
-
-const static char * file_xpm[] = {
-"16 16 21 1",
-" c None",
-". c #999999",
-"+ c #818181",
-"@ c #FFFFFF",
-"# c #ECECEC",
-"$ c #EAEAEA",
-"% c #EBEBEB",
-"& c #EDEDED",
-"* c #F0F0F0",
-"= c #C4C4C4",
-"- c #C5C5C5",
-"; c #C6C6C6",
-"> c #C7C7C7",
-", c #EEEEEE",
-"' c #EDEDE5",
-") c #EDEDE6",
-"! c #EFEFEF",
-"~ c #C8C8C8",
-"{ c #F1F1F1",
-"] c #F2F2F2",
-"^ c #959595",
-".++++++++++++ ",
-"+@@@@@@@@@@@@+ ",
-"+@#$$%%%##&*@+ ",
-"+@$=--;;;;>*@+ ",
-"+@$%%###&&,*@+ ",
-"+@%-;;;;;;>*@+ ",
-"+@%%##&&'#,*@+ ",
-"+@%;;;;,,),*@+ ",
-"+@##&&,,!!!*@+ ",
-"+@#;;;>>~~~*@+ ",
-"+@#&,,!!*{{{@+ ",
-"+@&;>>~~~{{]@+ ",
-"+@&&,!!**{]]@+ ",
-"+@@@@@@@@@@@@+ ",
-"^++++++++++++^ ",
-" "};
-
-const static char * folder_xpm[] = {
-"16 16 121 2",
-" c None",
-". c #D9B434",
-"+ c #E1C25E",
-"@ c #E2C360",
-"# c #E2C35F",
-"$ c #DBB63C",
-"% c #DAB336",
-"& c #FEFEFD",
-"* c #FFFFFE",
-"= c #FFFEFE",
-"- c #FFFEFD",
-"; c #FBF7EA",
-"> c #E4C76B",
-", c #E3C76B",
-"' c #E6CD79",
-") c #E5CA74",
-"! c #DAAF35",
-"~ c #FEFCF7",
-"{ c #F8E48E",
-"] c #F5DE91",
-"^ c #F5E09F",
-"/ c #F6E1AC",
-"( c #FEFBEF",
-"_ c #FEFDF4",
-": c #FEFCF3",
-"< c #FEFCF1",
-"[ c #FEFBEE",
-"} c #FFFDFA",
-"| c #DAAF36",
-"1 c #DAAA36",
-"2 c #FDFAF1",
-"3 c #F5DE94",
-"4 c #F4DC93",
-"5 c #F2D581",
-"6 c #EDCA6A",
-"7 c #EACB6C",
-"8 c #EFD385",
-"9 c #EFD280",
-"0 c #EFD07A",
-"a c #EECF76",
-"b c #EECF72",
-"c c #FBF7E9",
-"d c #DAAE34",
-"e c #DAAB35",
-"f c #FBF6E8",
-"g c #EFD494",
-"h c #EECE88",
-"i c #E9C173",
-"j c #F6E9C9",
-"k c #FEFCF2",
-"l c #FEFCF0",
-"m c #DAAB36",
-"n c #DAA637",
-"o c #FFFDF8",
-"p c #FFFDF6",
-"q c #FFFCF5",
-"r c #FCF6D8",
-"s c #F8E694",
-"t c #F7E385",
-"u c #F6DF76",
-"v c #F5DB68",
-"w c #F4D85C",
-"x c #FCF4D7",
-"y c #DAA435",
-"z c #DAA136",
-"A c #FEFCF6",
-"B c #FCF2C8",
-"C c #FBEFB9",
-"D c #FAECAC",
-"E c #F9E89C",
-"F c #F7E38B",
-"G c #F6E07C",
-"H c #F6DC6C",
-"I c #F5D95D",
-"J c #F4D64F",
-"K c #F3D344",
-"L c #FCF3D0",
-"M c #DA9F35",
-"N c #DA9A36",
-"O c #FDFAF2",
-"P c #FAEDB3",
-"Q c #F9E9A4",
-"R c #F8E695",
-"S c #F7E285",
-"T c #F6DE76",
-"U c #F5DB65",
-"V c #F4D757",
-"W c #F3D449",
-"X c #F2D13B",
-"Y c #F1CE30",
-"Z c #FBF2CC",
-"` c #DA9835",
-" . c #DA9435",
-".. c #FEFAEF",
-"+. c #F9E9A1",
-"@. c #F8E591",
-"#. c #F7E181",
-"$. c #F6DE72",
-"%. c #F5DA63",
-"&. c #F4D754",
-"*. c #F3D347",
-"=. c #F2D039",
-"-. c #F1CD2E",
-";. c #F0CB26",
-">. c #FBF2CA",
-",. c #D98E33",
-"'. c #FAF0DC",
-"). c #F4DDA7",
-"!. c #F4DB9E",
-"~. c #F3DA96",
-"{. c #F3D88E",
-"]. c #F3D786",
-"^. c #F2D47F",
-"/. c #F2D379",
-"(. c #F1D272",
-"_. c #F1D06C",
-":. c #F1CF69",
-"<. c #F8EAC2",
-"[. c #D8882D",
-"}. c #D8872D",
-"|. c #D8862C",
-" ",
-" ",
-" ",
-" . + @ @ @ # $ ",
-" % & * = - * ; > , , , ' ) ",
-" ! ~ { ] ^ / ( _ : < ( [ } | ",
-" 1 2 3 4 5 6 7 8 9 0 a b c d ",
-" e f g h i j k : k l ( [ * m ",
-" n * o p q : r s t u v w x y ",
-" z A B C D E F G H I J K L M ",
-" N O P Q R S T U V W X Y Z ` ",
-" ...+.@.#.$.%.&.*.=.-.;.>. . ",
-" ,.'.).!.~.{.].^./.(._.:.<.,. ",
-" [.}.[.[.[.[.[.[.[.[.}.[.|. ",
-" ",
-" "};
-
-/* image for file and folder */
-static rtgui_image_t *file_image, *folder_image;
-static struct filelist_view *filelist_view = RT_NULL; /* only one view in global */
-
-static void _filelist_view_constructor(struct filelist_view *view)
-{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
-
- /* set default widget rect and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view),filelist_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
-
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
-
- view->current_directory = RT_NULL;
- view->pattern = RT_NULL;
- RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
-
- file_image = rtgui_image_create_from_mem("xpm",
- (rt_uint8_t*)file_xpm, sizeof(file_xpm), RT_TRUE);
- folder_image = rtgui_image_create_from_mem("xpm",
- (rt_uint8_t*)folder_xpm, sizeof(folder_xpm), RT_TRUE);
-}
-
-rtgui_type_t *filelist_view_type_get(void)
-{
- static rtgui_type_t *filelist_view_type = RT_NULL;
-
- if (!filelist_view_type)
- {
- filelist_view_type = rtgui_type_create("flview", RTGUI_VIEW_TYPE,
- sizeof(filelist_view_t), RTGUI_CONSTRUCTOR(_filelist_view_constructor), RT_NULL);
- }
-
- return filelist_view_type;
-}
-
-void filelist_view_ondraw(struct filelist_view* view)
-{
- struct rtgui_rect rect, item_rect, image_rect;
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
- struct file_item* item;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_dc_fill_rect(dc, &rect);
-
- /* get item base rect */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- /* get image base rect */
- image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- /* get current page */
- page_index = (view->current_item / view->page_items) * view->page_items;
- for (index = 0; index < view->page_items; index ++)
- {
- if (page_index + index >= view->items_count) break;
-
- item = &(view->items[page_index + index]);
-
- if (page_index + index == view->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
- else
- {
- /* draw background */
- rtgui_dc_fill_rect(dc, &item_rect);
- }
-
- /* draw item */
-
- if (item->type == FITEM_FILE)
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- /* draw text */
- item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
- item_rect.x1 -= FILELIST_MARGIN + file_image->w + 2;
-
- /* move to next item position */
- item_rect.y1 += (rtgui_theme_get_selected_height() + 1);
- item_rect.y2 += (rtgui_theme_get_selected_height() + 1);
-
- image_rect.y1 += (rtgui_theme_get_selected_height() + 1);
- image_rect.y2 += (rtgui_theme_get_selected_height() + 1);
- }
-
- rtgui_dc_end_drawing(dc);
-}
-
-void filelist_view_update_current(struct filelist_view* view, rt_uint16_t old_item)
-{
- struct rtgui_dc* dc;
- struct file_item* item;
- rtgui_rect_t rect, item_rect, image_rect;
-
- if (old_item/view->page_items != view->current_item/view->page_items)
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(view));
- return;
- }
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
-
- /* get old item rect */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y1 += (old_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- /* get image rect */
- image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
-
- item = &(view->items[old_item]);
- if (item->type == FITEM_FILE) /* draw item image */
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- /* draw current item */
- item_rect = rect;
- item_rect.y1 += 1;
- item_rect.y1 += (view->current_item % view->page_items) * (1 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (1 + rtgui_theme_get_selected_height());
-
- rtgui_theme_draw_selected(dc, &item_rect);
-
- /* get image base rect */
- image_rect.x1 = FILELIST_MARGIN; image_rect.y1 = 0;
- image_rect.x2 = FILELIST_MARGIN + file_image->w; image_rect.y2 = file_image->h;
- rtgui_rect_moveto_align(&item_rect, &image_rect, RTGUI_ALIGN_CENTER_VERTICAL);
-
- item = &(view->items[view->current_item]);
- if (item->type == FITEM_FILE) /* draw item image */
- rtgui_image_blit(file_image, dc, &image_rect);
- else
- rtgui_image_blit(folder_image, dc, &image_rect);
-
- item_rect.x1 += FILELIST_MARGIN + file_image->w + 2;
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- rtgui_dc_end_drawing(dc);
-}
-
-rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct filelist_view* view = RT_NULL;
-
- view = FILELIST_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- filelist_view_ondraw(view);
- return RT_FALSE;
-
- case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
-
- resize = (struct rtgui_event_resize*)event;
-
- /* recalculate page items */
- if (file_image != RT_NULL)
- view->page_items = resize->h / (1 + rtgui_theme_get_selected_height());
- else
- view->page_items = resize->h / (2 + 14);
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
- switch (ekbd->key)
- {
- case RTGUIK_UP:
- if (view->current_item > 0)
- view->current_item --;
- filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_DOWN:
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
- filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_LEFT:
- if (view->current_item - view->page_items >= 0)
- view->current_item -= view->page_items;
- filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RIGHT:
- if (view->current_item + view->page_items < view->items_count - 1)
- view->current_item += view->page_items;
- filelist_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RETURN:
- if (view->items[view->current_item].type == FITEM_DIR)
- {
- char new_path[64];
-
- if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE;
- if (strcmp(view->items[view->current_item].name, "..") == 0)
- {
- char *ptr;
- ptr = strrchr(view->current_directory, PATH_SEPARATOR);
-
- if (ptr == RT_NULL) return RT_FALSE;
- if (ptr == &(view->current_directory[0]))
- {
- /* it's root directory */
- new_path[0] = PATH_SEPARATOR;
- new_path[1] = '\0';
- }
- else
- {
- strncpy(new_path, view->current_directory, ptr - view->current_directory + 1);
- new_path[ptr - view->current_directory] = '\0';
- }
- }
- else if (view->current_item == 0 &&
- (view->current_directory[0] == '/') && (view->current_directory[1] == '\0'))
- {
- if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
- {
- rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
- }
- else
- {
- filelist_view_destroy(view);
- }
-
- return RT_FALSE;
- }
- else
- {
- if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR)
- sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR,
- view->items[view->current_item].name);
- else
- sprintf(new_path, "%s%s",view->current_directory,
- view->items[view->current_item].name);
- }
- filelist_view_set_directory(view, new_path);
- }
- else
- {
- if (RTGUI_VIEW(view)->modal_show == RT_TRUE)
- {
- rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
- }
- }
- return RT_FALSE;
-
- default:
- break;
- }
- }
- }
- return RT_FALSE;
- }
-
- /* use view event handler */
- return rtgui_view_event_handler(widget, event);
-}
-
-filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect)
-{
- struct filelist_view* view = RT_NULL;
-
- if (filelist_view != RT_NULL)
- {
- rtgui_view_show(RTGUI_VIEW(filelist_view), RT_FALSE);
- }
- else
- {
- /* create a new view */
- view = (struct filelist_view*) rtgui_widget_create(FILELIST_VIEW_TYPE);
- if (view != RT_NULL)
- {
- view->items = RT_NULL;
- view->pattern = rt_strdup(pattern);
- view->page_items = rtgui_rect_height(*rect) / (1 + rtgui_theme_get_selected_height());
- filelist_view_set_directory(view, directory);
-
- rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
- }
- filelist_view = view;
- }
-
- return view;
-}
-
-void filelist_view_destroy(filelist_view_t* view)
-{
- /* delete all file items */
- filelist_view_clear(view);
- /* delete current directory and pattern */
- rtgui_free(view->current_directory); view->current_directory = RT_NULL;
- rtgui_free(view->pattern); view->pattern = RT_NULL;
-
- /* delete image */
- rtgui_image_destroy(file_image);
- rtgui_image_destroy(folder_image);
-
- filelist_view = RT_NULL;
-
- /* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
-
-/* clear all file items */
-void filelist_view_clear(filelist_view_t* view)
-{
- rt_uint32_t index;
- struct file_item* item;
-
- for (index = 0; index < view->items_count; index ++)
- {
- item = &(view->items[index]);
-
- /* release item name */
- rt_free(item->name);
- item->name = RT_NULL;
- }
-
- /* release items */
- rtgui_free(view->items);
- view->items = RT_NULL;
-
- view->items_count = 0;
- view->current_item = 0;
-}
-
-void filelist_view_set_directory(filelist_view_t* view, const char* directory)
-{
- rt_uint8_t fullpath[256];
- struct file_item *item;
-
- RT_ASSERT(view != RT_NULL);
-
- /* clear file items firstly */
- filelist_view_clear(view);
- if (directory != RT_NULL)
- {
- DIR* dir;
- struct stat s;
- rt_uint32_t index;
- struct dirent* dirent;
-
- view->items_count = 0;
- dir = opendir(directory);
- if (dir == RT_NULL) goto __return;
-
- /* current directory exists, set it */
- if (view->current_directory != RT_NULL) rt_free(view->current_directory);
- view->current_directory = rt_strdup(directory);
-
- do
- {
- dirent = readdir(dir);
- if (dirent == RT_NULL) break;
-
- if (strcmp(dirent->d_name, ".") == 0) continue;
- if (strcmp(dirent->d_name, "..") == 0) continue;
-
- view->items_count ++;
- } while (dirent != RT_NULL);
- closedir(dir);
-
- view->items_count ++; /* root directory for [x] exit, others for .. */
-
- view->items = (struct file_item*) rtgui_malloc(sizeof(struct file_item) * view->items_count);
- if (view->items == RT_NULL) return; /* no memory */
-
- index = 0;
- if (directory[0] == '/' && directory[1] != '\0')
- {
- item = &(view->items[0]);
-
- /* add .. directory */
- item->name = rt_strdup("..");
- item->type = FITEM_DIR;
- item->size = 0;
-
- index ++;
- }
- else
- {
- item = &(view->items[0]);
-
- /* add .. directory */
- item->name = rt_strdup("�˳��ļ����");
- item->type = FITEM_DIR;
- item->size = 0;
-
- index ++;
- }
-
- /* reopen directory */
- dir = opendir(directory);
- for (; index < view->items_count; index ++)
- {
- dirent = readdir(dir);
- if (dirent == RT_NULL) break;
-
- item = &(view->items[index]);
- item->name = rt_strdup(dirent->d_name);
-
- rt_memset(&s, 0, sizeof(struct stat));
-
- /* build full path for the file */
- if (directory[strlen(directory) - 1] != PATH_SEPARATOR)
- sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name);
- else
- sprintf(fullpath, "%s%s", directory, dirent->d_name);
-
- stat(fullpath, &s);
- if ( s.st_mode & S_IFDIR )
- {
- item->type = FITEM_DIR;
- item->size = 0;
- }
- else
- {
- item->type = FITEM_FILE;
- item->size = s.st_size;
- }
- }
-
- closedir(dir);
- }
-
- view->current_item = 0;
-
-__return:
- /* update view */
- rtgui_widget_update(RTGUI_WIDGET(view));
-}
diff --git a/bsp/stm32_radio/filelist.h b/bsp/stm32_radio/filelist.h
deleted file mode 100644
index 35cee0f785..0000000000
--- a/bsp/stm32_radio/filelist.h
+++ /dev/null
@@ -1,55 +0,0 @@
-#ifndef __FILE_LIST_VIEW_H__
-#define __FILE_LIST_VIEW_H__
-
-#include <rtgui/widgets/view.h>
-
-#define FITEM_FILE 0x0
-#define FITEM_DIR 0x1
-struct file_item
-{
- rt_uint8_t* name;
-
- rt_uint32_t type;
- rt_uint32_t size;
-};
-
-/** Gets the type of a filelist view */
-#define FILELIST_VIEW_TYPE (filelist_view_type_get())
-/** Casts the object to a filelist */
-#define FILELIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), FILELIST_VIEW_TYPE, filelist_view_t))
-/** Checks if the object is a filelist view */
-#define IS_FILELIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), FILELIST_VIEW_TYPE))
-
-struct filelist_view
-{
- struct rtgui_view parent;
-
- /* widget private data */
-
- /* current directory */
- rt_uint8_t* current_directory;
- rt_uint8_t* pattern;
-
- /* the number of item in a page */
- rt_uint16_t page_items;
- rt_uint16_t items_count;
-
- /* the selected item */
- rt_uint16_t current_item;
-
- /* items array */
- struct file_item *items;
-};
-typedef struct filelist_view filelist_view_t;
-
-rtgui_type_t *filelist_view_type_get(void);
-
-filelist_view_t* filelist_view_create(rtgui_workbench_t* workbench, const char* directory, const char* pattern, const rtgui_rect_t* rect);
-void filelist_view_destroy(filelist_view_t* view);
-
-void filelist_view_clear(filelist_view_t* view);
-
-rt_bool_t filelist_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
-void filelist_view_set_directory(filelist_view_t* view, const char* directory);
-
-#endif
diff --git a/bsp/stm32_radio/http.c b/bsp/stm32_radio/http.c
index bfc191ce24..b86a6fc1ae 100644
--- a/bsp/stm32_radio/http.c
+++ b/bsp/stm32_radio/http.c
@@ -8,12 +8,7 @@
#include <lwip/sockets.h>
#include <lwip/netdb.h>
-const char _http_get[] = "GET ";
-const char _http_host[] = "Host: ";
-const char _http_getend[] = " HTTP/1.0\r\n";
-const char _http_user_agent[] = "User-Agent: RT-Thread HTTP Agent\r\n";
-const char _http_endheader[] = "\r\n";
-
+const char _http_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\n\r\n";
const char _shoutcast_get[] = "GET %s HTTP/1.0\r\nHost: %s:%d\r\nUser-Agent: RT-Thread HTTP Agent\r\nIcy-MetaData: 1\r\nConnection: close\r\n\r\n";
extern long int strtol(const char *nptr, char **endptr, int base);
@@ -167,7 +162,6 @@ const char *http_resolve_address( struct sockaddr_in *server, const char * url,
port[w] = url[w + i + 1];
port[w] = '\0';
- rt_kprintf("HTTP: using port %s for connection\n", port);
break;
}
else is_domain = 1;
@@ -225,51 +219,19 @@ static int http_connect(struct http_session* session,
return -1;
}
- // Needs more error checking here.....
-#if 0
- rc = send( peer_handle, _http_get, sizeof( _http_get ) - 1, 0 );
- rc = send( peer_handle, (void*) url, strlen( url ), 0 );
- rc = send( peer_handle, _http_getend, sizeof( _http_getend ) - 1, 0 );
-
- rc = send( peer_handle, _http_host, sizeof( _http_host ) - 1, 0 );
- rc = send( peer_handle, host_addr, strlen( host_addr ), 0 );
- rc = send( peer_handle, _http_endheader, sizeof( _http_endheader ) - 1, 0 ); // "\r\n"
-
- rc = send( peer_handle, _http_user_agent, sizeof( _http_user_agent ) - 1, 0 );
- rc = send( peer_handle, _http_endheader, sizeof( _http_endheader ) - 1, 0 );
-#else
{
- rt_uint8_t *ptr, *buf;
+ char *buf;
+ rt_uint32_t length;
buf = rt_malloc (512);
- ptr = buf;
- rt_memcpy(ptr, _http_get, sizeof(_http_get) - 1);
- ptr += sizeof(_http_get) - 1;
-
- rt_memcpy(ptr, url, strlen(url));
- ptr += strlen(url);
-
- rt_memcpy(ptr, _http_getend, sizeof(_http_getend) - 1);
- ptr += sizeof(_http_getend) - 1;
-
- rt_memcpy(ptr, _http_host, sizeof(_http_host) - 1);
- ptr += sizeof(_http_host) - 1;
-
- rt_memcpy(ptr, host_addr, strlen(host_addr));
- ptr += strlen(host_addr);
-
- rt_memcpy(ptr, _http_endheader, sizeof(_http_endheader) - 1);
- ptr += sizeof(_http_endheader) - 1;
-
- rt_memcpy(ptr, _http_user_agent, sizeof(_http_user_agent) - 1);
- ptr += sizeof(_http_user_agent) - 1;
+ length = rt_snprintf(buf, 512, _http_get, url, host_addr, server->sin_port);
- rt_memcpy(ptr, _http_endheader, sizeof(_http_endheader) - 1);
- ptr += sizeof(_http_endheader) - 1;
- rc = send(peer_handle, buf,
- (rt_uint32_t)ptr - (rt_uint32_t)buf, 0);
+ rc = send(peer_handle, buf, length, 0);
+ rt_kprintf("HTTP request:\n%s", buf);
+
+ /* release buffer */
+ rt_free(buf);
}
-#endif
// We now need to read the header information
while ( 1 )
@@ -425,7 +387,7 @@ static int shoutcast_connect(struct shoutcast_session* session,
}
{
- rt_uint8_t *buf;
+ char *buf;
rt_uint32_t length;
buf = rt_malloc (512);
@@ -498,7 +460,7 @@ static int shoutcast_connect(struct shoutcast_session* session,
if (strstr(mimeBuffer, "content-type:"))
{
/* check content-type */
- if (strstr(mimeBuffer, "content-type:audio/mpeg") == RT_NULL)
+ if (strstr(mimeBuffer, "content-type: audio/mpeg") == RT_NULL)
{
rt_kprintf("ICY content is not audio/mpeg.\n");
return -1;
@@ -574,7 +536,12 @@ rt_size_t shoutcast_session_read(struct shoutcast_session* session, rt_uint8_t *
do
{
bytesRead = recv(session->socket, buffer + totalRead, left, 0);
- if(bytesRead <= 0) break;
+ if(bytesRead <= 0)
+ {
+ rt_kprintf("no data on recv, len %d,err %d\n", bytesRead,
+ lwip_get_error(session->socket));
+ break;
+ }
left -= bytesRead;
totalRead += bytesRead;
@@ -645,7 +612,7 @@ void http_test(char* url)
do
{
rt_memset(buffer, 0, sizeof(buffer));
- length = http_session_read(session, buffer, sizeof(buffer));
+ length = http_session_read(session, (rt_uint8_t*)buffer, sizeof(buffer));
rt_kprintf(buffer);rt_kprintf("\n");
} while (length > 0);
@@ -668,3 +635,4 @@ void shoutcast_test(char* url)
shoutcast_session_close(session);
}
FINSH_FUNCTION_EXPORT(shoutcast_test, shoutcast client test);
+
diff --git a/bsp/stm32_radio/listview.c b/bsp/stm32_radio/listview.c
deleted file mode 100644
index 6a8a0b93dd..0000000000
--- a/bsp/stm32_radio/listview.c
+++ /dev/null
@@ -1,245 +0,0 @@
-#include "listview.h"
-#include <rtgui/rtgui_theme.h>
-
-#define LIST_MARGIN 5
-
-static void _list_view_constructor(struct list_view *view)
-{
- /* default rect */
- struct rtgui_rect rect = {0, 0, 200, 200};
-
- /* set default widget rect and set event handler */
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view),list_view_event_handler);
- rtgui_widget_set_rect(RTGUI_WIDGET(view), &rect);
-
- RTGUI_WIDGET(view)->flag |= RTGUI_WIDGET_FLAG_FOCUSABLE;
-
- view->current_item = 0;
- view->items_count = 0;
- view->page_items = 0;
-
- RTGUI_WIDGET_BACKGROUND(RTGUI_WIDGET(view)) = white;
- RTGUI_WIDGET_TEXTALIGN(RTGUI_WIDGET(view)) = RTGUI_ALIGN_CENTER_VERTICAL;
-}
-
-rtgui_type_t *list_view_type_get(void)
-{
- static rtgui_type_t *list_view_type = RT_NULL;
-
- if (!list_view_type)
- {
- list_view_type = rtgui_type_create("listview", RTGUI_VIEW_TYPE,
- sizeof(list_view_t), RTGUI_CONSTRUCTOR(_list_view_constructor), RT_NULL);
- }
-
- return list_view_type;
-}
-
-void list_view_ondraw(struct list_view* view)
-{
- struct rtgui_rect rect, item_rect;
- struct rtgui_dc* dc;
- rt_uint16_t page_index, index;
- struct list_item* item;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
- rtgui_dc_fill_rect(dc, &rect);
-
- /* get item base rect */
- item_rect = rect;
- item_rect.y1 += 2;
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* get current page */
- page_index = (view->current_item / view->page_items) * view->page_items;
- for (index = 0; index < view->page_items; index ++)
- {
- if (page_index + index >= view->items_count) break;
-
- item = &(view->items[page_index + index]);
-
- if (page_index + index == view->current_item)
- {
- rtgui_theme_draw_selected(dc, &item_rect);
- }
- item_rect.x1 += LIST_MARGIN;
-
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += item->image->w + 2;
- }
- /* draw text */
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- if (item->image != RT_NULL)
- item_rect.x1 -= (item->image->w + 2);
- item_rect.x1 -= LIST_MARGIN;
-
- /* move to next item position */
- item_rect.y1 += (rtgui_theme_get_selected_height() + 2);
- item_rect.y2 += (rtgui_theme_get_selected_height() + 2);
- }
- rtgui_dc_end_drawing(dc);
-}
-
-void list_view_update_current(struct list_view* view, rt_uint16_t old_item)
-{
- struct rtgui_dc* dc;
- struct list_item* item;
- rtgui_rect_t rect, item_rect;
-
- if (old_item/view->page_items != view->current_item/view->page_items)
- {
- /* it's not a same page, update all */
- rtgui_widget_update(RTGUI_WIDGET(view));
- return;
- }
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view));
- if (dc == RT_NULL) return;
-
- rtgui_widget_get_rect(RTGUI_WIDGET(view), &rect);
-
- item_rect = rect;
- /* get old item's rect */
- item_rect.y1 += 2;
- item_rect.y1 += (old_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* draw old item */
- rtgui_dc_fill_rect(dc, &item_rect);
-
- item_rect.x1 += LIST_MARGIN;
-
- item = &(view->items[old_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += item->image->w + 2;
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- /* draw current item */
- item_rect = rect;
- /* get current item's rect */
- item_rect.y1 += 2;
- item_rect.y1 += (view->current_item % view->page_items) * (2 + rtgui_theme_get_selected_height());
- item_rect.y2 = item_rect.y1 + (2 + rtgui_theme_get_selected_height());
-
- /* draw current item */
- rtgui_theme_draw_selected(dc, &item_rect);
-
- item_rect.x1 += LIST_MARGIN;
-
- item = &(view->items[view->current_item]);
- if (item->image != RT_NULL)
- {
- rtgui_image_blit(item->image, dc, &item_rect);
- item_rect.x1 += (item->image->w + 2);
- }
- rtgui_dc_draw_text(dc, item->name, &item_rect);
-
- rtgui_dc_end_drawing(dc);
-}
-
-rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- struct list_view* view = RT_NULL;
-
- view = LIST_VIEW(widget);
- switch (event->type)
- {
- case RTGUI_EVENT_PAINT:
- list_view_ondraw(view);
- return RT_FALSE;
-
- case RTGUI_EVENT_RESIZE:
- {
- struct rtgui_event_resize* resize;
-
- resize = (struct rtgui_event_resize*)event;
-
- /* recalculate page items */
- view->page_items = resize->h / (2 + rtgui_theme_get_selected_height());
- }
- break;
-
- case RTGUI_EVENT_KBD:
- {
- struct rtgui_event_kbd* ekbd = (struct rtgui_event_kbd*)event;
- if (ekbd->type == RTGUI_KEYDOWN)
- {
- rt_uint16_t old_item;
-
- old_item = view->current_item;
- switch (ekbd->key)
- {
- case RTGUIK_LEFT:
- if (view->current_item - view->page_items >= 0)
- view->current_item -= view->page_items;
- list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_UP:
- if (view->current_item > 0)
- view->current_item --;
- list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RIGHT:
- if (view->current_item + view->page_items < view->items_count - 1)
- view->current_item += view->page_items;
- list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_DOWN:
- if (view->current_item < view->items_count - 1)
- view->current_item ++;
- list_view_update_current(view, old_item);
- return RT_FALSE;
-
- case RTGUIK_RETURN:
- if (view->items[view->current_item].action != RT_NULL)
- {
- view->items[view->current_item].action(view->items[view->current_item].parameter);
- }
- return RT_FALSE;
-
- default:
- break;
- }
- }
- }
- return RT_FALSE;
- }
-
- /* use view event handler */
- return rtgui_view_event_handler(widget, event);
-}
-
-list_view_t* list_view_create(struct list_item* items, rt_uint16_t count, rtgui_rect_t *rect)
-{
- struct list_view* view = RT_NULL;
-
- view = (struct list_view*) rtgui_widget_create(LIST_VIEW_TYPE);
- if (view != RT_NULL)
- {
- view->items = items;
- view->items_count = count;
-
- view->page_items = rtgui_rect_height(*rect) / (2 + rtgui_theme_get_selected_height());
- }
-
- return view;
-}
-
-void list_view_destroy(list_view_t* view)
-{
- /* destroy view */
- rtgui_widget_destroy(RTGUI_WIDGET(view));
-}
-
diff --git a/bsp/stm32_radio/listview.h b/bsp/stm32_radio/listview.h
deleted file mode 100644
index b5b7ce744a..0000000000
--- a/bsp/stm32_radio/listview.h
+++ /dev/null
@@ -1,53 +0,0 @@
-#ifndef __RTGUI_LIST_VIEW_H__
-#define __RTGUI_LIST_VIEW_H__
-
-#include <rtgui/rtgui.h>
-#include <rtgui/image.h>
-#include <rtgui/rtgui_system.h>
-
-#include <rtgui/widgets/view.h>
-
-typedef void (*item_action)(void* parameter);
-struct list_item
-{
- char* name;
- rtgui_image_t *image;
-
- item_action action;
- void *parameter;
-};
-
-/** Gets the type of a list view */
-#define LIST_VIEW_TYPE (list_view_type_get())
-/** Casts the object to a filelist */
-#define LIST_VIEW(obj) (RTGUI_OBJECT_CAST((obj), LIST_VIEW_TYPE, list_view_t))
-/** Checks if the object is a filelist view */
-#define IS_LIST_VIEW(obj) (RTGUI_OBJECT_CHECK_TYPE((obj), LIST_VIEW_TYPE))
-
-struct list_view
-{
- struct rtgui_view parent;
-
- /* widget private data */
- /* list item */
- struct list_item* items;
-
- /* total number of items */
- rt_uint16_t items_count;
- /* the number of item in a page */
- rt_uint16_t page_items;
- /* current item */
- rt_uint16_t current_item;
-};
-typedef struct list_view list_view_t;
-
-rtgui_type_t *list_view_type_get(void);
-
-list_view_t* list_view_create(struct list_item* items, rt_uint16_t count,
- rtgui_rect_t *rect);
-void list_view_clear(list_view_t* view);
-
-rt_bool_t list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event);
-
-#endif
-
diff --git a/bsp/stm32_radio/mp3.c b/bsp/stm32_radio/mp3.c
index b923e1c600..69070a5d47 100644
--- a/bsp/stm32_radio/mp3.c
+++ b/bsp/stm32_radio/mp3.c
@@ -523,8 +523,7 @@ void http_mp3(char* url)
}
FINSH_FUNCTION_EXPORT(http_mp3, http mp3 decode test);
-/* http mp3 */
-#include "http.h"
+/* ice mp3 */
static rt_size_t ice_fetch(rt_uint8_t* ptr, rt_size_t len, void* parameter)
{
struct shoutcast_session* session = (struct shoutcast_session*)parameter;
@@ -577,15 +576,4 @@ void ice_mp3(char* url)
}
FINSH_FUNCTION_EXPORT(ice_mp3, shoutcast mp3 decode test);
-char ice_url[] = "http://192.168.1.5:8000/stream";
-void ice()
-{
- rt_thread_t tid;
-
- tid = rt_thread_create("ice", ice_mp3, (void*)ice_url,
- 4096, 0x08, 5);
- if (tid != RT_NULL) rt_thread_startup(tid);
-}
-FINSH_FUNCTION_EXPORT(ice, shoutcast thread test);
-
#endif
diff --git a/bsp/stm32_radio/mp3.h b/bsp/stm32_radio/mp3.h
new file mode 100644
index 0000000000..c15011983f
--- /dev/null
+++ b/bsp/stm32_radio/mp3.h
@@ -0,0 +1,12 @@
+#ifndef __MP3_H__
+#define __MP3_H__
+
+#include "player_ui.h"
+
+void mp3_get_info(const char* filename, struct tag_info* info);
+
+void mp3(char* filename);
+void http_mp3(char* url);
+void ice_mp3(char* url);
+
+#endif
diff --git a/bsp/stm32_radio/netbuffer.c b/bsp/stm32_radio/netbuffer.c
index aa0198445d..f970d2a67c 100644
--- a/bsp/stm32_radio/netbuffer.c
+++ b/bsp/stm32_radio/netbuffer.c
@@ -2,6 +2,7 @@
#include <rtthread.h>
#include "netbuffer.h"
+#include "player_ui.h"
#define MP3_DECODE_MP_CNT 2
#define MP3_DECODE_MP_SZ 2560
@@ -151,7 +152,7 @@ rt_size_t net_buf_read(rt_uint8_t* buffer, rt_size_t length)
rt_hw_interrupt_enable(level);
}
}
-
+
return length;
}
diff --git a/bsp/stm32_radio/play_list.c b/bsp/stm32_radio/play_list.c
index 2484951f47..32c7d1d002 100644
--- a/bsp/stm32_radio/play_list.c
+++ b/bsp/stm32_radio/play_list.c
@@ -1,5 +1,7 @@
#include "play_list.h"
#include "player_ui.h"
+#include "mp3.h"
+
#include <string.h>
static struct play_item **play_list = RT_NULL;
diff --git a/bsp/stm32_radio/player_bg.c b/bsp/stm32_radio/player_bg.c
index 353ed0ec0e..a134484cbd 100644
--- a/bsp/stm32_radio/player_bg.c
+++ b/bsp/stm32_radio/player_bg.c
@@ -1,5 +1,6 @@
#include "player_bg.h"
#include "player_ui.h"
+#include "mp3.h"
#include <string.h>
@@ -23,17 +24,7 @@ void player_play_req(const char* fn)
rt_mq_send(player_thread_mq, (void*)&request, sizeof(struct player_request));
}
-#ifdef RT_USING_FINSH
-#include <finsh.h>
-static const char _fn[] = "/005.mp3";
-void play()
-{
- player_play_file(_fn);
-}
-FINSH_FUNCTION_EXPORT(play, play mp3 file test);
-#endif
-
-void player_stop()
+void player_stop_req()
{
is_playing = RT_FALSE;
}
@@ -109,3 +100,4 @@ void player_init()
player_ui_init();
}
}
+
diff --git a/bsp/stm32_radio/player_bg.h b/bsp/stm32_radio/player_bg.h
index c419e828e3..715fcba86a 100644
--- a/bsp/stm32_radio/player_bg.h
+++ b/bsp/stm32_radio/player_bg.h
@@ -8,21 +8,23 @@ enum PLAYER_REQUEST_TYPE
PLAYER_REQUEST_PLAY_SINGLE_FILE,
PLAYER_REQUEST_PLAY_LIST,
PLAYER_REQUEST_STOP,
- PLAYER_REQUEST_NEXT,
- PLAYER_REQUEST_PREV,
};
struct player_request
{
enum PLAYER_REQUEST_TYPE type;
-
char fn[64];
};
+/* get player background status */
rt_bool_t player_is_playing(void);
-void player_stop(void);
+/* player background thread init */
+void player_init(void);
-void player_play_list(const char** list);
-void player_play_file(const char* fn);
+/* send a stop request to player background thread */
+void player_stop_req(void);
+/* send a play request to player background thread */
+void player_play_req(const char* fn);
#endif
+
diff --git a/bsp/stm32_radio/player_ui.c b/bsp/stm32_radio/player_ui.c
index 9d3f35156e..d481261abd 100644
--- a/bsp/stm32_radio/player_ui.c
+++ b/bsp/stm32_radio/player_ui.c
@@ -3,25 +3,27 @@
#include <rtgui/rtgui_system.h>
#include <rtgui/widgets/view.h>
+#include <rtgui/widgets/list_view.h>
#include <rtgui/widgets/workbench.h>
-#include <string.h>
+#include <rtgui/widgets/filelist_view.h>
+#include <string.h>
#include <dfs_posix.h>
+#include "mp3.h"
+#include "picture.h"
#include "player_ui.h"
#include "player_bg.h"
#include "play_list.h"
-
-#include "listview.h"
-#include "filelist.h"
+#include "station_list.h"
#include "play.hdh"
#include "stop.hdh"
-static rtgui_image_t *background = RT_NULL;
+#define RADIO_FN "/radio.pls"
-static struct rtgui_view* function_view;
static struct rtgui_view* home_view;
+static struct rtgui_list_view* function_view;
static struct rtgui_workbench* workbench;
static rtgui_timer_t* info_timer;
static rt_thread_t player_ui_tid = RT_NULL;
@@ -29,32 +31,10 @@ static enum PLAYER_MODE player_mode = PLAYER_STOP;
static enum PLAYER_STEP next_step = PLAYER_STEP_STOP;
static struct tag_info tinfo;
-void player_set_position(rt_uint32_t position)
-{
- if (player_mode != PLAYER_PLAY_RADIO)
- {
- tinfo.position = position / (tinfo.bit_rate / 8);
- }
- else
- {
- tinfo.position = position;
- }
-}
+void player_play_file(const char* fn);
+void player_play_url(const char* url);
-void player_set_title(const char* title)
-{
- strncpy(tinfo.title, title, 40);
-}
-
-void player_set_buffer_status(rt_bool_t buffering)
-{
- if (buffering == RT_TRUE)
- strncpy(tinfo.artist, "������...", 40);
- else
- strncpy(tinfo.artist, "������...", 40);
-}
-
-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;
rtgui_color_t saved;
@@ -68,7 +48,7 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
rtgui_dc_draw_hline(dc, 14, 14 + (tinfo.position * 212)/ tinfo.duration,
75);
- if (player_mode == PLAYER_PLAY_RADIO)
+ 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_dc_draw_hline(dc, 14 + (tinfo.position * 212)/ tinfo.duration, 226, 75);
@@ -78,43 +58,12 @@ void info_timer_timeout(rtgui_timer_t* timer, void* parameter)
rtgui_dc_end_drawing(dc);
}
-static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
-{
- char *pos, *next;
- rt_uint32_t length;
-
- length = read(fd, line, line_size);
- if (length > 0)
- {
- pos = strstr(line, "\r\n");
- if (pos == RT_NULL)
- {
- pos = strstr(line, "\n");
- next = pos ++;
- }
- else next = pos + 2;
-
- if (pos != RT_NULL)
- {
- *pos = '\0';
-
- /* move back */
- lseek(fd, -(length - (next - line)), SEEK_CUR);
-
- length = pos - line;
- }
- else length = 0;
- }
-
- rt_kprintf("line %s\n", line);
- return length;
-}
-
static void player_update_tag_info(struct rtgui_dc* dc)
{
rtgui_rect_t rect;
char line[32];
rtgui_color_t saved;
+ rtgui_image_t *background;
saved = rtgui_dc_get_color(dc);
rtgui_dc_set_color(dc, black);
@@ -170,126 +119,62 @@ static void player_update_tag_info(struct rtgui_dc* dc)
rtgui_dc_set_color(dc, saved);
}
-void player_play_file(const char* fn)
+static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
{
- struct rtgui_dc* dc;
- rtgui_color_t saved;
- rt_bool_t is_mp3;
-
- is_mp3 = RT_FALSE;
-
- if (strstr(fn, ".mp3") != RT_NULL ||
- strstr(fn, ".MP3") != RT_NULL)
- is_mp3 = RT_TRUE;
- else if (strstr(fn, ".wav") != RT_NULL ||
- strstr(fn, ".wav") != RT_NULL)
- is_mp3 = RT_FALSE;
- else return; /* not supported audio format */
-
- if (is_mp3 == RT_TRUE)
- {
- /* get music tag information */
- mp3_get_info(fn, &tinfo);
- if (tinfo.title[0] == '\0')
- rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
- }
- else
- {
- /* wav file */
- rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
- rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav����>");
-
- tinfo.duration = 0;
- }
-
- /* set player mode */
- player_mode = PLAYER_PLAY_FILE;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
- if (dc != RT_NULL)
- {
- rtgui_rect_t play_rect;
- rtgui_image_t *button;
-
- /* update tag information */
- player_update_tag_info(dc);
+ char *pos, *next;
+ rt_uint32_t length;
- /* reset progress bar */
- saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
- RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
- rtgui_dc_draw_hline(dc, 14, 226, 75);
- RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
+ length = read(fd, line, line_size);
+ if (length > 0)
+ {
+ pos = strstr(line, "\r\n");
+ if (pos == RT_NULL)
+ {
+ pos = strstr(line, "\n");
+ next = pos ++;
+ }
+ else next = pos + 2;
- /* update play button */
- button = rtgui_image_create_from_mem("hdc",
- play_hdh, sizeof(play_hdh), RT_FALSE);
- play_rect.x1 = 32; play_rect.y1 = 92;
- play_rect.x2 = 61; play_rect.y2 = 114;
- rtgui_image_blit(button, dc, &play_rect);
- rtgui_image_destroy(button);
+ if (pos != RT_NULL)
+ {
+ *pos = '\0';
- rtgui_dc_end_drawing(dc);
- }
+ /* move back */
+ lseek(fd, -(length - (next - line)), SEEK_CUR);
- rtgui_view_show(home_view, RT_FALSE);
+ length = pos - line;
+ }
+ else length = 0;
+ }
- rt_kprintf("play file: %s\n", fn);
- player_play_req(fn);
+ return length;
}
-void player_play_url(const char* url)
+static void function_play_radio(void* parameter)
{
- struct rtgui_dc* dc;
+ struct station_list* list;
+ struct station_item* item;
- /* set music tag information */
- strncpy(tinfo.title, "�����̨", 40);
- player_set_buffer_status(RT_TRUE);
- tinfo.duration = 320 * 1024; /* 320 k */
-
- /* set player mode */
- player_mode = PLAYER_PLAY_RADIO;
-
- dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
- if (dc != RT_NULL)
+ list = station_list_create(RADIO_FN);
+ if (list != RT_NULL)
{
- rtgui_rect_t play_rect;
- rtgui_image_t *button;
-
- /* update tag information */
- player_update_tag_info(dc);
-
- /* update play button */
- button = rtgui_image_create_from_mem("hdc",
- play_hdh, sizeof(play_hdh), RT_FALSE);
- play_rect.x1 = 32; play_rect.y1 = 92;
- play_rect.x2 = 61; play_rect.y2 = 114;
- rtgui_image_blit(button, dc, &play_rect);
- rtgui_image_destroy(button);
+ item = station_list_select(list, workbench);
+ if (item != RT_NULL)
+ {
+ player_play_url(item->url);
+ }
- rtgui_dc_end_drawing(dc);
+ station_list_destroy(list);
}
-
- rtgui_view_show(home_view, RT_FALSE);
-
- rt_kprintf("play radio url: %s\n", url);
- player_play_req(url);
}
-void function_play_radio(void* parameter)
-{
- next_step = PLAYER_STEP_STOP;
- player_play_url("http://syragon.com:8000/ices");
- // player_play_url("http://192.168.1.6:8000/stream");
- // player_play_url("http://radio.aozima.com:8000/stream");
-}
-
-void function_filelist(void* parameter)
+static void function_filelist(void* parameter)
{
rtgui_rect_t rect;
- filelist_view_t *view;
+ rtgui_filelist_view_t *view;
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
- view = filelist_view_create(workbench, "/", "*.*", &rect);
+ view = rtgui_filelist_view_create(workbench, "/", "*.*", &rect);
if (view != RT_NULL)
{
if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
@@ -334,7 +219,11 @@ void function_filelist(void* parameter)
length = read_line(fd, line, sizeof(line));
if (length > 0)
{
- if (line[0] != '/')
+ if (strstr(line, "http:") != RT_NULL)
+ {
+ play_list_append(line);
+ }
+ else if (line[0] != '/')
{
rt_snprintf(fn, sizeof(fn),
"%s/%s", view->current_directory, line);
@@ -357,13 +246,13 @@ void function_filelist(void* parameter)
}
/* destroy view */
- filelist_view_destroy(view);
+ rtgui_filelist_view_destroy(view);
}
return;
}
-void function_device(void* parameter)
+static void function_device(void* parameter)
{
rtgui_view_t *view;
extern rtgui_view_t* device_view_create(rtgui_workbench_t* workbench);
@@ -377,14 +266,13 @@ void function_device(void* parameter)
return;
}
-void function_player(void* parameter)
+static void function_player(void* parameter)
{
rtgui_view_show(home_view, RT_FALSE);
return;
}
-#include "picture.h"
-void function_show_picure(void* parameter)
+static void function_show_picure(void* parameter)
{
rtgui_view_t *view;
@@ -404,13 +292,13 @@ void function_action(void* parameter)
return;
}
-extern void USB_cable(void);
-void function_cable(void)
+void function_cable(void* parameter)
{
+ extern void USB_cable(void);
USB_cable();
}
-struct list_item function_list[] =
+const struct rtgui_list_item function_list[] =
{
{"ѡ���̨", RT_NULL, function_play_radio, RT_NULL},
{"���µ�̨", RT_NULL, function_action, RT_NULL},
@@ -422,6 +310,134 @@ struct list_item function_list[] =
{"���ز�����", RT_NULL, function_player, RT_NULL},
};
+void player_set_position(rt_uint32_t position)
+{
+ if (player_mode != PLAYER_PLAY_RADIO)
+ {
+ tinfo.position = position / (tinfo.bit_rate / 8);
+ }
+ else
+ {
+ tinfo.position = position;
+ }
+}
+
+void player_set_title(const char* title)
+{
+ strncpy(tinfo.title, title, 40);
+}
+
+void player_set_buffer_status(rt_bool_t buffering)
+{
+ if (buffering == RT_TRUE)
+ strncpy(tinfo.artist, "������...", 40);
+ else
+ strncpy(tinfo.artist, "������...", 40);
+}
+
+void player_play_file(const char* fn)
+{
+ struct rtgui_dc* dc;
+ rtgui_color_t saved;
+ rt_bool_t is_mp3;
+
+ is_mp3 = RT_FALSE;
+
+ if (strstr(fn, ".mp3") != RT_NULL ||
+ strstr(fn, ".MP3") != RT_NULL)
+ is_mp3 = RT_TRUE;
+ else if (strstr(fn, ".wav") != RT_NULL ||
+ strstr(fn, ".wav") != RT_NULL)
+ is_mp3 = RT_FALSE;
+ else return; /* not supported audio format */
+
+ if (is_mp3 == RT_TRUE)
+ {
+ /* get music tag information */
+ mp3_get_info(fn, &tinfo);
+ if (tinfo.title[0] == '\0')
+ rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
+ }
+ else
+ {
+ /* wav file */
+ rt_snprintf(tinfo.title, sizeof(tinfo.title), "<δ֪������>");
+ rt_snprintf(tinfo.artist, sizeof(tinfo.title), "<wav����>");
+
+ tinfo.duration = 0;
+ }
+
+ /* set player mode */
+ player_mode = PLAYER_PLAY_FILE;
+
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
+ if (dc != RT_NULL)
+ {
+ rtgui_rect_t play_rect;
+ rtgui_image_t *button;
+
+ /* update tag information */
+ player_update_tag_info(dc);
+
+ /* reset progress bar */
+ saved = RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view));
+ RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = RTGUI_RGB(82, 199, 16);
+ rtgui_dc_draw_hline(dc, 14, 226, 75);
+ RTGUI_WIDGET_FOREGROUND(RTGUI_WIDGET(home_view)) = saved;
+
+ /* update play button */
+ button = rtgui_image_create_from_mem("hdc",
+ play_hdh, sizeof(play_hdh), RT_FALSE);
+ play_rect.x1 = 32; play_rect.y1 = 92;
+ play_rect.x2 = 61; play_rect.y2 = 114;
+ rtgui_image_blit(button, dc, &play_rect);
+ rtgui_image_destroy(button);
+
+ rtgui_dc_end_drawing(dc);
+ }
+
+ rtgui_view_show(home_view, RT_FALSE);
+
+ player_play_req(fn);
+}
+
+void player_play_url(const char* url)
+{
+ struct rtgui_dc* dc;
+
+ /* set music tag information */
+ strncpy(tinfo.title, "�����̨", 40);
+ player_set_buffer_status(RT_TRUE);
+ tinfo.duration = 320 * 1024; /* 320 k */
+
+ /* set player mode */
+ player_mode = PLAYER_PLAY_RADIO;
+
+ dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(home_view));
+ if (dc != RT_NULL)
+ {
+ rtgui_rect_t play_rect;
+ rtgui_image_t *button;
+
+ /* update tag information */
+ player_update_tag_info(dc);
+
+ /* update play button */
+ button = rtgui_image_create_from_mem("hdc",
+ play_hdh, sizeof(play_hdh), RT_FALSE);
+ play_rect.x1 = 32; play_rect.y1 = 92;
+ play_rect.x2 = 61; play_rect.y2 = 114;
+ rtgui_image_blit(button, dc, &play_rect);
+ rtgui_image_destroy(button);
+
+ rtgui_dc_end_drawing(dc);
+ }
+
+ rtgui_view_show(home_view, RT_FALSE);
+
+ player_play_req(url);
+}
+
static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
{
if (event->type == RTGUI_EVENT_PAINT)
@@ -429,6 +445,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
struct rtgui_dc* dc;
struct rtgui_rect rect;
rtgui_color_t saved;
+ rtgui_image_t *background;
dc = rtgui_dc_begin_drawing(widget);
if (dc == RT_NULL) return RT_FALSE;
@@ -544,14 +561,14 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
case RTGUIK_RIGHT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{
- player_stop();
+ player_stop_req();
next_step = PLAYER_STEP_NEXT;
}
break;
case RTGUIK_LEFT:
if (player_mode == PLAYER_PLAY_FILE && play_list_items() > 0)
{
- player_stop();
+ player_stop_req();
next_step = PLAYER_STEP_PREV;
}
break;
@@ -559,7 +576,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
case RTGUIK_RETURN:
if (player_is_playing() == RT_TRUE)
{
- player_stop();
+ player_stop_req();
next_step = PLAYER_STEP_STOP;
}
else
@@ -573,7 +590,7 @@ static rt_bool_t home_view_event_handler(struct rtgui_widget* widget, struct rtg
break;
case RTGUIK_DOWN:
- rtgui_view_show(function_view, RT_FALSE);
+ rtgui_view_show(RTGUI_VIEW(function_view), RT_FALSE);
break;
}
}
@@ -735,10 +752,10 @@ static void player_entry(void* parameter)
/* add function view */
rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
- function_view = (struct rtgui_view*)list_view_create(function_list,
- sizeof(function_list)/sizeof(struct list_item),
+ function_view = rtgui_list_view_create(function_list,
+ sizeof(function_list)/sizeof(struct rtgui_list_item),
&rect);
- rtgui_workbench_add_view(workbench, function_view);
+ rtgui_workbench_add_view(workbench, RTGUI_VIEW(function_view));
rtgui_workbench_event_loop(workbench);
@@ -769,7 +786,8 @@ void player_notify_stop()
void player_ui_init()
{
player_ui_tid = rt_thread_create("ply_ui", player_entry, RT_NULL,
- 4096, 25, 5);
+ 0x800, 25, 5);
if (player_ui_tid != RT_NULL)
rt_thread_startup(player_ui_tid);
}
+
diff --git a/bsp/stm32_radio/player_ui.h b/bsp/stm32_radio/player_ui.h
index 50d4e0ce7d..921f2873b6 100644
--- a/bsp/stm32_radio/player_ui.h
+++ b/bsp/stm32_radio/player_ui.h
@@ -37,11 +37,16 @@ enum PLAYER_STEP
PLAYER_STEP_NEXT,
};
+/* init player ui */
void player_ui_init(void);
+/* notification function, which invoked by player background thread */
void player_notify_play(void);
void player_notify_stop(void);
+/* set player information */
void player_set_position(rt_uint32_t position);
+void player_set_title(const char* title);
+void player_set_buffer_status(rt_bool_t buffering);
#endif
diff --git a/bsp/stm32_radio/project.Uv2 b/bsp/stm32_radio/project.Uv2
index fa3a181903..3067d8c452 100644
--- a/bsp/stm32_radio/project.Uv2
+++ b/bsp/stm32_radio/project.Uv2
@@ -37,9 +37,7 @@ File 1,1,<.\wav.c><wav.c>
File 1,1,<.\netbuffer.c><netbuffer.c>
File 1,1,<.\key.c><key.c>
File 1,1,<.\info.c><info.c>
-File 1,1,<.\filelist.c><filelist.c>
File 1,1,<.\device_info.c><device_info.c>
-File 1,1,<.\listview.c><listview.c>
File 1,1,<.\player_ui.c><player_ui.c>
File 1,1,<.\player_bg.c><player_bg.c>
File 1,1,<.\play_list.c><play_list.c>
@@ -48,6 +46,7 @@ File 1,1,<.\codec.c><codec.c>
File 1,1,<.\spi_flash.c><spi_flash.c>
File 1,1,<.\remote.c><remote.c>
File 1,1,<.\picture.c><picture.c>
+File 1,1,<.\station_list.c><station_list.c>
File 2,1,<..\..\src\clock.c><clock.c>
File 2,1,<..\..\src\idle.c><idle.c>
File 2,1,<..\..\src\ipc.c><ipc.c>
@@ -210,6 +209,8 @@ File 11,1,<..\..\rtgui\server\topwin.c><topwin.c>
File 11,1,<..\..\rtgui\common\font_hz_file.c><font_hz_file.c>
File 11,1,<..\..\rtgui\common\hz16font.c><hz16font.c>
File 11,1,<..\..\rtgui\common\hz12font.c><hz12font.c>
+File 11,1,<..\..\rtgui\widgets\list_view.c><list_view.c>
+File 11,1,<..\..\rtgui\widgets\filelist_view.c><filelist_view.c>
File 12,1,<.\Libraries\Mass_Storage\src\hw_config.c><hw_config.c>
File 12,1,<.\Libraries\Mass_Storage\src\mass_mal.c><mass_mal.c>
File 12,1,<.\Libraries\Mass_Storage\src\memory.c><memory.c>
@@ -279,7 +280,7 @@ Options 1,0,0 // Target 'RT-Thread STM32 Radio'
OCR_RVCT { 1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0,1,0,0,0,8,0,0,8,0,1,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,32,0,0,1,0,0,0,0,0,0,0,0,0,0 }
RV_STAVEC ()
ADSCCFLG { 5,32,0,4,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 }
- ADSCMISC ()
+ ADSCMISC (--diag_suppress=870)
ADSCDEFN (USE_STDPERIPH_DRIVER, STM32F10X_HD,)
ADSCUDEF ()
ADSCINCD (.;.\Libraries\STM32F10x_StdPeriph_Driver\inc;.\Libraries\CMSIS\Core\CM3;..\..\include;..\..\libcpu\arm\stm32;..\..\finsh;..\..\net\lwip\src;..\..\net\lwip\src\include;..\..\net\lwip\src\arch\include;..\..\net\lwip\src\include\ipv4;..\..\filesystem\dfs;..\..\filesystem\dfs\include;..\..\filesystem\dfs\filesystems\efsl\src\include;..\..\filesystem\dfs\filesystems\efsl\src\base\include;..\..\filesystem\dfs\filesystems\efsl\src\fs\vfat\include;..\..\rtgui\include;..\..\rtgui\common\libz)
diff --git a/bsp/stm32_radio/rtconfig.h b/bsp/stm32_radio/rtconfig.h
index bf5952159e..1a25d6846c 100644
--- a/bsp/stm32_radio/rtconfig.h
+++ b/bsp/stm32_radio/rtconfig.h
@@ -121,7 +121,7 @@
#define RT_LWIP_TCP_SND_BUF 2048
/* TCP Window Size */
-#define RT_LWIP_TCP_WND (1024 * 2)
+#define RT_LWIP_TCP_WND (1024 * 20)
/* Enable SNMP protocol */
/* #define RT_LWIP_SNMP */
diff --git a/bsp/stm32_radio/station_list.c b/bsp/stm32_radio/station_list.c
new file mode 100644
index 0000000000..34d429e9e3
--- /dev/null
+++ b/bsp/stm32_radio/station_list.c
@@ -0,0 +1,219 @@
+#include <string.h>
+#include <dfs_posix.h>
+#include "station_list.h"
+
+static rt_uint32_t read_line(int fd, char* line, rt_uint32_t line_size)
+{
+ char *pos, *next;
+ rt_uint32_t length;
+
+ length = read(fd, line, line_size);
+ if (length > 0)
+ {
+ pos = strstr(line, "\r\n");
+ if (pos == RT_NULL)
+ {
+ pos = strstr(line, "\n");
+ next = pos ++;
+ }
+ else next = pos + 2;
+
+ if (pos != RT_NULL)
+ {
+ *pos = '\0';
+
+ /* move back */
+ lseek(fd, -(length - (next - line)), SEEK_CUR);
+
+ length = pos - line;
+ }
+ else length = 0;
+ }
+
+ return length;
+}
+
+static char *strncasestr(const char *haystack, const char *needle)
+{
+ size_t nl=strlen(needle);
+ size_t hl=strlen(haystack);
+ size_t i;
+
+ if (!nl) goto found;
+ if (nl>hl) return 0;
+ for (i=hl-nl+1; i; --i)
+ {
+ if (*haystack==*needle && !strncasecmp(haystack,needle,nl))
+found:
+ return (char*)haystack;
+ ++haystack;
+ }
+ return 0;
+}
+
+/*
+ station list file format:
+
+ [playlist]
+ numberofentries=1
+ File1=http://67.159.5.47:8110
+ Title1=(#1 - 7/500) The Dominican.net Radio
+ */
+struct station_list* station_list_create(const char* fn)
+{
+ int fd;
+ rt_uint32_t length, index;
+ struct station_list* list;
+ char *line, *pos, prefix[8];
+
+ list = (struct station_list*)rt_malloc(sizeof(struct station_list));
+ if (list == RT_NULL) goto _return0; /* no memory */
+ list->count = 0; list->items = RT_NULL;
+
+#define LINE_BUFFER_SIZE 128
+ line = rt_malloc(LINE_BUFFER_SIZE);
+ if (line == RT_NULL)
+ goto _return1; /* no memory */
+
+ fd = open(fn, O_RDONLY, 0);
+ if (fd < 0) goto _return2; /* open file failed */
+
+ length = read_line(fd, line, LINE_BUFFER_SIZE);
+ pos = strncasestr(line, "[playlist]");
+ if (pos == RT_NULL)
+ {
+ station_list_destroy(list);
+ list = RT_NULL;
+ goto _return2;
+ }
+
+ length = read_line(fd, line, LINE_BUFFER_SIZE);
+ pos = strncasestr(line, "numberofentries=");
+ if (pos != RT_NULL)
+ {
+ list->count = (int)strtol(pos + strlen("numberofentries="), RT_NULL, 10);
+ if (list->count > 0)
+ {
+ list->items = (struct station_item*) rt_malloc (sizeof(struct station_item) * list->count);
+ rt_memset(list->items, 0, sizeof(struct station_item) * list->count);
+ }
+ }
+ else
+ {
+ station_list_destroy(list);
+ list = RT_NULL;
+ goto _return2;
+ }
+
+ if (list->items == RT_NULL)
+ {
+ station_list_destroy(list);
+ list = RT_NULL;
+ goto _return2;
+ }
+
+ index = 0;
+ while (index < list->count)
+ {
+ length = read_line(fd, line, LINE_BUFFER_SIZE);
+ if (length > 0)
+ {
+ rt_snprintf(prefix, sizeof(prefix), "File%d", index + 1);
+ pos = strncasestr(line, prefix);
+ if (pos != RT_NULL)
+ strncpy(list->items[index].url, pos + strlen(prefix) + 1, 128);
+
+ rt_snprintf(prefix, sizeof(prefix), "Title%d", index + 1);
+ pos = strncasestr(line, prefix);
+ if (pos != RT_NULL)
+ {
+ strncpy(list->items[index].title, pos + strlen(prefix) + 1, 40);
+ index ++;
+ }
+ }
+ else break;
+ }
+
+_return2:
+ close(fd);
+_return1:
+ rt_free(line);
+
+_return0:
+ return list;
+}
+
+void station_list_destroy(struct station_list* list)
+{
+ /* release memory */
+ rt_free(list->items);
+ rt_free(list);
+}
+
+/* update station list file from network */
+void station_list_update(struct rtgui_workbench* workbench)
+{
+}
+
+static void station_list_selected(void* parameter)
+{
+ rtgui_list_view_t *view;
+
+ view = RTGUI_LIST_VIEW(parameter);
+
+ if (view->current_item != 0)
+ rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_OK);
+ else
+ rtgui_view_end_modal(RTGUI_VIEW(view), RTGUI_MODAL_CANCEL);
+}
+
+/* select a station from list */
+struct station_item* station_list_select(struct station_list* list, struct rtgui_workbench* workbench)
+{
+ rt_size_t index;
+ rtgui_rect_t rect;
+ rtgui_list_view_t *view;
+ struct rtgui_list_item* items;
+ struct station_item* station;
+ char exit_str[] = "����..";
+
+ RT_ASSERT(list != RT_NULL);
+ RT_ASSERT(workbench != RT_NULL);
+
+ station = RT_NULL;
+
+ items = (struct rtgui_list_item*) rt_malloc (sizeof(struct rtgui_list_item) * (list->count + 1));
+ if (items == RT_NULL) return RT_NULL; /* no memory */
+
+ /* create view */
+ rtgui_widget_get_rect(RTGUI_WIDGET(workbench), &rect);
+ view = rtgui_list_view_create(items, list->count + 1, &rect);
+
+ items[0].image = RT_NULL;
+ items[0].action = station_list_selected;
+ items[0].name = exit_str;
+ items[0].parameter = view;
+
+ for (index = 1; index < list->count + 1; index ++)
+ {
+ items[index].image = RT_NULL;
+ items[index].action = station_list_selected;
+ items[index].name = list->items[index - 1].title;
+ items[index].parameter = view;
+ }
+
+ /* add view to workbench */
+ rtgui_workbench_add_view(workbench, RTGUI_VIEW(view));
+
+ /* show view as modal */
+ if (rtgui_view_show(RTGUI_VIEW(view), RT_TRUE) == RTGUI_MODAL_OK)
+ {
+ station = &list->items[view->current_item - 1];
+ }
+
+ /* destroy view */
+ rtgui_list_view_destroy(view);
+
+ return station;
+}
+
diff --git a/bsp/stm32_radio/station_list.h b/bsp/stm32_radio/station_list.h
new file mode 100644
index 0000000000..6f7956ec84
--- /dev/null
+++ b/bsp/stm32_radio/station_list.h
@@ -0,0 +1,31 @@
+#ifndef __STATION_LIST_H__
+#define __STATION_LIST_H__
+
+#include <rtthread.h>
+#include <rtgui/rtgui.h>
+#include <rtgui/widgets/list_view.h>
+#include <rtgui/widgets/workbench.h>
+
+struct station_item
+{
+ char title[40];
+ char url[128];
+};
+
+struct station_list
+{
+ rt_uint32_t count;
+ struct station_item* items;
+};
+
+struct station_list* station_list_create(const char* fn);
+void station_list_destroy(struct station_list* list);
+
+/* update station list file from network */
+void station_list_update(struct rtgui_workbench* workbench);
+
+/* select a station from list */
+struct station_item* station_list_select(struct station_list* list, struct rtgui_workbench* workbench);
+
+#endif
+
diff --git a/bsp/stm32_radio/workbench.c b/bsp/stm32_radio/workbench.c
deleted file mode 100644
index 92474cf15c..0000000000
--- a/bsp/stm32_radio/workbench.c
+++ /dev/null
@@ -1,95 +0,0 @@
-#include <rtgui/rtgui.h>
-#include <rtgui/rtgui_system.h>
-
-#include <rtgui/widgets/view.h>
-#include <rtgui/widgets/workbench.h>
-
-static rt_bool_t view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event)
-{
- /* 我们目前只对绘制事件感兴趣 */
- if (event->type == RTGUI_EVENT_PAINT)
- {
- struct rtgui_dc* dc;
- struct rtgui_rect rect;
-
- /* 获得一个设备上下文 */
- dc = rtgui_dc_begin_drawing(widget);
- if (dc == RT_NULL) return RT_FALSE; /* 如果获取失败代表什么?这个控件是隐藏的或... */
- rtgui_widget_get_rect(widget, &rect); /* 获得控件的可视区域 */
-
- /* 先对所在可视区域全部填充为背景色 */
- rtgui_dc_fill_rect(dc, &rect);
-
- /* 绘制一个hello! */
- rtgui_dc_draw_text(dc, "hello world", &rect);
-
- /* 通知RTGUI,绘制结束 */
- rtgui_dc_end_drawing(dc);
-
- return RT_FALSE;
- }
-
- /* 如果不是绘制事件,使用view原来的事件处理函数处理 */
- return rtgui_view_event_handler(widget, event);
-}
-
-static void workbench_entry(void* parameter)
-{
- rt_mq_t mq;
- struct rtgui_view* view;
- struct rtgui_workbench* workbench;
-
- /* 创建GUI应用需要的消息队列 */
- mq = rt_mq_create("qWB", 256, 4, RT_IPC_FLAG_FIFO);
- /* 注册当前线程为GUI线程 */
- rtgui_thread_register(rt_thread_self(), mq);
-
- /* 创建一个工作台 */
- workbench = rtgui_workbench_create("main", "workbench");
- if (workbench == RT_NULL) return;
-
- /* 创建一个工作台上的一个视图 */
- view = rtgui_view_create("view");
- rtgui_widget_set_event_handler(RTGUI_WIDGET(view), view_event_handler);
-
- /* 在工作台上添加一个视图 */
- rtgui_workbench_add_view(workbench, view);
-
- /* 显示这个视图 */
- rtgui_view_show(view);
-
- /* 执行工作台事件循环 */
- rtgui_workbench_event_loop(workbench);
-
- /* 去注册GUI线程 */
- rtgui_thread_deregister(rt_thread_self());
- rt_mq_delete(mq);
-}
-
-void workbench_init()
-{
- static rt_bool_t inited = RT_FALSE;
-
- if (inited == RT_FALSE) /* 避免重复初始化而做的保护 */
- {
- rt_thread_t tid;
-
- tid = rt_thread_create("wb",
- workbench_entry, RT_NULL,
- 2048, 25, 10);
-
- if (tid != RT_NULL) rt_thread_startup(tid);
-
- inited = RT_TRUE;
- }
-}
-
-#ifdef RT_USING_RTGUI
-#include <finsh.h>
-void workbench()
-{
- workbench_init();
-}
-/* finsh的命令输出,可以直接执行workbench()函数以执行上面的函数 */
-FINSH_FUNCTION_EXPORT(workbench, workbench demo)
-#endif