2006-01-25 18:35:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Alexander Spyridakis, Hristo Kovachev
|
|
|
|
*
|
|
|
|
* 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.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
#ifndef SIMULATOR /* not for the simulator */
|
|
|
|
|
|
|
|
#include "plugin.h"
|
|
|
|
PLUGIN_HEADER
|
|
|
|
|
|
|
|
#define BATTERY_LOG "/battery_bench.txt"
|
|
|
|
#define BUF_SIZE 16000
|
|
|
|
#define DISK_SPINDOWN_TIMEOUT 3600
|
|
|
|
|
|
|
|
#define EV_EXIT 1337
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
/* seems to work with 1300, but who knows... */
|
2006-11-27 02:16:32 +00:00
|
|
|
#define THREAD_STACK_SIZE DEFAULT_STACK_SIZE + 0x200
|
2006-02-07 14:46:03 +00:00
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
#if CONFIG_KEYPAD == RECORDER_PAD
|
2006-05-13 07:41:12 +00:00
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
2006-01-25 18:35:36 +00:00
|
|
|
#define BATTERY_OFF BUTTON_OFF
|
2006-11-27 02:16:32 +00:00
|
|
|
|
|
|
|
#if BUTTON_REMOTE != 0
|
|
|
|
#define BATTERY_RC_ON BUTTON_RC_PLAY
|
2006-05-13 07:41:12 +00:00
|
|
|
#define BATTERY_RC_OFF BUTTON_RC_STOP
|
2006-11-27 02:16:32 +00:00
|
|
|
#endif
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == ONDIO_PAD
|
2006-05-13 07:41:12 +00:00
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
#define BATTERY_ON BUTTON_RIGHT
|
|
|
|
#define BATTERY_OFF BUTTON_OFF
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == PLAYER_PAD
|
2006-05-13 07:41:12 +00:00
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
|
|
|
#define BATTERY_RC_ON BUTTON_RC_PLAY
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
#define BATTERY_OFF BUTTON_STOP
|
2006-05-13 07:41:12 +00:00
|
|
|
#define BATTERY_RC_OFF BUTTON_RC_STOP
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
#elif (CONFIG_KEYPAD == IRIVER_H100_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == IRIVER_H300_PAD)
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_ON
|
|
|
|
#define BATTERY_RC_ON BUTTON_RC_ON
|
|
|
|
|
|
|
|
#define BATTERY_OFF BUTTON_OFF
|
|
|
|
#define BATTERY_RC_OFF BUTTON_RC_STOP
|
2006-01-25 20:57:13 +00:00
|
|
|
|
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)
|
2006-01-25 20:57:13 +00:00
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
|
|
|
#define BATTERY_OFF BUTTON_MENU
|
|
|
|
|
2007-03-16 23:02:39 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD
|
2006-03-30 21:17:19 +00:00
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_PLAY
|
|
|
|
|
2006-02-03 23:16:24 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_PLAY
|
|
|
|
|
2006-10-26 13:38:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == SANSA_E200_PAD
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
|
2006-08-20 23:05:47 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_H10_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
2006-12-05 10:09:07 +00:00
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
2006-08-20 23:05:47 +00:00
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
/****************************** Plugin Entry Point ****************************/
|
2006-01-25 18:35:36 +00:00
|
|
|
static struct plugin_api* rb;
|
2007-06-13 15:35:07 +00:00
|
|
|
MEM_FUNCTION_WRAPPERS(rb);
|
2006-01-25 18:35:36 +00:00
|
|
|
int main(void);
|
2006-10-31 11:17:00 +00:00
|
|
|
bool exit_tsr(bool);
|
2006-01-25 18:35:36 +00:00
|
|
|
void thread(void);
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
rb = api;
|
|
|
|
|
|
|
|
return main();
|
|
|
|
}
|
|
|
|
|
2006-12-21 02:33:01 +00:00
|
|
|
bool thread_stopped = false;
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
/* Struct for battery information */
|
|
|
|
struct batt_info
|
|
|
|
{
|
|
|
|
int ticks, level, eta;
|
|
|
|
unsigned int voltage;
|
2006-02-07 14:46:03 +00:00
|
|
|
} bat[BUF_SIZE/sizeof(struct batt_info)];
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
struct event_queue thread_q;
|
|
|
|
|
2006-10-31 11:17:00 +00:00
|
|
|
bool exit_tsr(bool reenter)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
2006-10-31 11:17:00 +00:00
|
|
|
bool exit = true;
|
|
|
|
(void)reenter;
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running.");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "Press OFF to cancel the test");
|
2006-10-31 11:34:46 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_puts_scroll(0, 2, "Anything else will resume");
|
2006-10-31 11:34:46 +00:00
|
|
|
#endif
|
2007-04-06 22:55:00 +00:00
|
|
|
rb->lcd_update();
|
|
|
|
|
2006-10-31 11:17:00 +00:00
|
|
|
if (rb->button_get(true) != BATTERY_OFF)
|
|
|
|
exit = false;
|
|
|
|
if (exit)
|
|
|
|
{
|
2006-12-19 16:50:07 +00:00
|
|
|
rb->queue_post(&thread_q, EV_EXIT, 0);
|
2006-12-21 02:33:01 +00:00
|
|
|
while (!thread_stopped)
|
2006-10-31 11:17:00 +00:00
|
|
|
rb->yield();
|
|
|
|
/* remove the thread's queue from the broadcast list */
|
|
|
|
rb->queue_delete(&thread_q);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
2006-01-25 18:35:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
#define BIT_CHARGER 0x1000
|
|
|
|
#define BIT_CHARGING 0x2000
|
|
|
|
#define BIT_USB_POWER 0x4000
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
#define HMS(x) (x)/3600,((x)%3600)/60,((x)%3600)%60
|
2006-02-07 14:46:03 +00:00
|
|
|
|
|
|
|
/* use long for aligning */
|
|
|
|
unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)];
|
|
|
|
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2006-02-07 14:46:03 +00:00
|
|
|
unsigned int charge_state(void)
|
|
|
|
{
|
|
|
|
unsigned int ret = 0;
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2006-02-07 14:46:03 +00:00
|
|
|
if(rb->charger_inserted())
|
|
|
|
ret = BIT_CHARGER;
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING == CHARGING_MONITOR
|
2006-02-07 14:46:03 +00:00
|
|
|
if(rb->charging_state())
|
|
|
|
ret |= BIT_CHARGING;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
if(rb->usb_powered())
|
|
|
|
ret |= BIT_USB_POWER;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
void thread(void)
|
|
|
|
{
|
|
|
|
bool got_info = false, timeflag = false, in_usb_mode = false;
|
|
|
|
int fd, buffelements, tick = 1, i = 0, skipped = 0, exit = 0;
|
|
|
|
int fst = 0, lst = 0; /* first and last skipped tick */
|
|
|
|
unsigned int last_voltage = 0;
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2006-02-07 14:46:03 +00:00
|
|
|
unsigned int last_state = 0;
|
|
|
|
#endif
|
2007-08-01 08:50:44 +00:00
|
|
|
long sleep_time = 5 * HZ;
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
struct event ev;
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
buffelements = sizeof(bat)/sizeof(struct batt_info);
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2007-08-01 08:50:44 +00:00
|
|
|
#ifndef HAVE_FLASH_STORAGE
|
|
|
|
if(rb->global_settings->disk_spindown > 1)
|
|
|
|
sleep_time = (rb->global_settings->disk_spindown - 1) * HZ;
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
if(!in_usb_mode && got_info &&
|
|
|
|
(exit || timeflag || rb->ata_disk_is_active()) )
|
|
|
|
{
|
|
|
|
int last, secs, j, temp = skipped;
|
|
|
|
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND);
|
|
|
|
if(fd < 0)
|
|
|
|
exit = 1;
|
|
|
|
else
|
|
|
|
{
|
|
|
|
do
|
|
|
|
{
|
|
|
|
if(skipped)
|
|
|
|
{
|
|
|
|
last = buffelements;
|
|
|
|
fst /= HZ;
|
|
|
|
lst /= HZ;
|
|
|
|
rb->fdprintf(fd,"-Skipped %d measurements from "
|
|
|
|
"%02d:%02d:%02d to %02d:%02d:%02d-\n",skipped,
|
|
|
|
HMS(fst),HMS(lst));
|
|
|
|
skipped = 0;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
last = i;
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(j = i; j < last; j++)
|
|
|
|
{
|
|
|
|
secs = bat[j].ticks/HZ;
|
|
|
|
rb->fdprintf(fd,
|
|
|
|
"%02d:%02d:%02d, %05d, %03d%%, "
|
2006-02-07 14:46:03 +00:00
|
|
|
"%02d:%02d, %04d, %04d"
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2006-02-07 14:46:03 +00:00
|
|
|
", %c"
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING == CHARGING_MONITOR
|
2006-02-07 14:46:03 +00:00
|
|
|
", %c"
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
", %c"
|
|
|
|
#endif
|
|
|
|
"\n",
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
HMS(secs), secs, bat[j].level,
|
|
|
|
bat[j].eta / 60, bat[j].eta % 60,
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2006-02-07 14:46:03 +00:00
|
|
|
(bat[j].voltage &
|
|
|
|
(~(BIT_CHARGER|BIT_CHARGING|BIT_USB_POWER)))
|
|
|
|
*10,
|
|
|
|
#else
|
|
|
|
bat[j].voltage * 10,
|
|
|
|
#endif
|
|
|
|
temp + 1 + (j-i)
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2006-02-07 14:46:03 +00:00
|
|
|
,(bat[j].voltage & BIT_CHARGER)?'A':'-'
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING == CHARGING_MONITOR
|
2006-02-07 14:46:03 +00:00
|
|
|
,(bat[j].voltage & BIT_CHARGING)?'C':'-'
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
,(bat[j].voltage & BIT_USB_POWER)?'U':'-'
|
|
|
|
#endif
|
|
|
|
|
|
|
|
);
|
2006-01-25 18:35:36 +00:00
|
|
|
if(!j % 100 && !j) /* yield() at every 100 writes */
|
|
|
|
rb->yield();
|
|
|
|
}
|
|
|
|
temp += j - i;
|
|
|
|
|
|
|
|
}while(i != 0);
|
|
|
|
|
|
|
|
rb->close(fd);
|
|
|
|
tick = *rb->current_tick;
|
|
|
|
got_info = false;
|
|
|
|
timeflag = false;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2006-02-07 14:46:03 +00:00
|
|
|
unsigned int current_voltage;
|
2006-01-25 20:57:13 +00:00
|
|
|
if(
|
|
|
|
#if CONFIG_CODEC == SWCODEC
|
|
|
|
!rb->pcm_is_playing()
|
|
|
|
#else
|
|
|
|
!rb->mp3_is_playing()
|
|
|
|
#endif
|
|
|
|
&& (*rb->current_tick - tick) > DISK_SPINDOWN_TIMEOUT * HZ)
|
2006-01-25 18:35:36 +00:00
|
|
|
timeflag = true;
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
if(last_voltage != (current_voltage=rb->battery_voltage())
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2006-02-07 14:46:03 +00:00
|
|
|
|| last_state != charge_state()
|
|
|
|
#endif
|
|
|
|
)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
|
|
|
if(i == buffelements)
|
|
|
|
{
|
|
|
|
if(!skipped++)
|
|
|
|
fst = bat[0].ticks;
|
|
|
|
i = 0;
|
|
|
|
}
|
|
|
|
else if(skipped)
|
|
|
|
{
|
|
|
|
skipped++;
|
|
|
|
lst = bat[i].ticks;
|
|
|
|
}
|
|
|
|
bat[i].ticks = *rb->current_tick;
|
|
|
|
bat[i].level = rb->battery_level();
|
|
|
|
bat[i].eta = rb->battery_time();
|
2006-02-07 14:46:03 +00:00
|
|
|
last_voltage = bat[i].voltage = current_voltage;
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2006-02-07 14:46:03 +00:00
|
|
|
bat[i].voltage |= last_state = charge_state();
|
|
|
|
#endif
|
|
|
|
i++;
|
2006-01-25 18:35:36 +00:00
|
|
|
got_info = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
if(exit)
|
|
|
|
{
|
|
|
|
if(exit == 2)
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ,
|
2006-02-07 14:46:03 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
"Exiting battery_bench...");
|
|
|
|
#else
|
|
|
|
"bench exit");
|
|
|
|
#endif
|
2006-12-21 02:33:01 +00:00
|
|
|
thread_stopped = true;
|
|
|
|
rb->remove_thread(NULL); /* Suicide. Never returns. */
|
2006-01-25 18:35:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
rb->queue_wait_w_tmo(&thread_q, &ev, sleep_time);
|
|
|
|
switch (ev.id)
|
|
|
|
{
|
|
|
|
case SYS_USB_CONNECTED:
|
|
|
|
in_usb_mode = true;
|
|
|
|
rb->usb_acknowledge(SYS_USB_CONNECTED_ACK);
|
|
|
|
break;
|
|
|
|
case SYS_USB_DISCONNECTED:
|
|
|
|
in_usb_mode = false;
|
|
|
|
rb->usb_acknowledge(SYS_USB_DISCONNECTED_ACK);
|
|
|
|
break;
|
|
|
|
case SYS_POWEROFF:
|
|
|
|
exit = 1;
|
|
|
|
break;
|
|
|
|
case EV_EXIT:
|
|
|
|
exit = 2;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
} while (1);
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
typedef void (*plcdfunc)(int x, int y, const unsigned char *str);
|
|
|
|
|
|
|
|
void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, int line)
|
|
|
|
{
|
|
|
|
int strwdt, strhgt;
|
|
|
|
rb->lcd_getstringsize(str, &strwdt, &strhgt);
|
|
|
|
putsxy((lcd_width - strwdt)/2, line*(strhgt), str);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
int main(void)
|
|
|
|
{
|
2006-02-07 14:46:03 +00:00
|
|
|
int button, fd;
|
2006-01-25 18:35:36 +00:00
|
|
|
bool on = false;
|
2006-02-07 16:41:29 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2007-04-06 22:55:00 +00:00
|
|
|
int i;
|
2006-02-07 14:46:03 +00:00
|
|
|
const char *msgs[] = { "Battery Benchmark","Check file", BATTERY_LOG,
|
|
|
|
"for more info", "PLAY - start", "OFF - quit" };
|
2006-02-07 16:41:29 +00:00
|
|
|
#endif
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->lcd_clear_display();
|
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
2006-02-07 14:46:03 +00:00
|
|
|
rb->lcd_clear_display();
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->lcd_setfont(FONT_SYSFIXED);
|
2006-02-07 14:46:03 +00:00
|
|
|
|
|
|
|
for(i = 0; i<(int)(sizeof(msgs)/sizeof(char *)); i++)
|
|
|
|
put_centered_str(msgs[i],rb->lcd_putsxy,LCD_WIDTH,i+1);
|
2007-04-06 22:55:00 +00:00
|
|
|
#else
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Batt.Bench.");
|
|
|
|
rb->lcd_puts_scroll(0, 1, "PLAY/STOP");
|
|
|
|
#endif
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->lcd_update();
|
2007-04-06 22:55:00 +00:00
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
#ifdef HAVE_REMOTE_LCD
|
|
|
|
rb->lcd_remote_clear_display();
|
|
|
|
put_centered_str(msgs[0],rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,0);
|
|
|
|
put_centered_str(msgs[sizeof(msgs)/sizeof(char*)-2],
|
|
|
|
rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,1);
|
|
|
|
put_centered_str(msgs[sizeof(msgs)/sizeof(char*)-1],
|
|
|
|
rb->lcd_remote_putsxy,LCD_REMOTE_WIDTH,2);
|
|
|
|
rb->lcd_remote_update();
|
|
|
|
#endif
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
do
|
|
|
|
{
|
|
|
|
button = rb->button_get(true);
|
|
|
|
switch(button)
|
|
|
|
{
|
|
|
|
case BATTERY_ON:
|
|
|
|
#ifdef BATTERY_RC_ON
|
|
|
|
case BATTERY_RC_ON:
|
|
|
|
#endif
|
|
|
|
on = true;
|
|
|
|
break;
|
|
|
|
case BATTERY_OFF:
|
|
|
|
#ifdef BATTERY_RC_OFF
|
|
|
|
case BATTERY_RC_OFF:
|
|
|
|
#endif
|
|
|
|
return PLUGIN_OK;
|
|
|
|
|
|
|
|
default: if(rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|
|
|
|
}while(!on);
|
|
|
|
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDONLY);
|
|
|
|
if(fd < 0)
|
|
|
|
{
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT);
|
|
|
|
if(fd >= 0)
|
|
|
|
{
|
|
|
|
rb->fdprintf(fd,
|
|
|
|
"This plugin will log your battery performance in a\n"
|
|
|
|
"file (%s) every time the disk is accessed (or every hour).\n"
|
|
|
|
"To properly test your battery:\n"
|
|
|
|
"1) Select and playback an album. "
|
|
|
|
"(Be sure to be more than the player's buffer)\n"
|
|
|
|
"2) Set to repeat.\n"
|
|
|
|
"3) Let the player run completely out of battery.\n"
|
|
|
|
"4) Recharge and copy (or whatever you want) the txt file to "
|
|
|
|
"your computer.\n"
|
|
|
|
"Now you can make graphs with the data of the battery log.\n"
|
|
|
|
"Do not enter another plugin during the test or else the "
|
|
|
|
"logging activity will end.\n\n"
|
|
|
|
"P.S: You can decide how you will make your tests.\n"
|
|
|
|
"Just don't open another plugin to be sure that your log "
|
|
|
|
"will continue.\n"
|
|
|
|
"M/DA (Measurements per Disk Activity) shows how many times\n"
|
|
|
|
"data was logged in the buffer between Disk Activity.\n\n"
|
|
|
|
"Battery type: %d mAh Buffer Entries: %d\n"
|
|
|
|
" Time:, Seconds:, Level:, Time Left:, Voltage[mV]:,"
|
2006-02-07 14:46:03 +00:00
|
|
|
" M/DA:"
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2006-02-07 14:46:03 +00:00
|
|
|
", C:"
|
|
|
|
#endif
|
2006-06-06 22:23:52 +00:00
|
|
|
#if CONFIG_CHARGING == CHARGING_MONITOR
|
2006-02-07 14:46:03 +00:00
|
|
|
", S:"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
", U:"
|
|
|
|
#endif
|
|
|
|
"\n"
|
2006-01-25 18:35:36 +00:00
|
|
|
,BATTERY_LOG,rb->global_settings->battery_capacity,
|
2007-03-17 09:02:53 +00:00
|
|
|
BUF_SIZE / (unsigned)sizeof(struct batt_info));
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ / 2, "Cannot create file!");
|
2006-01-25 18:35:36 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
rb->close(fd);
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_APPEND);
|
2006-02-07 14:46:03 +00:00
|
|
|
rb->fdprintf(fd, "\n--File already present. Resuming Benchmark--\n");
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->close(fd);
|
|
|
|
}
|
|
|
|
|
2006-09-16 16:18:11 +00:00
|
|
|
rb->queue_init(&thread_q, true); /* put the thread's queue in the bcast list */
|
2006-12-21 02:33:01 +00:00
|
|
|
if(rb->create_thread(thread, thread_stack,
|
2006-09-16 16:18:11 +00:00
|
|
|
sizeof(thread_stack), "Battery Benchmark"
|
2007-03-04 20:06:41 +00:00
|
|
|
IF_PRIO(, PRIORITY_BACKGROUND)
|
|
|
|
IF_COP(, CPU, false)) == NULL)
|
2006-04-05 08:33:20 +00:00
|
|
|
{
|
2007-03-16 21:56:08 +00:00
|
|
|
rb->splash(HZ, "Cannot create thread!");
|
2006-04-05 08:33:20 +00:00
|
|
|
return PLUGIN_ERROR;
|
|
|
|
}
|
|
|
|
|
2006-01-25 18:35:36 +00:00
|
|
|
rb->plugin_tsr(exit_tsr);
|
|
|
|
|
|
|
|
return PLUGIN_OK;
|
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|