1 /***************************************************************************
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
10 * Copyright (C) 2004 Mike Holden
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
18 ****************************************************************************/
22 #ifdef HAVE_LCD_BITMAP
30 #define LAP_Y TIMER_Y+1
32 #define MAX_SCROLL (MAX_LAPS - LAP_LINES)
34 /* variable button definitions */
35 #if CONFIG_KEYPAD == RECORDER_PAD
36 #define STOPWATCH_QUIT BUTTON_OFF
37 #define STOPWATCH_START_STOP BUTTON_PLAY
38 #define STOPWATCH_RESET_TIMER BUTTON_LEFT
39 #define STOPWATCH_LAP_TIMER BUTTON_ON
40 #define STOPWATCH_SCROLL_UP BUTTON_UP
41 #define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
42 #elif CONFIG_KEYPAD == ONDIO_PAD
43 #define STOPWATCH_QUIT BUTTON_OFF
44 #define STOPWATCH_START_STOP BUTTON_RIGHT
45 #define STOPWATCH_RESET_TIMER BUTTON_LEFT
46 #define STOPWATCH_LAP_TIMER BUTTON_MENU
47 #define STOPWATCH_SCROLL_UP BUTTON_UP
48 #define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
49 #elif CONFIG_KEYPAD == PLAYER_PAD
50 #define STOPWATCH_QUIT BUTTON_MENU
51 #define STOPWATCH_START_STOP BUTTON_PLAY
52 #define STOPWATCH_RESET_TIMER BUTTON_STOP
53 #define STOPWATCH_LAP_TIMER BUTTON_ON
54 #define STOPWATCH_SCROLL_UP BUTTON_RIGHT
55 #define STOPWATCH_SCROLL_DOWN BUTTON_LEFT
58 static struct plugin_api
* rb
;
60 static int stopwatch
= 0;
61 static long start_at
= 0;
62 static int prev_total
= 0;
63 static bool counting
= false;
64 static int curr_lap
= 0;
65 static int lap_scroll
= 0;
67 static int lap_times
[MAX_LAPS
];
69 static void ticks_to_string(int ticks
,int lap
,int buflen
, char * buf
)
71 int hours
, minutes
, seconds
, cs
;
73 hours
= ticks
/ (HZ
* 3600);
74 ticks
-= (HZ
* hours
* 3600);
75 minutes
= ticks
/ (HZ
* 60);
76 ticks
-= (HZ
* minutes
* 60);
78 ticks
-= (HZ
* seconds
);
82 rb
->snprintf(buf
, buflen
,
84 hours
, minutes
, seconds
, cs
);
88 rb
->snprintf(buf
, buflen
,
89 "%2d %2d:%02d:%02d.%02d",
90 lap
, hours
, minutes
, seconds
, cs
);
94 enum plugin_status
plugin_start(struct plugin_api
* api
, void* parameter
)
100 bool update_lap
= true;
102 TEST_PLUGIN_API(api
);
106 #ifdef HAVE_LCD_BITMAP
107 rb
->lcd_setfont(FONT_UI
);
110 rb
->lcd_clear_display();
116 stopwatch
= prev_total
+ *rb
->current_tick
- start_at
;
120 stopwatch
= prev_total
;
123 ticks_to_string(stopwatch
,0,32,buf
);
124 rb
->lcd_puts(0, TIMER_Y
, buf
);
128 lap_start
= curr_lap
- lap_scroll
;
129 for (lap
= lap_start
; lap
> lap_start
- LAP_LINES
; lap
--)
133 ticks_to_string(lap_times
[(lap
-1)%MAX_LAPS
],lap
,32,buf
);
134 rb
->lcd_puts_scroll(0, LAP_Y
+ lap_start
- lap
, buf
);
138 rb
->lcd_puts(0, LAP_Y
+ lap_start
- lap
,
145 #ifdef HAVE_LCD_BITMAP
151 button
= rb
->button_get(true);
155 button
= rb
->button_get_w_tmo(10);
157 /* Make sure that the jukebox isn't powered off
159 rb
->reset_poweroff_timer();
169 /* Stop/Start toggle */
170 case STOPWATCH_START_STOP
:
171 counting
= ! counting
;
174 start_at
= *rb
->current_tick
;
175 stopwatch
= prev_total
+ *rb
->current_tick
- start_at
;
179 prev_total
+= *rb
->current_tick
- start_at
;
180 stopwatch
= prev_total
;
185 case STOPWATCH_RESET_TIMER
:
195 case STOPWATCH_LAP_TIMER
:
196 lap_times
[curr_lap
%MAX_LAPS
] = stopwatch
;
201 /* Scroll Lap timer up */
202 case STOPWATCH_SCROLL_UP
:
210 /* Scroll Lap timer down */
211 case STOPWATCH_SCROLL_DOWN
:
212 if ((lap_scroll
< curr_lap
- LAP_LINES
) &&
213 (lap_scroll
< MAX_SCROLL
) )
221 if (rb
->default_event_handler(button
) == SYS_USB_CONNECTED
)
222 return PLUGIN_USB_CONNECTED
;