diff options
Diffstat (limited to 'utils/nwztools/plattools/all_tools.c')
-rw-r--r-- | utils/nwztools/plattools/all_tools.c | 132 |
1 files changed, 132 insertions, 0 deletions
diff --git a/utils/nwztools/plattools/all_tools.c b/utils/nwztools/plattools/all_tools.c new file mode 100644 index 0000000000..f3ecb51c05 --- /dev/null +++ b/utils/nwztools/plattools/all_tools.c | |||
@@ -0,0 +1,132 @@ | |||
1 | /*************************************************************************** | ||
2 | * __________ __ ___. | ||
3 | * Open \______ \ ____ ____ | | _\_ |__ _______ ___ | ||
4 | * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / | ||
5 | * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < | ||
6 | * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ | ||
7 | * \/ \/ \/ \/ \/ | ||
8 | * $Id$ | ||
9 | * | ||
10 | * Copyright (C) 2011 by Amaury Pouly | ||
11 | * | ||
12 | * Based on Rockbox iriver bootloader by Linus Nielsen Feltzing | ||
13 | * and the ipodlinux bootloader by Daniel Palffy and Bernard Leach | ||
14 | * | ||
15 | * This program is free software; you can redistribute it and/or | ||
16 | * modify it under the terms of the GNU General Public License | ||
17 | * as published by the Free Software Foundation; either version 2 | ||
18 | * of the License, or (at your option) any later version. | ||
19 | * | ||
20 | * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY | ||
21 | * KIND, either express or implied. | ||
22 | * | ||
23 | ****************************************************************************/ | ||
24 | #include "nwz_lib.h" | ||
25 | #include "nwz_plattools.h" | ||
26 | |||
27 | #define TOOL_LIST \ | ||
28 | TOOL(dest_tool) \ | ||
29 | TOOL(test_adc) \ | ||
30 | TOOL(test_bl) \ | ||
31 | TOOL(test_display) \ | ||
32 | TOOL(test_keys) \ | ||
33 | TOOL(test_power) \ | ||
34 | TOOL(test_ts) | ||
35 | |||
36 | typedef int (*nwz_tool_main_t)(int argc, char **argv); | ||
37 | |||
38 | struct nwz_tool_t | ||
39 | { | ||
40 | const char *name; | ||
41 | nwz_tool_main_t main; | ||
42 | }; | ||
43 | |||
44 | /* create list of extern definition */ | ||
45 | #define TOOL(name) extern int NWZ_TOOL_MAIN(name)(int argc, char **argv); | ||
46 | TOOL_LIST | ||
47 | #undef TOOL | ||
48 | |||
49 | /* create actual list */ | ||
50 | #define TOOL(name) { #name, NWZ_TOOL_MAIN(name) }, | ||
51 | static struct nwz_tool_t g_tools[] = | ||
52 | { | ||
53 | TOOL_LIST | ||
54 | }; | ||
55 | #undef TOOL | ||
56 | |||
57 | #define NR_TOOLS (sizeof(g_tools) / sizeof(g_tools[0])) | ||
58 | |||
59 | static void hello(void) | ||
60 | { | ||
61 | /* clear screen and display welcome message */ | ||
62 | nwz_lcdmsg(true, 0, 0, "all_tools"); | ||
63 | nwz_lcdmsg(false, 0, 2, "BACK: quit"); | ||
64 | nwz_lcdmsg(false, 0, 2, "LEFT/RIGHT: change tool"); | ||
65 | nwz_lcdmsg(false, 0, 3, "PLAY: run tool"); | ||
66 | } | ||
67 | |||
68 | /* this tool itself can be embedded in the dualboot */ | ||
69 | #ifdef NWZ_DUALBOOT | ||
70 | int NWZ_TOOL_MAIN(all_tools)(int argc, char **argv) | ||
71 | #else | ||
72 | int main(int argc, char **argv) | ||
73 | #endif | ||
74 | { | ||
75 | hello(); | ||
76 | /* open input device */ | ||
77 | int input_fd = nwz_key_open(); | ||
78 | if(input_fd < 0) | ||
79 | { | ||
80 | nwz_lcdmsg(false, 3, 5, "Cannot open input device"); | ||
81 | sleep(2); | ||
82 | return 1; | ||
83 | } | ||
84 | /* main loop */ | ||
85 | int cur_tool = 0; | ||
86 | while(true) | ||
87 | { | ||
88 | /* print tools */ | ||
89 | int line = 5; | ||
90 | for(size_t i = 0; i < NR_TOOLS; i++) | ||
91 | { | ||
92 | nwz_lcdmsgf(false, 0, line++, "%c %s", (i == cur_tool) ? '>' : ' ', | ||
93 | g_tools[i].name); | ||
94 | } | ||
95 | /* wait for event (1000ms) */ | ||
96 | int ret = nwz_key_wait_event(input_fd, 1000000); | ||
97 | if(ret != 1) | ||
98 | continue; | ||
99 | struct input_event evt; | ||
100 | if(nwz_key_read_event(input_fd, &evt) != 1) | ||
101 | continue; | ||
102 | /* only act on key release */ | ||
103 | if(nwz_key_event_is_press(&evt)) | ||
104 | continue; | ||
105 | int keycode = nwz_key_event_get_keycode(&evt); | ||
106 | if(keycode == NWZ_KEY_LEFT) | ||
107 | { | ||
108 | cur_tool--; | ||
109 | if(cur_tool == -1) | ||
110 | cur_tool += NR_TOOLS; | ||
111 | } | ||
112 | else if(keycode == NWZ_KEY_RIGHT) | ||
113 | { | ||
114 | cur_tool++; | ||
115 | if(cur_tool == NR_TOOLS) | ||
116 | cur_tool = 0; | ||
117 | } | ||
118 | else if(keycode == NWZ_KEY_PLAY) | ||
119 | { | ||
120 | /* close input */ | ||
121 | nwz_key_close(input_fd); | ||
122 | g_tools[cur_tool].main(argc, argv); | ||
123 | /* reopen input and clear the screen */ | ||
124 | input_fd = nwz_key_open(); | ||
125 | hello(); | ||
126 | } | ||
127 | else if(keycode == NWZ_KEY_BACK) | ||
128 | break; | ||
129 | } | ||
130 | nwz_key_close(input_fd); | ||
131 | return 0; | ||
132 | } | ||