summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
authorJens Arnold <amiconn@rockbox.org>2005-05-08 19:09:32 +0000
committerJens Arnold <amiconn@rockbox.org>2005-05-08 19:09:32 +0000
commitb0b12e685eb0d084684a9715c946cc762bc134d5 (patch)
treefc80bc0e84b5133ce87cbf8515664b729dd434ee /apps/plugins
parenta1483e6e1d04781dd91862ff6f2eebbc3266c460 (diff)
downloadrockbox-b0b12e685eb0d084684a9715c946cc762bc134d5.tar.gz
rockbox-b0b12e685eb0d084684a9715c946cc762bc134d5.zip
Changed to rockbox style button handling, using the api functions. Support for all possible keypads, proper USB handling. Fixed to work correctly on SH1 based archoses, and fixed some slight quirks.
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@6441 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/databox/databox.c160
-rw-r--r--apps/plugins/databox/databox.h4
2 files changed, 75 insertions, 89 deletions
diff --git a/apps/plugins/databox/databox.c b/apps/plugins/databox/databox.c
index c801f172f4..a6de483063 100644
--- a/apps/plugins/databox/databox.c
+++ b/apps/plugins/databox/databox.c
@@ -18,13 +18,28 @@
18 ****************************************************************************/ 18 ****************************************************************************/
19#include "databox.h" 19#include "databox.h"
20 20
21/* welcome to the example rockbox plugin */ 21/* variable button definitions */
22#if CONFIG_KEYPAD == IRIVER_H100_PAD
23#define DBX_SELECT BUTTON_SELECT
24#define DBX_STOP BUTTON_OFF
25#elif CONFIG_KEYPAD == RECORDER_PAD
26#define DBX_SELECT BUTTON_PLAY
27#define DBX_STOP BUTTON_OFF
28#elif CONFIG_KEYPAD == ONDIO_PAD
29#define DBX_SELECT BUTTON_MENU
30#define DBX_STOP BUTTON_OFF
31#elif CONFIG_KEYPAD == PLAYER_PAD
32#define DBX_SELECT BUTTON_PLAY
33#define DBX_STOP BUTTON_STOP
34#endif
35
36#define MAX_TOKENS 70
22 37
23/* here is a global api struct pointer. while not strictly necessary, 38/* here is a global api struct pointer. while not strictly necessary,
24 it's nice not to have to pass the api pointer in all function calls 39 it's nice not to have to pass the api pointer in all function calls
25 in the plugin */ 40 in the plugin */
26struct plugin_api* rb; 41struct plugin_api* rb;
27struct token tokenbuf[200]; 42struct token tokenbuf[MAX_TOKENS];
28 43
29struct print printing; 44struct print printing;
30struct editor editor; 45struct editor editor;
@@ -164,20 +179,6 @@ int writetstream(char *filename,struct token *token) {
164 return i; 179 return i;
165} 180}
166 181
167int hcl_button_get(void) {
168 int oldbuttonstate,newbuttonstate,pressed=0;
169 oldbuttonstate = rb->button_status();
170 do {
171 newbuttonstate = rb->button_status();
172 pressed = newbuttonstate & ~oldbuttonstate;
173 oldbuttonstate = newbuttonstate;
174 rb->yield();
175 }
176 while(!pressed);
177 rb->button_clear_queue();
178 return pressed;
179}
180
181/* this is the plugin entry point */ 182/* this is the plugin entry point */
182enum plugin_status plugin_start(struct plugin_api* api, void* parameter) 183enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
183{ 184{
@@ -199,13 +200,14 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
199 /* now go ahead and have fun! */ 200 /* now go ahead and have fun! */
200 rb->splash(HZ*2, true, "Databox! Enter filename ^.^"); 201 rb->splash(HZ*2, true, "Databox! Enter filename ^.^");
201 databox_init(); 202 databox_init();
202 if(rb->kbd_input(filename, 100)) { 203 filename[0] = '\0';
204 if(rb->kbd_input(filename, sizeof filename)) {
203 rb->splash(HZ*2, true, "Something went wrong with the filename.. exiting.."); 205 rb->splash(HZ*2, true, "Something went wrong with the filename.. exiting..");
204 return PLUGIN_ERROR; 206 return PLUGIN_ERROR;
205 } 207 }
206 /* add / in front if omitted */ 208 /* add / in front if omitted */
207 if(filename[0]!='/') { 209 if(filename[0]!='/') {
208 rb->strncpy(buf+1,filename,99); 210 rb->strncpy(buf+1,filename,sizeof(filename)-1);
209 buf[0]='/'; 211 buf[0]='/';
210 rb->strcpy(filename,buf); 212 rb->strcpy(filename,buf);
211 } 213 }
@@ -213,9 +215,8 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
213 if(rb->strncasecmp(filename+rb->strlen(filename)-4,".rsp",4)) { 215 if(rb->strncasecmp(filename+rb->strlen(filename)-4,".rsp",4)) {
214 rb->strcat(filename,".rsp"); 216 rb->strcat(filename,".rsp");
215 } 217 }
216 rb->lcd_clear_display(); 218 editor.currentindex=editor.tokencount
217 rb->lcd_update(); 219 =readtstream(filename,editor.token,MAX_TOKENS);
218 editor.currentindex=editor.tokencount=readtstream(filename,editor.token,200);
219 editing.currentselection=0; 220 editing.currentselection=0;
220 editing.selecting=0; 221 editing.selecting=0;
221 if(editor.currentindex==0) { 222 if(editor.currentindex==0) {
@@ -226,47 +227,44 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
226 rb->memset(&editing.old_token,0,sizeof(struct token)); 227 rb->memset(&editing.old_token,0,sizeof(struct token));
227 } 228 }
228 do { 229 do {
230 rb->lcd_setfont(FONT_SYSFIXED);
229 rb->lcd_clear_display(); 231 rb->lcd_clear_display();
230 rb->lcd_update();
231 printing.line=0; 232 printing.line=0;
232 printing.position=0; 233 printing.position=0;
233 displaytstream(editor.token); 234 displaytstream(editor.token);
234 editor.valid=check_tokenstream(editor.token,editor.editingmode); 235 editor.valid=check_tokenstream(editor.token,editor.editingmode);
235 check_accepted(editor.token,editor.currentindex); 236 check_accepted(editor.token,editor.currentindex);
236 rb->lcd_update(); 237 rb->lcd_update();
237 button=hcl_button_get(); 238 button = rb->button_get(true);
238 if(editing.selecting) { 239 switch (button) {
239 // button handling, up, down, select,stop 240 case BUTTON_LEFT:
240 // up/right = move currentselection one up 241#ifdef BUTTON_DOWN
241 // down/left = move currentselection one down 242 case BUTTON_DOWN:
242 // select = build token in place.
243 // stop = cancel editing
244 if(button&BUTTON_LEFT
245#if CONFIG_KEYPAD == IRIVER_H100_PAD
246 ||button&BUTTON_DOWN
247#endif 243#endif
248 ) { 244 if (editing.selecting)
249 editing.currentselection=(editing.currentselection+ 245 editing.currentselection = (editing.currentselection +
250 1) %editing.selectionmax; 246 editing.selectionmax-1) % editing.selectionmax;
251 } 247 else
252 else if(button&BUTTON_RIGHT 248 editor.currentindex = (editor.currentindex + editor.tokencount)
253#if CONFIG_KEYPAD == IRIVER_H100_PAD 249 % (editor.tokencount+1);
254 ||button&BUTTON_UP 250 break;
255#endif 251
256 ) { 252 case BUTTON_RIGHT:
257 editing.currentselection=(editing.currentselection + 253#ifdef BUTTON_DOWN
258 editing.selectionmax-1) % editing.selectionmax; 254 case BUTTON_UP:
259 }
260 else if(button&BUTTON_OFF) {
261 rb->memcpy(&editor.token[editor.currentindex],&editing.old_token,sizeof(struct token));
262 editing.selecting=0;
263 }
264 else if(button&BUTTON_PLAY
265#if CONFIG_KEYPAD == IRIVER_H100_PAD
266 ||button&BUTTON_SELECT
267#endif 255#endif
268 ) { 256 if (editing.selecting)
269 buildtoken(editing.selection_candidates[editing.currentselection],&editor.token[editor.currentindex]); 257 editing.currentselection = (editing.currentselection+1)
258 % editing.selectionmax;
259 else
260 editor.currentindex = (editor.currentindex+1)
261 % (editor.tokencount+1);
262 break;
263
264 case DBX_SELECT:
265 if(editing.selecting) {
266 buildtoken(editing.selection_candidates[editing.currentselection],
267 &editor.token[editor.currentindex]);
270 editing.selecting=0; 268 editing.selecting=0;
271 if(editor.token[editor.currentindex].kind==TOKEN_EOF) 269 if(editor.token[editor.currentindex].kind==TOKEN_EOF)
272 done=1; 270 done=1;
@@ -278,46 +276,38 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
278 editing.selecting=1; 276 editing.selecting=1;
279 editing.currentselection=0; 277 editing.currentselection=0;
280 buildchoices(acceptedmask); 278 buildchoices(acceptedmask);
281 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],sizeof(struct token)); 279 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],
280 sizeof(struct token));
282 } 281 }
283 } 282 }
284 } 283 else {
285 else {
286 // button handling, left, right, select, stop
287 // left/down = move currentindex down
288 // right/up = move currentindex up
289 // select = enter selecting mode.
290 // stop = quit editor.
291 if(button&BUTTON_LEFT
292#if CONFIG_KEYPAD == IRIVER_H100_PAD
293 ||button&BUTTON_DOWN
294#endif
295 ) {
296 editor.currentindex=(editor.currentindex +
297 editor.tokencount) % (editor.tokencount+1);
298 }
299 else if(button&BUTTON_RIGHT
300#if CONFIG_KEYPAD == IRIVER_H100_PAD
301 ||button&BUTTON_UP
302#endif
303 ) {
304 editor.currentindex=(editor.currentindex+1) % (editor.tokencount+1);
305 }
306 else if(button&BUTTON_OFF) {
307 done=1;
308 }
309 else if(button&BUTTON_PLAY
310#if CONFIG_KEYPAD == IRIVER_H100_PAD
311 ||button&BUTTON_SELECT
312#endif
313 ) {
314 editing.selecting=1; 284 editing.selecting=1;
315 editing.currentselection=0; 285 editing.currentselection=0;
316 buildchoices(acceptedmask); 286 buildchoices(acceptedmask);
317 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],sizeof(struct token)); 287 rb->memcpy(&editing.old_token,&editor.token[editor.currentindex],
288 sizeof(struct token));
289 }
290 break;
291
292 case DBX_STOP:
293 if(editing.selecting) {
294 rb->memcpy(&editor.token[editor.currentindex],&editing.old_token,
295 sizeof(struct token));
296 editing.selecting=0;
297 }
298 else
299 done=1;
300 break;
301
302 default:
303 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
304 rb->lcd_setfont(FONT_UI);
305 return PLUGIN_USB_CONNECTED;
318 } 306 }
307 break;
319 } 308 }
320 } while (!done); 309 } while (!done);
310 rb->lcd_setfont(FONT_UI);
321 if(editor.valid&&editor.tokencount>0) { 311 if(editor.valid&&editor.tokencount>0) {
322 if(writetstream(filename,editor.token)) { 312 if(writetstream(filename,editor.token)) {
323 rb->splash(HZ*2,true,"Wrote file succesfully ^.^"); 313 rb->splash(HZ*2,true,"Wrote file succesfully ^.^");
diff --git a/apps/plugins/databox/databox.h b/apps/plugins/databox/databox.h
index a8bb608765..ffbaf1d35d 100644
--- a/apps/plugins/databox/databox.h
+++ b/apps/plugins/databox/databox.h
@@ -55,8 +55,4 @@ extern struct print printing;
55extern struct editor editor; 55extern struct editor editor;
56extern struct editing editing; 56extern struct editing editing;
57 57
58#if CONFIG_KEYPAD == IRIVER_H100_PAD
59#define BUTTON_PLAY BUTTON_ON
60#endif
61
62#endif 58#endif