summaryrefslogtreecommitdiff
path: root/apps/plugins
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins')
-rw-r--r--apps/plugins/chessclock.c106
1 files changed, 51 insertions, 55 deletions
diff --git a/apps/plugins/chessclock.c b/apps/plugins/chessclock.c
index 514cac174e..8954e9ab13 100644
--- a/apps/plugins/chessclock.c
+++ b/apps/plugins/chessclock.c
@@ -276,6 +276,14 @@ PLUGIN_HEADER
276 276
277#define MAX_PLAYERS 10 277#define MAX_PLAYERS 10
278 278
279enum {
280 CHCL_OK,
281 CHCL_CANCEL,
282 CHCL_USB,
283 CHCL_NEXT,
284 CHCL_PREV,
285};
286
279static struct { 287static struct {
280 int nr_timers; 288 int nr_timers;
281 int total_time; 289 int total_time;
@@ -311,14 +319,17 @@ enum plugin_status plugin_start(const void* parameter)
311 int nr; 319 int nr;
312 320
313 (void)parameter; 321 (void)parameter;
314 rb->memset(&settings, 0, sizeof(settings)); 322
323 settings.nr_timers = 1;
324 settings.total_time = 10;
325 settings.round_time = 10;
315 326
316 /* now go ahead and have fun! */ 327 /* now go ahead and have fun! */
317 rb->splash(HZ, "Chess Clock"); 328 rb->splash(HZ, "Chess Clock");
318 329
319 rb->lcd_clear_display(); 330 rb->lcd_clear_display();
320 i=0; 331 i=0;
321 while (i>=0) { 332 while (1) {
322 int res; 333 int res;
323 switch (i) { 334 switch (i) {
324 case 0: 335 case 0:
@@ -328,31 +339,30 @@ enum plugin_status plugin_start(const void* parameter)
328 break; 339 break;
329 case 1: 340 case 1:
330 res=chessclock_set_int("Total time", 341 res=chessclock_set_int("Total time",
331 &settings.total_time, 10, 0, MAX_TIME, 342 &settings.total_time, 10, 10, MAX_TIME,
332 FLAGS_SET_INT_SECONDS); 343 FLAGS_SET_INT_SECONDS);
333 settings.round_time=settings.total_time; 344 settings.round_time=settings.total_time;
334 break; 345 break;
335 case 2: 346 case 2:
336 res=chessclock_set_int("Max round time", &settings.round_time, 347 res=chessclock_set_int("Max round time", &settings.round_time,
337 10, 0, settings.round_time, 348 10, 10, settings.round_time,
338 FLAGS_SET_INT_SECONDS); 349 FLAGS_SET_INT_SECONDS);
339 break; 350 break;
340 default: 351 default:
341 i=-1; /* done */ 352 res=-2; /* done */
342 res=-2;
343 break; 353 break;
344 } 354 }
345 if (res==-1) { 355 if (res==CHCL_USB) {
346 return PLUGIN_USB_CONNECTED; 356 return PLUGIN_USB_CONNECTED;
347 } 357 } else if (res==CHCL_CANCEL) {
348 if (res==0) {
349 i--; 358 i--;
350 if (i<0) { 359 if (i<0) {
351 return PLUGIN_OK; 360 return PLUGIN_OK;
352 } 361 }
353 } 362 } else if (res==CHCL_OK) {
354 if (res>0) {
355 i++; 363 i++;
364 } else if (res==-2) { /* done */
365 break;
356 } 366 }
357 } 367 }
358 for (i=0; i<settings.nr_timers; i++) { 368 for (i=0; i<settings.nr_timers; i++) {
@@ -382,19 +392,20 @@ enum plugin_status plugin_start(const void* parameter)
382 if (done) { 392 if (done) {
383 return PLUGIN_OK; 393 return PLUGIN_OK;
384 } 394 }
395
385 ret = run_timer(nr); 396 ret = run_timer(nr);
386 switch (ret) { 397 switch (ret) {
387 case -1: /* exit */ 398 case CHCL_CANCEL: /* exit */
388 done=true; 399 done=true;
389 break; 400 break;
390 case 3: 401 case CHCL_USB:
391 return PLUGIN_USB_CONNECTED; 402 return PLUGIN_USB_CONNECTED;
392 case 1: 403 case CHCL_NEXT:
393 nr++; 404 nr++;
394 if (nr>=settings.nr_timers) 405 if (nr>=settings.nr_timers)
395 nr=0; 406 nr=0;
396 break; 407 break;
397 case 2: 408 case CHCL_PREV:
398 do { 409 do {
399 nr--; 410 nr--;
400 if (nr<0) 411 if (nr<0)
@@ -420,30 +431,22 @@ static void show_pause_mode(bool enabled)
420 rb->lcd_set_drawmode(DRMODE_SOLID); 431 rb->lcd_set_drawmode(DRMODE_SOLID);
421 } 432 }
422} 433}
434#else
435#define show_pause_mode(enabled) rb->lcd_icon(ICON_PAUSE, enabled)
423#endif 436#endif
424 437
425/*
426 -1= exit
427 1 = next player
428 2 = prev player
429 3 = usb connected
430*/
431static int run_timer(int nr) 438static int run_timer(int nr)
432{ 439{
433 char buf[40]; 440 char buf[40];
434 char player_info[13]; 441 char player_info[13];
435 long last_tick; 442 long last_tick;
436 bool done=false; 443 bool done=false;
437 int retval=0; 444 int retval=CHCL_OK;
438 long max_ticks=timer_holder[nr].total_time*HZ-timer_holder[nr].used_time; 445 long max_ticks=timer_holder[nr].total_time*HZ-timer_holder[nr].used_time;
439 long ticks=0; 446 long ticks=0;
440 bool round_time=false; 447 bool round_time=false;
441 448
442#ifdef HAVE_LCD_CHARCELLS
443 rb->lcd_icon(ICON_PAUSE, pause);
444#else
445 show_pause_mode(pause); 449 show_pause_mode(pause);
446#endif
447 450
448 if (settings.round_time*HZ<max_ticks) { 451 if (settings.round_time*HZ<max_ticks) {
449 max_ticks=settings.round_time*HZ; 452 max_ticks=settings.round_time*HZ;
@@ -456,21 +459,14 @@ static int run_timer(int nr)
456 while (!done) { 459 while (!done) {
457 int button; 460 int button;
458 long now; 461 long now;
459 if (ticks>max_ticks) { 462 if (ticks>=max_ticks) {
460 if (round_time) 463 if (round_time)
461 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"ROUND UP!"); 464 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"ROUND UP!");
462 else 465 else
463 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"TIME OUT!"); 466 rb->lcd_puts(0, FIRST_LINE+1, (unsigned char *)"TIME OUT!");
464 rb->backlight_on(); 467 rb->backlight_on();
468 ticks = max_ticks;
465 } else { 469 } else {
466 /*
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);
471 }
472 */
473 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
474 now=*rb->current_tick; 470 now=*rb->current_tick;
475 if (!pause) { 471 if (!pause) {
476 ticks+=now-last_tick; 472 ticks+=now-last_tick;
@@ -500,16 +496,12 @@ static int run_timer(int nr)
500 switch (button) { 496 switch (button) {
501 /* OFF/ON key to exit */ 497 /* OFF/ON key to exit */
502 case CHC_QUIT: 498 case CHC_QUIT:
503 return -1; /* Indicate exit */ 499 return CHCL_CANCEL; /* Indicate exit */
504 500
505 /* PLAY = Stop/Start toggle */ 501 /* PLAY = Stop/Start toggle */
506 case CHC_STARTSTOP: 502 case CHC_STARTSTOP:
507 pause=!pause; 503 pause=!pause;
508#ifdef HAVE_LCD_CHARCELLS
509 rb->lcd_icon(ICON_PAUSE, pause);
510#else
511 show_pause_mode(pause); 504 show_pause_mode(pause);
512#endif
513 break; 505 break;
514 506
515 /* LEFT = Reset timer */ 507 /* LEFT = Reset timer */
@@ -530,12 +522,13 @@ static int run_timer(int nr)
530 case 0: 522 case 0:
531 /* delete player */ 523 /* delete player */
532 timer_holder[nr].hidden=true; 524 timer_holder[nr].hidden=true;
533 retval=1; 525 retval = CHCL_NEXT;
534 done=true; 526 done=true;
535 break; 527 break;
536 case 1: 528 case 1:
537 /* restart */ 529 /* restart */
538 ticks=0; 530 ticks=0;
531 last_tick=*rb->current_tick;
539 break; 532 break;
540 case 2: 533 case 2:
541 /* set round time */ 534 /* set round time */
@@ -544,11 +537,12 @@ static int run_timer(int nr)
544 &val, 537 &val,
545 10, 0, MAX_TIME, 538 10, 0, MAX_TIME,
546 FLAGS_SET_INT_SECONDS); 539 FLAGS_SET_INT_SECONDS);
547 if (res==-1) { /*usb*/ 540 if (res==CHCL_USB) {
548 retval = 3; 541 retval = CHCL_USB;
549 done=true; 542 done=true;
550 } else if (res==1) { 543 } else if (res==CHCL_OK) {
551 ticks=max_ticks-val*HZ; 544 ticks=max_ticks-val*HZ;
545 last_tick=*rb->current_tick;
552 } 546 }
553 break; 547 break;
554 case 3: 548 case 3:
@@ -558,37 +552,39 @@ static int run_timer(int nr)
558 &val, 552 &val,
559 10, 0, MAX_TIME, 553 10, 0, MAX_TIME,
560 FLAGS_SET_INT_SECONDS); 554 FLAGS_SET_INT_SECONDS);
561 if (res==-1) { /*usb*/ 555 if (res==CHCL_USB) {
562 retval = 3; 556 retval = CHCL_USB;
563 done=true; 557 done=true;
564 } else if (res==1) { 558 } else if (res==CHCL_OK) {
565 timer_holder[nr].total_time=val; 559 timer_holder[nr].total_time=val;
566 } 560 }
567 break; 561 break;
568 case MENU_ATTACHED_USB: 562 case MENU_ATTACHED_USB:
569 retval = 3; 563 retval = CHCL_USB;
570 done=true; 564 done=true;
571 break; 565 break;
572 } 566 }
573 rb->lcd_clear_display(); 567 rb->lcd_clear_display();
568 show_pause_mode(pause);
569 rb->lcd_puts(0, FIRST_LINE, (unsigned char *)player_info);
574 } 570 }
575 break; 571 break;
576 572
577 /* UP (RIGHT/+) = Scroll Lap timer up */ 573 /* UP (RIGHT/+) = Scroll Lap timer up */
578 case CHC_SETTINGS_INC: 574 case CHC_SETTINGS_INC:
579 retval = 1; 575 retval = CHCL_NEXT;
580 done = true; 576 done = true;
581 break; 577 break;
582 578
583 /* DOWN (LEFT/-) = Scroll Lap timer down */ 579 /* DOWN (LEFT/-) = Scroll Lap timer down */
584 case CHC_SETTINGS_DEC: 580 case CHC_SETTINGS_DEC:
585 retval = 2; 581 retval = CHCL_PREV;
586 done = true; 582 done = true;
587 break; 583 break;
588 584
589 default: 585 default:
590 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) { 586 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) {
591 retval = 3; /* been in usb mode */ 587 retval = CHCL_USB;
592 done = true; 588 done = true;
593 } 589 }
594 break; 590 break;
@@ -646,12 +642,12 @@ static int chessclock_set_int(char* string,
646#ifdef CHC_SETTINGS_CANCEL2 642#ifdef CHC_SETTINGS_CANCEL2
647 case CHC_SETTINGS_CANCEL2: 643 case CHC_SETTINGS_CANCEL2:
648#endif 644#endif
649 return 0; /* cancel */ 645 return CHCL_CANCEL;
650 break; 646 break;
651 647
652 default: 648 default:
653 if (rb->default_event_handler(button) == SYS_USB_CONNECTED) 649 if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
654 return -1; /* been in usb mode */ 650 return CHCL_USB;
655 break; 651 break;
656 652
657 } 653 }
@@ -664,7 +660,7 @@ static int chessclock_set_int(char* string,
664 } 660 }
665 rb->lcd_stop_scroll(); 661 rb->lcd_stop_scroll();
666 662
667 return 1; 663 return CHCL_OK;
668} 664}
669 665
670static char * show_time(int seconds) 666static char * show_time(int seconds)