very minor code police. also fix a possible but unlikely missed cpu_boost(false)
[Rockbox.git] / apps / plugins / flipit.c
blob9d3a9a25f4fb42341f4fb053f21c1f762083d6c0
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Vicentini Martin
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version 2
15 * of the License, or (at your option) any later version.
17 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
18 * KIND, either express or implied.
20 ****************************************************************************/
21 #include "plugin.h"
23 PLUGIN_HEADER
25 /* variable button definitions */
26 #if CONFIG_KEYPAD == RECORDER_PAD
27 #define FLIPIT_LEFT BUTTON_LEFT
28 #define FLIPIT_RIGHT BUTTON_RIGHT
29 #define FLIPIT_UP BUTTON_UP
30 #define FLIPIT_DOWN BUTTON_DOWN
31 #define FLIPIT_QUIT BUTTON_OFF
32 #define FLIPIT_SHUFFLE BUTTON_F1
33 #define FLIPIT_SOLVE BUTTON_F2
34 #define FLIPIT_STEP_BY_STEP BUTTON_F3
35 #define FLIPIT_TOGGLE BUTTON_PLAY
37 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
38 #define FLIPIT_LEFT BUTTON_LEFT
39 #define FLIPIT_RIGHT BUTTON_RIGHT
40 #define FLIPIT_UP BUTTON_UP
41 #define FLIPIT_DOWN BUTTON_DOWN
42 #define FLIPIT_QUIT BUTTON_OFF
43 #define FLIPIT_SHUFFLE BUTTON_F1
44 #define FLIPIT_SOLVE BUTTON_F2
45 #define FLIPIT_STEP_BY_STEP BUTTON_F3
46 #define FLIPIT_TOGGLE BUTTON_SELECT
48 #elif CONFIG_KEYPAD == PLAYER_PAD
49 #define FLIPIT_LEFT BUTTON_LEFT
50 #define FLIPIT_RIGHT BUTTON_RIGHT
51 #define FLIPIT_UP_PRE BUTTON_ON
52 #define FLIPIT_UP (BUTTON_ON | BUTTON_REL)
53 #define FLIPIT_DOWN BUTTON_MENU
54 #define FLIPIT_QUIT BUTTON_STOP
55 #define FLIPIT_SHUFFLE (BUTTON_ON | BUTTON_LEFT)
56 #define FLIPIT_SOLVE (BUTTON_ON | BUTTON_RIGHT)
57 #define FLIPIT_STEP_BY_STEP (BUTTON_ON | BUTTON_PLAY)
58 #define FLIPIT_TOGGLE BUTTON_PLAY
60 #elif CONFIG_KEYPAD == ONDIO_PAD
61 #define FLIPIT_LEFT BUTTON_LEFT
62 #define FLIPIT_RIGHT BUTTON_RIGHT
63 #define FLIPIT_UP BUTTON_UP
64 #define FLIPIT_DOWN BUTTON_DOWN
65 #define FLIPIT_QUIT BUTTON_OFF
66 #define FLIPIT_SHUFFLE (BUTTON_MENU | BUTTON_LEFT)
67 #define FLIPIT_SOLVE (BUTTON_MENU | BUTTON_UP)
68 #define FLIPIT_STEP_BY_STEP (BUTTON_MENU | BUTTON_RIGHT)
69 #define FLIPIT_TOGGLE_PRE BUTTON_MENU
70 #define FLIPIT_TOGGLE (BUTTON_MENU | BUTTON_REL)
72 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
73 (CONFIG_KEYPAD == IRIVER_H300_PAD)
74 #define FLIPIT_LEFT BUTTON_LEFT
75 #define FLIPIT_RIGHT BUTTON_RIGHT
76 #define FLIPIT_UP BUTTON_UP
77 #define FLIPIT_DOWN BUTTON_DOWN
78 #define FLIPIT_QUIT BUTTON_OFF
79 #define FLIPIT_SHUFFLE BUTTON_MODE
80 #define FLIPIT_SOLVE BUTTON_ON
81 #define FLIPIT_STEP_BY_STEP BUTTON_REC
82 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
83 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
85 #define FLIPIT_RC_QUIT BUTTON_RC_STOP
87 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
88 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
89 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
91 #define FLIPIT_SCROLLWHEEL
92 #define FLIPIT_LEFT BUTTON_LEFT
93 #define FLIPIT_RIGHT BUTTON_RIGHT
94 #define FLIPIT_UP BUTTON_MENU
95 #define FLIPIT_DOWN BUTTON_PLAY
96 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
97 #define FLIPIT_PREV BUTTON_SCROLL_BACK
98 #define FLIPIT_QUIT (BUTTON_SELECT | BUTTON_MENU)
99 #define FLIPIT_SHUFFLE (BUTTON_SELECT | BUTTON_LEFT)
100 #define FLIPIT_SOLVE (BUTTON_SELECT | BUTTON_PLAY)
101 #define FLIPIT_STEP_BY_STEP (BUTTON_SELECT | BUTTON_RIGHT)
102 #define FLIPIT_TOGGLE_PRE BUTTON_SELECT
103 #define FLIPIT_TOGGLE (BUTTON_SELECT | BUTTON_REL)
105 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
107 #define FLIPIT_LEFT BUTTON_LEFT
108 #define FLIPIT_RIGHT BUTTON_RIGHT
109 #define FLIPIT_UP BUTTON_UP
110 #define FLIPIT_DOWN BUTTON_DOWN
111 #define FLIPIT_QUIT BUTTON_POWER
112 #define FLIPIT_SHUFFLE BUTTON_REC
113 #define FLIPIT_SOLVE_PRE BUTTON_PLAY
114 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_REPEAT)
115 #define FLIPIT_STEP_PRE BUTTON_PLAY
116 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_REL)
117 #define FLIPIT_TOGGLE BUTTON_SELECT
119 #elif CONFIG_KEYPAD == GIGABEAT_PAD
121 #define FLIPIT_LEFT BUTTON_LEFT
122 #define FLIPIT_RIGHT BUTTON_RIGHT
123 #define FLIPIT_UP BUTTON_UP
124 #define FLIPIT_DOWN BUTTON_DOWN
125 #define FLIPIT_QUIT BUTTON_POWER
126 #define FLIPIT_SHUFFLE BUTTON_MENU
127 #define FLIPIT_SOLVE BUTTON_VOL_UP
128 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
129 #define FLIPIT_TOGGLE BUTTON_SELECT
131 #elif CONFIG_KEYPAD == SANSA_E200_PAD
133 #define FLIPIT_SCROLLWHEEL
134 #define FLIPIT_LEFT BUTTON_LEFT
135 #define FLIPIT_RIGHT BUTTON_RIGHT
136 #define FLIPIT_UP BUTTON_UP
137 #define FLIPIT_DOWN BUTTON_DOWN
138 #define FLIPIT_NEXT BUTTON_SCROLL_FWD
139 #define FLIPIT_PREV BUTTON_SCROLL_BACK
140 #define FLIPIT_QUIT BUTTON_POWER
141 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
142 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
143 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
144 #define FLIPIT_TOGGLE BUTTON_SELECT
146 #elif CONFIG_KEYPAD == SANSA_C200_PAD
148 #define FLIPIT_LEFT BUTTON_LEFT
149 #define FLIPIT_RIGHT BUTTON_RIGHT
150 #define FLIPIT_UP BUTTON_UP
151 #define FLIPIT_DOWN BUTTON_DOWN
152 #define FLIPIT_QUIT BUTTON_POWER
153 #define FLIPIT_SHUFFLE (BUTTON_REC | BUTTON_LEFT)
154 #define FLIPIT_SOLVE (BUTTON_REC | BUTTON_RIGHT)
155 #define FLIPIT_STEP_BY_STEP (BUTTON_REC | BUTTON_SELECT)
156 #define FLIPIT_TOGGLE BUTTON_SELECT
158 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
160 #define FLIPIT_LEFT BUTTON_LEFT
161 #define FLIPIT_RIGHT BUTTON_RIGHT
162 #define FLIPIT_UP BUTTON_SCROLL_UP
163 #define FLIPIT_DOWN BUTTON_SCROLL_DOWN
164 #define FLIPIT_QUIT BUTTON_POWER
165 #define FLIPIT_SHUFFLE (BUTTON_PLAY | BUTTON_LEFT)
166 #define FLIPIT_SOLVE (BUTTON_PLAY | BUTTON_RIGHT)
167 #define FLIPIT_STEP_BY_STEP (BUTTON_PLAY | BUTTON_SCROLL_UP)
168 #define FLIPIT_TOGGLE_PRE BUTTON_REW
169 #define FLIPIT_TOGGLE (BUTTON_REW | BUTTON_REL)
171 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
173 #define FLIPIT_LEFT BUTTON_LEFT
174 #define FLIPIT_RIGHT BUTTON_RIGHT
175 #define FLIPIT_UP BUTTON_UP
176 #define FLIPIT_DOWN BUTTON_DOWN
177 #define FLIPIT_QUIT BUTTON_BACK
178 #define FLIPIT_SHUFFLE BUTTON_MENU
179 #define FLIPIT_SOLVE BUTTON_VOL_UP
180 #define FLIPIT_STEP_BY_STEP BUTTON_VOL_DOWN
181 #define FLIPIT_TOGGLE BUTTON_SELECT
183 #elif CONFIG_KEYPAD == MROBE100_PAD
185 #define FLIPIT_LEFT BUTTON_LEFT
186 #define FLIPIT_RIGHT BUTTON_RIGHT
187 #define FLIPIT_UP BUTTON_UP
188 #define FLIPIT_DOWN BUTTON_DOWN
189 #define FLIPIT_QUIT BUTTON_POWER
190 #define FLIPIT_SHUFFLE BUTTON_MENU
191 #define FLIPIT_SOLVE BUTTON_PLAY
192 #define FLIPIT_STEP_BY_STEP BUTTON_DISPLAY
193 #define FLIPIT_TOGGLE BUTTON_SELECT
195 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
197 #define FLIPIT_LEFT BUTTON_RC_REW
198 #define FLIPIT_RIGHT BUTTON_RC_FF
199 #define FLIPIT_UP BUTTON_RC_VOL_UP
200 #define FLIPIT_DOWN BUTTON_RC_VOL_DOWN
201 #define FLIPIT_QUIT BUTTON_RC_REC
202 #define FLIPIT_SHUFFLE BUTTON_RC_MODE
203 #define FLIPIT_SOLVE_PRE BUTTON_RC_MENU
204 #define FLIPIT_SOLVE (BUTTON_RC_MENU|BUTTON_REPEAT)
205 #define FLIPIT_STEP_PRE BUTTON_RC_MENU
206 #define FLIPIT_STEP_BY_STEP (BUTTON_RC_MENU|BUTTON_REL)
207 #define FLIPIT_TOGGLE BUTTON_RC_PLAY
209 #define FLIPIT_RC_QUIT BUTTON_REC
211 #elif CONFIG_KEYPAD == COWOND2_PAD
213 #define FLIPIT_QUIT BUTTON_POWER
215 #else
216 #error No keymap defined!
217 #endif
219 #ifdef HAVE_TOUCHPAD
220 #ifndef FLIPIT_LEFT
221 #define FLIPIT_LEFT BUTTON_MIDLEFT
222 #endif
223 #ifndef FLIPIT_RIGHT
224 #define FLIPIT_RIGHT BUTTON_MIDRIGHT
225 #endif
226 #ifndef FLIPIT_UP
227 #define FLIPIT_UP BUTTON_TOPMIDDLE
228 #endif
229 #ifndef FLIPIT_DOWN
230 #define FLIPIT_DOWN BUTTON_BOTTOMMIDDLE
231 #endif
232 #ifndef FLIPIT_QUIT
233 #define FLIPIT_QUIT BUTTON_TOPLEFT
234 #endif
235 #ifndef FLIPIT_SHUFFLE
236 #define FLIPIT_SHUFFLE BUTTON_TOPRIGHT
237 #endif
238 #ifndef FLIPIT_SOLVE
239 #define FLIPIT_SOLVE BUTTON_BOTTOMLEFT
240 #endif
241 #ifndef FLIPIT_STEP_BY_STEP
242 #define FLIPIT_STEP_BY_STEP BUTTON_BOTTOMRIGHT
243 #endif
244 #ifndef FLIPIT_TOGGLE
245 #define FLIPIT_TOGGLE BUTTON_CENTER
246 #endif
247 #endif
249 static const struct plugin_api* rb;
250 static int spots[20];
251 static int toggle[20];
252 static int cursor_pos, moves;
254 #ifdef HAVE_LCD_BITMAP
256 #include "flipit_cursor.h"
257 #include "flipit_tokens.h"
259 #define PANEL_HEIGHT 12
260 #define TK_WIDTH BMPWIDTH_flipit_cursor
261 #define TK_HEIGHT BMPHEIGHT_flipit_cursor
262 #define TK_SPACE MAX(0, MIN((LCD_WIDTH - 5*TK_WIDTH)/4, \
263 (LCD_HEIGHT - PANEL_HEIGHT - 4*TK_HEIGHT)/4))
264 #define GRID_WIDTH (5*TK_WIDTH + 4*TK_SPACE)
265 #define GRID_LEFT ((LCD_WIDTH - GRID_WIDTH)/2)
266 #define GRID_HEIGHT (4*TK_HEIGHT + 4*TK_SPACE) /* includes grid-panel space */
267 #define GRID_TOP MAX(0, ((LCD_HEIGHT - PANEL_HEIGHT - GRID_HEIGHT)/2))
269 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
270 static void draw_spot(int p)
272 rb->lcd_bitmap_part( flipit_tokens, 0, spots[p] * TK_HEIGHT, TK_WIDTH,
273 GRID_LEFT + (p%5) * (TK_WIDTH+TK_SPACE),
274 GRID_TOP + (p/5) * (TK_HEIGHT+TK_SPACE),
275 TK_WIDTH, TK_HEIGHT );
278 /* draw the cursor at the current cursor position */
279 static void draw_cursor(void)
281 #ifdef HAVE_LCD_COLOR
282 rb->lcd_bitmap_transparent( flipit_cursor,
283 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
284 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
285 TK_WIDTH, TK_HEIGHT );
286 #else
287 rb->lcd_set_drawmode(DRMODE_FG);
288 rb->lcd_mono_bitmap( flipit_cursor,
289 GRID_LEFT + (cursor_pos%5) * (TK_WIDTH+TK_SPACE),
290 GRID_TOP + (cursor_pos/5) * (TK_HEIGHT+TK_SPACE),
291 TK_WIDTH, TK_HEIGHT );
292 rb->lcd_set_drawmode(DRMODE_SOLID);
293 #endif
296 /* draw the info panel ... duh */
297 static void draw_info_panel(void)
299 char s[32];
301 rb->lcd_set_drawmode( DRMODE_SOLID|DRMODE_INVERSEVID );
302 rb->lcd_fillrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
303 GRID_WIDTH, PANEL_HEIGHT );
304 rb->lcd_set_drawmode( DRMODE_SOLID );
305 rb->lcd_drawrect( GRID_LEFT, GRID_TOP + 4*(TK_HEIGHT+TK_SPACE),
306 GRID_WIDTH, PANEL_HEIGHT );
308 rb->snprintf( s, sizeof(s), "Flips: %d", moves );
309 rb->lcd_putsxy( (LCD_WIDTH - rb->lcd_getstringsize(s, NULL, NULL)) / 2,
310 GRID_TOP + 4*(TK_HEIGHT+TK_SPACE) + 2, s );
313 #else /* HAVE_LCD_CHARCELLS */
315 static const unsigned char tk_pat[4][7] = {
316 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* white - white */
317 { 0x0e, 0x11, 0x0e, 0x00, 0x0e, 0x1f, 0x0e }, /* white - black */
318 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x11, 0x0e }, /* black - white */
319 { 0x0e, 0x1f, 0x0e, 0x00, 0x0e, 0x1f, 0x0e } /* black - black */
322 static unsigned char cur_pat[7];
323 static unsigned long gfx_chars[5];
325 static void release_gfx(void)
327 int i;
329 for (i = 0; i < 5; i++)
330 if (gfx_chars[i])
331 rb->lcd_unlock_pattern(gfx_chars[i]);
334 static bool init_gfx(void)
336 int i;
338 for (i = 0; i < 5; i++) {
339 if ((gfx_chars[i] = rb->lcd_get_locked_pattern()) == 0) {
340 release_gfx();
341 return false;
344 for (i = 0; i < 4; i++)
345 rb->lcd_define_pattern(gfx_chars[i], tk_pat[i]);
346 return true;
349 /* draw a spot at the coordinates (x,y), range of p is 0-19 */
350 static void draw_spot(int p)
352 if ((p/5) & 1)
353 p -= 5;
355 rb->lcd_putc (p%5, p/10, gfx_chars[2*spots[p]+spots[p+5]]);
358 /* draw the cursor at the current cursor position */
359 static void draw_cursor(void)
361 if ((cursor_pos/5) & 1) {
362 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos-5]+spots[cursor_pos]], 7 );
363 cur_pat[4] ^= 0x15;
364 cur_pat[6] ^= 0x11;
366 else {
367 rb->memcpy( cur_pat, tk_pat[2*spots[cursor_pos]+spots[cursor_pos+5]], 7 );
368 cur_pat[0] ^= 0x15;
369 cur_pat[2] ^= 0x11;
371 rb->lcd_define_pattern(gfx_chars[4], cur_pat);
372 rb->lcd_putc( cursor_pos%5, cursor_pos/10, gfx_chars[4] );
375 /* draw the info panel ... duh */
376 static void draw_info_panel(void)
378 char s[16];
380 rb->lcd_puts( 6, 0, "Flips" );
381 rb->snprintf( s, sizeof(s), "%d", moves );
382 rb->lcd_puts( 6, 1, s );
385 #endif /* LCD */
387 /* clear the cursor where it is */
388 static inline void clear_cursor(void)
390 draw_spot( cursor_pos );
393 /* check if the puzzle is finished */
394 static bool flipit_finished(void)
396 int i;
397 for (i=0; i<20; i++)
398 if (!spots[i])
399 return false;
400 clear_cursor();
401 return true;
404 /* draws the toggled spots */
405 static void flipit_toggle(void)
407 spots[cursor_pos] = 1-spots[cursor_pos];
408 toggle[cursor_pos] = 1-toggle[cursor_pos];
409 draw_spot(cursor_pos);
410 if (cursor_pos%5 > 0) {
411 spots[cursor_pos-1] = 1-spots[cursor_pos-1];
412 draw_spot(cursor_pos-1);
414 if (cursor_pos%5 < 4) {
415 spots[cursor_pos+1] = 1-spots[cursor_pos+1];
416 draw_spot(cursor_pos+1);
418 if (cursor_pos/5 > 0) {
419 spots[cursor_pos-5] = 1-spots[cursor_pos-5];
420 draw_spot(cursor_pos-5);
422 if (cursor_pos/5 < 3) {
423 spots[cursor_pos+5] = 1-spots[cursor_pos+5];
424 draw_spot(cursor_pos+5);
426 moves++;
428 draw_info_panel();
430 if (flipit_finished())
431 clear_cursor();
434 /* move the cursor in any direction */
435 static void move_cursor(int x, int y)
437 if (!(flipit_finished())) {
438 clear_cursor();
439 cursor_pos = ( x + 5 + cursor_pos%5 )%5
440 + ( ( y + 4 + cursor_pos/5 )%4 )*5;
441 draw_cursor();
443 rb->lcd_update();
446 /* initialize the board */
447 static void flipit_init(void)
449 int i;
451 rb->lcd_clear_display();
452 for (i=0; i<20; i++) {
453 spots[i]=1;
454 toggle[i]=1;
455 draw_spot(i);
457 rb->lcd_update();
459 for (i=0; i<20; i++) {
460 cursor_pos = (rb->rand() % 20);
461 flipit_toggle();
464 cursor_pos = 0;
465 draw_cursor();
466 moves = 0;
467 draw_info_panel();
468 rb->lcd_update();
471 /* the main game loop */
472 static bool flipit_loop(void)
474 int i;
475 int button;
476 int lastbutton = BUTTON_NONE;
478 flipit_init();
479 while(true) {
480 button = rb->button_get(true);
481 switch (button) {
482 #ifdef FLIPIT_RC_QUIT
483 case FLIPIT_RC_QUIT:
484 #endif
485 case FLIPIT_QUIT:
486 /* get out of here */
487 return PLUGIN_OK;
489 case FLIPIT_SHUFFLE:
490 /* mix up the pieces */
491 flipit_init();
492 break;
494 case FLIPIT_SOLVE:
495 #ifdef FLIPIT_SOLVE_PRE
496 if (lastbutton != FLIPIT_SOLVE_PRE)
497 break;
498 #endif
499 /* solve the puzzle */
500 if (!flipit_finished()) {
501 for (i=0; i<20; i++)
502 if (!toggle[i]) {
503 clear_cursor();
504 cursor_pos = i;
505 flipit_toggle();
506 draw_cursor();
507 rb->lcd_update();
508 rb->sleep(HZ*2/3);
511 break;
513 case FLIPIT_STEP_BY_STEP:
514 #ifdef FLIPIT_STEP_PRE
515 if (lastbutton != FLIPIT_STEP_PRE)
516 break;
517 #endif
518 if (!flipit_finished()) {
519 for (i=0; i<20; i++)
520 if (!toggle[i]) {
521 clear_cursor();
522 cursor_pos = i;
523 flipit_toggle();
524 draw_cursor();
525 rb->lcd_update();
526 break;
529 break;
531 case FLIPIT_TOGGLE:
532 #ifdef FLIPIT_TOGGLE_PRE
533 if (lastbutton != FLIPIT_TOGGLE_PRE)
534 break;
535 #endif
536 /* toggle the pieces */
537 if (!flipit_finished()) {
538 flipit_toggle();
539 draw_cursor();
540 rb->lcd_update();
542 break;
544 case FLIPIT_LEFT:
545 move_cursor(-1, 0);
546 break;
548 case FLIPIT_RIGHT:
549 move_cursor(1, 0);
550 break;
551 /*move cursor though the entire field*/
552 #ifdef FLIPIT_SCROLLWHEEL
553 case FLIPIT_PREV:
554 case FLIPIT_PREV|BUTTON_REPEAT:
555 if ((cursor_pos)%5 == 0) {
556 move_cursor(-1, -1);
558 else {
559 move_cursor(-1, 0);
561 break;
563 case FLIPIT_NEXT:
564 case FLIPIT_NEXT|BUTTON_REPEAT:
565 if ((cursor_pos+1)%5 == 0) {
566 move_cursor(1, 1);
568 else {
569 move_cursor(1, 0);
571 break;
572 #endif
573 case FLIPIT_UP:
574 #ifdef FLIPIT_UP_PRE
575 if (lastbutton != FLIPIT_UP_PRE)
576 break;
577 #endif
578 move_cursor(0, -1);
579 break;
581 case FLIPIT_DOWN:
582 move_cursor(0, 1);
583 break;
585 default:
586 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
587 return PLUGIN_USB_CONNECTED;
588 break;
590 if (button != BUTTON_NONE)
591 lastbutton = button;
595 /* called function from outside */
596 enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter)
598 int i, rc;
600 (void)parameter;
601 rb = api;
603 #ifdef HAVE_LCD_COLOR
604 rb->lcd_set_background(LCD_WHITE);
605 rb->lcd_set_foreground(LCD_BLACK);
606 #endif
608 #if LCD_DEPTH > 1
609 rb->lcd_set_backdrop(NULL);
610 #endif
612 rb->splash(HZ, "FlipIt!");
614 #ifdef HAVE_LCD_BITMAP
615 /* print instructions */
616 rb->lcd_clear_display();
617 rb->lcd_setfont(FONT_SYSFIXED);
618 #if CONFIG_KEYPAD == RECORDER_PAD
619 rb->lcd_putsxy(2, 8, "[OFF] to stop");
620 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
621 rb->lcd_putsxy(2, 28, "[F1] shuffle");
622 rb->lcd_putsxy(2, 38, "[F2] solution");
623 rb->lcd_putsxy(2, 48, "[F3] step by step");
624 #elif CONFIG_KEYPAD == ONDIO_PAD
625 rb->lcd_putsxy(2, 8, "[OFF] to stop");
626 rb->lcd_putsxy(2, 18, "[MODE] toggle");
627 rb->lcd_putsxy(2, 28, "[M-LEFT] shuffle");
628 rb->lcd_putsxy(2, 38, "[M-UP] solution");
629 rb->lcd_putsxy(2, 48, "[M-RIGHT] step by step");
630 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
631 (CONFIG_KEYPAD == IRIVER_H300_PAD)
632 rb->lcd_putsxy(2, 8, "[STOP] to stop");
633 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
634 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
635 rb->lcd_putsxy(2, 38, "[PLAY] solution");
636 rb->lcd_putsxy(2, 48, "[REC] step by step");
637 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
638 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
639 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
640 rb->lcd_putsxy(2, 8, "[S-MENU] to stop");
641 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
642 rb->lcd_putsxy(2, 28, "[S-LEFT] shuffle");
643 rb->lcd_putsxy(2, 38, "[S-PLAY] solution");
644 rb->lcd_putsxy(2, 48, "[S-RIGHT] step by step");
645 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
646 rb->lcd_putsxy(2, 8, "[POWER] to stop");
647 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
648 rb->lcd_putsxy(2, 28, "[REC] shuffle");
649 rb->lcd_putsxy(2, 38, "[PLAY..] solution");
650 rb->lcd_putsxy(2, 48, "[PLAY] step by step");
651 #elif CONFIG_KEYPAD == GIGABEAT_PAD
652 rb->lcd_putsxy(2, 8, "[POWER] to stop");
653 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
654 rb->lcd_putsxy(2, 28, "[MENU] shuffle");
655 rb->lcd_putsxy(2, 38, "[VOL+] solution");
656 rb->lcd_putsxy(2, 48, "[VOL-] step by step");
657 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
658 rb->lcd_putsxy(2, 8, "[POWER] to stop");
659 rb->lcd_putsxy(2, 18, "[REW] toggle");
660 rb->lcd_putsxy(2, 28, "[PL-LEFT] shuffle");
661 rb->lcd_putsxy(2, 38, "[PL-RIGHT] solution");
662 rb->lcd_putsxy(2, 48, "[PL-UP] step by step");
663 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
664 (CONFIG_KEYPAD == SANSA_C200_PAD)
665 rb->lcd_putsxy(2, 8, "[POWER] to stop");
666 rb->lcd_putsxy(2, 18, "[SELECT] toggle");
667 rb->lcd_putsxy(2, 28, "[REC-LEFT] shuffle");
668 rb->lcd_putsxy(2, 38, "[REC-RIGHT] solution");
669 rb->lcd_putsxy(2, 48, "[REC-SEL] step by step");
670 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
671 rb->lcd_putsxy(2, 8, "[REC] to stop");
672 rb->lcd_putsxy(2, 18, "[PLAY] toggle");
673 rb->lcd_putsxy(2, 28, "[MODE] shuffle");
674 rb->lcd_putsxy(2, 38, "[MENU..] solution");
675 rb->lcd_putsxy(2, 48, "[MENU] step by step");
676 #endif
678 #ifdef HAVE_TOUCHPAD
679 rb->lcd_putsxy(2, 8, "[BOTTOMLEFT] to stop");
680 rb->lcd_putsxy(2, 18, "[CENTRE] toggle");
681 rb->lcd_putsxy(2, 28, "[TOPRIGHT] shuffle");
682 rb->lcd_putsxy(2, 38, "[BOTTOMLEFT] solution");
683 rb->lcd_putsxy(2, 48, "[BOTTOMRIGHT] step by step");
684 #endif
686 rb->lcd_update();
687 #else /* HAVE_LCD_CHARCELLS */
688 if (!init_gfx())
689 return PLUGIN_ERROR;
690 #endif
691 rb->button_get_w_tmo(HZ*3);
693 rb->lcd_clear_display();
694 draw_info_panel();
695 for (i=0; i<20; i++) {
696 spots[i]=1;
697 draw_spot(i);
699 rb->lcd_update();
700 rb->sleep(HZ*3/2);
701 rb->srand(*rb->current_tick);
703 rc = flipit_loop();
704 #ifdef HAVE_LCD_CHARCELLS
705 release_gfx();
706 #endif
707 return rc;