summaryrefslogtreecommitdiff
path: root/apps/plugins/clock.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/clock.c')
-rw-r--r--apps/plugins/clock.c574
1 files changed, 460 insertions, 114 deletions
diff --git a/apps/plugins/clock.c b/apps/plugins/clock.c
index 7cf335f0e1..58a42cd4e0 100644
--- a/apps/plugins/clock.c
+++ b/apps/plugins/clock.c
@@ -22,11 +22,17 @@ RELEASE NOTES *******************
22********************************* 22*********************************
23 23
24********************************* 24*********************************
25VERSION 2.3 * STABLE ************
26*********************************
27Tab indentation removed
28Counter screen added at ON+F2, with countdown options
29
30*********************************
25VERSION 2.22 * STABLE *********** 31VERSION 2.22 * STABLE ***********
26********************************* 32*********************************
27Fixed two bugs: 33Fixed two bugs:
28-Digital settings are now independent of LCD settings 34Digital settings are now independent of LCD settings
29-12/24h "Analog" settings are now displayed correctly. 3512/24h "Analog" settings are now displayed correctly.
30 36
31********************************* 37*********************************
32VERSION 2.21 * STABLE *********** 38VERSION 2.21 * STABLE ***********
@@ -93,11 +99,12 @@ and a few options.
93 99
94#ifdef HAVE_LCD_BITMAP 100#ifdef HAVE_LCD_BITMAP
95 101
96#define CLOCK_VERSION "2.22" 102#define CLOCK_VERSION "2.3"
97 103
98/* prototypes */ 104/* prototypes */
99void show_logo(bool animate, bool show_clock_text); 105void show_logo(bool animate, bool show_clock_text);
100void exit_logo(void); 106void exit_logo(void);
107void save_settings(void);
101 108
102/* used in help screen */ 109/* used in help screen */
103int screen = 1; 110int screen = 1;
@@ -110,6 +117,11 @@ int displayed_value = 0;
110int count_h, count_m, count_s; 117int count_h, count_m, count_s;
111char count_text[8]; 118char count_text[8];
112bool counting = false; 119bool counting = false;
120bool counting_up = true;
121int target_hour=0, target_minute=0, target_second=0;
122int remaining_h=0, remaining_m=0, remaining_s=0;
123bool editing_target = false;
124bool display_counter = true;
113 125
114static struct plugin_api* rb; 126static struct plugin_api* rb;
115 127
@@ -381,6 +393,75 @@ const unsigned char clocklogo_4[] = {
3810x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 3930x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
382}; 394};
383 395
396/******************
397 * Time's Up bitmap
398 *****************/
399const unsigned char timesup[] = {
4000x78, 0x78, 0x78, 0x38, 0x08, 0x08, 0xf8, 0xfc, 0xfc, 0xfc, 0xfc, 0xfc, 0x04,
4010x04, 0x04, 0x0c, 0x3c, 0x3c, 0x3c, 0x04, 0x04, 0x04, 0xfc, 0xfc, 0xfc, 0xfc,
4020xfe, 0xfe, 0x06, 0x03, 0x03, 0x05, 0x05, 0x07, 0xff, 0xff, 0xff, 0xff, 0xff,
4030xfc, 0xfc, 0xf8, 0xf0, 0xc0, 0x00, 0x00, 0x00, 0x00, 0xc0, 0xf0, 0xfc, 0xfc,
4040xfc, 0xfc, 0xfc, 0x20, 0x22, 0x22, 0x22, 0x22, 0x02, 0x02, 0x02, 0x02, 0x0e,
4050xfe, 0xfe, 0xfe, 0xfe, 0x06, 0x06, 0x06, 0x06, 0x06, 0x0e, 0x1c, 0x3c, 0x3c,
4060x3c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0xfc, 0xfc, 0xfc, 0xfe, 0x00,
4070x00, 0x00, 0x00, 0x02, 0x02, 0x02, 0x02, 0x02, 0x02, 0xfe, 0xfe, 0xfe, 0xfe,
4080x86, 0x0e, 0x3e, 0xfe, 0xfe, 0xfe, 0xfe, 0x1e,
4090x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x40,
4100x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x00, 0xff, 0xff, 0xff, 0xff,
4110xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff,
4120x03, 0x0f, 0x3f, 0xff, 0xff, 0xfc, 0xf0, 0xfc, 0xff, 0x7f, 0x1f, 0x03, 0xff,
4130xff, 0xff, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4140xff, 0xff, 0xff, 0xff, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0e, 0x0e, 0x0e, 0x00,
4150x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x01, 0x03, 0x03, 0x03, 0x40,
4160x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0xc0, 0xe0, 0xe0, 0xe3, 0xc7, 0x8f, 0x0f,
4170x1f, 0x1f, 0x3e, 0xfe, 0xfc, 0xf8, 0xf8, 0xf0,
4180x08, 0x08, 0x08, 0x08, 0x18, 0x18, 0x1f, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x0c,
4190x08, 0x08, 0x00, 0x00, 0x08, 0x08, 0x08, 0x08, 0x0c, 0x0f, 0x0f, 0x0f, 0x0f,
4200x0f, 0x0f, 0x0c, 0x08, 0x08, 0x88, 0x80, 0xc0, 0xff, 0xff, 0xff, 0xff, 0xff,
4210x00, 0x00, 0x00, 0x00, 0x03, 0x0f, 0x0f, 0x07, 0x01, 0x10, 0x18, 0x1c, 0x0f,
4220x0f, 0x0f, 0x0f, 0x00, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x0c,
4230x0f, 0x0f, 0x0f, 0x0f, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x1c, 0x1c,
4240x1c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00,
4250x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x1f, 0x1f, 0x1f, 0x0f, 0x0f, 0x0f, 0x0f,
4260x0e, 0x0c, 0x0c, 0x0f, 0x0f, 0x0f, 0x0f, 0x03,
4270x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4280x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4290x00, 0x00, 0x00, 0x00, 0x40, 0x40, 0x40, 0xc0, 0xc0, 0xc0, 0xc0, 0xc0, 0x00,
4300x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x48, 0xc8, 0xf8, 0xf8, 0xf8, 0x18, 0x08,
4310x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0xe0, 0xe0, 0xe0, 0x60, 0x60, 0xe0, 0xe0,
4320xe0, 0xe0, 0xa0, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20,
4330x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4340x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4350x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4360x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4370x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4380x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00,
4390x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0x00, 0x00,
4400x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff, 0xff, 0xff, 0xc0, 0xc0, 0xe0, 0xf1,
4410xff, 0xff, 0x7f, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xff,
4420xff, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4430x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4440x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4450x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4460x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4470x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x07, 0x3f, 0x7f, 0xff, 0xff, 0xf0,
4480xe0, 0xc0, 0xc0, 0xc0, 0xe0, 0xf0, 0xf0, 0x7c, 0x7f, 0x3f, 0x07, 0x04, 0x04,
4490x04, 0x04, 0x04, 0x04, 0x04, 0xe4, 0xff, 0xff, 0xff, 0xc0, 0x80, 0x80, 0x00,
4500x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xc3,
4510xe1, 0xe7, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4520x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4530x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4540x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4550x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4560x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4570x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4580x00, 0x00, 0x00, 0x00, 0x00, 0x03, 0x03, 0x03, 0x03, 0x02, 0x00, 0x00, 0x00,
4590x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4600x03, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4610x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
4620x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00
463};
464
384/* settings saved to this location */ 465/* settings saved to this location */
385static char default_filename[] = "/.rockbox/rocks/.clock_settings"; 466static char default_filename[] = "/.rockbox/rocks/.clock_settings";
386 467
@@ -419,9 +500,9 @@ char* jobs[] = {
419bool done = false; /* This bool is used for most of the while loops */ 500bool done = false; /* This bool is used for most of the while loops */
420int logo = 4; /* must be set before we show the logo */ 501int logo = 4; /* must be set before we show the logo */
421 502
422/************************************ 503/***********************************
423 * This is saved to default_filename 504 * This is saved to default_filename
424 ************************************/ 505 **********************************/
425struct saved_settings 506struct saved_settings
426{ 507{
427 /* general */ 508 /* general */
@@ -452,9 +533,9 @@ struct saved_settings
452 bool fullscreen_invertseconds; 533 bool fullscreen_invertseconds;
453} settings; 534} settings;
454 535
455/************************* 536/************************
456 * Setting default values 537 * Setting default values
457 *************************/ 538 ***********************/
458void reset_settings(void) 539void reset_settings(void)
459{ 540{
460 /* general */ 541 /* general */
@@ -485,20 +566,36 @@ void reset_settings(void)
485 settings.fullscreen_invertseconds = false; 566 settings.fullscreen_invertseconds = false;
486} 567}
487 568
488/********************************* 569/**************
570 * Exits plugin
571 *************/
572bool quit(bool save)
573{
574 if(save)
575 save_settings();
576
577 /* restore set backlight timeout */
578 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
579
580 return PLUGIN_OK;
581}
582
583/********************************
489 * Saves "saved_settings" to disk 584 * Saves "saved_settings" to disk
490 *********************************/ 585 *******************************/
491void save_settings(void) 586void save_settings(void)
492{ 587{
493 int fd; 588 int fd;
494 589
495 rb->lcd_clear_display(); 590 rb->lcd_clear_display();
496 591
592 /* display information */
497 show_logo(true, true); 593 show_logo(true, true);
498 rb->lcd_puts(0, 7, "Saving..."); 594 rb->lcd_puts(0, 7, "Saving...");
499 595
500 rb->lcd_update(); 596 rb->lcd_update();
501 597
598 /* create the settings file and write the settings to it */
502 fd = rb->creat(default_filename, O_WRONLY); 599 fd = rb->creat(default_filename, O_WRONLY);
503 600
504 if(fd >= 0) 601 if(fd >= 0)
@@ -517,11 +614,12 @@ void save_settings(void)
517 exit_logo(); 614 exit_logo();
518} 615}
519 616
520/*********************************** 617/**********************************
521 * Loads "saved_settings" from disk 618 * Loads "saved_settings" from disk
522 ***********************************/ 619 *********************************/
523void load_settings(void) 620void load_settings(void)
524{ 621{
622 /* open the settings file */
525 int fd; 623 int fd;
526 fd = rb->open(default_filename, O_RDONLY); 624 fd = rb->open(default_filename, O_RDONLY);
527 625
@@ -559,9 +657,9 @@ void load_settings(void)
559 exit_logo(); 657 exit_logo();
560} 658}
561 659
562/************************************************************** 660/*************************************************************
563 * 7-Segment LED/LCD imitation code, by Linus Nielsen Feltzing 661 * 7-Segment LED/LCD imitation code, by Linus Nielsen Feltzing
564 **************************************************************/ 662 ************************************************************/
565/* 663/*
566 a 0 b 664 a 0 b
567 #########c 665 #########c
@@ -588,9 +686,9 @@ static unsigned int point_coords[6][2] =
588 {1, 2} /* f */ 686 {1, 2} /* f */
589}; 687};
590 688
591/********************************************* 689/********************************************
592 * The end points (a-f) for each segment line 690 * The end points (a-f) for each segment line
593 *********************************************/ 691 *******************************************/
594static unsigned int seg_points[7][2] = 692static unsigned int seg_points[7][2] =
595{ 693{
596 {0,1}, /* a to b */ 694 {0,1}, /* a to b */
@@ -602,10 +700,10 @@ static unsigned int seg_points[7][2] =
602 {4,5} /* e to f */ 700 {4,5} /* e to f */
603}; 701};
604 702
605/*********************************************************************** 703/**********************************************************************
606 * Lists that tell which segments (0-6) to enable for each digit (0-9), 704 * Lists that tell which segments (0-6) to enable for each digit (0-9),
607 * the list is terminated with -1 705 * the list is terminated with -1
608 ***********************************************************************/ 706 *********************************************************************/
609static int digit_segs[10][8] = 707static int digit_segs[10][8] =
610{ 708{
611 {0,1,2,4,5,6, -1}, /* 0 */ 709 {0,1,2,4,5,6, -1}, /* 0 */
@@ -620,9 +718,9 @@ static int digit_segs[10][8] =
620 {0,1,2,3,5,6, -1} /* 9 */ 718 {0,1,2,3,5,6, -1} /* 9 */
621}; 719};
622 720
623/************************************ 721/***********************************
624 * Draws one segment - LED imitation 722 * Draws one segment - LED imitation
625 ************************************/ 723 **********************************/
626void draw_seg_led(int seg, int x, int y, int width, int height) 724void draw_seg_led(int seg, int x, int y, int width, int height)
627{ 725{
628 int p1 = seg_points[seg][0]; 726 int p1 = seg_points[seg][0];
@@ -666,9 +764,9 @@ void draw_seg_led(int seg, int x, int y, int width, int height)
666 } 764 }
667} 765}
668 766
669/************************************ 767/***********************************
670 * Draws one segment - LCD imitation 768 * Draws one segment - LCD imitation
671 ************************************/ 769 **********************************/
672void draw_seg_lcd(int seg, int x, int y, int width, int height) 770void draw_seg_lcd(int seg, int x, int y, int width, int height)
673{ 771{
674 int p1 = seg_points[seg][0]; 772 int p1 = seg_points[seg][0];
@@ -738,9 +836,9 @@ void draw_seg_lcd(int seg, int x, int y, int width, int height)
738 } 836 }
739} 837}
740 838
741/****************** 839/*****************
742 * Draws one digit 840 * Draws one digit
743 ******************/ 841 ****************/
744void draw_7seg_digit(int digit, int x, int y, int width, int height, bool lcd_display) 842void draw_7seg_digit(int digit, int x, int y, int width, int height, bool lcd_display)
745{ 843{
746 int i; 844 int i;
@@ -757,49 +855,49 @@ void draw_7seg_digit(int digit, int x, int y, int width, int height, bool lcd_di
757 } 855 }
758} 856}
759 857
760/****************************************************** 858/*****************************************************
761 * Draws the entire 7-segment hour-minute time display 859 * Draws the entire 7-segment hour-minute time display
762 ******************************************************/ 860 ****************************************************/
763void draw_7seg_time(int hour, int minute, int x, int y, int width, int height, 861void draw_7seg_time(int hour, int minute, int x, int y, int width, int height,
764bool colon, bool lcd) 862bool colon, bool lcd)
765{ 863{
766 int xpos = x; 864 int xpos = x;
767 865
768 /* Draw PM indicator */ 866 /* Draw PM indicator */
769 if(settings.clock == 2) 867 if(settings.clock == 2)
770 { 868 {
771 if(settings.digital_12h) 869 if(settings.digital_12h)
772 { 870 {
773 if(hour > 12) 871 if(hour > 12)
774 rb->lcd_bitmap(pm, 97, 55, 15, 8, true); 872 rb->lcd_bitmap(pm, 97, 55, 15, 8, true);
775 else 873 else
776 rb->lcd_bitmap(am, 1, 55, 15, 8, true); 874 rb->lcd_bitmap(am, 1, 55, 15, 8, true);
777 } 875 }
778 } 876 }
779 else 877 else
780 { 878 {
781 if(settings.lcd_12h) 879 if(settings.lcd_12h)
782 { 880 {
783 if(hour > 12) 881 if(hour > 12)
784 rb->lcd_bitmap(pm, 97, 55, 15, 8, true); 882 rb->lcd_bitmap(pm, 97, 55, 15, 8, true);
785 else 883 else
786 rb->lcd_bitmap(am, 1, 55, 15, 8, true); 884 rb->lcd_bitmap(am, 1, 55, 15, 8, true);
787 } 885 }
788 } 886 }
789 887
790 /* Now change to 12H mode if requested */ 888 /* Now change to 12H mode if requested */
791 if(settings.clock == 2) 889 if(settings.clock == 2)
792 { 890 {
793 if(settings.digital_12h) 891 if(settings.digital_12h)
794 if(hour > 12) 892 if(hour > 12)
795 hour -= 12; 893 hour -= 12;
796 } 894 }
797 else 895 else
798 { 896 {
799 if(settings.lcd_12h) 897 if(settings.lcd_12h)
800 if(hour > 12) 898 if(hour > 12)
801 hour -= 12; 899 hour -= 12;
802 } 900 }
803 901
804 draw_7seg_digit(hour / 10, xpos, y, width, height, lcd); 902 draw_7seg_digit(hour / 10, xpos, y, width, height, lcd);
805 xpos += width + 6; 903 xpos += width + 6;
@@ -839,9 +937,9 @@ bool colon, bool lcd)
839 xpos += width + 6; 937 xpos += width + 6;
840} 938}
841 939
842/************** 940/*************
843 * Binary mode 941 * Binary mode
844 **************/ 942 ************/
845void binary(int hour, int minute, int second) 943void binary(int hour, int minute, int second)
846{ 944{
847 /* temporary modifiable versions of ints */ 945 /* temporary modifiable versions of ints */
@@ -851,9 +949,9 @@ void binary(int hour, int minute, int second)
851 949
852 rb->lcd_clear_display(); 950 rb->lcd_clear_display();
853 951
854 /***************** 952 /******
855 * HOUR 953 * HOUR
856 *****************/ 954 *****/
857 if(temphour >= 32) 955 if(temphour >= 32)
858 { 956 {
859 rb->lcd_bitmap(bitmap_1, 0, 1, 15, 20, true); 957 rb->lcd_bitmap(bitmap_1, 0, 1, 15, 20, true);
@@ -897,9 +995,9 @@ void binary(int hour, int minute, int second)
897 else 995 else
898 rb->lcd_bitmap(bitmap_0, 95, 1, 15, 20, true); 996 rb->lcd_bitmap(bitmap_0, 95, 1, 15, 20, true);
899 997
900 /**************** 998 /*********
901 * MINUTES 999 * MINUTES
902 ****************/ 1000 ********/
903 if(tempmin >= 32) 1001 if(tempmin >= 32)
904 { 1002 {
905 rb->lcd_bitmap(bitmap_1, 0, 21, 15, 20, true); 1003 rb->lcd_bitmap(bitmap_1, 0, 21, 15, 20, true);
@@ -943,9 +1041,9 @@ void binary(int hour, int minute, int second)
943 else 1041 else
944 rb->lcd_bitmap(bitmap_0, 95, 21, 15, 20, true); 1042 rb->lcd_bitmap(bitmap_0, 95, 21, 15, 20, true);
945 1043
946 /**************** 1044 /*********
947 * SECONDS 1045 * SECONDS
948 ****************/ 1046 ********/
949 if(tempsec >= 32) 1047 if(tempsec >= 32)
950 { 1048 {
951 rb->lcd_bitmap(bitmap_1, 0, 42, 15, 20, true); 1049 rb->lcd_bitmap(bitmap_1, 0, 42, 15, 20, true);
@@ -992,9 +1090,9 @@ void binary(int hour, int minute, int second)
992 rb->lcd_update(); 1090 rb->lcd_update();
993} 1091}
994 1092
995/***************** 1093/****************
996 * Shows the logo 1094 * Shows the logo
997 *****************/ 1095 ***************/
998void show_logo(bool animate, bool show_clock_text) 1096void show_logo(bool animate, bool show_clock_text)
999{ 1097{
1000 int x_position; 1098 int x_position;
@@ -1051,9 +1149,9 @@ void show_logo(bool animate, bool show_clock_text)
1051 } 1149 }
1052} 1150}
1053 1151
1054/********************* 1152/********************
1055 * Logo flies off lcd 1153 * Logo flies off lcd
1056 *********************/ 1154 *******************/
1057void exit_logo(void) 1155void exit_logo(void)
1058{ 1156{
1059 int x_position; 1157 int x_position;
@@ -1078,9 +1176,9 @@ void exit_logo(void)
1078 } 1176 }
1079} 1177}
1080 1178
1081/******************** 1179/*******************
1082 * Rolls the credits 1180 * Rolls the credits
1083 ********************/ 1181 ******************/
1084/* The following function is pretty confusing, so 1182/* The following function is pretty confusing, so
1085 * it's extra well commented. */ 1183 * it's extra well commented. */
1086bool roll_credits(void) 1184bool roll_credits(void)
@@ -1180,9 +1278,9 @@ bool roll_credits(void)
1180 return true; 1278 return true;
1181} 1279}
1182 1280
1183/***************************************** 1281/****************************************
1184 * Shows the logo, then rolls the credits 1282 * Shows the logo, then rolls the credits
1185 *****************************************/ 1283 ***************************************/
1186bool show_credits(void) 1284bool show_credits(void)
1187{ 1285{
1188 int j = 0; 1286 int j = 0;
@@ -1213,9 +1311,9 @@ bool show_credits(void)
1213 return false; 1311 return false;
1214} 1312}
1215 1313
1216/******************* 1314/******************
1217 * F1 Screen - HELP 1315 * F1 Screen - HELP
1218 *******************/ 1316 *****************/
1219bool f1_screen(void) 1317bool f1_screen(void)
1220{ 1318{
1221 done = false; 1319 done = false;
@@ -1232,18 +1330,19 @@ bool f1_screen(void)
1232 rb->lcd_puts(0, 2, "help, use LEFT and"); 1330 rb->lcd_puts(0, 2, "help, use LEFT and");
1233 rb->lcd_puts(0, 3, "RIGHT. F1 returns"); 1331 rb->lcd_puts(0, 3, "RIGHT. F1 returns");
1234 rb->lcd_puts(0, 4, "you to the clock."); 1332 rb->lcd_puts(0, 4, "you to the clock.");
1235 rb->lcd_puts(0, 6, ""); 1333 rb->lcd_puts(0, 5, "At any mode, [F1]");
1334 rb->lcd_puts(0, 6, "will show you this");
1236 rb->lcd_puts(0, 7, "<< ---- 1/9 NEXT >>"); 1335 rb->lcd_puts(0, 7, "<< ---- 1/9 NEXT >>");
1237 } 1336 }
1238 else if(screen == 2) 1337 else if(screen == 2)
1239 { 1338 {
1240 rb->lcd_puts(0, 0, "At any mode, [F1]"); 1339 rb->lcd_puts(0, 0, "help screen. [F2]");
1241 rb->lcd_puts(0, 1, "will show you this"); 1340 rb->lcd_puts(0, 1, "will start/stop");
1242 rb->lcd_puts(0, 2, "help screen. [F2]"); 1341 rb->lcd_puts(0, 2, "the Counter. Hold");
1243 rb->lcd_puts(0, 3, "will start/stop"); 1342 rb->lcd_puts(0, 3, "F2 to reset the");
1244 rb->lcd_puts(0, 4, "the Counter. Hold"); 1343 rb->lcd_puts(0, 4, "Counter. [ON+F2]");
1245 rb->lcd_puts(0, 5, "F2 to reset the"); 1344 rb->lcd_puts(0, 5, "gives you counting");
1246 rb->lcd_puts(0, 6, "Counter."); 1345 rb->lcd_puts(0, 6, "options.");
1247 rb->lcd_puts(0, 7, "<< BACK 2/9 NEXT >>"); 1346 rb->lcd_puts(0, 7, "<< BACK 2/9 NEXT >>");
1248 } 1347 }
1249 else if(screen == 3) 1348 else if(screen == 3)
@@ -1352,10 +1451,10 @@ bool f1_screen(void)
1352 return true; 1451 return true;
1353} 1452}
1354 1453
1355/************************** 1454/*************************
1356 * F2 Screen - Pick a Logo 1455 * F2 Screen - Pick a Logo
1357 * [[ NO LONGER USED ]] 1456 * [[ NO LONGER USED ]]
1358 **************************/ 1457 ************************/
1359void f2_screen(void) 1458void f2_screen(void)
1360{ 1459{
1361 rb->lcd_clear_display(); 1460 rb->lcd_clear_display();
@@ -1422,9 +1521,9 @@ void f2_screen(void)
1422 } 1521 }
1423} 1522}
1424 1523
1425/********************** 1524/*********************
1426 * F3 Screen - OPTIONS 1525 * F3 Screen - OPTIONS
1427 **********************/ 1526 ********************/
1428bool f3_screen(void) 1527bool f3_screen(void)
1429{ 1528{
1430 int invert_analog = 1; 1529 int invert_analog = 1;
@@ -1815,9 +1914,9 @@ bool f3_screen(void)
1815 return true; 1914 return true;
1816} 1915}
1817 1916
1818/***************************************** 1917/****************************************
1819 * Draws the extras, IE border, digits... 1918 * Draws the extras, IE border, digits...
1820 *****************************************/ 1919 ***************************************/
1821void draw_extras(int year, int day, int month, int hour, int minute, int second) 1920void draw_extras(int year, int day, int month, int hour, int minute, int second)
1822{ 1921{
1823 char buf[11]; 1922 char buf[11];
@@ -1977,9 +2076,9 @@ void draw_extras(int year, int day, int month, int hour, int minute, int second)
1977 } 2076 }
1978} 2077}
1979 2078
1980/**************** 2079/***************
1981 * Select a mode 2080 * Select a mode
1982 ****************/ 2081 **************/
1983void select_mode(void) 2082void select_mode(void)
1984{ 2083{
1985 int cursorpos = settings.clock; 2084 int cursorpos = settings.clock;
@@ -2060,8 +2159,63 @@ void select_mode(void)
2060 } 2159 }
2061} 2160}
2062 2161
2162/********************
2163 * Counter's all done
2164 *******************/
2165void counter_finished(void)
2166{
2167 int btn;
2168 int xpos = 0;
2169 bool bouncing_up = false;
2170 unsigned char *times_up = 0;
2171 times_up = (unsigned char *)timesup;
2172
2173 done = false;
2174
2175 while(!done)
2176 {
2177 rb->lcd_clear_display();
2178
2179 /* draw "TIME'S UP" text */
2180 rb->lcd_bitmap(times_up, 0, xpos, 112, 50, true);
2181
2182 /* invert lcd */
2183 rb->lcd_invertrect(0, 0, 112, 64);
2184
2185 rb->lcd_update();
2186
2187 /* pause */
2188 rb->sleep(HZ/15);
2189
2190 /* move bitmap up/down 1px */
2191 if(bouncing_up)
2192 {
2193 if(xpos > 0)
2194 xpos--;
2195 else
2196 bouncing_up = false;
2197 }
2198 else
2199 {
2200 if(xpos < 14)
2201 xpos++;
2202 else
2203 bouncing_up = true;
2204 }
2205
2206 /* exit on keypress */
2207 btn = rb->button_get(false);
2208 if (btn != BUTTON_NONE && !(btn & BUTTON_REL))
2209 done = true;
2210 }
2211}
2212
2213/*********************
2214 * Display the counter
2215 ********************/
2063void show_counter(void) 2216void show_counter(void)
2064{ 2217{
2218 /* increment counter */
2065 if(counting) 2219 if(counting)
2066 { 2220 {
2067 passed_time = *rb->current_tick - start_tick; 2221 passed_time = *rb->current_tick - start_tick;
@@ -2072,20 +2226,203 @@ void show_counter(void)
2072 displayed_value = counter + passed_time; 2226 displayed_value = counter + passed_time;
2073 displayed_value = displayed_value / HZ; 2227 displayed_value = displayed_value / HZ;
2074 2228
2229 /* these are the REAL displayed values */
2075 count_s = displayed_value % 60; 2230 count_s = displayed_value % 60;
2076 count_m = displayed_value % 3600 / 60; 2231 count_m = displayed_value % 3600 / 60;
2077 count_h = displayed_value / 3600; 2232 count_h = displayed_value / 3600;
2078 2233
2079 rb->snprintf(count_text, sizeof(count_text), "%d:%02d:%02d", count_h, count_m, count_s); 2234 /* compute "counting down" displayed value */
2235 if(!counting_up)
2236 {
2237 remaining_s = target_second - count_s;
2238 remaining_m = target_minute - count_m;
2239 remaining_h = target_hour - count_h;
2240 }
2241
2242 if(remaining_s < 0)
2243 {
2244 remaining_s += 60;
2245 remaining_m--;
2246 }
2247 if(remaining_m < 0)
2248 {
2249 remaining_m += 60;
2250 remaining_h--;
2251 }
2252 if(remaining_h < 0)
2253 {
2254 /* reset modes */
2255 counting = false;
2256 counting_up = true;
2080 2257
2081 if(settings.clock == 1) 2258 /* all done! */
2082 rb->lcd_puts(11, 7, count_text); 2259 counter_finished();
2083 else if(settings.clock == 2) 2260
2084 rb->lcd_putsxy(1, 5, count_text); 2261 /* reset all counter values */
2085 else if(settings.clock == 3) 2262 remaining_h = target_hour = 0;
2086 rb->lcd_putsxy(1, 5, count_text); 2263 remaining_m = target_minute = 0;
2087 else if(settings.clock == 4) 2264 remaining_s = target_second = 0;
2088 rb->lcd_puts(6, 6, count_text); 2265 }
2266
2267 if(counting_up)
2268 rb->snprintf(count_text, sizeof(count_text), "%d:%02d:%02d", count_h, count_m, count_s);
2269 else
2270 rb->snprintf(count_text, sizeof(count_text), "%d:%02d:%02d", remaining_h, remaining_m, remaining_s);
2271
2272 /* allows us to flash the counter if it's paused */
2273 if(display_counter)
2274 {
2275 if(settings.clock == 1)
2276 rb->lcd_puts(11, 7, count_text);
2277 else if(settings.clock == 2)
2278 rb->lcd_putsxy(1, 5, count_text);
2279 else if(settings.clock == 3)
2280 rb->lcd_putsxy(1, 5, count_text);
2281 else if(settings.clock == 4)
2282 rb->lcd_puts(6, 6, count_text);
2283 }
2284}
2285
2286/******************
2287 * Counter settings
2288 *****************/
2289void counter_options(void)
2290{
2291 int cursorpos = 1;
2292 char target_time[15];
2293 bool original = counting_up;
2294 bool current = counting_up;
2295
2296 done = false;
2297
2298 while(!done)
2299 {
2300 /* print text to string */
2301 rb->snprintf(target_time, sizeof(target_time), "%d:%02d:%02d", target_hour, target_minute, target_second);
2302
2303 /* draw text on lcd */
2304 rb->lcd_clear_display();
2305 rb->lcd_puts(0, 0, "Counter Options");
2306 rb->lcd_puts(2, 2, "Count UP");
2307 rb->lcd_puts(2, 3, "Count DOWN...");
2308 rb->lcd_puts(4, 4, "Target Time:");
2309 rb->lcd_puts(4, 5, target_time);
2310 rb->lcd_puts(0, 7, "OFF: Return");
2311
2312 /* tell user what mode is selected */
2313 rb->checkbox(1, 17, 8, 6, counting_up);
2314 rb->checkbox(1, 25, 8, 6, !counting_up);
2315
2316
2317 /* draw a cursor */
2318 switch(cursorpos)
2319 {
2320 case 1: rb->lcd_invertrect(0, 16, 112, 8); break;
2321 case 2: rb->lcd_invertrect(0, 24, 112, 8); break;
2322 case 3: rb->lcd_invertrect(24, 40, 06, 8); break;
2323 case 4: rb->lcd_invertrect(36, 40, 12, 8); break;
2324 case 5: rb->lcd_invertrect(54, 40, 12, 8); break;
2325 }
2326
2327 if(cursorpos > 2)
2328 editing_target = true;
2329 else
2330 editing_target = false;
2331
2332 rb->lcd_update();
2333
2334 /* button scan */
2335 switch(rb->button_get_w_tmo(HZ/4))
2336 {
2337 case BUTTON_F2: /* exit screen */
2338 case BUTTON_OFF:
2339 current = counting_up;
2340 if(current != original)
2341 counter = 0;
2342 done = true;
2343 break;
2344
2345 case BUTTON_UP: /* increase / move cursor */
2346 case BUTTON_UP | BUTTON_REPEAT:
2347 if(!editing_target)
2348 {
2349 if(cursorpos > 1)
2350 cursorpos--;
2351 }
2352 else
2353 {
2354 if(cursorpos == 3)
2355 if(target_hour < 9)
2356 target_hour++;
2357 else
2358 target_hour = 0;
2359 else if(cursorpos == 4)
2360 if(target_minute < 59)
2361 target_minute++;
2362 else
2363 target_minute = 0;
2364 else
2365 if(target_second < 59)
2366 target_second++;
2367 else
2368 target_second = 0;
2369 }
2370 break;
2371
2372 case BUTTON_DOWN: /* decrease / move cursor */
2373 case BUTTON_DOWN | BUTTON_REPEAT:
2374 if(!editing_target)
2375 {
2376 if(cursorpos < 3)
2377 cursorpos++;
2378 }
2379 else
2380 {
2381 if(cursorpos == 3)
2382 if(target_hour > 0)
2383 target_hour--;
2384 else
2385 target_hour = 9;
2386 else if(cursorpos == 4)
2387 if(target_minute > 0)
2388 target_minute--;
2389 else
2390 target_minute = 59;
2391 else
2392 if(target_second > 0)
2393 target_second--;
2394 else
2395 target_second = 59;
2396 }
2397 break;
2398
2399 case BUTTON_LEFT: /* move cursor */
2400 if(cursorpos > 3)
2401 cursorpos--;
2402 else
2403 cursorpos = 5;
2404 break;
2405
2406 case BUTTON_RIGHT: /* move cursor */
2407 if(cursorpos < 5)
2408 cursorpos++;
2409 else
2410 cursorpos = 3;
2411 break;
2412
2413 case BUTTON_PLAY: /* toggle */
2414 if(cursorpos == 1)
2415 counting_up = true;
2416 if(cursorpos == 2)
2417 counting_up = false;
2418 if(cursorpos >= 3 && cursorpos <= 5)
2419 {
2420 cursorpos = 2;
2421 counting_up = false;
2422 }
2423 break;
2424 }
2425 }
2089} 2426}
2090 2427
2091/********************************************************************** 2428/**********************************************************************
@@ -2150,11 +2487,18 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2150 { 2487 {
2151 rb->lcd_clear_display(); 2488 rb->lcd_clear_display();
2152 2489
2490 /* flash counter if needed */
2491 if(!counting && displayed_value != 0)
2492 display_counter = !display_counter;
2493 else
2494 display_counter = true;
2495
2496 /* and then print it */
2153 show_counter(); 2497 show_counter();
2154 2498
2155 /************** 2499 /*************
2156 * Analog Mode 2500 * Analog Mode
2157 **************/ 2501 ************/
2158 if(settings.clock == 1) 2502 if(settings.clock == 1)
2159 { 2503 {
2160 /* Second hand */ 2504 /* Second hand */
@@ -2232,9 +2576,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2232 2576
2233 2577
2234 } 2578 }
2235 /*************** 2579 /**************
2236 * Digital mode 2580 * Digital mode
2237 ***************/ 2581 *************/
2238 else if(settings.clock == 2) 2582 else if(settings.clock == 2)
2239 { 2583 {
2240 if(settings.digital_blinkcolon) 2584 if(settings.digital_blinkcolon)
@@ -2242,9 +2586,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2242 else 2586 else
2243 draw_7seg_time(hour, minute, 8, 16, 16, 32, true, false); 2587 draw_7seg_time(hour, minute, 8, 16, 16, 32, true, false);
2244 } 2588 }
2245 /*********** 2589 /**********
2246 * LCD mode 2590 * LCD mode
2247 ***********/ 2591 *********/
2248 else if(settings.clock == 3) 2592 else if(settings.clock == 3)
2249 { 2593 {
2250 if(settings.lcd_blinkcolon) 2594 if(settings.lcd_blinkcolon)
@@ -2252,9 +2596,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2252 else 2596 else
2253 draw_7seg_time(hour, minute, 8, 16, 16, 32, true, true); 2597 draw_7seg_time(hour, minute, 8, 16, 16, 32, true, true);
2254 } 2598 }
2255 /****************** 2599 /*****************
2256 * Fullscreen mode 2600 * Fullscreen mode
2257 ******************/ 2601 ****************/
2258 else if(settings.clock == 4) 2602 else if(settings.clock == 4)
2259 { 2603 {
2260 /* Second hand */ 2604 /* Second hand */
@@ -2320,9 +2664,9 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2320 (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)-3); 2664 (LCD_WIDTH/2)+1, (LCD_HEIGHT/2)-3);
2321 rb->lcd_drawpixel(LCD_WIDTH/2, LCD_HEIGHT/2); 2665 rb->lcd_drawpixel(LCD_WIDTH/2, LCD_HEIGHT/2);
2322 } 2666 }
2323 /************** 2667 /*************
2324 * Binary mode 2668 * Binary mode
2325 **************/ 2669 ************/
2326 else 2670 else
2327 { 2671 {
2328 binary(hour, minute, second); 2672 binary(hour, minute, second);
@@ -2339,26 +2683,28 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
2339 2683
2340 rb->lcd_update(); 2684 rb->lcd_update();
2341 2685
2342 /************************** 2686 /*************************
2343 * Scan for button presses 2687 * Scan for button presses
2344 **************************/ 2688 ************************/
2345 switch (rb->button_get_w_tmo(HZ/10)) 2689 switch (rb->button_get_w_tmo(HZ/10))
2346 { 2690 {
2347 case BUTTON_OFF: /* save and exit */ 2691 case BUTTON_OFF: /* save and exit */
2348 save_settings(); 2692 quit(true);
2349 rb->backlight_set_timeout(rb->global_settings->backlight_timeout);
2350 return PLUGIN_OK;
2351 break; 2693 break;
2352 2694
2353 case BUTTON_ON: /* credit roll */ 2695 case BUTTON_ON | BUTTON_REL: /* credit roll */
2354 show_credits(); 2696 show_credits();
2355 break; 2697 break;
2356 2698
2357 case BUTTON_F1: /* help */ 2699 case BUTTON_ON | BUTTON_F2: /* counter options */
2700 counter_options();
2701 break;
2702
2703 case BUTTON_F1 | BUTTON_REL: /* help */
2358 f1_screen(); 2704 f1_screen();
2359 break; 2705 break;
2360 2706
2361 case BUTTON_F2|BUTTON_REL: /* start/stop counter */ 2707 case BUTTON_F2 | BUTTON_REL: /* start/stop counter */
2362 if(settings.clock != 5) 2708 if(settings.clock != 5)
2363 { 2709 {
2364 /* Ignore if the counter was reset */ 2710 /* Ignore if the counter was reset */