More work on PDBox by Wincent Balin. The PDBox plug-in is now working with the pdpod_...
[kugel-rb.git] / apps / plugins / chessclock.c
blob514cac174e18d54cefd1971431e9e41be74b311a
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"
23 PLUGIN_HEADER
25 /* variable button definitions */
26 #if CONFIG_KEYPAD == RECORDER_PAD
27 #define CHC_QUIT BUTTON_OFF
28 #define CHC_STARTSTOP BUTTON_PLAY
29 #define CHC_RESET BUTTON_LEFT
30 #define CHC_MENU BUTTON_F1
31 #define CHC_SETTINGS_INC BUTTON_UP
32 #define CHC_SETTINGS_DEC BUTTON_DOWN
33 #define CHC_SETTINGS_OK BUTTON_PLAY
34 #define CHC_SETTINGS_OK2 BUTTON_LEFT
35 #define CHC_SETTINGS_CANCEL BUTTON_OFF
37 #elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
38 #define CHC_QUIT BUTTON_OFF
39 #define CHC_STARTSTOP BUTTON_SELECT
40 #define CHC_RESET BUTTON_LEFT
41 #define CHC_MENU BUTTON_F1
42 #define CHC_SETTINGS_INC BUTTON_UP
43 #define CHC_SETTINGS_DEC BUTTON_DOWN
44 #define CHC_SETTINGS_OK BUTTON_SELECT
45 #define CHC_SETTINGS_OK2 BUTTON_LEFT
46 #define CHC_SETTINGS_CANCEL BUTTON_OFF
48 #elif CONFIG_KEYPAD == ONDIO_PAD
49 #define CHC_QUIT BUTTON_OFF
50 #define CHC_STARTSTOP BUTTON_RIGHT
51 #define CHC_RESET BUTTON_LEFT
52 #define CHC_MENU BUTTON_MENU
53 #define CHC_SETTINGS_INC BUTTON_UP
54 #define CHC_SETTINGS_DEC BUTTON_DOWN
55 #define CHC_SETTINGS_OK BUTTON_RIGHT
56 #define CHC_SETTINGS_OK2 BUTTON_LEFT
57 #define CHC_SETTINGS_CANCEL BUTTON_MENU
59 #elif CONFIG_KEYPAD == PLAYER_PAD
60 #define CHC_QUIT BUTTON_ON
61 #define CHC_STARTSTOP BUTTON_PLAY
62 #define CHC_RESET BUTTON_STOP
63 #define CHC_MENU BUTTON_MENU
64 #define CHC_SETTINGS_INC BUTTON_RIGHT
65 #define CHC_SETTINGS_DEC BUTTON_LEFT
66 #define CHC_SETTINGS_OK BUTTON_PLAY
67 #define CHC_SETTINGS_CANCEL BUTTON_STOP
68 #define CHC_SETTINGS_CANCEL2 BUTTON_MENU
70 #elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
71 (CONFIG_KEYPAD == IRIVER_H300_PAD)
72 #define CHC_QUIT BUTTON_SELECT
73 #define CHC_STARTSTOP BUTTON_ON
74 #define CHC_RESET BUTTON_OFF
75 #define CHC_MENU BUTTON_REC
76 #define CHC_SETTINGS_INC BUTTON_RIGHT
77 #define CHC_SETTINGS_DEC BUTTON_LEFT
78 #define CHC_SETTINGS_OK BUTTON_ON
79 #define CHC_SETTINGS_CANCEL BUTTON_OFF
80 #define CHC_SETTINGS_CANCEL2 BUTTON_REC
82 #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
83 (CONFIG_KEYPAD == IPOD_3G_PAD) || \
84 (CONFIG_KEYPAD == IPOD_1G2G_PAD)
85 #define CHC_QUIT BUTTON_PLAY
86 #define CHC_STARTSTOP BUTTON_SELECT
87 #define CHC_RESET BUTTON_LEFT
88 #define CHC_MENU BUTTON_MENU
89 #define CHC_SETTINGS_INC BUTTON_SCROLL_FWD
90 #define CHC_SETTINGS_DEC BUTTON_SCROLL_BACK
91 #define CHC_SETTINGS_OK BUTTON_SELECT
92 #define CHC_SETTINGS_CANCEL BUTTON_MENU
94 #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
95 #define CHC_QUIT BUTTON_PLAY
96 #define CHC_STARTSTOP BUTTON_MODE
97 #define CHC_RESET BUTTON_EQ
98 #define CHC_MENU BUTTON_SELECT
99 #define CHC_SETTINGS_INC BUTTON_RIGHT
100 #define CHC_SETTINGS_DEC BUTTON_LEFT
101 #define CHC_SETTINGS_OK BUTTON_SELECT
102 #define CHC_SETTINGS_CANCEL BUTTON_PLAY
104 #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
105 #define CHC_QUIT BUTTON_REC
106 #define CHC_STARTSTOP BUTTON_PLAY
107 #define CHC_RESET BUTTON_POWER
108 #define CHC_MENU BUTTON_SELECT
109 #define CHC_SETTINGS_INC BUTTON_RIGHT
110 #define CHC_SETTINGS_DEC BUTTON_LEFT
111 #define CHC_SETTINGS_OK BUTTON_SELECT
112 #define CHC_SETTINGS_CANCEL BUTTON_REC
114 #elif CONFIG_KEYPAD == GIGABEAT_PAD
115 #define CHC_QUIT BUTTON_POWER
116 #define CHC_STARTSTOP BUTTON_SELECT
117 #define CHC_RESET BUTTON_A
118 #define CHC_MENU BUTTON_MENU
119 #define CHC_SETTINGS_INC BUTTON_UP
120 #define CHC_SETTINGS_DEC BUTTON_DOWN
121 #define CHC_SETTINGS_OK BUTTON_SELECT
122 #define CHC_SETTINGS_CANCEL BUTTON_POWER
124 #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
125 (CONFIG_KEYPAD == SANSA_C200_PAD) || \
126 (CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
127 (CONFIG_KEYPAD == SANSA_M200_PAD)
128 #define CHC_QUIT BUTTON_POWER
129 #define CHC_STARTSTOP BUTTON_SELECT
130 #define CHC_RESET BUTTON_DOWN
131 #define CHC_MENU BUTTON_UP
132 #define CHC_SETTINGS_INC BUTTON_RIGHT
133 #define CHC_SETTINGS_DEC BUTTON_LEFT
134 #define CHC_SETTINGS_OK BUTTON_SELECT
135 #define CHC_SETTINGS_CANCEL BUTTON_POWER
137 #elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
138 #define CHC_QUIT BUTTON_POWER
139 #define CHC_STARTSTOP BUTTON_SELECT
140 #define CHC_RESET BUTTON_DOWN
141 #define CHC_MENU BUTTON_UP
142 #define CHC_SETTINGS_INC BUTTON_RIGHT
143 #define CHC_SETTINGS_DEC BUTTON_LEFT
144 #define CHC_SETTINGS_OK BUTTON_SELECT
145 #define CHC_SETTINGS_CANCEL (BUTTON_HOME|BUTTON_REPEAT)
147 #elif CONFIG_KEYPAD == IRIVER_H10_PAD
148 #define CHC_QUIT BUTTON_POWER
149 #define CHC_STARTSTOP BUTTON_PLAY
150 #define CHC_RESET BUTTON_FF
151 #define CHC_MENU BUTTON_REW
152 #define CHC_SETTINGS_INC BUTTON_RIGHT
153 #define CHC_SETTINGS_DEC BUTTON_LEFT
154 #define CHC_SETTINGS_OK BUTTON_PLAY
155 #define CHC_SETTINGS_CANCEL BUTTON_POWER
157 #elif CONFIG_KEYPAD == MROBE500_PAD
158 #define CHC_QUIT BUTTON_POWER
159 #define CHC_STARTSTOP BUTTON_RC_PLAY
160 #define CHC_RESET BUTTON_RC_HEART
161 #define CHC_MENU BUTTON_RC_MODE
162 #define CHC_SETTINGS_INC BUTTON_RC_VOL_UP
163 #define CHC_SETTINGS_DEC BUTTON_RC_VOL_DOWN
164 #define CHC_SETTINGS_OK BUTTON_RC_PLAY
165 #define CHC_SETTINGS_CANCEL BUTTON_POWER
167 #elif CONFIG_KEYPAD == GIGABEAT_S_PAD
168 #define CHC_QUIT BUTTON_BACK
169 #define CHC_STARTSTOP BUTTON_PLAY
170 #define CHC_RESET BUTTON_PREV
171 #define CHC_MENU BUTTON_MENU
172 #define CHC_SETTINGS_INC BUTTON_UP
173 #define CHC_SETTINGS_DEC BUTTON_DOWN
174 #define CHC_SETTINGS_OK BUTTON_SELECT
175 #define CHC_SETTINGS_CANCEL BUTTON_BACK
177 #elif CONFIG_KEYPAD == MROBE100_PAD
178 #define CHC_QUIT BUTTON_POWER
179 #define CHC_STARTSTOP BUTTON_SELECT
180 #define CHC_RESET BUTTON_DISPLAY
181 #define CHC_MENU BUTTON_MENU
182 #define CHC_SETTINGS_INC BUTTON_UP
183 #define CHC_SETTINGS_DEC BUTTON_DOWN
184 #define CHC_SETTINGS_OK BUTTON_SELECT
185 #define CHC_SETTINGS_CANCEL BUTTON_POWER
187 #elif CONFIG_KEYPAD == IAUDIO_M3_PAD
188 #define CHC_QUIT BUTTON_RC_REC
189 #define CHC_STARTSTOP BUTTON_RC_PLAY
190 #define CHC_RESET BUTTON_RC_REW
191 #define CHC_MENU BUTTON_RC_MENU
192 #define CHC_SETTINGS_INC BUTTON_RC_VOL_UP
193 #define CHC_SETTINGS_DEC BUTTON_RC_VOL_DOWN
194 #define CHC_SETTINGS_OK BUTTON_RC_PLAY
195 #define CHC_SETTINGS_CANCEL BUTTON_RC_REC
197 #elif CONFIG_KEYPAD == COWOND2_PAD
198 #define CHC_QUIT BUTTON_POWER
199 #define CHC_RESET (BUTTON_CENTER|BUTTON_MENU)
200 #define CHC_MENU BUTTON_MENU
201 #define CHC_SETTINGS_INC BUTTON_PLUS
202 #define CHC_SETTINGS_DEC BUTTON_MINUS
203 #define CHC_SETTINGS_CANCEL BUTTON_POWER
205 #elif CONFIG_KEYPAD == IAUDIO67_PAD
206 #define CHC_QUIT BUTTON_POWER
207 #define CHC_STARTSTOP BUTTON_PLAY
208 #define CHC_RESET BUTTON_LEFT
209 #define CHC_MENU BUTTON_MENU
210 #define CHC_SETTINGS_INC BUTTON_VOLUP
211 #define CHC_SETTINGS_DEC BUTTON_VOLDOWN
212 #define CHC_SETTINGS_OK BUTTON_PLAY
213 #define CHC_SETTINGS_OK2 BUTTON_LEFT
214 #define CHC_SETTINGS_CANCEL BUTTON_POWER
216 #elif CONFIG_KEYPAD == CREATIVEZVM_PAD
217 #define CHC_QUIT BUTTON_BACK
218 #define CHC_STARTSTOP BUTTON_PLAY
219 #define CHC_RESET BUTTON_CUSTOM
220 #define CHC_MENU BUTTON_MENU
221 #define CHC_SETTINGS_INC BUTTON_UP
222 #define CHC_SETTINGS_DEC BUTTON_DOWN
223 #define CHC_SETTINGS_OK BUTTON_SELECT
224 #define CHC_SETTINGS_CANCEL BUTTON_BACK
226 #elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
227 #define CHC_QUIT BUTTON_POWER
228 #define CHC_STARTSTOP BUTTON_SELECT
229 #define CHC_RESET BUTTON_VIEW
230 #define CHC_MENU BUTTON_MENU
231 #define CHC_SETTINGS_INC BUTTON_RIGHT
232 #define CHC_SETTINGS_DEC BUTTON_LEFT
233 #define CHC_SETTINGS_OK BUTTON_SELECT
234 #define CHC_SETTINGS_CANCEL BUTTON_POWER
236 #elif CONFIG_KEYPAD == ONDAVX747_PAD
237 #define CHC_QUIT BUTTON_POWER
238 #define CHC_RESET (BUTTON_VOL_UP|BUTTON_VOL_DOWN)
239 #define CHC_MENU BUTTON_MENU
240 #define CHC_SETTINGS_INC BUTTON_VOL_UP
241 #define CHC_SETTINGS_DEC BUTTON_VOL_DOWN
242 #define CHC_SETTINGS_CANCEL BUTTON_POWER
244 #else
245 #error No keymap defined!
246 #endif
248 #ifdef HAVE_TOUCHSCREEN
249 #ifndef CHC_SETTINGS_OK
250 #define CHC_SETTINGS_OK BUTTON_CENTER
251 #endif
252 #ifndef CHC_STARTSTOP
253 #define CHC_STARTSTOP BUTTON_CENTER
254 #endif
255 #ifndef CHC_SETTINGS_INC
256 #define CHC_SETTINGS_INC BUTTON_TOPMIDDLE
257 #endif
258 #ifndef CHC_SETTINGS_DEC
259 #define CHC_SETTINGS_DEC BUTTON_BOTTOMMIDDLE
260 #endif
261 #ifndef CHC_RESET
262 #define CHC_RESET BUTTON_TOPLEFT
263 #endif
264 #ifndef CHC_MENU
265 #define CHC_MENU BUTTON_TOPRIGHT
266 #endif
267 #endif
270 /* leave first line blank on bitmap display, for pause icon */
271 #ifdef HAVE_LCD_BITMAP
272 #define FIRST_LINE 1
273 #else
274 #define FIRST_LINE 0
275 #endif
277 #define MAX_PLAYERS 10
279 static struct {
280 int nr_timers;
281 int total_time;
282 int round_time;
283 } settings;
285 static struct {
286 int total_time;
287 int used_time;
288 bool hidden;
289 } timer_holder[MAX_PLAYERS];
291 static int run_timer(int nr);
292 static int chessclock_set_int(char* string,
293 int* variable,
294 int step,
295 int min,
296 int max,
297 int flags);
298 #define FLAGS_SET_INT_SECONDS 1
300 static char * show_time(int secs);
302 static bool pause;
304 #define MAX_TIME 7200
306 /* this is the plugin entry point */
307 enum plugin_status plugin_start(const void* parameter)
309 int i;
310 bool done;
311 int nr;
313 (void)parameter;
314 rb->memset(&settings, 0, sizeof(settings));
316 /* now go ahead and have fun! */
317 rb->splash(HZ, "Chess Clock");
319 rb->lcd_clear_display();
320 i=0;
321 while (i>=0) {
322 int res;
323 switch (i) {
324 case 0:
325 res=chessclock_set_int("Number of players",
326 &settings.nr_timers, 1, 1,
327 MAX_PLAYERS, 0);
328 break;
329 case 1:
330 res=chessclock_set_int("Total time",
331 &settings.total_time, 10, 0, MAX_TIME,
332 FLAGS_SET_INT_SECONDS);
333 settings.round_time=settings.total_time;
334 break;
335 case 2:
336 res=chessclock_set_int("Max round time", &settings.round_time,
337 10, 0, settings.round_time,
338 FLAGS_SET_INT_SECONDS);
339 break;
340 default:
341 i=-1; /* done */
342 res=-2;
343 break;
345 if (res==-1) {
346 return PLUGIN_USB_CONNECTED;
348 if (res==0) {
349 i--;
350 if (i<0) {
351 return PLUGIN_OK;
354 if (res>0) {
355 i++;
358 for (i=0; i<settings.nr_timers; i++) {
359 timer_holder[i].total_time=settings.total_time;
360 timer_holder[i].used_time=0;
361 timer_holder[i].hidden=false;
364 pause=true; /* We start paused */
366 nr=0;
367 do {
368 int ret=0;
369 done=true;
370 i = nr;
371 do {
372 if (!timer_holder[i].hidden)
374 nr = i;
375 done = false;
376 break;
378 if (++i == settings.nr_timers)
379 i = 0;
380 } while (i != nr);
382 if (done) {
383 return PLUGIN_OK;
385 ret = run_timer(nr);
386 switch (ret) {
387 case -1: /* exit */
388 done=true;
389 break;
390 case 3:
391 return PLUGIN_USB_CONNECTED;
392 case 1:
393 nr++;
394 if (nr>=settings.nr_timers)
395 nr=0;
396 break;
397 case 2:
398 do {
399 nr--;
400 if (nr<0)
401 nr=settings.nr_timers-1;
402 } while (timer_holder[nr].hidden);
403 break;
405 } while (!done);
406 return PLUGIN_OK;
409 #ifdef HAVE_LCD_BITMAP
410 static void show_pause_mode(bool enabled)
412 static const char pause_icon[] = {0x00,0x7f,0x7f,0x00,0x7f,0x7f,0x00};
414 if (enabled)
415 rb->lcd_mono_bitmap((unsigned char *)pause_icon, 52, 0, 7, 8);
416 else
418 rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
419 rb->lcd_fillrect(52, 0, 7, 8);
420 rb->lcd_set_drawmode(DRMODE_SOLID);
423 #endif
426 -1= exit
427 1 = next player
428 2 = prev player
429 3 = usb connected
431 static int run_timer(int nr)
433 char buf[40];
434 char player_info[13];
435 long last_tick;
436 bool done=false;
437 int retval=0;
438 long max_ticks=timer_holder[nr].total_time*HZ-timer_holder[nr].used_time;
439 long ticks=0;
440 bool round_time=false;
442 #ifdef HAVE_LCD_CHARCELLS
443 rb->lcd_icon(ICON_PAUSE, pause);
444 #else
445 show_pause_mode(pause);
446 #endif
448 if (settings.round_time*HZ<max_ticks) {
449 max_ticks=settings.round_time*HZ;
450 round_time=true;
452 rb->snprintf(player_info, sizeof(player_info), "Player %d", nr+1);
453 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
454 last_tick=*rb->current_tick;
456 while (!done) {
457 int button;
458 long now;
459 if (ticks>max_ticks) {
460 if (round_time)
461 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"ROUND UP!");
462 else
463 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"TIME OUT!");
464 rb->backlight_on();
465 } else {
467 if (((int)(rb->current_tick - start_ticks)/HZ)&1) {
468 rb->lcd_puts(0, FIRST_LINE, player_info);
469 } else {
470 rb->lcd_puts(0, FIRST_LINE, player_info);
473 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
474 now=*rb->current_tick;
475 if (!pause) {
476 ticks+=now-last_tick;
477 if ((max_ticks-ticks)/HZ == 10) {
478 /* Backlight on if 10 seconds remain */
479 rb->backlight_on();
482 last_tick=now;
483 if (round_time) {
484 rb->snprintf(buf, sizeof(buf), "%s/",
485 show_time((max_ticks-ticks+HZ-1)/HZ));
486 /* Append total time */
487 rb->strcpy(&buf[rb->strlen(buf)],
488 show_time((timer_holder[nr].total_time*HZ-
489 timer_holder[nr].used_time-
490 ticks+HZ-1)/HZ));
491 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)buf);
492 } else {
493 rb->lcd_puts(0, FIRST_LINE+1,
494 (unsigned char *)show_time((max_ticks-ticks+HZ-1)/HZ));
497 rb->lcd_update();
499 button = rb->button_get(false);
500 switch (button) {
501 /* OFF/ON key to exit */
502 case CHC_QUIT:
503 return -1; /* Indicate exit */
505 /* PLAY = Stop/Start toggle */
506 case CHC_STARTSTOP:
507 pause=!pause;
508 #ifdef HAVE_LCD_CHARCELLS
509 rb->lcd_icon(ICON_PAUSE, pause);
510 #else
511 show_pause_mode(pause);
512 #endif
513 break;
515 /* LEFT = Reset timer */
516 case CHC_RESET:
517 ticks=0;
518 break;
520 /* MENU */
521 case CHC_MENU:
523 MENUITEM_STRINGLIST(menu, "Menu", NULL,
524 "Delete player", "Restart round",
525 "Set round time", "Set total time");
527 int val, res;
528 switch(rb->do_menu(&menu, NULL, NULL, false))
530 case 0:
531 /* delete player */
532 timer_holder[nr].hidden=true;
533 retval=1;
534 done=true;
535 break;
536 case 1:
537 /* restart */
538 ticks=0;
539 break;
540 case 2:
541 /* set round time */
542 val=(max_ticks-ticks)/HZ;
543 res=chessclock_set_int("Round time",
544 &val,
545 10, 0, MAX_TIME,
546 FLAGS_SET_INT_SECONDS);
547 if (res==-1) { /*usb*/
548 retval = 3;
549 done=true;
550 } else if (res==1) {
551 ticks=max_ticks-val*HZ;
553 break;
554 case 3:
555 /* set total time */
556 val=timer_holder[nr].total_time;
557 res=chessclock_set_int("Total time",
558 &val,
559 10, 0, MAX_TIME,
560 FLAGS_SET_INT_SECONDS);
561 if (res==-1) { /*usb*/
562 retval = 3;
563 done=true;
564 } else if (res==1) {
565 timer_holder[nr].total_time=val;
567 break;
568 case MENU_ATTACHED_USB:
569 retval = 3;
570 done=true;
571 break;
573 rb->lcd_clear_display();
575 break;
577 /* UP (RIGHT/+) = Scroll Lap timer up */
578 case CHC_SETTINGS_INC:
579 retval = 1;
580 done = true;
581 break;
583 /* DOWN (LEFT/-) = Scroll Lap timer down */
584 case CHC_SETTINGS_DEC:
585 retval = 2;
586 done = true;
587 break;
589 default:
590 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
591 retval = 3; /* been in usb mode */
592 done = true;
594 break;
596 rb->sleep(HZ/4); /* Sleep 1/4 of a second */
599 timer_holder[nr].used_time+=ticks;
601 return retval;
604 static int chessclock_set_int(char* string,
605 int* variable,
606 int step,
607 int min,
608 int max,
609 int flags)
611 bool done = false;
612 int button;
614 rb->lcd_clear_display();
615 rb->lcd_puts_scroll(0, FIRST_LINE, (unsigned char *)string);
617 while (!done) {
618 char str[32];
619 if (flags & FLAGS_SET_INT_SECONDS)
620 rb->snprintf(str, sizeof str,"%s (m:s)", show_time(*variable));
621 else
622 rb->snprintf(str, sizeof str,"%d", *variable);
623 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)str);
624 rb->lcd_update();
626 button = rb->button_get(true);
627 switch(button) {
628 case CHC_SETTINGS_INC:
629 case CHC_SETTINGS_INC | BUTTON_REPEAT:
630 *variable += step;
631 break;
633 case CHC_SETTINGS_DEC:
634 case CHC_SETTINGS_DEC | BUTTON_REPEAT:
635 *variable -= step;
636 break;
638 case CHC_SETTINGS_OK:
639 #ifdef CHC_SETTINGS_OK2
640 case CHC_SETTINGS_OK2:
641 #endif
642 done = true;
643 break;
645 case CHC_SETTINGS_CANCEL:
646 #ifdef CHC_SETTINGS_CANCEL2
647 case CHC_SETTINGS_CANCEL2:
648 #endif
649 return 0; /* cancel */
650 break;
652 default:
653 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
654 return -1; /* been in usb mode */
655 break;
658 if(*variable > max )
659 *variable = max;
661 if(*variable < min )
662 *variable = min;
665 rb->lcd_stop_scroll();
667 return 1;
670 static char * show_time(int seconds)
672 static char buf[]="00:00";
673 rb->snprintf(buf, sizeof(buf), "%02d:%02d", seconds/60, seconds%60);
674 return buf;