summaryrefslogtreecommitdiff
path: root/uisimulator/common/powermgmt-sim.c
diff options
context:
space:
mode:
Diffstat (limited to 'uisimulator/common/powermgmt-sim.c')
-rw-r--r--uisimulator/common/powermgmt-sim.c159
1 files changed, 159 insertions, 0 deletions
diff --git a/uisimulator/common/powermgmt-sim.c b/uisimulator/common/powermgmt-sim.c
new file mode 100644
index 0000000000..c06f84670d
--- /dev/null
+++ b/uisimulator/common/powermgmt-sim.c
@@ -0,0 +1,159 @@
1/***************************************************************************
2 * __________ __ ___.
3 * Open \______ \ ____ ____ | | _\_ |__ _______ ___
4 * Source | _// _ \_/ ___\| |/ /| __ \ / _ \ \/ /
5 * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
6 * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
7 * \/ \/ \/ \/ \/
8 * $Id$
9 *
10 * Copyright (C) 2002 by Heikki Hannikainen, Uwe Freese
11 * Revisions copyright (C) 2005 by Gerald Van Baren
12 *
13 * This program is free software; you can redistribute it and/or
14 * modify it under the terms of the GNU General Public License
15 * as published by the Free Software Foundation; either version 2
16 * of the License, or (at your option) any later version.
17 *
18 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY
19 * KIND, either express or implied.
20 *
21 ****************************************************************************/
22#include "config.h"
23#include "system.h"
24#include <time.h>
25#include "kernel.h"
26#include "powermgmt.h"
27
28#define BATT_MINMVOLT 2500 /* minimum millivolts of battery */
29#define BATT_MAXMVOLT 4500 /* maximum millivolts of battery */
30#define BATT_MAXRUNTIME (10 * 60) /* maximum runtime with full battery in
31 minutes */
32
33extern void send_battery_level_event(void);
34extern int last_sent_battery_level;
35extern int battery_percent;
36
37static unsigned int battery_millivolts = BATT_MAXMVOLT;
38/* estimated remaining time in minutes */
39static int powermgmt_est_runningtime_min = BATT_MAXRUNTIME;
40
41static void battery_status_update(void)
42{
43 static time_t last_change = 0;
44 static bool charging = false;
45 time_t now;
46
47 time(&now);
48
49 if (last_change < now) {
50 last_change = now;
51
52 /* change the values: */
53 if (charging) {
54 if (battery_millivolts >= BATT_MAXMVOLT) {
55 /* Pretend the charger was disconnected */
56 charging = false;
57 queue_broadcast(SYS_CHARGER_DISCONNECTED, 0);
58 last_sent_battery_level = 100;
59 }
60 }
61 else {
62 if (battery_millivolts <= BATT_MINMVOLT) {
63 /* Pretend the charger was connected */
64 charging = true;
65 queue_broadcast(SYS_CHARGER_CONNECTED, 0);
66 last_sent_battery_level = 0;
67 }
68 }
69
70 if (charging) {
71 battery_millivolts += (BATT_MAXMVOLT - BATT_MINMVOLT) / 50;
72 }
73 else {
74 battery_millivolts -= (BATT_MAXMVOLT - BATT_MINMVOLT) / 100;
75 }
76
77 battery_percent = 100 * (battery_millivolts - BATT_MINMVOLT) /
78 (BATT_MAXMVOLT - BATT_MINMVOLT);
79
80 powermgmt_est_runningtime_min =
81 battery_percent * BATT_MAXRUNTIME / 100;
82 }
83
84 send_battery_level_event();
85}
86
87void battery_read_info(int *voltage, int *level)
88{
89 battery_status_update();
90
91 if (voltage)
92 *voltage = battery_millivolts;
93
94 if (level)
95 *level = battery_percent;
96}
97
98unsigned int battery_voltage(void)
99{
100 battery_status_update();
101 return battery_millivolts;
102}
103
104int battery_level(void)
105{
106 battery_status_update();
107 return battery_percent;
108}
109
110int battery_time(void)
111{
112 battery_status_update();
113 return powermgmt_est_runningtime_min;
114}
115
116bool battery_level_safe(void)
117{
118 return battery_level() >= 10;
119}
120
121void set_poweroff_timeout(int timeout)
122{
123 (void)timeout;
124}
125
126void set_battery_capacity(int capacity)
127{
128 (void)capacity;
129}
130
131#if BATTERY_TYPES_COUNT > 1
132void set_battery_type(int type)
133{
134 (void)type;
135}
136#endif
137
138#ifdef HAVE_ACCESSORY_SUPPLY
139void accessory_supply_set(bool enable)
140{
141 (void)enable;
142}
143#endif
144
145void reset_poweroff_timer(void)
146{
147}
148
149void shutdown_hw(void)
150{
151}
152
153void sys_poweroff(void)
154{
155}
156
157void cancel_shutdown(void)
158{
159}