diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/demystify.c | 180 |
1 files changed, 73 insertions, 107 deletions
diff --git a/apps/plugins/demystify.c b/apps/plugins/demystify.c index c5162c6fa2..0cb06ee473 100644 --- a/apps/plugins/demystify.c +++ b/apps/plugins/demystify.c | |||
@@ -22,59 +22,9 @@ | |||
22 | #include "plugin.h" | 22 | #include "plugin.h" |
23 | 23 | ||
24 | #ifdef HAVE_LCD_BITMAP | 24 | #ifdef HAVE_LCD_BITMAP |
25 | 25 | #include "pluginlib_actions.h" | |
26 | PLUGIN_HEADER | 26 | PLUGIN_HEADER |
27 | 27 | ||
28 | /* Key assignement */ | ||
29 | #if (CONFIG_KEYPAD == IPOD_4G_PAD) || \ | ||
30 | (CONFIG_KEYPAD == IPOD_3G_PAD) | ||
31 | #define DEMYSTIFY_QUIT BUTTON_MENU | ||
32 | #define DEMYSTIFY_ADD_POLYGON BUTTON_RIGHT | ||
33 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_LEFT | ||
34 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_SCROLL_FWD | ||
35 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_SCROLL_BACK | ||
36 | #elif (CONFIG_KEYPAD == SANSA_E200_PAD) | ||
37 | #define DEMYSTIFY_QUIT BUTTON_POWER | ||
38 | #define DEMYSTIFY_ADD_POLYGON BUTTON_RIGHT | ||
39 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_LEFT | ||
40 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_SCROLL_DOWN | ||
41 | #define DEMYSTIFY_INCREASE_SPEED_REP (BUTTON_SCROLL_DOWN|BUTTON_REPEAT) | ||
42 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_SCROLL_UP | ||
43 | #define DEMYSTIFY_DECREASE_SPEED_REP (BUTTON_SCROLL_UP|BUTTON_REPEAT) | ||
44 | #elif (CONFIG_KEYPAD == IRIVER_H10_PAD) | ||
45 | #define DEMYSTIFY_QUIT BUTTON_POWER | ||
46 | #define DEMYSTIFY_ADD_POLYGON BUTTON_RIGHT | ||
47 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_LEFT | ||
48 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_SCROLL_UP | ||
49 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_SCROLL_DOWN | ||
50 | #elif (CONFIG_KEYPAD == IAUDIO_X5M5_PAD) | ||
51 | #define DEMYSTIFY_QUIT BUTTON_POWER | ||
52 | #define DEMYSTIFY_ADD_POLYGON BUTTON_RIGHT | ||
53 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_LEFT | ||
54 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_UP | ||
55 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_DOWN | ||
56 | #elif (CONFIG_KEYPAD == GIGABEAT_PAD) | ||
57 | #define DEMYSTIFY_QUIT BUTTON_POWER | ||
58 | #define DEMYSTIFY_ADD_POLYGON BUTTON_RIGHT | ||
59 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_LEFT | ||
60 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_UP | ||
61 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_DOWN | ||
62 | #else | ||
63 | #define DEMYSTIFY_QUIT BUTTON_OFF | ||
64 | #define DEMYSTIFY_ADD_POLYGON BUTTON_UP | ||
65 | #define DEMYSTIFY_REMOVE_POLYGON BUTTON_DOWN | ||
66 | #define DEMYSTIFY_INCREASE_SPEED BUTTON_RIGHT | ||
67 | #define DEMYSTIFY_DECREASE_SPEED BUTTON_LEFT | ||
68 | #if (CONFIG_KEYPAD == IRIVER_H100_PAD) || \ | ||
69 | (CONFIG_KEYPAD == IRIVER_H300_PAD) | ||
70 | #define DEMYSTIFY_RC_QUIT BUTTON_RC_STOP | ||
71 | #define DEMYSTIFY_RC_ADD_POLYGON BUTTON_RC_BITRATE | ||
72 | #define DEMYSTIFY_RC_REMOVE_POLYGON BUTTON_RC_SOURCE | ||
73 | #define DEMYSTIFY_RC_INCREASE_SPEED BUTTON_RC_VOL_UP | ||
74 | #define DEMYSTIFY_RC_DECREASE_SPEED BUTTON_RC_VOL_DOWN | ||
75 | #endif | ||
76 | #endif | ||
77 | |||
78 | #define DEFAULT_WAIT_TIME 3 | 28 | #define DEFAULT_WAIT_TIME 3 |
79 | #define DEFAULT_NB_POLYGONS 7 | 29 | #define DEFAULT_NB_POLYGONS 7 |
80 | #define NB_POINTS 4 | 30 | #define NB_POINTS 4 |
@@ -83,8 +33,28 @@ PLUGIN_HEADER | |||
83 | #define MAX_POLYGONS 40 | 33 | #define MAX_POLYGONS 40 |
84 | #define MIN_POLYGONS 1 | 34 | #define MIN_POLYGONS 1 |
85 | 35 | ||
36 | /* Key assignement */ | ||
37 | #define DEMYSTIFY_QUIT PLA_QUIT | ||
38 | |||
39 | #define DEMYSTIFY_INCREASE_SPEED PLA_RIGHT | ||
40 | #define DEMYSTIFY_DECREASE_SPEED PLA_LEFT | ||
41 | #define DEMYSTIFY_INCREASE_SPEED_REPEAT PLA_RIGHT_REPEAT | ||
42 | #define DEMYSTIFY_DECREASE_SPEED_REPEAT PLA_LEFT_REPEAT | ||
43 | |||
44 | #define DEMYSTIFY_ADD_POLYGON PLA_UP | ||
45 | #define DEMYSTIFY_REMOVE_POLYGON PLA_DOWN | ||
46 | #define DEMYSTIFY_ADD_POLYGON_REPEAT PLA_UP_REPEAT | ||
47 | #define DEMYSTIFY_REMOVE_POLYGON_REPEAT PLA_DOWN_REPEAT | ||
48 | |||
49 | const struct button_mapping *plugin_contexts[] | ||
50 | = {generic_directions, generic_actions}; | ||
51 | |||
86 | #ifdef HAVE_LCD_COLOR | 52 | #ifdef HAVE_LCD_COLOR |
87 | int r,g,b,rc,gc,bc; | 53 | struct line_color |
54 | { | ||
55 | int r,g,b; | ||
56 | int current_r,current_g,current_b; | ||
57 | }; | ||
88 | #endif | 58 | #endif |
89 | 59 | ||
90 | /******************************* Globals ***********************************/ | 60 | /******************************* Globals ***********************************/ |
@@ -287,31 +257,44 @@ void cleanup(void *parameter) | |||
287 | } | 257 | } |
288 | 258 | ||
289 | #ifdef HAVE_LCD_COLOR | 259 | #ifdef HAVE_LCD_COLOR |
290 | void new_color(void) | 260 | void color_randomize(struct line_color * color) |
261 | { | ||
262 | color->r = rb->rand()%255; | ||
263 | color->g = rb->rand()%255; | ||
264 | color->b = rb->rand()%255; | ||
265 | } | ||
266 | |||
267 | void color_init(struct line_color * color) | ||
291 | { | 268 | { |
292 | r = rb->rand()%255; | 269 | color_randomize(color); |
293 | g = rb->rand()%255; | 270 | color->current_r=color->r; |
294 | b = rb->rand()%255; | 271 | color->current_g=color->g; |
272 | color->current_b=color->b; | ||
295 | } | 273 | } |
296 | 274 | ||
297 | void change_color(void) | 275 | void color_change(struct line_color * color) |
298 | { | 276 | { |
299 | if(rc<r) | 277 | if(color->current_r<color->r) |
300 | ++rc; | 278 | ++color->current_r; |
301 | else if(rc>r) | 279 | else if(color->current_r>color->r) |
302 | --rc; | 280 | --color->current_r; |
303 | if(gc<g) | 281 | if(color->current_g<color->g) |
304 | ++gc; | 282 | ++color->current_g; |
305 | else if(gc>g) | 283 | else if(color->current_g>color->g) |
306 | --gc; | 284 | --color->current_g; |
307 | if(bc<b) | 285 | if(color->current_b<color->b) |
308 | ++bc; | 286 | ++color->current_b; |
309 | else if(bc>b) | 287 | else if(color->current_b>color->b) |
310 | --bc; | 288 | --color->current_b; |
311 | rb->lcd_set_foreground(LCD_RGBPACK(rc,gc,bc)); | 289 | |
312 | if(rc==r && gc==g && bc==b) | 290 | if(color->current_r==color->r && |
313 | new_color(); | 291 | color->current_g==color->g && |
292 | color->current_b==color->b) | ||
293 | color_randomize(color); | ||
314 | } | 294 | } |
295 | |||
296 | #define COLOR_RGBPACK(color) LCD_RGBPACK((color)->current_r, (color)->current_g, (color)->current_b) | ||
297 | |||
315 | #endif | 298 | #endif |
316 | 299 | ||
317 | /* | 300 | /* |
@@ -320,7 +303,7 @@ void change_color(void) | |||
320 | 303 | ||
321 | int plugin_main(void) | 304 | int plugin_main(void) |
322 | { | 305 | { |
323 | int button; | 306 | int action; |
324 | int sleep_time=DEFAULT_WAIT_TIME; | 307 | int sleep_time=DEFAULT_WAIT_TIME; |
325 | int nb_wanted_polygons=DEFAULT_NB_POLYGONS; | 308 | int nb_wanted_polygons=DEFAULT_NB_POLYGONS; |
326 | int i; | 309 | int i; |
@@ -332,7 +315,7 @@ int plugin_main(void) | |||
332 | { | 315 | { |
333 | #ifdef HAVE_LCD_COLOR | 316 | #ifdef HAVE_LCD_COLOR |
334 | struct screen *display = rb->screens[i]; | 317 | struct screen *display = rb->screens[i]; |
335 | if (display->depth > 8) | 318 | if (display->is_color) |
336 | display->set_background(LCD_BLACK); | 319 | display->set_background(LCD_BLACK); |
337 | #endif | 320 | #endif |
338 | fifo_init(&polygons[i]); | 321 | fifo_init(&polygons[i]); |
@@ -341,10 +324,8 @@ int plugin_main(void) | |||
341 | } | 324 | } |
342 | 325 | ||
343 | #ifdef HAVE_LCD_COLOR | 326 | #ifdef HAVE_LCD_COLOR |
344 | new_color(); | 327 | struct line_color color; |
345 | rc = r; | 328 | color_init(&color); |
346 | gc = g; | ||
347 | bc = b; | ||
348 | #endif | 329 | #endif |
349 | 330 | ||
350 | while (true) | 331 | while (true) |
@@ -373,16 +354,18 @@ int plugin_main(void) | |||
373 | /* Now the drawing part */ | 354 | /* Now the drawing part */ |
374 | 355 | ||
375 | #ifdef HAVE_LCD_COLOR | 356 | #ifdef HAVE_LCD_COLOR |
376 | if (display->depth > 8) | 357 | if (display->is_color){ |
377 | display->set_foreground(SCREEN_COLOR_TO_NATIVE(display, | 358 | unsigned foreground= |
378 | LCD_RGBPACK(rc, gc, bc))); | 359 | SCREEN_COLOR_TO_NATIVE(display,COLOR_RGBPACK(&color)); |
360 | display->set_foreground(foreground); | ||
361 | } | ||
379 | #endif | 362 | #endif |
380 | display->clear_display(); | 363 | display->clear_display(); |
381 | polygons_draw(&polygons[i], display); | 364 | polygons_draw(&polygons[i], display); |
382 | display->update(); | 365 | display->update(); |
383 | } | 366 | } |
384 | #ifdef HAVE_LCD_COLOR | 367 | #ifdef HAVE_LCD_COLOR |
385 | change_color(); | 368 | color_change(&color); |
386 | #endif | 369 | #endif |
387 | /* Speed handling*/ | 370 | /* Speed handling*/ |
388 | if (sleep_time<0)/* full speed */ | 371 | if (sleep_time<0)/* full speed */ |
@@ -390,55 +373,38 @@ int plugin_main(void) | |||
390 | else | 373 | else |
391 | rb->sleep(sleep_time); | 374 | rb->sleep(sleep_time); |
392 | 375 | ||
393 | /* Handle the user events */ | 376 | action = pluginlib_getaction(rb, TIMEOUT_NOBLOCK, plugin_contexts, 2); |
394 | button = rb->button_get(false); | 377 | switch(action) |
395 | switch(button) | ||
396 | { | 378 | { |
397 | #ifdef DEMYSTIFY_RC_QUIT | ||
398 | case DEMYSTIFY_RC_QUIT : | ||
399 | #endif | ||
400 | case DEMYSTIFY_QUIT: | 379 | case DEMYSTIFY_QUIT: |
401 | cleanup(NULL); | 380 | cleanup(NULL); |
402 | return PLUGIN_OK; | 381 | return PLUGIN_OK; |
403 | #ifdef DEMYSTIFY_RC_ADD_POLYGON | 382 | |
404 | case DEMYSTIFY_RC_ADD_POLYGON: | ||
405 | #endif | ||
406 | case DEMYSTIFY_ADD_POLYGON: | 383 | case DEMYSTIFY_ADD_POLYGON: |
384 | case DEMYSTIFY_ADD_POLYGON_REPEAT: | ||
407 | if(nb_wanted_polygons<MAX_POLYGONS) | 385 | if(nb_wanted_polygons<MAX_POLYGONS) |
408 | ++nb_wanted_polygons; | 386 | ++nb_wanted_polygons; |
409 | break; | 387 | break; |
410 | 388 | ||
411 | #ifdef DEMYSTIFY_RC_REMOVE_POLYGON | ||
412 | case DEMYSTIFY_RC_REMOVE_POLYGON: | ||
413 | #endif | ||
414 | case DEMYSTIFY_REMOVE_POLYGON: | 389 | case DEMYSTIFY_REMOVE_POLYGON: |
390 | case DEMYSTIFY_REMOVE_POLYGON_REPEAT: | ||
415 | if(nb_wanted_polygons>MIN_POLYGONS) | 391 | if(nb_wanted_polygons>MIN_POLYGONS) |
416 | --nb_wanted_polygons; | 392 | --nb_wanted_polygons; |
417 | break; | 393 | break; |
418 | 394 | ||
419 | #ifdef DEMYSTIFY_RC_INCREASE_SPEED | ||
420 | case DEMYSTIFY_RC_INCREASE_SPEED: | ||
421 | #endif | ||
422 | #ifdef DEMYSTIFY_INCREASE_SPEED_REP | ||
423 | case DEMYSTIFY_INCREASE_SPEED_REP: | ||
424 | #endif | ||
425 | case DEMYSTIFY_INCREASE_SPEED: | 395 | case DEMYSTIFY_INCREASE_SPEED: |
396 | case DEMYSTIFY_INCREASE_SPEED_REPEAT: | ||
426 | if(sleep_time>=0) | 397 | if(sleep_time>=0) |
427 | --sleep_time; | 398 | --sleep_time; |
428 | break; | 399 | break; |
429 | 400 | ||
430 | #ifdef DEMYSTIFY_RC_DECREASE_SPEED | ||
431 | case DEMYSTIFY_RC_DECREASE_SPEED: | ||
432 | #endif | ||
433 | #ifdef DEMYSTIFY_DECREASE_SPEED_REP | ||
434 | case DEMYSTIFY_DECREASE_SPEED_REP: | ||
435 | #endif | ||
436 | case DEMYSTIFY_DECREASE_SPEED: | 401 | case DEMYSTIFY_DECREASE_SPEED: |
402 | case DEMYSTIFY_DECREASE_SPEED_REPEAT: | ||
437 | ++sleep_time; | 403 | ++sleep_time; |
438 | break; | 404 | break; |
439 | 405 | ||
440 | default: | 406 | default: |
441 | if (rb->default_event_handler_ex(button, cleanup, NULL) | 407 | if (rb->default_event_handler_ex(action, cleanup, NULL) |
442 | == SYS_USB_CONNECTED) | 408 | == SYS_USB_CONNECTED) |
443 | return PLUGIN_USB_CONNECTED; | 409 | return PLUGIN_USB_CONNECTED; |
444 | break; | 410 | break; |