2006-01-25 18:35:36 +00:00
|
|
|
/***************************************************************************
|
|
|
|
* __________ __ ___.
|
|
|
|
* Open \______ \ ____ ____ | | _\_ |__ _______ ___
|
|
|
|
* Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
|
|
|
|
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
|
|
|
|
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
|
|
|
|
* \/ \/ \/ \/ \/
|
|
|
|
* $Id$
|
|
|
|
*
|
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Alexander Spyridakis, Hristo Kovachev
|
|
|
|
*
|
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.
|
2006-01-25 18:35:36 +00:00
|
|
|
*
|
|
|
|
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
|
|
|
|
* KIND, either express or implied.
|
|
|
|
*
|
|
|
|
****************************************************************************/
|
|
|
|
|
2008-09-22 19:59:00 +00:00
|
|
|
#include "version.h"
|
2006-01-25 18:35:36 +00:00
|
|
|
#include "plugin.h"
|
|
|
|
PLUGIN_HEADER
|
|
|
|
|
|
|
|
#define BATTERY_LOG "/battery_bench.txt"
|
|
|
|
#define BUF_SIZE 16000
|
|
|
|
|
|
|
|
#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
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "OFF"
|
2006-11-27 02:16:32 +00:00
|
|
|
|
2007-10-05 13:25:35 +00:00
|
|
|
#if BUTTON_REMOTE != 0
|
2006-11-27 02:16:32 +00:00
|
|
|
#define BATTERY_RC_ON BUTTON_RC_PLAY
|
2006-05-13 07:41:12 +00:00
|
|
|
#define BATTERY_RC_OFF BUTTON_RC_STOP
|
2007-10-05 13:25:35 +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
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "RIGHT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "OFF"
|
2006-01-25 18:35:36 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == PLAYER_PAD
|
2006-05-13 07:41:12 +00:00
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
2006-01-25 18:35:36 +00:00
|
|
|
#define BATTERY_OFF BUTTON_STOP
|
2008-10-03 14:35:07 +00:00
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
|
|
|
#define BATTERY_OFF_TXT "STOP"
|
2007-10-05 11:51:34 +00:00
|
|
|
|
|
|
|
#define BATTERY_RC_ON BUTTON_RC_PLAY
|
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
|
|
|
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "STOP"
|
2007-10-05 11:51:34 +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-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "MENU"
|
2006-01-25 20:57:13 +00:00
|
|
|
|
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
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2006-03-30 21:17:19 +00:00
|
|
|
|
2006-02-03 23:16:24 +00:00
|
|
|
#elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_PLAY
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "PLAY"
|
2006-02-03 23:16:24 +00:00
|
|
|
|
2007-09-20 10:49:48 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \
|
2009-01-04 23:33:15 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_C200_PAD) || \
|
|
|
|
(CONFIG_KEYPAD == SANSA_CLIP_PAD) || \
|
2009-04-10 17:28:26 +00:00
|
|
|
(CONFIG_KEYPAD == SANSA_M200_PAD)
|
2006-10-26 13:38:09 +00:00
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2006-10-26 13:38:09 +00:00
|
|
|
|
2009-04-10 17:28:26 +00:00
|
|
|
#elif (CONFIG_KEYPAD == SANSA_FUZE_PAD)
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
2009-06-06 09:08:11 +00:00
|
|
|
#define BATTERY_OFF BUTTON_HOME
|
2009-04-10 17:28:26 +00:00
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2009-06-06 09:08:11 +00:00
|
|
|
#define BATTERY_OFF_TXT "HOME"
|
2009-04-10 17:28:26 +00:00
|
|
|
|
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
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2006-12-05 10:09:07 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
2006-08-20 23:05:47 +00:00
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
2007-10-05 11:51:34 +00:00
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2006-08-20 23:05:47 +00:00
|
|
|
|
2008-02-17 12:23:02 +00:00
|
|
|
#elif CONFIG_KEYPAD == GIGABEAT_S_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_BACK
|
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "BACK"
|
2008-02-17 12:23:02 +00:00
|
|
|
|
2007-10-23 15:40:51 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE500_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_RC_PLAY
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2007-10-23 15:40:51 +00:00
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#elif CONFIG_KEYPAD == MROBE100_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_SELECT
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
#define BATTERY_ON_TXT "SELECT - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2008-03-01 22:55:09 +00:00
|
|
|
|
2008-03-22 10:24:28 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO_M3_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
|
|
|
#define BATTERY_OFF BUTTON_REC
|
|
|
|
#define BATTERY_RC_ON BUTTON_RC_PLAY
|
|
|
|
#define BATTERY_RC_OFF BUTTON_RC_REC
|
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "REC"
|
2008-03-22 10:24:28 +00:00
|
|
|
|
2008-03-22 22:03:34 +00:00
|
|
|
#elif CONFIG_KEYPAD == COWOND2_PAD
|
|
|
|
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2008-03-22 22:03:34 +00:00
|
|
|
|
2008-09-06 17:50:59 +00:00
|
|
|
#elif CONFIG_KEYPAD == IAUDIO67_PAD
|
|
|
|
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
2008-09-06 17:50:59 +00:00
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
2008-12-04 21:28:56 +00:00
|
|
|
|
|
|
|
#elif CONFIG_KEYPAD == CREATIVEZVM_PAD
|
|
|
|
#define BATTERY_ON BUTTON_PLAY
|
|
|
|
#define BATTERY_ON_TXT "PLAY - start"
|
|
|
|
#define BATTERY_OFF BUTTON_BACK
|
|
|
|
#define BATTERY_OFF_TXT "BACK"
|
|
|
|
|
2009-01-24 22:41:55 +00:00
|
|
|
#elif CONFIG_KEYPAD == PHILIPS_HDD1630_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_MENU
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
#define BATTERY_ON_TXT "MENU - start"
|
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
|
|
|
|
2009-04-07 23:41:44 +00:00
|
|
|
#elif CONFIG_KEYPAD == ONDAVX747_PAD
|
|
|
|
|
|
|
|
#define BATTERY_OFF BUTTON_POWER
|
|
|
|
#define BATTERY_OFF_TXT "POWER"
|
|
|
|
|
2009-08-04 03:08:32 +00:00
|
|
|
#elif CONFIG_KEYPAD == SAMSUNG_YH_PAD
|
|
|
|
|
|
|
|
#define BATTERY_ON BUTTON_LEFT
|
|
|
|
#define BATTERY_OFF BUTTON_RIGHT
|
|
|
|
#define BATTERY_ON_TXT "LEFT"
|
|
|
|
#define BATTERY_OFF_TXT "RIGHT"
|
|
|
|
|
2008-03-01 22:55:09 +00:00
|
|
|
#else
|
|
|
|
#error No keymap defined!
|
2006-01-25 18:35:36 +00:00
|
|
|
#endif
|
|
|
|
|
2008-08-23 09:46:38 +00:00
|
|
|
#ifdef HAVE_TOUCHSCREEN
|
2008-04-27 15:30:19 +00:00
|
|
|
#ifndef BATTERY_ON
|
|
|
|
#define BATTERY_ON BUTTON_CENTER
|
|
|
|
#endif
|
|
|
|
#ifndef BATTERY_OFF
|
|
|
|
#define BATTERY_OFF BUTTON_TOPLEFT
|
|
|
|
#endif
|
|
|
|
#ifndef BATTERY_ON_TXT
|
|
|
|
#define BATTERY_ON_TXT "CENTRE - start"
|
|
|
|
#endif
|
|
|
|
#ifndef BATTERY_OFF_TXT
|
2008-10-03 11:51:50 +00:00
|
|
|
#define BATTERY_OFF_TXT "TOPLEFT"
|
2008-04-27 15:30:19 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
/****************************** Plugin Entry Point ****************************/
|
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
|
|
|
|
2009-01-16 10:34:40 +00:00
|
|
|
enum plugin_status plugin_start(const void* parameter)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
|
|
|
(void)parameter;
|
|
|
|
|
|
|
|
return main();
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Struct for battery information */
|
|
|
|
struct batt_info
|
|
|
|
{
|
2007-09-09 20:46:45 +00:00
|
|
|
/* the size of the struct elements is optimised to make the struct size
|
|
|
|
* a power of 2 */
|
|
|
|
long ticks;
|
|
|
|
int eta;
|
2006-01-25 18:35:36 +00:00
|
|
|
unsigned int voltage;
|
2007-09-09 20:46:45 +00:00
|
|
|
short level;
|
|
|
|
unsigned short flags;
|
2006-02-07 14:46:03 +00:00
|
|
|
} bat[BUF_SIZE/sizeof(struct batt_info)];
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
#define BUF_ELEMENTS (sizeof(bat)/sizeof(struct batt_info))
|
|
|
|
|
2008-12-10 08:57:10 +00:00
|
|
|
static unsigned int thread_id;
|
2008-08-14 22:35:00 +00:00
|
|
|
static struct event_queue thread_q;
|
|
|
|
static bool in_usb_mode;
|
|
|
|
static unsigned int buf_idx;
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2006-10-31 11:17:00 +00:00
|
|
|
bool exit_tsr(bool reenter)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
2009-01-03 13:27:19 +00:00
|
|
|
long button;
|
2006-10-31 11:17:00 +00:00
|
|
|
(void)reenter;
|
|
|
|
rb->lcd_clear_display();
|
|
|
|
rb->lcd_puts_scroll(0, 0, "Batt.Bench is currently running.");
|
2008-10-03 11:51:50 +00:00
|
|
|
rb->lcd_puts_scroll(0, 1, "Press " BATTERY_OFF_TXT " 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();
|
|
|
|
|
2009-01-03 13:27:19 +00:00
|
|
|
while (1)
|
2006-10-31 11:17:00 +00:00
|
|
|
{
|
2009-01-03 13:27:19 +00:00
|
|
|
button = rb->button_get(true);
|
|
|
|
if (IS_SYSEVENT(button))
|
|
|
|
continue;
|
|
|
|
if (button == BATTERY_OFF)
|
|
|
|
{
|
|
|
|
rb->queue_post(&thread_q, EV_EXIT, 0);
|
|
|
|
rb->thread_wait(thread_id);
|
|
|
|
/* remove the thread's queue from the broadcast list */
|
|
|
|
rb->queue_delete(&thread_q);
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
else return false;
|
2006-10-31 11:17:00 +00:00
|
|
|
}
|
2006-01-25 18:35:36 +00:00
|
|
|
}
|
|
|
|
|
2007-09-09 20:46:45 +00:00
|
|
|
#define BIT_CHARGER 0x1
|
|
|
|
#define BIT_CHARGING 0x2
|
|
|
|
#define BIT_USB_POWER 0x4
|
2006-02-07 14:46:03 +00:00
|
|
|
|
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)
|
2008-08-14 22:35:00 +00:00
|
|
|
static unsigned int charge_state(void)
|
2006-02-07 14:46:03 +00:00
|
|
|
{
|
|
|
|
unsigned int ret = 0;
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2008-08-14 22:35:00 +00:00
|
|
|
if (rb->charger_inserted())
|
2006-02-07 14:46:03 +00:00
|
|
|
ret = BIT_CHARGER;
|
2009-03-24 21:59:44 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2008-08-14 22:35:00 +00:00
|
|
|
if (rb->charging_state())
|
2006-02-07 14:46:03 +00:00
|
|
|
ret |= BIT_CHARGING;
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
2008-08-14 22:35:00 +00:00
|
|
|
if (rb->usb_powered())
|
2006-02-07 14:46:03 +00:00
|
|
|
ret |= BIT_USB_POWER;
|
|
|
|
#endif
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
|
|
|
|
static bool flush_buffer(void)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
2008-08-14 22:35:00 +00:00
|
|
|
int fd, secs;
|
|
|
|
unsigned int i;
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
/* don't access the disk when in usb mode, or when no data is available */
|
|
|
|
if (in_usb_mode || (buf_idx == 0))
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND);
|
|
|
|
if (fd < 0)
|
|
|
|
{
|
|
|
|
return false;
|
|
|
|
}
|
2007-08-01 08:50:44 +00:00
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
for (i = 0; i < buf_idx; i++)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
2008-08-14 22:35:00 +00:00
|
|
|
secs = bat[i].ticks/HZ;
|
|
|
|
rb->fdprintf(fd,
|
|
|
|
"%02d:%02d:%02d, %05d, %03d%%, "
|
|
|
|
"%02d:%02d, %04d, "
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2008-08-14 22:35:00 +00:00
|
|
|
" %c"
|
2009-03-24 21:59:44 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2008-08-14 22:35:00 +00:00
|
|
|
", %c"
|
2006-02-07 14:46:03 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
2008-08-14 22:35:00 +00:00
|
|
|
", %c"
|
2006-02-07 14:46:03 +00:00
|
|
|
#endif
|
2008-08-14 22:35:00 +00:00
|
|
|
"\n",
|
|
|
|
|
|
|
|
HMS(secs), secs, bat[i].level,
|
|
|
|
bat[i].eta / 60, bat[i].eta % 60,
|
|
|
|
bat[i].voltage
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2008-08-14 22:35:00 +00:00
|
|
|
, (bat[i].flags & BIT_CHARGER) ? 'A' : '-'
|
2009-03-24 21:59:44 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2008-08-14 22:35:00 +00:00
|
|
|
, (bat[i].flags & BIT_CHARGING) ? 'C' : '-'
|
2006-02-07 14:46:03 +00:00
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
2008-08-14 22:35:00 +00:00
|
|
|
, (bat[i].flags & BIT_USB_POWER) ? 'U' : '-'
|
2006-02-07 14:46:03 +00:00
|
|
|
#endif
|
2008-08-14 22:35:00 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
rb->close(fd);
|
|
|
|
|
|
|
|
buf_idx = 0;
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void thread(void)
|
|
|
|
{
|
|
|
|
bool exit = false;
|
|
|
|
char *exit_reason = "unknown";
|
|
|
|
long sleep_time = 60 * HZ;
|
|
|
|
struct queue_event ev;
|
|
|
|
int fd;
|
|
|
|
|
|
|
|
in_usb_mode = false;
|
|
|
|
buf_idx = 0;
|
|
|
|
|
|
|
|
while (!exit)
|
|
|
|
{
|
|
|
|
/* add data to buffer */
|
|
|
|
if (buf_idx < BUF_ELEMENTS)
|
|
|
|
{
|
|
|
|
bat[buf_idx].ticks = *rb->current_tick;
|
|
|
|
bat[buf_idx].level = rb->battery_level();
|
|
|
|
bat[buf_idx].eta = rb->battery_time();
|
|
|
|
bat[buf_idx].voltage = rb->battery_voltage();
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING || defined(HAVE_USB_POWER)
|
2008-08-14 22:35:00 +00:00
|
|
|
bat[buf_idx].flags = charge_state();
|
2006-02-07 14:46:03 +00:00
|
|
|
#endif
|
2008-08-14 22:35:00 +00:00
|
|
|
buf_idx++;
|
2008-11-01 16:14:28 +00:00
|
|
|
rb->register_storage_idle_func(flush_buffer);
|
2008-08-14 22:35:00 +00:00
|
|
|
}
|
2006-01-25 18:35:36 +00:00
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
/* What to do when the measurement buffer is full:
|
|
|
|
1) save our measurements to disk but waste some power doing so?
|
|
|
|
2) throw away measurements to save some power?
|
|
|
|
The choice made here is to save the measurements. It is quite unusual
|
|
|
|
for this to occur because it requires > 16 hours of no disk activity.
|
|
|
|
*/
|
|
|
|
if (buf_idx == BUF_ELEMENTS) {
|
|
|
|
flush_buffer();
|
2006-01-25 18:35:36 +00:00
|
|
|
}
|
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
/* sleep some time until next measurement */
|
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:
|
2008-08-14 22:35:00 +00:00
|
|
|
exit_reason = "power off";
|
|
|
|
exit = true;
|
2006-01-25 18:35:36 +00:00
|
|
|
break;
|
|
|
|
case EV_EXIT:
|
2008-08-14 22:35:00 +00:00
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
rb->splash(HZ, "Exiting battery_bench...");
|
|
|
|
#else
|
|
|
|
rb->splash(HZ, "bench exit");
|
|
|
|
#endif
|
|
|
|
exit_reason = "plugin exit";
|
|
|
|
exit = true;
|
2006-01-25 18:35:36 +00:00
|
|
|
break;
|
|
|
|
}
|
2008-08-14 22:35:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* unregister flush callback and flush to disk */
|
2008-11-01 16:14:28 +00:00
|
|
|
rb->unregister_storage_idle_func(flush_buffer, true);
|
2008-08-14 22:35:00 +00:00
|
|
|
|
|
|
|
/* log end of bench and exit reason */
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT | O_APPEND);
|
|
|
|
if (fd >= 0)
|
|
|
|
{
|
|
|
|
rb->fdprintf(fd, "--Battery bench ended, reason: %s--\n", exit_reason);
|
|
|
|
rb->close(fd);
|
|
|
|
}
|
2006-01-25 18:35:36 +00:00
|
|
|
}
|
|
|
|
|
2006-02-07 14:46:03 +00:00
|
|
|
|
|
|
|
#ifdef HAVE_LCD_BITMAP
|
|
|
|
typedef void (*plcdfunc)(int x, int y, const unsigned char *str);
|
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
static void put_centered_str(const char* str, plcdfunc putsxy, int lcd_width, int line)
|
2006-02-07 14:46:03 +00:00
|
|
|
{
|
|
|
|
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,
|
2008-10-03 11:51:50 +00:00
|
|
|
"for more info", BATTERY_ON_TXT, BATTERY_OFF_TXT " - 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
|
|
|
|
2008-08-14 22:35:00 +00:00
|
|
|
for (i = 0; i<(int)(sizeof(msgs)/sizeof(char *)); i++)
|
2006-02-07 14:46:03 +00:00
|
|
|
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);
|
2008-08-14 22:35:00 +00:00
|
|
|
switch (button)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
|
|
|
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:
|
2008-08-14 22:35:00 +00:00
|
|
|
#endif
|
2006-01-25 18:35:36 +00:00
|
|
|
return PLUGIN_OK;
|
2008-08-14 22:35:00 +00:00
|
|
|
|
|
|
|
default:
|
|
|
|
if (rb->default_event_handler(button) == SYS_USB_CONNECTED)
|
2006-01-25 18:35:36 +00:00
|
|
|
return PLUGIN_USB_CONNECTED;
|
|
|
|
}
|
|
|
|
}while(!on);
|
|
|
|
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDONLY);
|
2008-08-14 22:35:00 +00:00
|
|
|
if (fd < 0)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
|
|
|
fd = rb->open(BATTERY_LOG, O_RDWR | O_CREAT);
|
2008-08-14 22:35:00 +00:00
|
|
|
if (fd >= 0)
|
2006-01-25 18:35:36 +00:00
|
|
|
{
|
|
|
|
rb->fdprintf(fd,
|
|
|
|
"This plugin will log your battery performance in a\n"
|
2008-08-14 22:35:00 +00:00
|
|
|
"file (%s) every minute.\n"
|
2006-01-25 18:35:36 +00:00
|
|
|
"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"
|
2008-08-14 22:35:00 +00:00
|
|
|
"Just don't open another plugin to be sure that your log "
|
2008-09-22 19:59:00 +00:00
|
|
|
"will continue.\n\n",BATTERY_LOG);
|
|
|
|
rb->fdprintf(fd,
|
|
|
|
"Battery bench run for %s version %s\n\n"
|
|
|
|
,MODEL_NAME,rb->appsversion);
|
|
|
|
|
|
|
|
rb->fdprintf(fd,
|
2006-01-25 18:35:36 +00:00
|
|
|
"Battery type: %d mAh Buffer Entries: %d\n"
|
2008-08-14 22:35:00 +00:00
|
|
|
" Time:, Seconds:, Level:, Time Left:, Voltage[mV]:"
|
2007-02-18 05:32:06 +00:00
|
|
|
#if CONFIG_CHARGING
|
2006-02-07 14:46:03 +00:00
|
|
|
", C:"
|
|
|
|
#endif
|
2009-03-24 21:59:44 +00:00
|
|
|
#if CONFIG_CHARGING >= CHARGING_MONITOR
|
2006-02-07 14:46:03 +00:00
|
|
|
", S:"
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_USB_POWER
|
|
|
|
", U:"
|
|
|
|
#endif
|
|
|
|
"\n"
|
2008-09-22 19:59:00 +00:00
|
|
|
,rb->global_settings->battery_capacity,
|
2008-08-14 22:35:00 +00:00
|
|
|
(int)BUF_ELEMENTS);
|
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");
|
2008-09-22 19:59:00 +00:00
|
|
|
rb->fdprintf(fd,
|
|
|
|
"Battery bench run for %s version %s\n\n"
|
|
|
|
,MODEL_NAME,rb->appsversion);
|
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 */
|
2008-08-14 22:35:00 +00:00
|
|
|
if ((thread_id = rb->create_thread(thread, thread_stack,
|
2007-10-16 01:25:17 +00:00
|
|
|
sizeof(thread_stack), 0, "Battery Benchmark"
|
2007-03-04 20:06:41 +00:00
|
|
|
IF_PRIO(, PRIORITY_BACKGROUND)
|
2008-12-10 08:57:10 +00:00
|
|
|
IF_COP(, CPU))) == 0)
|
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;
|
|
|
|
}
|