/*************************************************************************** * __________ __ ___. * Open \______ \ ____ ____ | | _\_ |__ _______ ___ * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ / * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * \/ \/ \/ \/ \/ * $Id$ * * * Copyright (C) 2006 Alexander Spyridakis, Hristo Kovachev * * 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. * * 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 /* seems to work with 1300, but who knows... */ #define THREAD_STACK_SIZE DEFAULT_STACK_SIZE + 0x200 #if CONFIG_KEYPAD == RECORDER_PAD #define BATTERY_ON BUTTON_PLAY #define BATTERY_OFF BUTTON_OFF #define BATTERY_ON_TXT "PLAY - start" #define BATTERY_OFF_TXT "OFF - quit" #if BUTTON_REMOTE != 0 #define BATTERY_RC_ON BUTTON_RC_PLAY #define BATTERY_RC_OFF BUTTON_RC_STOP #endif #elif CONFIG_KEYPAD == ONDIO_PAD #define BATTERY_ON BUTTON_RIGHT #define BATTERY_OFF BUTTON_OFF #define BATTERY_ON_TXT "RIGHT - start" #define BATTERY_OFF_TXT "OFF - quit" #elif CONFIG_KEYPAD == PLAYER_PAD #define BATTERY_ON BUTTON_PLAY #define BATTERY_OFF BUTTON_STOP #define BATTERY_RC_ON BUTTON_RC_PLAY #define BATTERY_RC_OFF BUTTON_RC_STOP #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 #define BATTERY_ON_TXT "PLAY - start" #define BATTERY_OFF_TXT "STOP - quit" #elif (CONFIG_KEYPAD == IPOD_4G_PAD) || \ (CONFIG_KEYPAD == IPOD_3G_PAD) || \ (CONFIG_KEYPAD == IPOD_1G2G_PAD) #define BATTERY_ON BUTTON_PLAY #define BATTERY_OFF BUTTON_MENU #define BATTERY_ON_TXT "PLAY - start" #define BATTERY_OFF_TXT "MENU - quit" #elif CONFIG_KEYPAD == IAUDIO_X5M5_PAD #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "POWER - quit" #elif CONFIG_KEYPAD == IRIVER_IFP7XX_PAD #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_PLAY #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "PLAY - quit" #elif (CONFIG_KEYPAD == SANSA_E200_PAD) || \ (CONFIG_KEYPAD == SANSA_C200_PAD) #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "POWER - quit" #elif CONFIG_KEYPAD == IRIVER_H10_PAD #define BATTERY_ON BUTTON_PLAY #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "PLAY - start" #define BATTERY_OFF_TXT "POWER - quit" #elif CONFIG_KEYPAD == GIGABEAT_PAD #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "POWER - quit" #elif CONFIG_KEYPAD == GIGABEAT_S_PAD #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_BACK #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "BACK - quit" #elif CONFIG_KEYPAD == MROBE500_PAD #define BATTERY_ON BUTTON_RC_PLAY #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "PLAY - start" #define BATTERY_OFF_TXT "POWER - quit" #elif CONFIG_KEYPAD == MROBE100_PAD #define BATTERY_ON BUTTON_SELECT #define BATTERY_OFF BUTTON_POWER #define BATTERY_ON_TXT "SELECT - start" #define BATTERY_OFF_TXT "POWER - quit" #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" #define BATTERY_OFF_TXT "REC - quit" #elif CONFIG_KEYPAD == COWOND2_PAD #define BATTERY_OFF BUTTON_POWER #define BATTERY_OFF_TXT "POWER - quit" #else #error No keymap defined! #endif #ifdef HAVE_TOUCHPAD #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 #define BATTERY_OFF_TXT "TOPLEFT - quit" #endif #endif /****************************** Plugin Entry Point ****************************/ static const struct plugin_api* rb; MEM_FUNCTION_WRAPPERS(rb); int main(void); bool exit_tsr(bool); void thread(void); enum plugin_status plugin_start(const struct plugin_api* api, const void* parameter) { (void)parameter; rb = api; return main(); } /* Struct for battery information */ struct batt_info { /* the size of the struct elements is optimised to make the struct size * a power of 2 */ long ticks; int eta; unsigned int voltage; short level; unsigned short flags; } bat[BUF_SIZE/sizeof(struct batt_info)]; struct thread_entry *thread_id; struct event_queue thread_q; bool exit_tsr(bool reenter) { 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"); #ifdef HAVE_LCD_BITMAP rb->lcd_puts_scroll(0, 2, "Anything else will resume"); #endif rb->lcd_update(); if (rb->button_get(true) != BATTERY_OFF) exit = false; if (exit) { 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; } #define BIT_CHARGER 0x1 #define BIT_CHARGING 0x2 #define BIT_USB_POWER 0x4 #define HMS(x) (x)/3600,((x)%3600)/60,((x)%3600)%60 /* use long for aligning */ unsigned long thread_stack[THREAD_STACK_SIZE/sizeof(long)]; #if CONFIG_CHARGING || defined(HAVE_USB_POWER) unsigned int charge_state(void) { unsigned int ret = 0; #if CONFIG_CHARGING if(rb->charger_inserted()) ret = BIT_CHARGER; #if CONFIG_CHARGING == CHARGING_MONITOR 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 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; #if CONFIG_CHARGING || defined(HAVE_USB_POWER) unsigned int last_state = 0; #endif long sleep_time = 5 * HZ; struct queue_event ev; buffelements = sizeof(bat)/sizeof(struct batt_info); #ifndef HAVE_FLASH_STORAGE if(rb->global_settings->disk_spindown > 1) sleep_time = (rb->global_settings->disk_spindown - 1) * HZ; #endif 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%%, " "%02d:%02d, %04d, %04d" #if CONFIG_CHARGING ", %c" #if CONFIG_CHARGING == CHARGING_MONITOR ", %c" #endif #endif #ifdef HAVE_USB_POWER typedef struct Token { int token; SemInfo seminfo; } Token; typedef struct LexState { int current; /* current character (charint) */ int linenumber; /* input line counter */ int lastline; /* line of last token `consumed' */ Token t; /* current token */ Token lookahead; /* look ahead token */ struct FuncState *fs; /* `FuncState' is private to the parser */ struct lua_State *L; ZIO *z; /* input stream */ Mbuffer *buff; /* buffer for tokens */ TString *source; /* current source name */ char decpoint; /* locale decimal point */ } LexState; LUAI_FUNC void luaX_init (lua_State *L); LUAI_FUNC void luaX_setinput (lua_State *L, LexState *ls, ZIO *z, TString *source); LUAI_FUNC TString *luaX_newstring (LexState *ls, const char *str, size_t l); LUAI_FUNC void luaX_next (LexState *ls); LUAI_FUNC void luaX_lookahead (LexState *ls); LUAI_FUNC void luaX_lexerror (LexState *ls, const char *msg, int token); LUAI_FUNC void luaX_syntaxerror (LexState *ls, const char *s); LUAI_FUNC const char *luaX_token2str (LexState *ls, int token); #endif