diff options
Diffstat (limited to 'apps/menu.h')
-rw-r--r-- | apps/menu.h | 178 |
1 files changed, 88 insertions, 90 deletions
diff --git a/apps/menu.h b/apps/menu.h index f9a3d1ffd8..b0a1b4cb7f 100644 --- a/apps/menu.h +++ b/apps/menu.h | |||
@@ -22,101 +22,14 @@ | |||
22 | 22 | ||
23 | #include <stdbool.h> | 23 | #include <stdbool.h> |
24 | 24 | ||
25 | /* button definitions */ | ||
26 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | ||
27 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
28 | #define MENU_EXIT BUTTON_LEFT | ||
29 | #define MENU_EXIT2 BUTTON_OFF | ||
30 | #define MENU_EXIT_MENU BUTTON_MODE | ||
31 | #define MENU_ENTER BUTTON_RIGHT | ||
32 | #define MENU_ENTER2 BUTTON_SELECT | ||
33 | |||
34 | #define MENU_RC_EXIT BUTTON_RC_STOP | ||
35 | #define MENU_RC_EXIT_MENU BUTTON_RC_MODE | ||
36 | #define MENU_RC_ENTER BUTTON_RC_ON | ||
37 | #define MENU_RC_ENTER2 BUTTON_RC_MENU | ||
38 | |||
39 | |||
40 | #elif CONFIG_KEYPAD == RECORDER_PAD | ||
41 | |||
42 | #define MENU_EXIT BUTTON_LEFT | ||
43 | #define MENU_EXIT2 BUTTON_OFF | ||
44 | #define MENU_EXIT_MENU BUTTON_F1 | ||
45 | #define MENU_ENTER BUTTON_RIGHT | ||
46 | #define MENU_ENTER2 BUTTON_PLAY | ||
47 | |||
48 | #define MENU_RC_EXIT BUTTON_RC_STOP | ||
49 | #define MENU_RC_ENTER BUTTON_RC_PLAY | ||
50 | |||
51 | #elif CONFIG_KEYPAD == PLAYER_PAD | ||
52 | #define MENU_EXIT BUTTON_STOP | ||
53 | #define MENU_EXIT_MENU BUTTON_MENU | ||
54 | #define MENU_ENTER BUTTON_PLAY | ||
55 | |||
56 | #define MENU_RC_EXIT BUTTON_RC_STOP | ||
57 | #define MENU_RC_ENTER BUTTON_RC_PLAY | ||
58 | |||
59 | #elif CONFIG_KEYPAD == ONDIO_PAD | ||
60 | #define MENU_EXIT BUTTON_LEFT | ||
61 | #define MENU_EXIT_MENU BUTTON_MENU | ||
62 | #define MENU_ENTER BUTTON_RIGHT | ||
63 | |||
64 | #elif (CONFIG_KEYPAD == IPOD_3G_PAD) || (CONFIG_KEYPAD == IPOD_4G_PAD) | ||
65 | |||
66 | /* TODO: Check menu button assignments */ | ||
67 | |||
68 | #define MENU_NEXT BUTTON_DOWN | ||
69 | #define MENU_PREV BUTTON_UP | ||
70 | #define MENU_EXIT BUTTON_LEFT | ||
71 | #define MENU_EXIT_MENU BUTTON_MENU | ||
72 | #define MENU_ENTER BUTTON_RIGHT | ||
73 | #define MENU_ENTER2 BUTTON_SELECT | ||
74 | |||
75 | #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD | ||
76 | |||
77 | #define MENU_NEXT BUTTON_DOWN | ||
78 | #define MENU_PREV BUTTON_UP | ||
79 | #define MENU_EXIT BUTTON_LEFT | ||
80 | #define MENU_EXIT_MENU BUTTON_PLAY | ||
81 | #define MENU_ENTER BUTTON_RIGHT | ||
82 | |||
83 | #elif CONFIG_KEYPAD == IAUDIO_X5_PAD | ||
84 | |||
85 | #define MENU_NEXT BUTTON_DOWN | ||
86 | #define MENU_PREV BUTTON_UP | ||
87 | #define MENU_EXIT BUTTON_LEFT | ||
88 | #define MENU_EXIT_MENU BUTTON_REC | ||
89 | #define MENU_ENTER BUTTON_RIGHT | ||
90 | #define MENU_ENTER2 BUTTON_SELECT | ||
91 | |||
92 | #elif CONFIG_KEYPAD == GIGABEAT_PAD | ||
93 | |||
94 | #define MENU_EXIT BUTTON_LEFT | ||
95 | #define MENU_EXIT2 BUTTON_A | ||
96 | #define MENU_EXIT_MENU BUTTON_MENU | ||
97 | #define MENU_ENTER BUTTON_RIGHT | ||
98 | #define MENU_ENTER2 BUTTON_SELECT | ||
99 | #define MENU_NEXT BUTTON_DOWN | ||
100 | #define MENU_PREV BUTTON_UP | ||
101 | |||
102 | #elif CONFIG_KEYPAD == IRIVER_H10_PAD | ||
103 | |||
104 | #define MENU_NEXT BUTTON_SCROLL_DOWN | ||
105 | #define MENU_PREV BUTTON_SCROLL_UP | ||
106 | #define MENU_EXIT BUTTON_LEFT | ||
107 | #define MENU_EXIT_MENU BUTTON_REW | ||
108 | #define MENU_ENTER BUTTON_RIGHT | ||
109 | #define MENU_ENTER2 BUTTON_FF | ||
110 | |||
111 | #endif | ||
112 | |||
113 | struct menu_item { | 25 | struct menu_item { |
114 | unsigned char *desc; /* string or ID */ | 26 | unsigned char *desc; /* string or ID */ |
115 | bool (*function) (void); /* return true if USB was connected */ | 27 | bool (*function) (void); /* return true if USB was connected */ |
116 | }; | 28 | }; |
117 | 29 | ||
118 | int menu_init(const struct menu_item* mitems, int count, int (*callback)(int, int), | 30 | int menu_init(const struct menu_item* mitems, int count, |
119 | const char *button1, const char *button2, const char *button3); | 31 | int (*callback)(int, int), |
32 | const char *button1, const char *button2, const char *button3); | ||
120 | void menu_exit(int menu); | 33 | void menu_exit(int menu); |
121 | 34 | ||
122 | void put_cursorxy(int x, int y, bool on); | 35 | void put_cursorxy(int x, int y, bool on); |
@@ -125,6 +38,8 @@ void put_cursorxy(int x, int y, bool on); | |||
125 | int menu_show(int m); | 38 | int menu_show(int m); |
126 | #define MENU_ATTACHED_USB -1 | 39 | #define MENU_ATTACHED_USB -1 |
127 | #define MENU_SELECTED_EXIT -2 | 40 | #define MENU_SELECTED_EXIT -2 |
41 | #define MENU_EXIT_ALL -3 | ||
42 | #define MENU_RETURN_TO_WPS -4 | ||
128 | 43 | ||
129 | bool menu_run(int menu); | 44 | bool menu_run(int menu); |
130 | int menu_cursor(int menu); | 45 | int menu_cursor(int menu); |
@@ -138,4 +53,87 @@ void menu_insert(int menu, int position, char *desc, bool (*function) (void)); | |||
138 | void menu_set_cursor(int menu, int position); | 53 | void menu_set_cursor(int menu, int position); |
139 | void menu_talk_selected(int m); | 54 | void menu_talk_selected(int m); |
140 | 55 | ||
56 | |||
57 | enum menu_item_type { | ||
58 | MT_MENU = 0, | ||
59 | MT_SETTING, | ||
60 | MT_FUNCTION_CALL, /* used when the standard code wont work */ | ||
61 | MT_FUNCTION_WITH_PARAM, | ||
62 | MT_RETURN_ID, /* returns the position of the selected item (starting at 0)*/ | ||
63 | }; | ||
64 | |||
65 | typedef int (*menu_function)(void); | ||
66 | struct menu_func_with_param { | ||
67 | int (*function)(void* param); | ||
68 | void *param; | ||
69 | }; | ||
70 | |||
71 | #define MENU_TYPE_MASK 0xF /* MT_* type */ | ||
72 | #define MENU_HAS_DESC 0x10 | ||
73 | #define MENU_COUNT_MASK (~(MENU_TYPE_MASK|MENU_HAS_DESC)) /* unless we need more flags*/ | ||
74 | #define MENU_COUNT_SHIFT 5 | ||
75 | |||
76 | struct menu_item_ex { | ||
77 | int flags; /* above defines */ | ||
78 | union { | ||
79 | const struct menu_item_ex **submenus; /* used with MT_MENU */ | ||
80 | void *variable; /* used with MT_SETTING, | ||
81 | must be in the settings_list.c list */ | ||
82 | int (*function)(void); /* used with MT_FUNCTION_CALL */ | ||
83 | const struct menu_func_with_param | ||
84 | *func_with_param; /* MT_FUNCTION_WITH_PARAM */ | ||
85 | const char **strings; /* used with MT_RETURN_ID */ | ||
86 | }; | ||
87 | union { | ||
88 | int (*menu_callback)(int action, const struct menu_item_ex *this_item); | ||
89 | const struct menu_callback_with_desc { | ||
90 | int (*menu_callback)(int action, | ||
91 | const struct menu_item_ex *this_item); | ||
92 | unsigned char *desc; /* string or ID */ | ||
93 | } *callback_and_desc; | ||
94 | }; | ||
95 | }; | ||
96 | |||
97 | typedef int (*menu_callback_type)(int action, | ||
98 | const struct menu_item_ex *this_item); | ||
99 | int do_menu(const struct menu_item_ex *menu); | ||
100 | |||
101 | #define MENU_ITEM_COUNT(c) (c<<MENU_COUNT_SHIFT) | ||
102 | |||
103 | #define MENUITEM_SETTING(name,var,callback) \ | ||
104 | static const struct menu_item_ex name = \ | ||
105 | {MT_SETTING, {.variable = (void*)var},{callback}}; | ||
106 | |||
107 | #define MAKE_MENU( name, str, cb, ... ) \ | ||
108 | static const struct menu_item_ex *name##_[] = {__VA_ARGS__}; \ | ||
109 | static const struct menu_callback_with_desc name##__ = {cb,str}; \ | ||
110 | const struct menu_item_ex name = \ | ||
111 | {MT_MENU|MENU_HAS_DESC| \ | ||
112 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ | ||
113 | { (void*)name##_},{.callback_and_desc = & name##__}}; | ||
114 | |||
115 | #define MENUITEM_STRINGLIST(name, str, callback, ... ) \ | ||
116 | static const char *name##_[] = {__VA_ARGS__}; \ | ||
117 | static const struct menu_callback_with_desc name##__ = {cb,str}; \ | ||
118 | static const struct menu_item_ex name = \ | ||
119 | {MT_RETURN_ID|MENU_HAS_DESC| \ | ||
120 | MENU_ITEM_COUNT(sizeof( name##_)/sizeof(*name##_)), \ | ||
121 | { .submenus = name##_},{.callback_and_desc = & name##__}}; | ||
122 | /* This one should be static'ed also, | ||
123 | but cannot be done untill sound and playlist menus are done */ | ||
124 | #define MENUITEM_FUNCTION(name, str, func, cb) \ | ||
125 | static const struct menu_callback_with_desc name##_ = {cb,str}; \ | ||
126 | const struct menu_item_ex name = \ | ||
127 | { MT_FUNCTION_CALL|MENU_HAS_DESC, { .function = func}, \ | ||
128 | {.callback_and_desc = & name##_}}; | ||
129 | |||
130 | #define MENUITEM_FUNCTION_WPARAM(name, str, func, param, callback) \ | ||
131 | static const struct menu_callback_with_desc name##_ = {callback,str}; \ | ||
132 | static const struct menu_func_with_param name##__ = {func, param}; \ | ||
133 | static const struct menu_item_ex name = \ | ||
134 | { MT_FUNCTION_WITH_PARAM|MENU_HAS_DESC, \ | ||
135 | { .func_with_param = &name##__}, \ | ||
136 | {.callback_and_desc = & name##_}}; | ||
137 | |||
138 | |||
141 | #endif /* End __MENU_H__ */ | 139 | #endif /* End __MENU_H__ */ |