diff --git a/bsp/stm32_radio/device_info.c b/bsp/stm32_radio/device_info.c index c32d59430dce38dd17ab6552dcb0f9e3c0289604..495df65bbdc76563682118e0acfc63b3452a59aa 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 a5ae054b01d535db245b001d7df497e244eec9b2..fb26bf1910c03b0e26f1d2911e4fafd5c974b8a0 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 8c2aed8b5a8e6eddd8168bcd52dddbfa699682ee..0000000000000000000000000000000000000000 --- a/bsp/stm32_radio/filelist.c +++ /dev/null @@ -1,676 +0,0 @@ -#include -#include -#include - -#include -#include -#include -#include - -#include "filelist.h" -#include -#include - -#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 35cee0f78530b4a76b15b0ad27fc3a8eb227619c..0000000000000000000000000000000000000000 --- a/bsp/stm32_radio/filelist.h +++ /dev/null @@ -1,55 +0,0 @@ -#ifndef __FILE_LIST_VIEW_H__ -#define __FILE_LIST_VIEW_H__ - -#include - -#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 bfc191ce24eab11f5dd48e174925ed34079db52f..b86a6fc1ae24ba0148a4387119647c23a74ebfc3 100644 --- a/bsp/stm32_radio/http.c +++ b/bsp/stm32_radio/http.c @@ -8,12 +8,7 @@ #include #include -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 6a8a0b93dd8eaceafb87886683c88762a9647922..0000000000000000000000000000000000000000 --- a/bsp/stm32_radio/listview.c +++ /dev/null @@ -1,245 +0,0 @@ -#include "listview.h" -#include - -#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 b5b7ce744a71c14d62e37ac66943d2687adcaed3..0000000000000000000000000000000000000000 --- a/bsp/stm32_radio/listview.h +++ /dev/null @@ -1,53 +0,0 @@ -#ifndef __RTGUI_LIST_VIEW_H__ -#define __RTGUI_LIST_VIEW_H__ - -#include -#include -#include - -#include - -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 b923e1c600aee04fefc880673a5029c65b8862ff..69070a5d4702cf2fd02ff7f233fe3f58ed2a3403 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 0000000000000000000000000000000000000000..c15011983f769ff7eebb1c97aa93666dec5fe5e9 --- /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 aa0198445d69ff8090f6b87973f9137cbc895eeb..f970d2a67ce176db463c28b771553a5f2b63e710 100644 --- a/bsp/stm32_radio/netbuffer.c +++ b/bsp/stm32_radio/netbuffer.c @@ -2,6 +2,7 @@ #include #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 2484951f4746356fa78d536a773cf4d086d75366..32c7d1d00277b6c23ddaabdaf6150c653d5a2432 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 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 353ed0ec0eff7a7429ed476b22f2e0d02c87b6c3..a134484cbd26d4f3e31a55bae192f4a82208608e 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 @@ -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 -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 c419e828e34d67f66688424312746bb5f28d3e86..715fcba86ae93dc5576ecc2b4c7b9fc6402b34bc 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 9d3f35156e9e12be2d3d50afa5219008552b7c6e..d481261abdae4430d4111652ced319315a79dc84 100644 --- a/bsp/stm32_radio/player_ui.c +++ b/bsp/stm32_radio/player_ui.c @@ -3,25 +3,27 @@ #include #include +#include #include -#include +#include +#include #include +#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), ""); - - 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), ""); + + 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 50d4e0ce7df606d446dadf79c4923ae95874bcba..921f2873b68453b29c78df1973a1e39e5f5b7707 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 fa3a1819030707ce788a5a4e96b914d8cdf400c3..3067d8c452ee92113707528bf7898a99018e3190 100644 --- a/bsp/stm32_radio/project.Uv2 +++ b/bsp/stm32_radio/project.Uv2 @@ -37,9 +37,7 @@ File 1,1,<.\wav.c> File 1,1,<.\netbuffer.c> File 1,1,<.\key.c> File 1,1,<.\info.c> -File 1,1,<.\filelist.c> File 1,1,<.\device_info.c> -File 1,1,<.\listview.c> File 1,1,<.\player_ui.c> File 1,1,<.\player_bg.c> File 1,1,<.\play_list.c> @@ -48,6 +46,7 @@ File 1,1,<.\codec.c> File 1,1,<.\spi_flash.c> File 1,1,<.\remote.c> File 1,1,<.\picture.c> +File 1,1,<.\station_list.c> File 2,1,<..\..\src\clock.c> File 2,1,<..\..\src\idle.c> File 2,1,<..\..\src\ipc.c> @@ -210,6 +209,8 @@ File 11,1,<..\..\rtgui\server\topwin.c> File 11,1,<..\..\rtgui\common\font_hz_file.c> File 11,1,<..\..\rtgui\common\hz16font.c> File 11,1,<..\..\rtgui\common\hz12font.c> +File 11,1,<..\..\rtgui\widgets\list_view.c> +File 11,1,<..\..\rtgui\widgets\filelist_view.c> File 12,1,<.\Libraries\Mass_Storage\src\hw_config.c> File 12,1,<.\Libraries\Mass_Storage\src\mass_mal.c> File 12,1,<.\Libraries\Mass_Storage\src\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 bf5952159ee06d3bdf92afc6b245f98c091052e8..1a25d6846c34a70f73390041849d30d4f6fd306e 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 0000000000000000000000000000000000000000..34d429e9e32564ddcd8631b5f094f878a49e6b2f --- /dev/null +++ b/bsp/stm32_radio/station_list.c @@ -0,0 +1,219 @@ +#include +#include +#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 0000000000000000000000000000000000000000..6f7956ec8451f9c8268e642647d08f483fbfa261 --- /dev/null +++ b/bsp/stm32_radio/station_list.h @@ -0,0 +1,31 @@ +#ifndef __STATION_LIST_H__ +#define __STATION_LIST_H__ + +#include +#include +#include +#include + +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 92474cf15c2ac969c418811aeabb26cb6d44887f..0000000000000000000000000000000000000000 --- a/bsp/stm32_radio/workbench.c +++ /dev/null @@ -1,95 +0,0 @@ -#include -#include - -#include -#include - -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; /* 濡傛灉鑾峰彇澶辫触浠h〃浠涔堬紵杩欎釜鎺т欢鏄殣钘忕殑鎴... */ - rtgui_widget_get_rect(widget, &rect); /* 鑾峰緱鎺т欢鐨勫彲瑙嗗尯鍩 */ - - /* 鍏堝鎵鍦ㄥ彲瑙嗗尯鍩熷叏閮ㄥ~鍏呬负鑳屾櫙鑹 */ - rtgui_dc_fill_rect(dc, &rect); - - /* 缁樺埗涓涓猦ello! */ - rtgui_dc_draw_text(dc, "hello world", &rect); - - /* 閫氱煡RTGUI锛岀粯鍒剁粨鏉 */ - rtgui_dc_end_drawing(dc); - - return RT_FALSE; - } - - /* 濡傛灉涓嶆槸缁樺埗浜嬩欢锛屼娇鐢╲iew鍘熸潵鐨勪簨浠跺鐞嗗嚱鏁板鐞 */ - 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); - /* 娉ㄥ唽褰撳墠绾跨▼涓篏UI绾跨▼ */ - 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); - - /* 鍘绘敞鍐孏UI绾跨▼ */ - 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 -void workbench() -{ - workbench_init(); -} -/* finsh鐨勫懡浠よ緭鍑猴紝鍙互鐩存帴鎵цworkbench()鍑芥暟浠ユ墽琛屼笂闈㈢殑鍑芥暟 */ -FINSH_FUNCTION_EXPORT(workbench, workbench demo) -#endif diff --git a/rtgui/common/dc.c b/rtgui/common/dc.c index 68a02e863b73eb632b8d4cf3d568ea3a688a6173..41967bb92e757f3581b8987d5b0e35088c50bb99 100644 --- a/rtgui/common/dc.c +++ b/rtgui/common/dc.c @@ -167,7 +167,7 @@ void rtgui_dc_blit(struct rtgui_dc* dc, struct rtgui_point* dc_point, struct rtg dc->blit(dc, dc_point, dest, rect); } -void rtgui_dc_draw_text (struct rtgui_dc* dc, const rt_uint8_t* text, struct rtgui_rect* rect) +void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect) { rt_uint32_t len; struct rtgui_font *font; diff --git a/rtgui/common/font.c b/rtgui/common/font.c index 475effa72699760de01d76cc4e149a871f615f4a..9e9f63c7e4cb581b486394a1c11b939aedde0f9a 100644 --- a/rtgui/common/font.c +++ b/rtgui/common/font.c @@ -120,7 +120,7 @@ void rtgui_font_derefer(struct rtgui_font* font) } /* draw a text */ -void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) +void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect) { RT_ASSERT(font != RT_NULL); @@ -131,7 +131,7 @@ void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint } } -int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text) +int rtgui_font_get_string_width(struct rtgui_font* font, const char* text) { rtgui_rect_t rect; @@ -141,7 +141,7 @@ int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text) return rect.x2 - rect.x1; } -void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) +void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect) { RT_ASSERT(font != RT_NULL); @@ -157,8 +157,8 @@ void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtg } } -static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); -static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); +static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); +static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect); struct rtgui_font_engine bmp_font_engine = { RT_NULL, @@ -197,7 +197,7 @@ void rtgui_bitmap_font_draw_char(struct rtgui_font_bitmap* font, struct rtgui_dc } } -static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) +static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect) { struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); @@ -213,7 +213,7 @@ static void rtgui_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc } } -static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) +static void rtgui_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect) { struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); diff --git a/rtgui/common/font_hz_bmp.c b/rtgui/common/font_hz_bmp.c index 239f6f9fe93de1c1ddf0cc4d68921c860fce6305..1190cb473c2e3e476f6700ceba0ab7f2aa8b39fc 100644 --- a/rtgui/common/font_hz_bmp.c +++ b/rtgui/common/font_hz_bmp.c @@ -4,8 +4,8 @@ #ifdef RTGUI_USING_HZ_BMP -static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); -static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); +static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); +static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect); struct rtgui_font_engine hz_bmp_font_engine = { RT_NULL, @@ -14,7 +14,7 @@ struct rtgui_font_engine hz_bmp_font_engine = rtgui_hz_bitmap_font_get_metrics }; -static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) +static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect) { rt_base_t h; rt_uint8_t* str; @@ -61,7 +61,7 @@ static void rtgui_hz_bitmap_font_draw_text(struct rtgui_font* font, struct rtgui } } -static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) +static void rtgui_hz_bitmap_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect) { struct rtgui_font_bitmap* bmp_font = (struct rtgui_font_bitmap*)(font->data); diff --git a/rtgui/common/font_hz_file.c b/rtgui/common/font_hz_file.c index 11ee300f86af9e8335f7b46bd7df3f220a7c12bb..b805de5ad43b1ccc931a62a0bf034cec3afc0a4d 100644 --- a/rtgui/common/font_hz_file.c +++ b/rtgui/common/font_hz_file.c @@ -13,8 +13,8 @@ static int _font_cache_compare(struct hz_cache* node1, struct hz_cache* node2); static void rtgui_hz_file_font_load(struct rtgui_font* font); -static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); -static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect); +static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); +static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect); struct rtgui_font_engine rtgui_hz_file_font_engine = { RT_NULL, @@ -91,7 +91,7 @@ static void rtgui_hz_file_font_load(struct rtgui_font* font) hz_file_font->fd = open(hz_file_font->font_fn, O_RDONLY, 0); } -static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect) +static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect) { rt_base_t h; rt_uint8_t* str; @@ -133,7 +133,7 @@ static void rtgui_hz_file_font_draw_text(struct rtgui_font* font, struct rtgui_d } } -static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, rtgui_rect_t* rect) +static void rtgui_hz_file_font_get_metrics(struct rtgui_font* font, const char* text, rtgui_rect_t* rect) { struct rtgui_hz_file_font* hz_file_font = (struct rtgui_hz_file_font*)font->data; RT_ASSERT(hz_file_font != RT_NULL); diff --git a/rtgui/include/rtgui/dc.h b/rtgui/include/rtgui/dc.h index 43704d17854fc7626ef0591c5975841a9a5c0819..955ef2c226bf33924eb16480c8ff0fecef73e7e5 100644 --- a/rtgui/include/rtgui/dc.h +++ b/rtgui/include/rtgui/dc.h @@ -106,7 +106,7 @@ void rtgui_dc_draw_line (struct rtgui_dc* dc, int x1, int y1, int x2, int y2); void rtgui_dc_draw_rect (struct rtgui_dc* dc, struct rtgui_rect* rect); void rtgui_dc_draw_round_rect(struct rtgui_dc* dc, struct rtgui_rect* rect); -void rtgui_dc_draw_text (struct rtgui_dc* dc, const rt_uint8_t* text, struct rtgui_rect* rect); +void rtgui_dc_draw_text (struct rtgui_dc* dc, const char* text, struct rtgui_rect* rect); void rtgui_dc_draw_byte(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); void rtgui_dc_draw_word(struct rtgui_dc*dc, int x, int y, int h, const rt_uint8_t* data); diff --git a/rtgui/include/rtgui/font.h b/rtgui/include/rtgui/font.h index 43af8fd6a3f53d9883f95ac4c17a6de749c5b989..512290efde5b3499c776a2e21a72c50552010934 100644 --- a/rtgui/include/rtgui/font.h +++ b/rtgui/include/rtgui/font.h @@ -27,9 +27,9 @@ struct rtgui_font_engine void (*font_init)(struct rtgui_font* font); void (*font_load)(struct rtgui_font* font); - void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, + void (*font_draw_text)(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); - void (*font_get_metrics)(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect); + void (*font_get_metrics)(struct rtgui_font* font, const char* text, struct rtgui_rect* rect); }; /* @@ -107,8 +107,8 @@ struct rtgui_font* rtgui_font_refer(const rt_uint8_t* family, rt_uint16_t height void rtgui_font_derefer(struct rtgui_font* font); /* draw a text */ -void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const rt_uint8_t* text, rt_ubase_t len, struct rtgui_rect* rect); -int rtgui_font_get_string_width(struct rtgui_font* font, const rt_uint8_t* text); -void rtgui_font_get_metrics(struct rtgui_font* font, const rt_uint8_t* text, struct rtgui_rect* rect); +void rtgui_font_draw(struct rtgui_font* font, struct rtgui_dc* dc, const char* text, rt_ubase_t len, struct rtgui_rect* rect); +int rtgui_font_get_string_width(struct rtgui_font* font, const char* text); +void rtgui_font_get_metrics(struct rtgui_font* font, const char* text, struct rtgui_rect* rect); #endif diff --git a/rtgui/include/rtgui/widgets/button.h b/rtgui/include/rtgui/widgets/button.h index 7ecc574ad0cfaa19678d482a204073941689a33c..8b6b18fb737c28adb9c13f98007f5aebb2971a33 100644 --- a/rtgui/include/rtgui/widgets/button.h +++ b/rtgui/include/rtgui/widgets/button.h @@ -62,8 +62,8 @@ typedef void (*rtgui_onbutton_func_t)(struct rtgui_widget* widget, rtgui_event_t rtgui_type_t *rtgui_button_type_get(void); -rtgui_button_t* rtgui_button_create(unsigned char* text); -rtgui_button_t* rtgui_pushbutton_create(unsigned char* text); +rtgui_button_t* rtgui_button_create(char* text); +rtgui_button_t* rtgui_pushbutton_create(char* text); void rtgui_button_destroy(rtgui_button_t* btn); void rtgui_button_set_pressed_image(rtgui_button_t* btn, rtgui_image_t* image); diff --git a/rtgui/include/rtgui/widgets/filelist_view.h b/rtgui/include/rtgui/widgets/filelist_view.h index e3fab1fc904a4f7413f94680b9461a722aeaccf6..61144031049793dcbeb905998f0f8af178ab4691 100644 --- a/rtgui/include/rtgui/widgets/filelist_view.h +++ b/rtgui/include/rtgui/widgets/filelist_view.h @@ -7,7 +7,7 @@ #define RTGUI_FITEM_DIR 0x1 struct rtgui_file_item { - rt_uint8_t* name; + char* name; rt_uint32_t type; rt_uint32_t size; @@ -27,8 +27,8 @@ struct rtgui_filelist_view /* widget private data */ /* current directory */ - rt_uint8_t* current_directory; - rt_uint8_t* pattern; + char* current_directory; + char* pattern; /* the number of item in a page */ rt_uint16_t page_items; diff --git a/rtgui/include/rtgui/widgets/iconbox.h b/rtgui/include/rtgui/widgets/iconbox.h index 73ebd682a6669aa682124d7efbf28eeed7f85f9e..c6807e2a9b9bd9144b46bc004456312f50485192 100644 --- a/rtgui/include/rtgui/widgets/iconbox.h +++ b/rtgui/include/rtgui/widgets/iconbox.h @@ -37,7 +37,7 @@ struct rtgui_iconbox /* widget private data */ struct rtgui_image* image; - unsigned char *text; + char *text; rt_ubase_t text_position; rt_bool_t selected; @@ -46,7 +46,7 @@ typedef struct rtgui_iconbox rtgui_iconbox_t; rtgui_type_t *rtgui_iconbox_type_get(void); -struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const unsigned char* text, int position); +struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, const char* text, int position); void rtgui_iconbox_destroy(struct rtgui_iconbox* iconbox); rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); diff --git a/rtgui/include/rtgui/widgets/label.h b/rtgui/include/rtgui/widgets/label.h index d9f87d9b88568e6f7d01f166f0fa32c939e295af..cced499f869faae68e01653082dfcd07e6d10a31 100644 --- a/rtgui/include/rtgui/widgets/label.h +++ b/rtgui/include/rtgui/widgets/label.h @@ -32,18 +32,18 @@ struct rtgui_label struct rtgui_widget parent; /* label */ - unsigned char* text; + char* text; }; typedef struct rtgui_label rtgui_label_t; rtgui_type_t *rtgui_label_type_get(void); -rtgui_label_t* rtgui_label_create(const unsigned char* text); +rtgui_label_t* rtgui_label_create(const char* text); void rtgui_label_destroy(rtgui_label_t* label); rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); -void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text); -unsigned char* rtgui_label_get_text(rtgui_label_t* label); +void rtgui_label_set_text(rtgui_label_t* label, const char* text); +char* rtgui_label_get_text(rtgui_label_t* label); #endif diff --git a/rtgui/include/rtgui/widgets/list_view.h b/rtgui/include/rtgui/widgets/list_view.h index 69463eb98bb0a26ef56626b1799e9cae76c87754..d15671eca034061e8094f4cb8bf635dc88052858 100644 --- a/rtgui/include/rtgui/widgets/list_view.h +++ b/rtgui/include/rtgui/widgets/list_view.h @@ -44,7 +44,7 @@ struct rtgui_list_view /* widget private data */ /* list item */ - struct rtgui_list_item* items; + const struct rtgui_list_item* items; /* total number of items */ rt_uint16_t items_count; @@ -57,10 +57,13 @@ typedef struct rtgui_list_view rtgui_list_view_t; rtgui_type_t *rtgui_list_view_type_get(void); -rtgui_list_view_t* rtgui_list_view_create(struct rtgui_list_item* items, rt_uint16_t count, +rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect); +void rtgui_list_view_destroy(rtgui_list_view_t* view); + void rtgui_list_view_clear(rtgui_list_view_t* view); rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgui_event* event); #endif + diff --git a/rtgui/include/rtgui/widgets/textbox.h b/rtgui/include/rtgui/widgets/textbox.h index c1378fd2fc34f713a97af8d72f7b72c867dd701e..5dfc64d8c6e9224e692a3cafbb7012d8ace28185 100644 --- a/rtgui/include/rtgui/widgets/textbox.h +++ b/rtgui/include/rtgui/widgets/textbox.h @@ -35,7 +35,7 @@ struct rtgui_textbox_line { - rt_uint8_t* line_text; + char* line_text; struct rtgui_textbox_line *prev, *next; }; @@ -51,7 +51,7 @@ struct rtgui_textbox /* current line and position */ rt_uint16_t line, line_begin, position, line_length; - rt_uint8_t* text; + char* text; rt_size_t font_width; struct rtgui_timer* caret_timer; diff --git a/rtgui/include/rtgui/widgets/title.h b/rtgui/include/rtgui/widgets/title.h index 0eda0f16a46439a0cbb393e5eafd4a288ce998bd..97f446340755029c5fe0554356d0b755199ac3d7 100644 --- a/rtgui/include/rtgui/widgets/title.h +++ b/rtgui/include/rtgui/widgets/title.h @@ -28,18 +28,18 @@ struct rtgui_wintitle struct rtgui_toplevel parent; /* title */ - rt_uint8_t* title; + char* title; }; typedef struct rtgui_wintitle rtgui_wintitle_t; rtgui_type_t* rtgui_wintitle_type_get(void); -rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title); +rtgui_wintitle_t* rtgui_wintitle_create(const char* title); void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle); rt_bool_t rtgui_wintile_event_handler(rtgui_widget_t* widget, rtgui_event_t* event); -void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title); -rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle); +void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title); +char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle); #endif diff --git a/rtgui/widgets/button.c b/rtgui/widgets/button.c index 45db6239fb50856ec9982f44bfee92684346809b..36e010f28a32e459fd5cfa968d6baf9348cecb6b 100644 --- a/rtgui/widgets/button.c +++ b/rtgui/widgets/button.c @@ -188,7 +188,7 @@ rt_bool_t rtgui_button_event_handler(struct rtgui_widget* widget, struct rtgui_e return RT_FALSE; } -rtgui_button_t* rtgui_button_create(unsigned char* text) +rtgui_button_t* rtgui_button_create(char* text) { struct rtgui_button* btn; @@ -208,7 +208,7 @@ rtgui_button_t* rtgui_button_create(unsigned char* text) return btn; } -rtgui_button_t* rtgui_pushbutton_create(unsigned char* text) +rtgui_button_t* rtgui_pushbutton_create(char* text) { rtgui_button_t* btn; diff --git a/rtgui/widgets/filelist_view.c b/rtgui/widgets/filelist_view.c index 3724b84d6d8e8a5f1e302bc6a2978148beb5e5ba..bef3f9003099f3b151042ca8c807616b00c8a88d 100644 --- a/rtgui/widgets/filelist_view.c +++ b/rtgui/widgets/filelist_view.c @@ -219,7 +219,6 @@ const static char * folder_xpm[] = { /* image for file and folder */ static rtgui_image_t *file_image, *folder_image; -static struct rtgui_filelist_view *filelist_view = RT_NULL; /* only one view in global */ static void _rtgui_filelist_view_constructor(struct rtgui_filelist_view *view) { @@ -489,7 +488,7 @@ rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct if (strcmp(view->items[view->current_item].name, ".") == 0) return RT_FALSE; if (strcmp(view->items[view->current_item].name, "..") == 0) { - rt_uint8_t *ptr; + char *ptr; ptr = strrchr(view->current_directory, PATH_SEPARATOR); if (ptr == RT_NULL) return RT_FALSE; @@ -526,11 +525,11 @@ rt_bool_t rtgui_filelist_view_event_handler(struct rtgui_widget* widget, struct else { if (view->current_directory[strlen(view->current_directory) - 1] != PATH_SEPARATOR) - sprintf(new_path, "%s%c%s",view->current_directory, PATH_SEPARATOR, + rt_snprintf(new_path, sizeof(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); + rt_snprintf(new_path, sizeof(new_path), "%s%s",view->current_directory, + view->items[view->current_item].name); } rtgui_filelist_view_set_directory(view, new_path); } @@ -616,7 +615,7 @@ void rtgui_filelist_view_clear(rtgui_filelist_view_t* view) void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* directory) { - rt_uint8_t fullpath[256]; + char fullpath[256]; struct rtgui_file_item *item; RT_ASSERT(view != RT_NULL); @@ -693,9 +692,9 @@ void rtgui_filelist_view_set_directory(rtgui_filelist_view_t* view, const char* /* build full path for the file */ if (directory[strlen(directory) - 1] != PATH_SEPARATOR) - sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name); + rt_sprintf(fullpath, "%s%c%s", directory, PATH_SEPARATOR, dirent->d_name); else - sprintf(fullpath, "%s%s", directory, dirent->d_name); + rt_sprintf(fullpath, "%s%s", directory, dirent->d_name); stat(fullpath, &s); if ( s.st_mode & S_IFDIR ) @@ -726,4 +725,4 @@ void rtgui_filelist_get_fullpath(rtgui_filelist_view_t* view, char* path, rt_siz rt_sprintf(path, "%s%c%s", view->current_directory, PATH_SEPARATOR, view->items[view->current_item].name); -} \ No newline at end of file +} diff --git a/rtgui/widgets/iconbox.c b/rtgui/widgets/iconbox.c index 65f094e64f4a5af3080a0379c3000ca9b026529a..7a25f3df267029856d3870ea9d31b309dc92cadd 100644 --- a/rtgui/widgets/iconbox.c +++ b/rtgui/widgets/iconbox.c @@ -76,7 +76,7 @@ rt_bool_t rtgui_iconbox_event_handler(struct rtgui_widget* widget, struct rtgui_ } struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, - const unsigned char* text, + const char* text, int position) { struct rtgui_iconbox* iconbox; @@ -115,7 +115,7 @@ struct rtgui_iconbox* rtgui_iconbox_create(struct rtgui_image* image, /* set image and text position */ iconbox->image = image; - iconbox->text = (unsigned char*)rt_strdup((const char*)text); + iconbox->text = (char*)rt_strdup((const char*)text); iconbox->text_position = position; } diff --git a/rtgui/widgets/label.c b/rtgui/widgets/label.c index 574ec7cea75223908e74580f4e060d7372833c45..ae5448080cd0a9bafad78e6f2fbd295d1032ca17 100644 --- a/rtgui/widgets/label.c +++ b/rtgui/widgets/label.c @@ -64,7 +64,7 @@ rt_bool_t rtgui_label_event_handler(struct rtgui_widget* widget, struct rtgui_ev return RT_FALSE; } -rtgui_label_t* rtgui_label_create(const unsigned char* text) +rtgui_label_t* rtgui_label_create(const char* text) { struct rtgui_label* label; @@ -80,7 +80,7 @@ rtgui_label_t* rtgui_label_create(const unsigned char* text) rtgui_widget_set_rect(RTGUI_WIDGET(label), &rect); /* set text */ - label->text = (unsigned char*)rt_strdup((const char*)text); + label->text = (char*)rt_strdup((const char*)text); } return label; @@ -91,14 +91,14 @@ void rtgui_label_destroy(rtgui_label_t* label) rtgui_widget_destroy(RTGUI_WIDGET(label)); } -unsigned char* rtgui_label_get_text(rtgui_label_t* label) +char* rtgui_label_get_text(rtgui_label_t* label) { RT_ASSERT(label != RT_NULL); return label->text; } -void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text) +void rtgui_label_set_text(rtgui_label_t* label, const char* text) { RT_ASSERT(label != RT_NULL); @@ -108,7 +108,7 @@ void rtgui_label_set_text(rtgui_label_t* label, const unsigned char* text) rt_free(label->text); } - if (text != RT_NULL) label->text = (unsigned char*)rt_strdup((const char*)text); + if (text != RT_NULL) label->text = (char*)rt_strdup((const char*)text); else label->text = RT_NULL; /* update widget */ diff --git a/rtgui/widgets/list_view.c b/rtgui/widgets/list_view.c index 42f50b702c4c850cdae6a69be2cc0d5197ab9b6c..857a9454a1f39f05533d5d02815f71eeb41b2956 100644 --- a/rtgui/widgets/list_view.c +++ b/rtgui/widgets/list_view.c @@ -54,7 +54,7 @@ void rtgui_list_view_ondraw(struct rtgui_list_view* view) struct rtgui_rect rect, item_rect; struct rtgui_dc* dc; rt_uint16_t page_index, index; - struct rtgui_list_item* item; + const struct rtgui_list_item* item; dc = rtgui_dc_begin_drawing(RTGUI_WIDGET(view)); if (dc == RT_NULL) return; @@ -103,7 +103,7 @@ void rtgui_list_view_ondraw(struct rtgui_list_view* view) void rtgui_list_view_update_current(struct rtgui_list_view* view, rt_uint16_t old_item) { struct rtgui_dc* dc; - struct rtgui_list_item* item; + const struct rtgui_list_item* item; rtgui_rect_t rect, item_rect; if (old_item/view->page_items != view->current_item/view->page_items) @@ -267,7 +267,7 @@ rt_bool_t rtgui_list_view_event_handler(struct rtgui_widget* widget, struct rtgu return rtgui_view_event_handler(widget, event); } -rtgui_list_view_t* rtgui_list_view_create(struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect) +rtgui_list_view_t* rtgui_list_view_create(const struct rtgui_list_item* items, rt_uint16_t count, rtgui_rect_t *rect) { struct rtgui_list_view* view = RT_NULL; diff --git a/rtgui/widgets/textbox.c b/rtgui/widgets/textbox.c index c28f193b37594fb0c1a41df2dd23d97df81bc24c..d7e6ca798d3646b9e2781411f787f3ac168efe7a 100644 --- a/rtgui/widgets/textbox.c +++ b/rtgui/widgets/textbox.c @@ -156,7 +156,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb } else { - unsigned char *c; + char *c; /* remove character */ for (c = &box->text[box->position]; c[1] != '\0'; c++) @@ -176,7 +176,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb /* remove current character */ if (box->position != 0) { - unsigned char *c; + char *c; /* remove character */ for (c = &box->text[box->position - 1]; c[1] != '\0'; c++) @@ -218,7 +218,7 @@ static void rtgui_textbox_onkey(struct rtgui_textbox* box, struct rtgui_event_kb if (box->position < length - 1) { - unsigned char* c; + char* c; for (c = &box->text[length]; c != &box->text[box->position]; c--) *c = *(c-1); diff --git a/rtgui/widgets/title.c b/rtgui/widgets/title.c index 005f125ee2e0c9de25ec601334b62448666cbc5a..c1b2419f3719085fd2054843310edbbdedacfdb3 100644 --- a/rtgui/widgets/title.c +++ b/rtgui/widgets/title.c @@ -43,7 +43,7 @@ rtgui_type_t* rtgui_wintitle_type_get() return wintitle_type; } -rtgui_wintitle_t* rtgui_wintitle_create(const rt_uint8_t* title) +rtgui_wintitle_t* rtgui_wintitle_create(const char* title) { rtgui_wintitle_t* wintitle; @@ -61,7 +61,7 @@ void rtgui_wintitle_destroy(rtgui_wintitle_t* wintitle) rtgui_widget_destroy(RTGUI_WIDGET(wintitle)); } -void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* title) +void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const char* title) { RT_ASSERT(wintitle != RT_NULL); @@ -70,11 +70,11 @@ void rtgui_wintitle_set_title(rtgui_wintitle_t* wintitle, const rt_uint8_t* titl rtgui_free(wintitle->title); } - if (title != RT_NULL) wintitle->title = (unsigned char*)rt_strdup((const char*)title); + if (title != RT_NULL) wintitle->title = (char*)rt_strdup((const char*)title); else wintitle->title = RT_NULL; } -rt_uint8_t *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle) +char *rtgui_wintitle_get_title(rtgui_wintitle_t* wintitle) { RT_ASSERT(wintitle != RT_NULL);