summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBjörn Stenberg <bjorn@haxx.se>2004-06-15 23:24:06 +0000
committerBjörn Stenberg <bjorn@haxx.se>2004-06-15 23:24:06 +0000
commitbe52a11038d82658a26907ccbebcb1a9d9677baf (patch)
treeaf1091468f62249dc9772e0cf8d6750b07dd5d64
parentb876296c9bc9f010c29d90b4e502fcda5f0bf0c6 (diff)
downloadrockbox-be52a11038d82658a26907ccbebcb1a9d9677baf.tar.gz
rockbox-be52a11038d82658a26907ccbebcb1a9d9677baf.zip
Simple battery runtime test
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4751 a1c6a512-1295-4272-9138-f99709370657
-rw-r--r--apps/plugins/battery_test.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/apps/plugins/battery_test.c b/apps/plugins/battery_test.c
new file mode 100644
index 0000000000..01a075f72b
--- /dev/null
+++ b/apps/plugins/battery_test.c
@@ -0,0 +1,107 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2004 Björn Stenberg
11 *
12 * All files in this archive are subject to the GNU General Public License.
13 * See the file COPYING in the source tree root for full license agreement.
14 *
15 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
16 * KIND, either express or implied.
17 *
18 ****************************************************************************/
19#include "plugin.h"
20
21/* This plugin is designed to measure your battery performance in real-time.
22 It will create a big file, read it every ~90 seconds and log the
23 battery level in /battery.log
24
25 When battery level goes below 5% the plugin exits, to avoid writing to
26 disk in very low battery situations.
27
28 Note that this test will run for 10-15 hours or more and is very boring
29 to watch.
30*/
31
32static struct plugin_api* rb;
33
34void* buffer;
35int buffersize;
36
37int init(void)
38{
39 int f;
40 buffer = rb->plugin_get_mp3_buffer(&buffersize);
41
42 /* create a big dummy file */
43 f = rb->creat("/battery.dummy", 0);
44 if (f<0) {
45 rb->splash(HZ, true, "Can't create /battery.dummy");
46 return -1;
47 }
48 rb->write(f, buffer, buffersize);
49 rb->close(f);
50
51 return 0;
52}
53
54void loop(void)
55{
56 while (true) {
57 struct tm* t;
58 char buf[80];
59 int f;
60 int batt = rb->battery_level();
61
62 /* stop measuring when <5% battery left */
63 if ((batt > 0) && (batt < 5))
64 break;
65
66 /* log current time */
67 f = rb->open("/battery.log", O_WRONLY | O_APPEND | O_CREAT);
68 if (f<0) {
69 rb->splash(HZ, true, "Failed creating /battery.log");
70 break;
71 }
72 t = rb->get_time();
73 rb->snprintf(buf, sizeof buf, "%02d:%02d:%02d Battery %d%%\n",
74 t->tm_hour, t->tm_min, t->tm_sec, batt);
75 rb->write(f, buf, rb->strlen(buf));
76 rb->close(f);
77
78 rb->splash(0, true, buf);
79
80 /* simulate 128kbit/s (16kbyte/s) playback duration */
81 rb->sleep(HZ * (buffersize / 16384) - HZ*10);
82
83 /* simulate filling the mp3 buffer */
84 f = rb->open("/battery.dummy", O_RDONLY);
85 if (f<0) {
86 rb->splash(HZ, true, "Failed opening /battery.dummy");
87 break;
88 }
89 rb->read(f, buffer, buffersize);
90 rb->close(f);
91 }
92}
93
94enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
95{
96 TEST_PLUGIN_API(api);
97 (void)parameter;
98 rb = api;
99
100 if (init() < 0)
101 return PLUGIN_OK;
102
103 loop();
104
105 return PLUGIN_OK;
106}
107