summaryrefslogtreecommitdiff
path: root/firmware/powermgmt.c
diff options
context:
space:
mode:
authorDan Everton <dan@iocaine.org>2006-03-25 14:31:44 +0000
committerDan Everton <dan@iocaine.org>2006-03-25 14:31:44 +0000
commitf6bdfbdcd09648454373a376ce19b20a561bbdef (patch)
tree626c583f893f7773431b44d14a2a3c2a61d9f78e /firmware/powermgmt.c
parentb66477adccfd08987e409182e15bb17e70283fae (diff)
Add simulated battery drain to the simulator. Patch from Matthias Mohr (task 4886).
git-svn-id: svn://svn.rockbox.org/rockbox/trunk@9247 a1c6a512-1295-4272-9138-f99709370657
Diffstat (limited to 'firmware/powermgmt.c')
-rw-r--r--firmware/powermgmt.c40
1 files changed, 37 insertions, 3 deletions
diff --git a/firmware/powermgmt.c b/firmware/powermgmt.c
index c80e711a16..8712d6c8f2 100644
--- a/firmware/powermgmt.c
+++ b/firmware/powermgmt.c
@@ -51,6 +51,9 @@
#endif
#include "logf.h"
#include "lcd-remote.h"
+#ifdef SIMULATOR
+#include <time.h>
+#endif
/*
* Define DEBUG_FILE to create a csv (spreadsheet) with battery information
@@ -73,19 +76,50 @@ static int shutdown_timeout = 0;
#ifdef SIMULATOR /***********************************************************/
+#define TIME2CHANGE 10 /* change levels every 10 seconds */
+#define BATT_MINCVOLT 250 /* minimum centivolts of battery */
+#define BATT_MAXCVOLT 450 /* maximum centivolts of battery */
+#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in minutes */
+
+static unsigned int batt_centivolts = (unsigned int)BATT_MAXCVOLT;
+static int batt_level = 100; /* battery capacity level in percent */
+static int batt_time = BATT_MAXRUNTIME; /* estimated remaining time in minutes */
+static time_t last_change = 0;
+
+static void battery_status_update(void)
+{
+ time_t now;
+
+ time(&now);
+ if (last_change < (now - TIME2CHANGE)) {
+ last_change = now;
+
+ /* change the values: */
+ batt_centivolts -= (unsigned int)(BATT_MAXCVOLT - BATT_MINCVOLT) / 11;
+ if (batt_centivolts < (unsigned int)BATT_MINCVOLT)
+ batt_centivolts = (unsigned int)BATT_MAXCVOLT;
+
+ batt_level = 100 * (batt_centivolts - BATT_MINCVOLT) / (BATT_MAXCVOLT - BATT_MINCVOLT);
+ batt_time = batt_level * BATT_MAXRUNTIME / 100;
+ }
+}
+
unsigned int battery_voltage(void)
{
- return 400;
+ battery_status_update();
+ return batt_centivolts;
}
int battery_level(void)
{
- return 75;
+ battery_status_update();
+ return batt_level;
}
int battery_time(void)
{
- return 500;
+ battery_status_update();
+ return batt_time;
}
bool battery_level_safe(void)