summaryrefslogtreecommitdiff
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
parentb66477adccfd08987e409182e15bb17e70283fae (diff)
downloadrockbox-f6bdfbdcd09648454373a376ce19b20a561bbdef.tar.gz
rockbox-f6bdfbdcd09648454373a376ce19b20a561bbdef.zip
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
-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 @@
51#endif 51#endif
52#include "logf.h" 52#include "logf.h"
53#include "lcd-remote.h" 53#include "lcd-remote.h"
54#ifdef SIMULATOR
55#include <time.h>
56#endif
54 57
55/* 58/*
56 * Define DEBUG_FILE to create a csv (spreadsheet) with battery information 59 * Define DEBUG_FILE to create a csv (spreadsheet) with battery information
@@ -73,19 +76,50 @@ static int shutdown_timeout = 0;
73 76
74#ifdef SIMULATOR /***********************************************************/ 77#ifdef SIMULATOR /***********************************************************/
75 78
79#define TIME2CHANGE 10 /* change levels every 10 seconds */
80#define BATT_MINCVOLT 250 /* minimum centivolts of battery */
81#define BATT_MAXCVOLT 450 /* maximum centivolts of battery */
82#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in minutes */
83
84static unsigned int batt_centivolts = (unsigned int)BATT_MAXCVOLT;
85static int batt_level = 100; /* battery capacity level in percent */
86static int batt_time = BATT_MAXRUNTIME; /* estimated remaining time in minutes */
87static time_t last_change = 0;
88
89static void battery_status_update(void)
90{
91 time_t now;
92
93 time(&now);
94 if (last_change < (now - TIME2CHANGE)) {
95 last_change = now;
96
97 /* change the values: */
98 batt_centivolts -= (unsigned int)(BATT_MAXCVOLT - BATT_MINCVOLT) / 11;
99 if (batt_centivolts < (unsigned int)BATT_MINCVOLT)
100 batt_centivolts = (unsigned int)BATT_MAXCVOLT;
101
102 batt_level = 100 * (batt_centivolts - BATT_MINCVOLT) / (BATT_MAXCVOLT - BATT_MINCVOLT);
103 batt_time = batt_level * BATT_MAXRUNTIME / 100;
104 }
105}
106
76unsigned int battery_voltage(void) 107unsigned int battery_voltage(void)
77{ 108{
78 return 400; 109 battery_status_update();
110 return batt_centivolts;
79} 111}
80 112
81int battery_level(void) 113int battery_level(void)
82{ 114{
83 return 75; 115 battery_status_update();
116 return batt_level;
84} 117}
85 118
86int battery_time(void) 119int battery_time(void)
87{ 120{
88 return 500; 121 battery_status_update();
122 return batt_time;
89} 123}
90 124
91bool battery_level_safe(void) 125bool battery_level_safe(void)