Rename variables sectorbuf and verbose to avoid clashes in rbutil. Cleanup exports...
[Rockbox.git] / apps / plugins / flipit.c
blob7e865b0ea8845311089dc7c1e859530d1ed30770
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Vicentini Martin
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
19 #include "plugin.h"
21 PLUGIN_HEADER
23 /* variable button definitions */
24 #if CONFIG_KEYPAD == RECORDER_PAD
25 #define FLIPIT_LEFT BUTTON_LEFT
26 #define FLIPIT_RIGHT BUTTON_RIGHT
27 #define FLIPIT_UP BUTTON_UP
28 #define FLIPIT_DOWN BUTTON_DOWN
29 #define FLIPIT_QUIT BUTTON_OFF
30 #define FLIPIT_SHUFFLE BUTTON_F1
31 #define FLIPIT_SOLVE BUTTON_F2
32 #define FLIPIT_STEP_BY_STEP BUTTON_F3
33 #define FLIPIT_TOGGLE BUTTON_PLAY
35 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
36 #define FLIPIT_LEFT BUTTON_LEFT
37 #define FLIPIT_RIGHT BUTTON_RIGHT
38 #define FLIPIT_UP BUTTON_UP
39 #define FLIPIT_DOWN BUTTON_DOWN
40 #define FLIPIT_QUIT BUTTON_OFF
41 #define FLIPIT_SHUFFLE BUTTON_F1
42 #define FLIPIT_SOLVE BUTTON_F2
43 #define FLIPIT_STEP_BY_STEP BUTTON_F3
44 #define FLIPIT_TOGGLE BUTTON_SELECT
46 #elif CONFIG_KEYPAD == PLAYER_PAD
47 #define FLIPIT_LEFT BUTTON_LEFT
48 #define FLIPIT_RIGHT BUTTON_RIGHT
49 #define FLIPIT_UP_PRE BUTTON_ON
50 #define FLIPIT_UP (BUTTON_ON | BUTTON_REL)
51 #define FLIPIT_DOWN BUTTON_MENU
52 #define FLIPIT_QUIT BUTTON_STOP
53 #define FLIPIT_SHUFFLE (BUTTON_ON | BUTTON_LEFT)
54 #define FLIPIT_SOLVE (BUTTON_ON | BUTTON_RIGHT)
55 #define FLIPIT_STEP_BY_STEP (BUTTON_ON | BUTTON_PLAY)
56 #define FLIPIT_TOGGLE BUTTON_PLAY
58 #elif CONFIG_KEYPAD == ONDIO_PAD
59 #define FLIPIT_LEFT BUTTON_LEFT
60 #define FLIPIT_RIGHT BUTTON_RIGHT
61 #define FLIPIT_UP BUTTON_UP
62 #define FLIPIT_DOWN BUTTON_DOWN
63 #define FLIPIT_QUIT BUTTON_OFF
64 #define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
65 #define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
66 #define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
67 #define FLIPIT_TOGGLE_PRE BUTTON_MENU
68 #define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
70 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
71 (CONFIG_KEYPAD == IRIVER_H300_PAD)
72 #define FLIPIT_LEFT BUTTON_LEFT
73 #define FLIPIT_RIGHT BUTTON_RIGHT
74 #define FLIPIT_UP BUTTON_UP
75 #define FLIPIT_DOWN BUTTON_DOWN
76 #define FLIPIT_QUIT BUTTON_OFF
77 #define FLIPIT_SHUFFLE BUTTON_MODE
78 #define FLIPIT_SOLVE BUTTON_ON
79 #define FLIPIT_STEP_BY_STEP BUTTON_REC
80 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
81 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
83 #define FLIPIT_RC_QUIT BUTTON_RC_STOP
85 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
86 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
87 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
89 #define FLIPIT_SCROLLWHEEL
90 #define FLIPIT_LEFT BUTTON_LEFT
91 #define FLIPIT_RIGHT BUTTON_RIGHT
92 #define FLIPIT_UP BUTTON_MENU
93 #define FLIPIT_DOWN BUTTON_PLAY
94 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
95 #define FLIPIT_PREV BUTTON_SCROLL_BACK
96 #define FLIPIT_QUIT (BUTTON_SELECT | BUTTON_MENU)
97 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
98 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_PLAY)
99 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
100 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
101 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
103 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
105 #define FLIPIT_LEFT BUTTON_LEFT
106 #define FLIPIT_RIGHT BUTTON_RIGHT
107 #define FLIPIT_UP BUTTON_UP
108 #define FLIPIT_DOWN BUTTON_DOWN
109 #define FLIPIT_QUIT BUTTON_POWER
110 #define FLIPIT_SHUFFLE BUTTON_REC
111 #define FLIPIT_SOLVE_PRE BUTTON_PLAY
112 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_REPEAT)
113 #define FLIPIT_STEP_PRE BUTTON_PLAY
114 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_REL)
115 #define FLIPIT_TOGGLE BUTTON_SELECT
117 #elif CONFIG_KEYPAD == GIGABEAT_PAD
119 #define FLIPIT_LEFT BUTTON_LEFT
120 #define FLIPIT_RIGHT BUTTON_RIGHT
121 #define FLIPIT_UP BUTTON_UP
122 #define FLIPIT_DOWN BUTTON_DOWN
123 #define FLIPIT_QUIT BUTTON_POWER
124 #define FLIPIT_SHUFFLE BUTTON_MENU
125 #define FLIPIT_SOLVE BUTTON_VOL_UP
126 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
127 #define FLIPIT_TOGGLE BUTTON_SELECT
129 #elif CONFIG_KEYPAD == SANSA_E200_PAD
131 #define FLIPIT_SCROLLWHEEL
132 #define FLIPIT_LEFT BUTTON_LEFT
133 #define FLIPIT_RIGHT BUTTON_RIGHT
134 #define FLIPIT_UP BUTTON_UP
135 #define FLIPIT_DOWN BUTTON_DOWN
136 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
137 #define FLIPIT_PREV BUTTON_SCROLL_BACK
138 #define FLIPIT_QUIT BUTTON_POWER
139 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
140 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
141 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
142 #define FLIPIT_TOGGLE BUTTON_SELECT
144 #elif CONFIG_KEYPAD == SANSA_C200_PAD
146 #define FLIPIT_LEFT BUTTON_LEFT
147 #define FLIPIT_RIGHT BUTTON_RIGHT
148 #define FLIPIT_UP BUTTON_UP
149 #define FLIPIT_DOWN BUTTON_DOWN
150 #define FLIPIT_QUIT BUTTON_POWER
151 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
152 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
153 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
154 #define FLIPIT_TOGGLE BUTTON_SELECT
156 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
158 #define FLIPIT_LEFT BUTTON_LEFT
159 #define FLIPIT_RIGHT BUTTON_RIGHT
160 #define FLIPIT_UP BUTTON_SCROLL_UP
161 #define FLIPIT_DOWN BUTTON_SCROLL_DOWN
162 #define FLIPIT_QUIT BUTTON_POWER
163 #define FLIPIT_SHUFFLE (BUTTON_PLAY | BUTTON_LEFT)
164 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_RIGHT)
165 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_SCROLL_UP)
166 #define FLIPIT_TOGGLE_PRE BUTTON_REW
167 #define FLIPIT_TOGGLE (BUTTON_REW | BUTTON_REL)
169 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
171 #define FLIPIT_LEFT BUTTON_LEFT
172 #define FLIPIT_RIGHT BUTTON_RIGHT
173 #define FLIPIT_UP BUTTON_UP
174 #define FLIPIT_DOWN BUTTON_DOWN
175 #define FLIPIT_QUIT BUTTON_BACK
176 #define FLIPIT_SHUFFLE BUTTON_MENU
177 #define FLIPIT_SOLVE BUTTON_VOL_UP
178 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
179 #define FLIPIT_TOGGLE BUTTON_SELECT
181 #elif CONFIG_KEYPAD == MROBE100_PAD
183 #define FLIPIT_LEFT BUTTON_LEFT
184 #define FLIPIT_RIGHT BUTTON_RIGHT
185 #define FLIPIT_UP BUTTON_UP
186 #define FLIPIT_DOWN BUTTON_DOWN
187 #define FLIPIT_QUIT BUTTON_POWER
188 #define FLIPIT_SHUFFLE BUTTON_MENU
189 #define FLIPIT_SOLVE BUTTON_PLAY
190 #define FLIPIT_STEP_BY_STEP BUTTON_DISPLAY
191 #define FLIPIT_TOGGLE BUTTON_SELECT
193 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
195 #define FLIPIT_LEFT BUTTON_RC_REW
196 #define FLIPIT_RIGHT BUTTON_RC_FF
197 #define FLIPIT_UP BUTTON_RC_VOL_UP
198 #define FLIPIT_DOWN BUTTON_RC_VOL_DOWN
199 #define FLIPIT_QUIT BUTTON_RC_REC
200 #define FLIPIT_SHUFFLE BUTTON_RC_MODE
201 #define FLIPIT_SOLVE_PRE BUTTON_RC_MENU
202 #define FLIPIT_SOLVE (BUTTON_RC_MENU|BUTTON_REPEAT)
203 #define FLIPIT_STEP_PRE BUTTON_RC_MENU
204 #define FLIPIT_STEP_BY_STEP (BUTTON_RC_MENU|BUTTON_REL)
205 #define FLIPIT_TOGGLE BUTTON_RC_PLAY
207 #define FLIPIT_RC_QUIT BUTTON_REC
209 #elif CONFIG_KEYPAD == COWOND2_PAD
211 #define FLIPIT_QUIT BUTTON_POWER
213 #else
214 #error No keymap defined!
215 #endif
217 #ifdef HAVE_TOUCHPAD
218 #ifndef FLIPIT_LEFT
219 #define FLIPIT_LEFT BUTTON_MIDLEFT
220 #endif
221 #ifndef FLIPIT_RIGHT
222 #define FLIPIT_RIGHT BUTTON_MIDRIGHT
223 #endif
224 #ifndef FLIPIT_UP
225 #define FLIPIT_UP BUTTON_TOPMIDDLE
226 #endif
227 #ifndef FLIPIT_DOWN
228 #define FLIPIT_DOWN BUTTON_BOTTOMMIDDLE
229 #endif
230 #ifndef FLIPIT_QUIT
231 #define FLIPIT_QUIT BUTTON_TOPLEFT
232 #endif
233 #ifndef FLIPIT_SHUFFLE
234 #define FLIPIT_SHUFFLE BUTTON_TOPRIGHT
235 #endif
236 #ifndef FLIPIT_SOLVE
237 #define FLIPIT_SOLVE BUTTON_BOTTOMLEFT
238 #endif
239 #ifndef FLIPIT_STEP_BY_STEP
240 #define FLIPIT_STEP_BY_STEP BUTTON_BOTTOMRIGHT
241 #endif
242 #ifndef FLIPIT_TOGGLE
243 #define FLIPIT_TOGGLE BUTTON_CENTER
244 #endif
245 #endif
247 static const struct plugin_api* rb;
248 static int spots[20];
249 static int toggle[20];
250 static int cursor_pos, moves;
252 #ifdef HAVE_LCD_BITMAP
254 #include "flipit_cursor.h"
255 #include "flipit_tokens.h"
257 #define PANEL_HEIGHT 12
258 #define TK_WIDTH BMPWIDTH_flipit_cursor
259 #define TK_HEIGHT BMPHEIGHT_flipit_cursor
260 #define TK_SPACE MAX(0, MIN((LCD_WIDTH - 5*TK_WIDTH)/4, \
261 (LCD_HEIGHT - PANEL_HEIGHT - 4*TK_HEIGHT)/4))
262 #define GRID_WIDTH (5*TK_WIDTH + 4*TK_SPACE)
263 #define GRID_LEFT ((LCD_WIDTH - GRID_WIDTH)/2)
264 #define GRID_HEIGHT (4*TK_HEIGHT + 4*TK_SPACE) /* includes grid-panel space */
265 #define GRID_TOP MAX(0, ((LCD_HEIGHT - PANEL_HEIGHT - GRID_HEIGHT)/2))
267 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
268 static void draw_spot(int p)
270 rb->lcd_bitmap_part( flipit_tokens, 0, spots[p] * TK_HEIGHT, TK_WIDTH,
271 GRID_LEFT + (p%5) * (TK_WIDTH+TK_SPACE),
272 GRID_TOP + (p/5) * (TK_HEIGHT+TK_SPACE),
273 TK_WIDTH, TK_HEIGHT );
276 /* draw the cursor at the current cursor position */
277 static void draw_cursor(void)
279 #ifdef HAVE_LCD_COLOR
280 rb->lcd_bitmap_transparent( flipit_cursor,
281 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
282 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
283 TK_WIDTH, TK_HEIGHT );
284 #else
285 rb->lcd_set_drawmode(DRMODE_FG);
286 rb->lcd_mono_bitmap( flipit_cursor,
287 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
288 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
289 TK_WIDTH, TK_HEIGHT );
290 rb->lcd_set_drawmode(DRMODE_SOLID);
291 #endif
294 /* draw the info panel ... duh */
295 static void draw_info_panel(void)
297 char s[32];
299 rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
300 rb->lcd_fillrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
301 GRID_WIDTH, PANEL_HEIGHT );
302 rb->lcd_set_drawmode( DRMODE_SOLID );
303 rb->lcd_drawrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
304 GRID_WIDTH, PANEL_HEIGHT );
306 rb->snprintf( s, sizeof(s), "Flips: %d", moves );
307 rb->lcd_putsxy( (LCD_WIDTH - rb->lcd_getstringsize(s, NULL, NULL)) / 2,
308 GRID_TOP + 4*(TK_HEIGHT+TK_SPACE) + 2, s );
311 #else /* HAVE_LCD_CHARCELLS */
313 static const unsigned char tk_pat[4][7] = {
314 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* white - white */
315 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x1f, 0x0e }, /* white - black */
316 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* black - white */
317 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x1f, 0x0e } /* black - black */
320 static unsigned char cur_pat[7];
321 static unsigned long gfx_chars[5];
323 static void release_gfx(void)
325 int i;
327 for (i = 0; i < 5; i++)
328 if (gfx_chars[i])
329 rb->lcd_unlock_pattern(gfx_chars[i]);
332 static bool init_gfx(void)
334 int i;
336 for (i = 0; i < 5; i++) {
337 if ((gfx_chars[i] = rb->lcd_get_locked_pattern()) == 0) {
338 release_gfx();
339 return false;
342 for (i = 0; i < 4; i++)
343 rb->lcd_define_pattern(gfx_chars[i], tk_pat[i]);
344 return true;
347 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
348 static void draw_spot(int p)
350 if ((p/5) & 1)
351 p -= 5;
353 rb->lcd_putc (p%5, p/10, gfx_chars[2*spots[p]+spots[p+5]]);
356 /* draw the cursor at the current cursor position */
357 static void draw_cursor(void)
359 if ((cursor_pos/5) & 1) {
360 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos-5]+spots[cursor_pos]], 7 );
361 cur_pat[4] ^= 0x15;
362 cur_pat[6] ^= 0x11;
364 else {
365 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos]+spots[cursor_pos+5]], 7 );
366 cur_pat[0] ^= 0x15;
367 cur_pat[2] ^= 0x11;
369 rb->lcd_define_pattern(gfx_chars[4], cur_pat);
370 rb->lcd_putc( cursor_pos%5, cursor_pos/10, gfx_chars[4] );
373 /* draw the info panel ... duh */
374 static void draw_info_panel(void)
376 char s[16];
378 rb->lcd_puts( 6, 0, "Flips" );
379 rb->snprintf( s, sizeof(s), "%d", moves );
380 rb->lcd_puts( 6, 1, s );
383 #endif /* LCD */
385 /* clear the cursor where it is */
386 static inline void clear_cursor(void)
388 draw_spot( cursor_pos );
391 /* check if the puzzle is finished */
392 static bool flipit_finished(void)
394 int i;
395 for (i=0; i<20; i++)
396 if (!spots[i])
397 return false;
398 clear_cursor();
399 return true;
402 /* draws the toggled spots */
403 static void flipit_toggle(void)
405 spots[cursor_pos] = 1-spots[cursor_pos];
406 toggle[cursor_pos] = 1-toggle[cursor_pos];
407 draw_spot(cursor_pos);
408 if (cursor_pos%5 > 0) {
409 spots[cursor_pos-1] = 1-spots[cursor_pos-1];
410 draw_spot(cursor_pos-1);
412 if (cursor_pos%5 < 4) {
413 spots[cursor_pos+1] = 1-spots[cursor_pos+1];
414 draw_spot(cursor_pos+1);
416 if (cursor_pos/5 > 0) {
417 spots[cursor_pos-5] = 1-spots[cursor_pos-5];
418 draw_spot(cursor_pos-5);
420 if (cursor_pos/5 < 3) {
421 spots[cursor_pos+5] = 1-spots[cursor_pos+5];
422 draw_spot(cursor_pos+5);
424 moves++;
426 draw_info_panel();
428 if (flipit_finished())
429 clear_cursor();
432 /* move the cursor in any direction */
433 static void move_cursor(int x, int y)
435 if (!(flipit_finished())) {
436 clear_cursor();
437 cursor_pos = ( x + 5 + cursor_pos%5 )%5
438 + ( ( y + 4 + cursor_pos/5 )%4 )*5;
439 draw_cursor();
441 rb->lcd_update();
444 /* initialize the board */
445 static void flipit_init(void)
447 int i;
449 rb->lcd_clear_display();
450 for (i=0; i<20; i++) {
451 spots[i]=1;
452 toggle[i]=1;
453 draw_spot(i);
455 rb->lcd_update();
457 for (i=0; i<20; i++) {
458 cursor_pos = (rb->rand() % 20);
459 flipit_toggle();
462 cursor_pos = 0;
463 draw_cursor();
464 moves = 0;
465 draw_info_panel();
466 rb->lcd_update();
469 /* the main game loop */
470 static bool flipit_loop(void)
472 int i;
473 int button;
474 int lastbutton = BUTTON_NONE;
476 flipit_init();
477 while(true) {
478 button = rb->button_get(true);
479 switch (button) {
480 #ifdef FLIPIT_RC_QUIT
481 case FLIPIT_RC_QUIT:
482 #endif
483 case FLIPIT_QUIT:
484 /* get out of here */
485 return PLUGIN_OK;
487 case FLIPIT_SHUFFLE:
488 /* mix up the pieces */
489 flipit_init();
490 break;
492 case FLIPIT_SOLVE:
493 #ifdef FLIPIT_SOLVE_PRE
494 if (lastbutton != FLIPIT_SOLVE_PRE)
495 break;
496 #endif
497 /* solve the puzzle */
498 if (!flipit_finished()) {
499 for (i=0; i<20; i++)
500 if (!toggle[i]) {
501 clear_cursor();
502 cursor_pos = i;
503 flipit_toggle();
504 draw_cursor();
505 rb->lcd_update();
506 rb->sleep(HZ*2/3);
509 break;
511 case FLIPIT_STEP_BY_STEP:
512 #ifdef FLIPIT_STEP_PRE
513 if (lastbutton != FLIPIT_STEP_PRE)
514 break;
515 #endif
516 if (!flipit_finished()) {
517 for (i=0; i<20; i++)
518 if (!toggle[i]) {
519 clear_cursor();
520 cursor_pos = i;
521 flipit_toggle();
522 draw_cursor();
523 rb->lcd_update();
524 break;
527 break;
529 case FLIPIT_TOGGLE:
530 #ifdef FLIPIT_TOGGLE_PRE
531 if (lastbutton != FLIPIT_TOGGLE_PRE)
532 break;
533 #endif
534 /* toggle the pieces */
535 if (!flipit_finished()) {
536 flipit_toggle();
537 draw_cursor();
538 rb->lcd_update();
540 break;
542 case FLIPIT_LEFT:
543 move_cursor(-1, 0);
544 break;
546 case FLIPIT_RIGHT:
547 move_cursor(1, 0);
548 break;
549 /*move cursor though the entire field*/
550 #ifdef FLIPIT_SCROLLWHEEL
551 case FLIPIT_PREV:
552 case FLIPIT_PREV|BUTTON_REPEAT:
553 if ((cursor_pos)%5 == 0) {
554 move_cursor(-1, -1);
556 else {
557 move_cursor(-1, 0);
559 break;
561 case FLIPIT_NEXT:
562 case FLIPIT_NEXT|BUTTON_REPEAT:
563 if ((cursor_pos+1)%5 == 0) {
564 move_cursor(1, 1);
566 else {
567 move_cursor(1, 0);
569 break;
570 #endif
571 case FLIPIT_UP:
572 #ifdef FLIPIT_UP_PRE
573 if (lastbutton != FLIPIT_UP_PRE)
574 break;
575 #endif
576 move_cursor(0, -1);
577 break;
579 case FLIPIT_DOWN:
580 move_cursor(0, 1);
581 break;
583 default:
584 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
585 return PLUGIN_USB_CONNECTED;
586 break;
588 if (button != BUTTON_NONE)
589 lastbutton = button;
593 /* called function from outside */
594 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
596 int i, rc;
598 (void)parameter;
599 rb = api;
601 #ifdef HAVE_LCD_COLOR
602 rb->lcd_set_background(LCD_WHITE);
603 rb->lcd_set_foreground(LCD_BLACK);
604 #endif
606 #if LCD_DEPTH > 1
607 rb->lcd_set_backdrop(NULL);
608 #endif
610 rb->splash(HZ, "FlipIt!");
612 #ifdef HAVE_LCD_BITMAP
613 /* print instructions */
614 rb->lcd_clear_display();
615 rb->lcd_setfont(FONT_SYSFIXED);
616 #if CONFIG_KEYPAD == RECORDER_PAD
617 rb->lcd_putsxy(2, 8, "[OFF] to stop");
618 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
619 rb->lcd_putsxy(2, 28, "[F1] shuffle");
620 rb->lcd_putsxy(2, 38, "[F2] solution");
621 rb->lcd_putsxy(2, 48, "[F3] step by step");
622 #elif CONFIG_KEYPAD == ONDIO_PAD
623 rb->lcd_putsxy(2, 8, "[OFF] to stop");
624 rb->lcd_putsxy(2, 18, "[MODE] toggle");
625 rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
626 rb->lcd_putsxy(2, 38, "[M-UP] solution");
627 rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
628 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
629 (CONFIG_KEYPAD == IRIVER_H300_PAD)
630 rb->lcd_putsxy(2, 8, "[STOP] to stop");
631 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
632 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
633 rb->lcd_putsxy(2, 38, "[PLAY] solution");
634 rb->lcd_putsxy(2, 48, "[REC] step by step");
635 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
636 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
637 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
638 rb->lcd_putsxy(2, 8, "[S-MENU] to stop");
639 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
640 rb->lcd_putsxy(2, 28, "[S-LEFT] shuffle");
641 rb->lcd_putsxy(2, 38, "[S-PLAY] solution");
642 rb->lcd_putsxy(2, 48, "[S-RIGHT] step by step");
643 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
644 rb->lcd_putsxy(2, 8, "[POWER] to stop");
645 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
646 rb->lcd_putsxy(2, 28, "[REC] shuffle");
647 rb->lcd_putsxy(2, 38, "[PLAY..] solution");
648 rb->lcd_putsxy(2, 48, "[PLAY] step by step");
649 #elif CONFIG_KEYPAD == GIGABEAT_PAD
650 rb->lcd_putsxy(2, 8, "[POWER] to stop");
651 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
652 rb->lcd_putsxy(2, 28, "[MENU] shuffle");
653 rb->lcd_putsxy(2, 38, "[VOL+] solution");
654 rb->lcd_putsxy(2, 48, "[VOL-] step by step");
655 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
656 rb->lcd_putsxy(2, 8, "[POWER] to stop");
657 rb->lcd_putsxy(2, 18, "[REW] toggle");
658 rb->lcd_putsxy(2, 28, "[PL-LEFT] shuffle");
659 rb->lcd_putsxy(2, 38, "[PL-RIGHT] solution");
660 rb->lcd_putsxy(2, 48, "[PL-UP] step by step");
661 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
662 (CONFIG_KEYPAD == SANSA_C200_PAD)
663 rb->lcd_putsxy(2, 8, "[POWER] to stop");
664 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
665 rb->lcd_putsxy(2, 28, "[REC-LEFT] shuffle");
666 rb->lcd_putsxy(2, 38, "[REC-RIGHT] solution");
667 rb->lcd_putsxy(2, 48, "[REC-SEL] step by step");
668 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
669 rb->lcd_putsxy(2, 8, "[REC] to stop");
670 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
671 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
672 rb->lcd_putsxy(2, 38, "[MENU..] solution");
673 rb->lcd_putsxy(2, 48, "[MENU] step by step");
674 #endif
676 #ifdef HAVE_TOUCHPAD
677 rb->lcd_putsxy(2, 8, "[BOTTOMLEFT] to stop");
678 rb->lcd_putsxy(2, 18, "[CENTRE] toggle");
679 rb->lcd_putsxy(2, 28, "[TOPRIGHT] shuffle");
680 rb->lcd_putsxy(2, 38, "[BOTTOMLEFT] solution");
681 rb->lcd_putsxy(2, 48, "[BOTTOMRIGHT] step by step");
682 #endif
684 rb->lcd_update();
685 #else /* HAVE_LCD_CHARCELLS */
686 if (!init_gfx())
687 return PLUGIN_ERROR;
688 #endif
689 rb->button_get_w_tmo(HZ*3);
691 rb->lcd_clear_display();
692 draw_info_panel();
693 for (i=0; i<20; i++) {
694 spots[i]=1;
695 draw_spot(i);
697 rb->lcd_update();
698 rb->sleep(HZ*3/2);
699 rb->srand(*rb->current_tick);
701 rc = flipit_loop();
702 #ifdef HAVE_LCD_CHARCELLS
703 release_gfx();
704 #endif
705 return rc;