2004-04-16 09:28:09 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
* Copyright (C) 2004 Mike Holden
|
|
|
|
*
|
2008-06-28 18:10:04 +00:00
|
|
|
* This program is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU General Public License
|
|
|
|
* as published by the Free Software Foundation; either version 2
|
|
|
|
* of the License, or (at your option) any later version.
|
2004-04-16 09:28:09 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
|
2006-01-15 18:20:18 +00:00
|
|
|
PLUGIN_HEADER
|
|
|
|
|
2004-04-16 09:28:09 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
#define TIMER_Y 1
|
|
|
|
#else
|
|
|
|
#define TIMER_Y 0
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#define LAP_Y TIMER_Y+1
|
2007-04-26 13:52:53 +00:00
|
|
|
#define MAX_LAPS 64
|
2004-04-16 09:28:09 +00:00
|
|
|
|
2009-05-27 20:31:07 +00:00
|
|
|
#define STOPWATCH_FILE PLUGIN_APPS_DIR "/stopwatch.dat"
|
2008-06-28 21:01:08 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* variable button definitions */
|
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_OFF
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_ON
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
2007-01-14 13:48:09 +00:00
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2007-01-14 13:48:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == ARCHOS_AV300_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_OFF
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_ON
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
2004-10-16 00:07:43 +00:00
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_OFF
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_MENU
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
#elif CONFIG_KEYPAD == PLAYER_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_MENU
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_STOP
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_ON
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_LEFT
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2005-06-29 12:47:24 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
2005-02-04 12:41:09 +00:00
|
|
|
#define STOPWATCH_QUIT BUTTON_OFF
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_DOWN
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_ON
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_LEFT
|
2006-06-30 16:43:47 +00:00
|
|
|
#define STOPWATCH_RC_QUIT BUTTON_RC_STOP
|
|
|
|
|
2006-02-24 20:54:09 +00:00
|
|
|
#elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \
|
2007-07-27 09:57:27 +00:00
|
|
|
(CONFIG_KEYPAD == IPOD_3G_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IPOD_1G2G_PAD)
|
2005-12-14 01:31:37 +00:00
|
|
|
#define STOPWATCH_QUIT BUTTON_MENU
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_SCROLL_FWD
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_SCROLL_BACK
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2006-01-12 00:35:50 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_PLAY
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_MODE
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_EQ
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_SELECT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-01-18 11:09:06 +00:00
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_REC
|
2006-02-24 15:06:25 +00:00
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_SELECT
|
2006-01-18 11:09:06 +00:00
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2006-02-24 15:42:52 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
2007-05-19 23:38:09 +00:00
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
2006-02-24 15:42:52 +00:00
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
2007-05-19 23:38:09 +00:00
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_A
|
2006-02-24 15:42:52 +00:00
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_MENU
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2008-12-12 19:50:49 +00:00
|
|
|
|
2007-09-20 10:49:48 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
|
2008-12-12 19:50:49 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_C200_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_M200_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
2007-09-20 10:49:48 +00:00
|
|
|
#define STOPWATCH_START_STOP BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
2006-10-26 13:38:09 +00:00
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_SELECT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2008-12-12 19:50:49 +00:00
|
|
|
|
2009-01-04 23:33:15 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
|
2009-04-10 17:28:26 +00:00
|
|
|
#define STOPWATCH_QUIT (BUTTON_HOME|BUTTON_REPEAT)
|
2009-01-04 23:33:15 +00:00
|
|
|
#define STOPWATCH_START_STOP BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_SELECT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_SCROLL_BACK
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_SCROLL_FWD
|
|
|
|
|
2006-08-03 20:17:25 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_REW
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_FF
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_SCROLL_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_SCROLL_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2007-10-23 15:40:51 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_BACK
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_MENU
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_SELECT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE100_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_DISPLAY
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_MENU
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_RC_REC
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_RC_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_RC_REW
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_RC_FF
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_RC_VOL_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_RC_VOL_DOWN
|
|
|
|
#define STOPWATCH_RC_QUIT BUTTON_REC
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-03-22 22:03:34 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWOND2_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-10-07 16:38:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_MENU
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_STOP
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_VOLUP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_VOLDOWN
|
|
|
|
#define STOPWATCH_RC_QUIT BUTTON_POWER
|
2009-01-24 22:41:55 +00:00
|
|
|
|
2008-12-04 21:28:56 +00:00
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_BACK
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
2008-12-08 09:51:42 +00:00
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_SELECT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_CUSTOM
|
2008-12-04 21:28:56 +00:00
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
2009-01-24 22:41:55 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_SELECT
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_MENU
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_VIEW
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
|
|
|
|
2009-04-07 23:41:44 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_POWER
|
|
|
|
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
|
|
|
|
#define STOPWATCH_QUIT BUTTON_REC
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_PLAY
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_LEFT
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_RIGHT
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_UP
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_DOWN
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2004-10-16 00:07:43 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef STOPWATCH_QUIT
|
|
|
|
#define STOPWATCH_QUIT BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef STOPWATCH_START_STOP
|
|
|
|
#define STOPWATCH_START_STOP BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#ifndef STOPWATCH_RESET_TIMER
|
|
|
|
#define STOPWATCH_RESET_TIMER BUTTON_MIDRIGHT
|
|
|
|
#endif
|
|
|
|
#ifndef STOPWATCH_LAP_TIMER
|
|
|
|
#define STOPWATCH_LAP_TIMER BUTTON_MIDLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef STOPWATCH_SCROLL_UP
|
|
|
|
#define STOPWATCH_SCROLL_UP BUTTON_TOPMIDDLE
|
|
|
|
#endif
|
|
|
|
#ifndef STOPWATCH_SCROLL_DOWN
|
|
|
|
#define STOPWATCH_SCROLL_DOWN BUTTON_BOTTOMMIDDLE
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
|
2004-04-16 09:28:09 +00:00
|
|
|
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
|
|
|
|
{
|
2007-04-26 13:52:53 +00:00
|
|
|
|
|
|
|
if (lap > 1)
|
|
|
|
{
|
|
|
|
int last_ticks, last_hours, last_minutes, last_seconds, last_cs;
|
|
|
|
last_ticks = lap_times[(lap-1)%MAX_LAPS] - lap_times[(lap-2)%MAX_LAPS];
|
|
|
|
last_hours = last_ticks / (HZ * 3600);
|
|
|
|
last_ticks -= (HZ * last_hours * 3600);
|
|
|
|
last_minutes = last_ticks / (HZ * 60);
|
|
|
|
last_ticks -= (HZ * last_minutes * 60);
|
|
|
|
last_seconds = last_ticks / HZ;
|
|
|
|
last_ticks -= (HZ * last_seconds);
|
|
|
|
last_cs = last_ticks;
|
|
|
|
|
|
|
|
rb->snprintf(buf, buflen,
|
|
|
|
"%2d %2d:%02d:%02d.%02d [%2d:%02d:%02d.%02d]",
|
|
|
|
lap, hours, minutes, seconds, cs, last_hours,
|
|
|
|
last_minutes, last_seconds, last_cs);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->snprintf(buf, buflen,
|
|
|
|
"%2d %2d:%02d:%02d.%02d",
|
|
|
|
lap, hours, minutes, seconds, cs);
|
|
|
|
}
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2008-06-28 21:01:08 +00:00
|
|
|
/*
|
|
|
|
* Load saved stopwatch state, if exists.
|
|
|
|
*/
|
|
|
|
void load_stopwatch(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = rb->open(STOPWATCH_FILE, O_RDONLY);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* variable stopwatch isn't saved/loaded, because it is only used
|
|
|
|
* temporarily in main loop
|
|
|
|
*/
|
|
|
|
|
|
|
|
rb->read(fd, &start_at, sizeof(start_at));
|
|
|
|
rb->read(fd, &prev_total, sizeof(prev_total));
|
|
|
|
rb->read(fd, &counting, sizeof(counting));
|
|
|
|
rb->read(fd, &curr_lap, sizeof(curr_lap));
|
|
|
|
rb->read(fd, &lap_scroll, sizeof(lap_scroll));
|
|
|
|
rb->read(fd, &lap_start, sizeof(lap_start));
|
|
|
|
rb->read(fd, lap_times, sizeof(lap_times));
|
|
|
|
|
|
|
|
if (counting && start_at > *rb->current_tick)
|
|
|
|
{
|
|
|
|
/* Stopwatch started in the future? Unlikely; probably started on a
|
|
|
|
* previous session and powered off in-between. We'll keep
|
|
|
|
* everything intact (user can clear manually) but stop the
|
|
|
|
* stopwatch to avoid negative timing.
|
|
|
|
*/
|
|
|
|
start_at = 0;
|
|
|
|
counting = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Save stopwatch state.
|
|
|
|
*/
|
|
|
|
void save_stopwatch(void)
|
|
|
|
{
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
fd = rb->open(STOPWATCH_FILE, O_CREAT|O_WRONLY|O_TRUNC);
|
|
|
|
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
/* variable stopwatch isn't saved/loaded, because it is only used
|
|
|
|
* temporarily in main loop
|
|
|
|
*/
|
|
|
|
|
|
|
|
rb->write(fd, &start_at, sizeof(start_at));
|
|
|
|
rb->write(fd, &prev_total, sizeof(prev_total));
|
|
|
|
rb->write(fd, &counting, sizeof(counting));
|
|
|
|
rb->write(fd, &curr_lap, sizeof(curr_lap));
|
|
|
|
rb->write(fd, &lap_scroll, sizeof(lap_scroll));
|
|
|
|
rb->write(fd, &lap_start, sizeof(lap_start));
|
|
|
|
rb->write(fd, lap_times, sizeof(lap_times));
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2004-04-16 09:28:09 +00:00
|
|
|
{
|
|
|
|
char buf[32];
|
|
|
|
int button;
|
|
|
|
int lap;
|
|
|
|
int done = false;
|
2004-04-22 01:09:12 +00:00
|
|
|
bool update_lap = true;
|
2007-04-26 14:02:10 +00:00
|
|
|
int lines;
|
2004-04-16 09:28:09 +00:00
|
|
|
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-26 14:02:10 +00:00
|
|
|
int h;
|
2004-04-16 09:28:09 +00:00
|
|
|
rb->lcd_setfont(FONT_UI);
|
2007-04-26 13:52:53 +00:00
|
|
|
rb->lcd_getstringsize("M", NULL, &h);
|
|
|
|
lines = (LCD_HEIGHT / h) - (LAP_Y);
|
|
|
|
#else
|
|
|
|
lines = 1;
|
2004-04-16 09:28:09 +00:00
|
|
|
#endif
|
|
|
|
|
2008-06-28 21:01:08 +00:00
|
|
|
load_stopwatch();
|
|
|
|
|
2004-04-16 09:28:09 +00:00
|
|
|
rb->lcd_clear_display();
|
2007-04-26 13:52:53 +00:00
|
|
|
|
2004-04-16 09:28:09 +00:00
|
|
|
while (!done)
|
|
|
|
{
|
2004-12-03 07:36:11 +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);
|
|
|
|
|
|
|
|
if(update_lap)
|
|
|
|
{
|
|
|
|
lap_start = curr_lap - lap_scroll;
|
2007-04-26 13:52:53 +00:00
|
|
|
for (lap = lap_start; lap > lap_start - lines; lap--)
|
2004-12-03 07:36:11 +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,
|
|
|
|
" ");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
update_lap = false;
|
|
|
|
}
|
|
|
|
|
|
|
|
rb->lcd_update();
|
|
|
|
|
2004-04-16 09:28:09 +00:00
|
|
|
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)
|
|
|
|
{
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* exit */
|
2006-06-30 16:43:47 +00:00
|
|
|
#ifdef STOPWATCH_RC_QUIT
|
|
|
|
case STOPWATCH_RC_QUIT:
|
|
|
|
#endif
|
2004-10-16 00:07:43 +00:00
|
|
|
case STOPWATCH_QUIT:
|
2008-06-28 21:01:08 +00:00
|
|
|
save_stopwatch();
|
2004-04-16 09:28:09 +00:00
|
|
|
done = true;
|
|
|
|
break;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* Stop/Start toggle */
|
|
|
|
case STOPWATCH_START_STOP:
|
2004-04-16 09:28:09 +00:00
|
|
|
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;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* Reset timer */
|
|
|
|
case STOPWATCH_RESET_TIMER:
|
2004-04-16 09:28:09 +00:00
|
|
|
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;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* Lap timer */
|
|
|
|
case STOPWATCH_LAP_TIMER:
|
2004-04-16 09:28:09 +00:00
|
|
|
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;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* Scroll Lap timer up */
|
|
|
|
case STOPWATCH_SCROLL_UP:
|
2004-04-16 09:28:09 +00:00
|
|
|
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;
|
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
/* Scroll Lap timer down */
|
|
|
|
case STOPWATCH_SCROLL_DOWN:
|
2007-04-26 13:52:53 +00:00
|
|
|
if ((lap_scroll < curr_lap - lines) &&
|
|
|
|
(lap_scroll < (MAX_LAPS - lines)) )
|
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;
|
2004-04-22 01:09:12 +00:00
|
|
|
|
2004-10-16 00:07:43 +00:00
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
break;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|
|
|
|
}
|
2004-10-18 06:16:11 +00:00
|
|
|
return PLUGIN_OK;
|
2004-04-16 09:28:09 +00:00
|
|
|
}
|