2004-04-16 09:28:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Mike Holden
|
|
|
|
*
|
|
|
|
* All files in this archive are subject to the GNU General Public License.
|
|
|
|
* See the file COPYING in the source tree root for full license agreement.
|
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#define LAP_LINES 6
|
|
|
|
#define TIMER_Y 1
|
|
|
|
#else
|
|
|
|
#define LAP_LINES 1
|
|
|
|
#define TIMER_Y 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LAP_Y TIMER_Y+1
|
|
|
|
#define MAX_LAPS 10
|
|
|
|
#define MAX_SCROLL (MAX_LAPS - LAP_LINES)
|
|
|
|
|
|
|
|
static struct plugin_api* rb;
|
|
|
|
|
|
|
|
static int stopwatch = 0;
|
|
|
|
static long start_at = 0;
|
|
|
|
static int prev_total = 0;
|
|
|
|
static bool counting = false;
|
|
|
|
static int curr_lap = 0;
|
|
|
|
static int lap_scroll = 0;
|
|
|
|
static int lap_start;
|
|
|
|
static int lap_times[MAX_LAPS];
|
|
|
|
|
|
|
|
static void ticks_to_string(int ticks,int lap,int buflen, char * buf)
|
|
|
|
{
|
|
|
|
int hours, minutes, seconds, cs;
|
|
|
|
|
|
|
|
hours = ticks / (HZ * 3600);
|
|
|
|
ticks -= (HZ * hours * 3600);
|
|
|
|
minutes = ticks / (HZ * 60);
|
|
|
|
ticks -= (HZ * minutes * 60);
|
|
|
|
seconds = ticks / HZ;
|
|
|
|
ticks -= (HZ * seconds);
|
|
|
|
cs = ticks;
|
|
|
|
if (!lap)
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, buflen,
|
|
|
|
"%2d:%02d:%02d.%02d",
|
|
|
|
hours, minutes, seconds, cs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, buflen,
|
|
|
|
"%2d %2d:%02d:%02d.%02d",
|
|
|
|
lap, hours, minutes, seconds, cs);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
int button;
|
|
|
|
int lap;
|
|
|
|
int done = false;
|
2004-04-22 01:09:12 +00:00
|
|
|
bool update_lap = true;
|
2004-04-16 09:28:09 +00:00
|
|
|
|
|
|
|
TEST_PLUGIN_API(api);
|
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->lcd_setfont(FONT_UI);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
while (!done)
|
|
|
|
{
|
|
|
|
if (! counting)
|
|
|
|
{
|
|
|
|
button = rb->button_get(true);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
button = rb->button_get_w_tmo(10);
|
2004-07-12 08:10:55 +00:00
|
|
|
|
|
|
|
/* Make sure that the jukebox isn't powered off
|
|
|
|
automatically */
|
|
|
|
rb->reset_poweroff_timer();
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
switch (button)
|
|
|
|
{
|
|
|
|
|
|
|
|
/* OFF/MENU key to exit */
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_OFF:
|
|
|
|
#else
|
|
|
|
case BUTTON_MENU:
|
|
|
|
#endif
|
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* PLAY = Stop/Start toggle */
|
|
|
|
case BUTTON_PLAY:
|
|
|
|
counting = ! counting;
|
|
|
|
if (counting)
|
|
|
|
{
|
|
|
|
start_at = *rb->current_tick;
|
|
|
|
stopwatch = prev_total + *rb->current_tick - start_at;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
prev_total += *rb->current_tick - start_at;
|
|
|
|
stopwatch = prev_total;
|
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* LEFT = Reset timer */
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#else
|
|
|
|
case BUTTON_STOP:
|
|
|
|
#endif
|
|
|
|
if (!counting)
|
|
|
|
{
|
|
|
|
prev_total = 0;
|
|
|
|
curr_lap = 0;
|
2004-04-22 01:09:12 +00:00
|
|
|
update_lap = true;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
break;
|
|
|
|
|
|
|
|
/* ON = Lap timer */
|
|
|
|
case BUTTON_ON:
|
|
|
|
lap_times[curr_lap%MAX_LAPS] = stopwatch;
|
|
|
|
curr_lap++;
|
2004-04-22 01:09:12 +00:00
|
|
|
update_lap = true;
|
2004-04-16 09:28:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* UP (RIGHT/+) = Scroll Lap timer up */
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_UP:
|
|
|
|
#else
|
|
|
|
case BUTTON_RIGHT:
|
|
|
|
#endif
|
|
|
|
if (lap_scroll > 0)
|
2004-04-22 01:09:12 +00:00
|
|
|
{
|
2004-04-16 09:28:09 +00:00
|
|
|
lap_scroll --;
|
2004-04-22 01:09:12 +00:00
|
|
|
update_lap = true;
|
|
|
|
}
|
2004-04-16 09:28:09 +00:00
|
|
|
break;
|
|
|
|
|
|
|
|
/* DOWN (LEFT/-) = Scroll Lap timer down */
|
|
|
|
#ifdef HAVE_RECORDER_KEYPAD
|
|
|
|
case BUTTON_DOWN:
|
|
|
|
#else
|
|
|
|
case BUTTON_LEFT:
|
|
|
|
#endif
|
|
|
|
if ((lap_scroll < curr_lap - LAP_LINES) &&
|
|
|
|
(lap_scroll < MAX_SCROLL) )
|
|
|
|
{
|
|
|
|
lap_scroll ++;
|
2004-04-22 01:09:12 +00:00
|
|
|
update_lap = true;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
break;
|
2004-04-22 01:09:12 +00:00
|
|
|
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
rb->usb_screen();
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (counting)
|
|
|
|
{
|
|
|
|
stopwatch = prev_total + *rb->current_tick - start_at;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
stopwatch = prev_total;
|
|
|
|
}
|
|
|
|
|
|
|
|
ticks_to_string(stopwatch,0,32,buf);
|
|
|
|
rb->lcd_puts(0, TIMER_Y, buf);
|
|
|
|
|
2004-04-22 01:09:12 +00:00
|
|
|
if(update_lap)
|
2004-04-16 09:28:09 +00:00
|
|
|
{
|
2004-04-22 01:09:12 +00:00
|
|
|
lap_start = curr_lap - lap_scroll;
|
|
|
|
for (lap = lap_start; lap > lap_start - LAP_LINES; lap--)
|
2004-04-16 09:28:09 +00:00
|
|
|
{
|
2004-04-22 01:09:12 +00:00
|
|
|
if (lap > 0)
|
|
|
|
{
|
|
|
|
ticks_to_string(lap_times[(lap-1)%MAX_LAPS],lap,32,buf);
|
|
|
|
rb->lcd_puts_scroll(0, LAP_Y + lap_start - lap, buf);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->lcd_puts(0, LAP_Y + lap_start - lap,
|
|
|
|
" ");
|
|
|
|
}
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
2004-04-22 01:09:12 +00:00
|
|
|
update_lap = false;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
|
2004-04-16 09:57:07 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2004-04-16 09:28:09 +00:00
|
|
|
rb->lcd_update();
|
2004-04-16 09:57:07 +00:00
|
|
|
#endif
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|