Use albumart opt in sliding puzzle manual
[kugel-rb.git] / apps / plugins / chessclock.c
blobf0a63f63dcd7f3b907593d0bc9084f03330122be
1 /***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
10 * Copyright (C) 2002 Kjell Ericson
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"
22 #include "lib/playback_control.h"
24 PLUGIN_HEADER
26 /* variable button definitions */
27 #if CONFIG_KEYPAD == RECORDER_PAD
28 #define CHC_QUIT BUTTON_OFF
29 #define CHC_STARTSTOP BUTTON_PLAY
30 #define CHC_RESET BUTTON_LEFT
31 #define CHC_MENU BUTTON_F1
32 #define CHC_SETTINGS_INC BUTTON_UP
33 #define CHC_SETTINGS_DEC BUTTON_DOWN
34 #define CHC_SETTINGS_OK BUTTON_PLAY
35 #define CHC_SETTINGS_OK2 BUTTON_LEFT
36 #define CHC_SETTINGS_CANCEL BUTTON_OFF
38 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
39 #define CHC_QUIT BUTTON_OFF
40 #define CHC_STARTSTOP BUTTON_SELECT
41 #define CHC_RESET BUTTON_LEFT
42 #define CHC_MENU BUTTON_F1
43 #define CHC_SETTINGS_INC BUTTON_UP
44 #define CHC_SETTINGS_DEC BUTTON_DOWN
45 #define CHC_SETTINGS_OK BUTTON_SELECT
46 #define CHC_SETTINGS_OK2 BUTTON_LEFT
47 #define CHC_SETTINGS_CANCEL BUTTON_OFF
49 #elif CONFIG_KEYPAD == ONDIO_PAD
50 #define CHC_QUIT BUTTON_OFF
51 #define CHC_STARTSTOP BUTTON_RIGHT
52 #define CHC_RESET BUTTON_LEFT
53 #define CHC_MENU BUTTON_MENU
54 #define CHC_SETTINGS_INC BUTTON_UP
55 #define CHC_SETTINGS_DEC BUTTON_DOWN
56 #define CHC_SETTINGS_OK BUTTON_RIGHT
57 #define CHC_SETTINGS_OK2 BUTTON_LEFT
58 #define CHC_SETTINGS_CANCEL BUTTON_MENU
60 #elif CONFIG_KEYPAD == PLAYER_PAD
61 #define CHC_QUIT BUTTON_ON
62 #define CHC_STARTSTOP BUTTON_PLAY
63 #define CHC_RESET BUTTON_STOP
64 #define CHC_MENU BUTTON_MENU
65 #define CHC_SETTINGS_INC BUTTON_RIGHT
66 #define CHC_SETTINGS_DEC BUTTON_LEFT
67 #define CHC_SETTINGS_OK BUTTON_PLAY
68 #define CHC_SETTINGS_CANCEL BUTTON_STOP
69 #define CHC_SETTINGS_CANCEL2 BUTTON_MENU
71 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
72 (CONFIG_KEYPAD == IRIVER_H300_PAD)
73 #define CHC_QUIT BUTTON_SELECT
74 #define CHC_STARTSTOP BUTTON_ON
75 #define CHC_RESET BUTTON_OFF
76 #define CHC_MENU BUTTON_REC
77 #define CHC_SETTINGS_INC BUTTON_RIGHT
78 #define CHC_SETTINGS_DEC BUTTON_LEFT
79 #define CHC_SETTINGS_OK BUTTON_ON
80 #define CHC_SETTINGS_CANCEL BUTTON_OFF
81 #define CHC_SETTINGS_CANCEL2 BUTTON_REC
83 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
84 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
85 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
86 #define CHC_QUIT BUTTON_PLAY
87 #define CHC_STARTSTOP BUTTON_SELECT
88 #define CHC_RESET BUTTON_LEFT
89 #define CHC_MENU BUTTON_MENU
90 #define CHC_SETTINGS_INC BUTTON_SCROLL_FWD
91 #define CHC_SETTINGS_DEC BUTTON_SCROLL_BACK
92 #define CHC_SETTINGS_OK BUTTON_SELECT
93 #define CHC_SETTINGS_CANCEL BUTTON_MENU
95 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
96 #define CHC_QUIT BUTTON_PLAY
97 #define CHC_STARTSTOP BUTTON_MODE
98 #define CHC_RESET BUTTON_EQ
99 #define CHC_MENU BUTTON_SELECT
100 #define CHC_SETTINGS_INC BUTTON_RIGHT
101 #define CHC_SETTINGS_DEC BUTTON_LEFT
102 #define CHC_SETTINGS_OK BUTTON_SELECT
103 #define CHC_SETTINGS_CANCEL BUTTON_PLAY
105 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
106 #define CHC_QUIT BUTTON_REC
107 #define CHC_STARTSTOP BUTTON_PLAY
108 #define CHC_RESET BUTTON_POWER
109 #define CHC_MENU BUTTON_SELECT
110 #define CHC_SETTINGS_INC BUTTON_RIGHT
111 #define CHC_SETTINGS_DEC BUTTON_LEFT
112 #define CHC_SETTINGS_OK BUTTON_SELECT
113 #define CHC_SETTINGS_CANCEL BUTTON_REC
115 #elif CONFIG_KEYPAD == GIGABEAT_PAD
116 #define CHC_QUIT BUTTON_POWER
117 #define CHC_STARTSTOP BUTTON_SELECT
118 #define CHC_RESET BUTTON_A
119 #define CHC_MENU BUTTON_MENU
120 #define CHC_SETTINGS_INC BUTTON_UP
121 #define CHC_SETTINGS_DEC BUTTON_DOWN
122 #define CHC_SETTINGS_OK BUTTON_SELECT
123 #define CHC_SETTINGS_CANCEL BUTTON_POWER
125 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
126 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
127 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
128 (CONFIG_KEYPAD == SANSA_M200_PAD)
129 #define CHC_QUIT BUTTON_POWER
130 #define CHC_STARTSTOP BUTTON_SELECT
131 #define CHC_RESET BUTTON_DOWN
132 #define CHC_MENU BUTTON_UP
133 #define CHC_SETTINGS_INC BUTTON_RIGHT
134 #define CHC_SETTINGS_DEC BUTTON_LEFT
135 #define CHC_SETTINGS_OK BUTTON_SELECT
136 #define CHC_SETTINGS_CANCEL BUTTON_POWER
138 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
139 #define CHC_QUIT BUTTON_POWER
140 #define CHC_STARTSTOP BUTTON_SELECT
141 #define CHC_RESET BUTTON_DOWN
142 #define CHC_MENU BUTTON_UP
143 #define CHC_SETTINGS_INC BUTTON_RIGHT
144 #define CHC_SETTINGS_DEC BUTTON_LEFT
145 #define CHC_SETTINGS_OK BUTTON_SELECT
146 #define CHC_SETTINGS_CANCEL (BUTTON_HOME|BUTTON_REPEAT)
148 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
149 #define CHC_QUIT BUTTON_POWER
150 #define CHC_STARTSTOP BUTTON_PLAY
151 #define CHC_RESET BUTTON_FF
152 #define CHC_MENU BUTTON_REW
153 #define CHC_SETTINGS_INC BUTTON_RIGHT
154 #define CHC_SETTINGS_DEC BUTTON_LEFT
155 #define CHC_SETTINGS_OK BUTTON_PLAY
156 #define CHC_SETTINGS_CANCEL BUTTON_POWER
158 #elif CONFIG_KEYPAD == MROBE500_PAD
159 #define CHC_QUIT BUTTON_POWER
160 #define CHC_STARTSTOP BUTTON_RC_PLAY
161 #define CHC_RESET BUTTON_RC_HEART
162 #define CHC_MENU BUTTON_RC_MODE
163 #define CHC_SETTINGS_INC BUTTON_RC_VOL_UP
164 #define CHC_SETTINGS_DEC BUTTON_RC_VOL_DOWN
165 #define CHC_SETTINGS_OK BUTTON_RC_PLAY
166 #define CHC_SETTINGS_CANCEL BUTTON_POWER
168 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
169 #define CHC_QUIT BUTTON_BACK
170 #define CHC_STARTSTOP BUTTON_PLAY
171 #define CHC_RESET BUTTON_PREV
172 #define CHC_MENU BUTTON_MENU
173 #define CHC_SETTINGS_INC BUTTON_UP
174 #define CHC_SETTINGS_DEC BUTTON_DOWN
175 #define CHC_SETTINGS_OK BUTTON_SELECT
176 #define CHC_SETTINGS_CANCEL BUTTON_BACK
178 #elif CONFIG_KEYPAD == MROBE100_PAD
179 #define CHC_QUIT BUTTON_POWER
180 #define CHC_STARTSTOP BUTTON_SELECT
181 #define CHC_RESET BUTTON_DISPLAY
182 #define CHC_MENU BUTTON_MENU
183 #define CHC_SETTINGS_INC BUTTON_UP
184 #define CHC_SETTINGS_DEC BUTTON_DOWN
185 #define CHC_SETTINGS_OK BUTTON_SELECT
186 #define CHC_SETTINGS_CANCEL BUTTON_POWER
188 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
189 #define CHC_QUIT BUTTON_RC_REC
190 #define CHC_STARTSTOP BUTTON_RC_PLAY
191 #define CHC_RESET BUTTON_RC_REW
192 #define CHC_MENU BUTTON_RC_MENU
193 #define CHC_SETTINGS_INC BUTTON_RC_VOL_UP
194 #define CHC_SETTINGS_DEC BUTTON_RC_VOL_DOWN
195 #define CHC_SETTINGS_OK BUTTON_RC_PLAY
196 #define CHC_SETTINGS_CANCEL BUTTON_RC_REC
198 #elif CONFIG_KEYPAD == COWON_D2_PAD
199 #define CHC_QUIT BUTTON_POWER
200 #define CHC_RESET (BUTTON_CENTER|BUTTON_MENU)
201 #define CHC_MENU BUTTON_MENU
202 #define CHC_SETTINGS_INC BUTTON_PLUS
203 #define CHC_SETTINGS_DEC BUTTON_MINUS
204 #define CHC_SETTINGS_CANCEL BUTTON_POWER
206 #elif CONFIG_KEYPAD == IAUDIO67_PAD
207 #define CHC_QUIT BUTTON_POWER
208 #define CHC_STARTSTOP BUTTON_PLAY
209 #define CHC_RESET BUTTON_LEFT
210 #define CHC_MENU BUTTON_MENU
211 #define CHC_SETTINGS_INC BUTTON_VOLUP
212 #define CHC_SETTINGS_DEC BUTTON_VOLDOWN
213 #define CHC_SETTINGS_OK BUTTON_PLAY
214 #define CHC_SETTINGS_OK2 BUTTON_LEFT
215 #define CHC_SETTINGS_CANCEL BUTTON_POWER
217 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
218 #define CHC_QUIT BUTTON_BACK
219 #define CHC_STARTSTOP BUTTON_PLAY
220 #define CHC_RESET BUTTON_CUSTOM
221 #define CHC_MENU BUTTON_MENU
222 #define CHC_SETTINGS_INC BUTTON_UP
223 #define CHC_SETTINGS_DEC BUTTON_DOWN
224 #define CHC_SETTINGS_OK BUTTON_SELECT
225 #define CHC_SETTINGS_CANCEL BUTTON_BACK
227 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
228 #define CHC_QUIT BUTTON_POWER
229 #define CHC_STARTSTOP BUTTON_SELECT
230 #define CHC_RESET BUTTON_VIEW
231 #define CHC_MENU BUTTON_MENU
232 #define CHC_SETTINGS_INC BUTTON_RIGHT
233 #define CHC_SETTINGS_DEC BUTTON_LEFT
234 #define CHC_SETTINGS_OK BUTTON_SELECT
235 #define CHC_SETTINGS_CANCEL BUTTON_POWER
237 #elif CONFIG_KEYPAD == PHILIPS_SA9200_PAD
238 #define CHC_QUIT BUTTON_POWER
239 #define CHC_STARTSTOP BUTTON_PLAY
240 #define CHC_RESET BUTTON_RIGHT
241 #define CHC_MENU BUTTON_MENU
242 #define CHC_SETTINGS_INC BUTTON_NEXT
243 #define CHC_SETTINGS_DEC BUTTON_PREV
244 #define CHC_SETTINGS_OK BUTTON_PLAY
245 #define CHC_SETTINGS_CANCEL BUTTON_POWER
247 #elif CONFIG_KEYPAD == ONDAVX747_PAD
248 #define CHC_QUIT BUTTON_POWER
249 #define CHC_RESET (BUTTON_VOL_UP|BUTTON_VOL_DOWN)
250 #define CHC_MENU BUTTON_MENU
251 #define CHC_SETTINGS_INC BUTTON_VOL_UP
252 #define CHC_SETTINGS_DEC BUTTON_VOL_DOWN
253 #define CHC_SETTINGS_CANCEL BUTTON_POWER
255 #elif CONFIG_KEYPAD == ONDAVX777_PAD
256 #define CHC_QUIT BUTTON_POWER
257 #define CHC_SETTINGS_CANCEL BUTTON_POWER
259 #elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
260 #define CHC_QUIT BUTTON_REC
261 #define CHC_STARTSTOP BUTTON_PLAY
262 #define CHC_RESET BUTTON_FFWD
263 #define CHC_MENU BUTTON_LEFT
264 #define CHC_SETTINGS_INC BUTTON_UP
265 #define CHC_SETTINGS_DEC BUTTON_DOWN
266 #define CHC_SETTINGS_OK BUTTON_PLAY
267 #define CHC_SETTINGS_CANCEL BUTTON_REW
269 #elif CONFIG_KEYPAD == PBELL_VIBE500_PAD
270 #define CHC_QUIT BUTTON_REC
271 #define CHC_STARTSTOP BUTTON_PLAY
272 #define CHC_RESET BUTTON_PREV
273 #define CHC_MENU BUTTON_MENU
274 #define CHC_SETTINGS_INC BUTTON_UP
275 #define CHC_SETTINGS_DEC BUTTON_DOWN
276 #define CHC_SETTINGS_OK BUTTON_OK
277 #define CHC_SETTINGS_CANCEL BUTTON_CANCEL
279 #else
280 #error No keymap defined!
281 #endif
283 #ifdef HAVE_TOUCHSCREEN
284 #ifndef CHC_SETTINGS_OK
285 #define CHC_SETTINGS_OK BUTTON_CENTER
286 #endif
287 #ifndef CHC_STARTSTOP
288 #define CHC_STARTSTOP BUTTON_CENTER
289 #endif
290 #ifndef CHC_SETTINGS_INC
291 #define CHC_SETTINGS_INC BUTTON_TOPMIDDLE
292 #endif
293 #ifndef CHC_SETTINGS_DEC
294 #define CHC_SETTINGS_DEC BUTTON_BOTTOMMIDDLE
295 #endif
296 #ifndef CHC_RESET
297 #define CHC_RESET BUTTON_TOPLEFT
298 #endif
299 #ifndef CHC_MENU
300 #define CHC_MENU BUTTON_TOPRIGHT
301 #endif
302 #endif
305 /* leave first line blank on bitmap display, for pause icon */
306 #ifdef HAVE_LCD_BITMAP
307 #define FIRST_LINE 1
308 #else
309 #define FIRST_LINE 0
310 #endif
312 #define MAX_PLAYERS 10
314 enum {
315 CHCL_OK,
316 CHCL_CANCEL,
317 CHCL_USB,
318 CHCL_NEXT,
319 CHCL_PREV,
322 static struct {
323 int nr_timers;
324 int total_time;
325 int round_time;
326 } settings;
328 static struct {
329 int total_time;
330 int used_time;
331 bool hidden;
332 } timer_holder[MAX_PLAYERS];
334 static int run_timer(int nr);
335 static int chessclock_set_int(char* string,
336 int* variable,
337 int step,
338 int min,
339 int max,
340 int flags);
341 #define FLAGS_SET_INT_SECONDS 1
343 static char * show_time(int secs);
345 static bool pause;
347 #define MAX_TIME 7200
349 /* this is the plugin entry point */
350 enum plugin_status plugin_start(const void* parameter)
352 int i;
353 bool done;
354 int nr;
356 (void)parameter;
358 settings.nr_timers = 1;
359 settings.total_time = 10;
360 settings.round_time = 10;
362 /* now go ahead and have fun! */
363 rb->splash(HZ, "Chess Clock");
365 rb->lcd_clear_display();
366 i=0;
367 while (1) {
368 int res;
369 switch (i) {
370 case 0:
371 res=chessclock_set_int("Number of players",
372 &settings.nr_timers, 1, 1,
373 MAX_PLAYERS, 0);
374 break;
375 case 1:
376 res=chessclock_set_int("Total time",
377 &settings.total_time, 10, 10, MAX_TIME,
378 FLAGS_SET_INT_SECONDS);
379 settings.round_time=settings.total_time;
380 break;
381 case 2:
382 res=chessclock_set_int("Max round time", &settings.round_time,
383 10, 10, settings.round_time,
384 FLAGS_SET_INT_SECONDS);
385 break;
386 default:
387 res=-2; /* done */
388 break;
390 if (res==CHCL_USB) {
391 return PLUGIN_USB_CONNECTED;
392 } else if (res==CHCL_CANCEL) {
393 i--;
394 if (i<0) {
395 return PLUGIN_OK;
397 } else if (res==CHCL_OK) {
398 i++;
399 } else if (res==-2) { /* done */
400 break;
403 for (i=0; i<settings.nr_timers; i++) {
404 timer_holder[i].total_time=settings.total_time;
405 timer_holder[i].used_time=0;
406 timer_holder[i].hidden=false;
409 pause=true; /* We start paused */
411 nr=0;
412 do {
413 int ret=0;
414 done=true;
415 i = nr;
416 do {
417 if (!timer_holder[i].hidden)
419 nr = i;
420 done = false;
421 break;
423 if (++i == settings.nr_timers)
424 i = 0;
425 } while (i != nr);
427 if (done) {
428 return PLUGIN_OK;
431 ret = run_timer(nr);
432 switch (ret) {
433 case CHCL_CANCEL: /* exit */
434 done=true;
435 break;
436 case CHCL_USB:
437 return PLUGIN_USB_CONNECTED;
438 case CHCL_NEXT:
439 nr++;
440 if (nr>=settings.nr_timers)
441 nr=0;
442 break;
443 case CHCL_PREV:
444 do {
445 nr--;
446 if (nr<0)
447 nr=settings.nr_timers-1;
448 } while (timer_holder[nr].hidden);
449 break;
451 } while (!done);
452 return PLUGIN_OK;
455 #ifdef HAVE_LCD_BITMAP
456 static void show_pause_mode(bool enabled)
458 static const char pause_icon[] = {0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00};
460 if (enabled)
461 rb->lcd_mono_bitmap((unsigned char *)pause_icon, 52, 0, 7, 8);
462 else
464 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
465 rb->lcd_fillrect(52, 0, 7, 8);
466 rb->lcd_set_drawmode(DRMODE_SOLID);
469 #else
470 #define show_pause_mode(enabled) rb->lcd_icon(ICON_PAUSE, enabled)
471 #endif
473 static int run_timer(int nr)
475 char buf[40];
476 char player_info[13];
477 long last_tick;
478 bool done=false;
479 int retval=CHCL_OK;
480 long max_ticks=timer_holder[nr].total_time*HZ-timer_holder[nr].used_time;
481 long ticks=0;
482 bool round_time=false;
484 show_pause_mode(pause);
486 if (settings.round_time*HZ<max_ticks) {
487 max_ticks=settings.round_time*HZ;
488 round_time=true;
490 rb->snprintf(player_info, sizeof(player_info), "Player %d", nr+1);
491 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
492 last_tick=*rb->current_tick;
494 while (!done) {
495 int button;
496 long now;
497 if (ticks>=max_ticks) {
498 if (round_time)
499 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"ROUND UP!");
500 else
501 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"TIME OUT!");
502 rb->backlight_on();
503 ticks = max_ticks;
504 } else {
505 now=*rb->current_tick;
506 if (!pause) {
507 ticks+=now-last_tick;
508 if ((max_ticks-ticks)/HZ == 10) {
509 /* Backlight on if 10 seconds remain */
510 rb->backlight_on();
513 last_tick=now;
514 if (round_time) {
515 rb->snprintf(buf, sizeof(buf), "%s/",
516 show_time((max_ticks-ticks+HZ-1)/HZ));
517 /* Append total time */
518 rb->strcpy(&buf[rb->strlen(buf)],
519 show_time((timer_holder[nr].total_time*HZ-
520 timer_holder[nr].used_time-
521 ticks+HZ-1)/HZ));
522 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)buf);
523 } else {
524 rb->lcd_puts(0, FIRST_LINE+1,
525 (unsigned char *)show_time((max_ticks-ticks+HZ-1)/HZ));
528 rb->lcd_update();
530 button = rb->button_get(false);
531 switch (button) {
532 /* OFF/ON key to exit */
533 case CHC_QUIT:
534 return CHCL_CANCEL; /* Indicate exit */
536 /* PLAY = Stop/Start toggle */
537 case CHC_STARTSTOP:
538 pause=!pause;
539 show_pause_mode(pause);
540 break;
542 /* LEFT = Reset timer */
543 case CHC_RESET:
544 ticks=0;
545 break;
547 /* MENU */
548 case CHC_MENU:
550 MENUITEM_STRINGLIST(menu, "Menu", NULL,
551 "Delete player", "Restart round",
552 "Set round time", "Set total time",
553 "Playback Control");
555 int val, res;
556 switch(rb->do_menu(&menu, NULL, NULL, false))
558 case 0:
559 /* delete player */
560 timer_holder[nr].hidden=true;
561 retval = CHCL_NEXT;
562 done=true;
563 break;
564 case 1:
565 /* restart */
566 ticks=0;
567 last_tick=*rb->current_tick;
568 break;
569 case 2:
570 /* set round time */
571 val=(max_ticks-ticks)/HZ;
572 res=chessclock_set_int("Round time",
573 &val, 10, 0, MAX_TIME,
574 FLAGS_SET_INT_SECONDS);
575 if (res==CHCL_USB) {
576 retval = CHCL_USB;
577 done=true;
578 } else if (res==CHCL_OK) {
579 ticks=max_ticks-val*HZ;
580 last_tick=*rb->current_tick;
582 break;
583 case 3:
584 /* set total time */
585 val=timer_holder[nr].total_time;
586 res=chessclock_set_int("Total time",
587 &val,
588 10, 0, MAX_TIME,
589 FLAGS_SET_INT_SECONDS);
590 if (res==CHCL_USB) {
591 retval = CHCL_USB;
592 done=true;
593 } else if (res==CHCL_OK) {
594 timer_holder[nr].total_time=val;
596 break;
597 case 4:
598 playback_control(NULL);
599 break;
600 case MENU_ATTACHED_USB:
601 retval = CHCL_USB;
602 done=true;
603 break;
605 rb->lcd_clear_display();
606 show_pause_mode(pause);
607 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
609 break;
611 /* UP (RIGHT/+) = Scroll Lap timer up */
612 case CHC_SETTINGS_INC:
613 retval = CHCL_NEXT;
614 done = true;
615 break;
617 /* DOWN (LEFT/-) = Scroll Lap timer down */
618 case CHC_SETTINGS_DEC:
619 retval = CHCL_PREV;
620 done = true;
621 break;
623 default:
624 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
625 retval = CHCL_USB;
626 done = true;
628 break;
630 rb->sleep(HZ/4); /* Sleep 1/4 of a second */
633 timer_holder[nr].used_time+=ticks;
635 return retval;
638 static int chessclock_set_int(char* string,
639 int* variable,
640 int step,
641 int min,
642 int max,
643 int flags)
645 bool done = false;
646 int button;
648 rb->lcd_clear_display();
649 rb->lcd_puts_scroll(0, FIRST_LINE, (unsigned char *)string);
651 while (!done) {
652 char str[32];
653 if (flags & FLAGS_SET_INT_SECONDS)
654 rb->snprintf(str, sizeof str,"%s (m:s)", show_time(*variable));
655 else
656 rb->snprintf(str, sizeof str,"%d", *variable);
657 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)str);
658 rb->lcd_update();
660 button = rb->button_get(true);
661 switch(button) {
662 case CHC_SETTINGS_INC:
663 case CHC_SETTINGS_INC | BUTTON_REPEAT:
664 *variable += step;
665 break;
667 case CHC_SETTINGS_DEC:
668 case CHC_SETTINGS_DEC | BUTTON_REPEAT:
669 *variable -= step;
670 break;
672 case CHC_SETTINGS_OK:
673 #ifdef CHC_SETTINGS_OK2
674 case CHC_SETTINGS_OK2:
675 #endif
676 done = true;
677 break;
679 case CHC_SETTINGS_CANCEL:
680 #ifdef CHC_SETTINGS_CANCEL2
681 case CHC_SETTINGS_CANCEL2:
682 #endif
683 return CHCL_CANCEL;
684 break;
686 default:
687 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
688 return CHCL_USB;
689 break;
692 if(*variable > max )
693 *variable = max;
695 if(*variable < min )
696 *variable = min;
699 rb->lcd_stop_scroll();
701 return CHCL_OK;
704 static char * show_time(int seconds)
706 static char buf[]="00:00";
707 rb->snprintf(buf, sizeof(buf), "%02d:%02d", seconds/60, seconds%60);
708 return buf;