summaryrefslogtreecommitdiffstats
path: root/src/hardware_battery.h
blob: 3e50c0a96310b711f5c4c80c6a0047d7673c30c0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
 /**************************************************************************
 *   Copyright (C) 2006-2007 by Danny Kukawka                              *
 *                              <[email protected]>, <[email protected]> *
 *                                                                         *
 *   This program is free software; you can redistribute it and/or modify  *
 *   it under the terms of version 2 of the GNU General Public License     *
 *   as published by the Free Software Foundation.                         *
 *                                                                         *
 *   This program is distributed in the hope that it will be useful,       *
 *   but WITHOUT ANY WARRANTY; without even the implied warranty of        *
 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the         *
 *   GNU General Public License for more details.                          *
 *                                                                         *
 *   You should have received a copy of the GNU General Public License     *
 *   along with this program; if not, write to the                         *
 *   Free Software Foundation, Inc.,                                       *
 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.             *
 ***************************************************************************/

 
/*! 
*  \file 	hardware_battery.h
*  \brief 	Headerfile for hardware_battery.cpp and the class \ref Battery.
*/
/*! 
*  \class 	Battery
*  \brief 	class for Battery related funtionality
*  \author 	Danny Kukawka, <[email protected]>, <[email protected]>
*  \date    	2006-2007
*/

#ifndef _BATTERY_H_
#define _BATTERY_H_

// Global Header
#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

// QT - Header
#include <tqstring.h>
#include <tqstringlist.h>
#include <tqobject.h>

// TDE hardware library
#include <tdehardwaredevices.h>

#include "dbusInterface.h"

class Battery : public TQObject {

	Q_OBJECT
  

private:
	TDEHardwareDevices *m_hwdevices;

	//! TDE hardware library udi of the battery to represent
	/*!
	* This TQString holds the TDE hardware library udi adress of the battery.
	* \li empty: all primary batteries are represented
	* \li e.g. "/org/freedesktop/Hal/devices/acpi_BAT0": first acpi battery
	*/
	TQString udi;

	//! Technologyname of the battery
	/*!
	* Tells the type of technologyname the battery is working with.
	* \li e.g. "LION"
	*/
	TQString technology;
	//! Current charging state of this battery as reported by TDE hardware library
	/*!
	* This TQString tells the current capacity_state TDE hardware library is reporting.
	* \li as of current TDE hardware library spec: "ok", "critical"
	*/
	TQString	capacity_state;
	//! Unit of charge_level_unit and charge_level_lastfull.
	/*! This TQString tells the physical unit the values of charge_level_unit. */
	TQString charge_level_unit;
	//! Serialnumber of the the battery
	/*! Identifies the currently installed battery uniquely. */
	TQString	serial;

	//! Boolean which tells if the battery is initalized first time
	/*!
	* When the battery (represented by the object) is intialised the first time
	* (via recheck() or init()) this value is true.
	* \li true: 	if battery object is now intialised
	* \li false: 	if not
	*/
	bool 	initialized;
	//! Boolean which tells if the battery is present/connected
	/*!
	* When the battery (represented by the object) is available this is true.
	* \li true: battery is available
	* \li false: battery is disconnected/not available
	*/
	bool 	present;

	//! Roletype of battery
	/*!
	* This int/enum tells what role this battery is used as.
	* \li BAT_PRIMARY: Std. battery for normal system operation
	* \li BAT_MOUSE: powersupply for wireless mouse
	* \li BAT_KEYBOARD: powersupply in wireless keyboards
	* \li BAT_KEY_MOUSE: powersupply in combined keyboard+mouse gadgets
	* \li BAT_UPS: Battery in UPS systems (step in on outage of mains)
	* \li BAT_CAMERA: battery is contained in a connected digital camera
	* \li UNKNOWN: Batterytype/role isn't known
	*/
	int 	type;
	//! Current general state this battery is in
	/*!
	* This int/enum tells what rough state the battery is currently in.
	* \li BAT_NORM: batterylevel is ok
	* \li BAT_WARN: battery is soon getting low
	* \li BAT_LOW: batterylevel is already low
	* \li BAT_CRIT: batterylevel has become really critical
	* \li BAT_NONE: battery state not available
	* \li BAT_TDE hardware library_ERROR: battery state couldn't be retrieved because of a TDE hardware library error
	*/
	int 	state;
	//! Current charging state of this battery
	/*!
	* This int/enum tells if the battery is charged or discharged.
	* \li CHARGING: battery gets charged
	* \li DISCHARGING: battery get discharged
	* \li UNKNOWN_STATE: battery is neither charged nor discharged
	*/
	int 	charging_state;	
	//! Current level the battery is charged to
	/*!
	* This int tells (in physical units of Battery::charge_level_unit) 
	* at what charging level the battery is currently at 
	* \li a value >= 0
	*/
	int 	charge_level_current;
	//! Charging level of battery it could hold when fully charged
	/*!
	* This int tells (in physical units of Battery::charge_level_unit) the 
	* maximum charginglevel of the battery on its last fullcharge. 
	* \li a value >=0
	*/
	int	charge_level_lastfull;
	//! Current charge level of battery in percentage
	/*!
	* This int tells the current charge level of the battery in percent.
	* \li a value between 0 and 100
	*/
	int 	charge_level_percentage;
	//! The maximum capacity by design of the battery.
	/*!
	* This int tells (in physical units of Battery::charge_level_unit) 
	* the maximum capacity this battery was designed for by its vendor.
	* \li a value > 0
	*/
	int	design_capacity;
	//! Current charging/discharging rate
	/*!
	* This int tells (in physical units of Battery::charge_level_unit per
	* second) the currently reported charging/discharging rate.
	* \li a value >= 0
	*/
	int 	present_rate;
	//! Expected minutes unitl fully discharged/charged
	/*!
	* This int tells the current estimate until the battery is fully 
	* discharged/charged (with current discharging/charging-rate and last 
	* full capacity).
	* \li a value >= 0
	*/
	int	remaining_minutes;

	//! charge_level in percent that will put battery into warning state
	int warn_level;
	//! charge_level in percent that will put battery into low state
	int low_level;
	//! charge_level in percent that will put battery into critical state
	int crit_level;

	// private functions
	//! function to set initial values for a battery
	void initDefault();

	//! to check battery.present
	bool checkBatteryPresent();
	//! to check battery.type
	bool checkBatteryType();
	//! to check battery.technology
	bool checkBatteryTechnology();
	//! to check battery.charge_level.capacity_state
	bool checkCapacityState();
	//! to check battery.charge_level.current
	bool checkChargeLevelCurrent();
	//! to check battery.charge_level.last_full
	bool checkChargeLevelLastfull();
	//! to check battery.charge_level.rate
	bool checkChargeLevelRate();
	//! to check battery.charge_level.unit
	bool checkChargeLevelUnit();
	//! to check battery.charge_level.design
	bool checkChargeLevelDesign();
	//! to check battery.charge_level.percentage
	bool checkRemainingPercentage();
	//! to check battery.remaining_time
	bool checkRemainingTime();
	//! to check battery.rechargeable.is_*
	bool checkChargingState();

signals:
	//! emitted if the remaining percentage changed
	void changedBatteryPercentage();
	//! emitted if the remaining time changed
	void changedBatteryTime();
	//! emitted if the the present state changed
	void changedBatteryPresent();
	//! emitted if the charging state changed
	void changedBatteryChargingState();
	//! emitted if the battery state changed
	void changedBatteryState();
	//! emitted if the Battery warning state changed
	void changedBatteryWarnState (int state);
	//! emitted if any Battery state changed
	void changedBattery();

public slots:
	//! update a property on device event
	void updateProperty(TDEGenericDevice*);

public:

	//! default constructor
	Battery( TQString _udi );
	//! default destructor
	~Battery();

	//! initialize this battery object with values from TDE hardware library
	void init();
	//! recheck all properties of the battery
	void recheck();
	//! rechecks only minimalistic set properties
	void minRecheck();


	//ro-Interface to internal data
	//! reports the TDE hardware library udi of this battery
	TQString getUdi() const;
	//! reports TDE hardware library capacity_state value
	TQString getCapacityState() const;
	//! reports the physical unit of values like DesignCapacity, PresentRate and Lastfull
	TQString getChargelevelUnit() const;
	//! gives the name of this battery technology
	TQString getTechnology() const;	

	//! get availability of this battery
	bool isPresent();

	//! reports the battery type
	int getType() const;
	//! tells the current batterystate as enum BAT_STATE_
	int getState() const;
	//! estimates the remaining minutes until fully charged/discharged
	int getRemainingMinutes() const;
	//! current charging/discharging rate 
	int getPresentRate() const;
	//! maximum capacity of this battery by design
	int getDesignCapacity() const;
	//! current charging state as enum BAT_CHARG_STATE
	int getChargingState() const;
	//! reports current chargelevel in percentage
	int getPercentage() const;
	//! reports last full capacity of this battery when fully charged
	int getLastfull() const;
	//! reports current chargelevel in units reported by getChargelevelUnit()
	int getCurrentLevel() const;
	
	//! reports the chargelevel in percent when battery goes to state warning
	int getWarnLevel() const;
	//! reports the chargelevel in percent when battery goes to state low
	int getLowLevel() const;
	//! reports the chargelevel in percent when battery goes to state critical
	int getCritLevel() const;

	//writeable access to internals
	//! Resets the current TDE hardware library udi used by the one given
	/*!
	* The given TQString will be (checked and) used as new TDE hardware library udi for the battery.
	* But don't forget to do a recheck of the battery afterwards.
	* \li returns TRUE: if reset was successfull
	* \li returns FALSE: if reset couldn't be applied
	*/
	bool resetUdi(TQString);

	//! sets the chargelevel in percent when battery should go into state warning
	void setWarnLevel(int _warn_level);
	//! sets the chargelevel in percent when battery should go into state low
	void setLowLevel(int _low_level);
	//! sets the chargelevel in percent when battery should go into state critical
	void setCritLevel(int _crit_level);

	//some convenience methods
	//! check if the battery is currently charged
	bool isCharging();
	//! check if the battery gets currently discharged
	bool isDischarging();
	//! check it this is a primary battery
	bool isPrimary() const;
	//! check if the battery state is ok/normal
	bool isOk();
	//! check if the battery is in warning level/state
	bool isWarning();
	//! check if the battery is in a low chargingstate
	bool isLow();
	//! check if the battery level is critical
	bool isCritical();
};


enum BAT_TYPE {
	BAT_PRIMARY,
	BAT_MOUSE,
	BAT_KEYBOARD,
	BAT_KEY_MOUSE,
	BAT_UPS,
	BAT_CAMERA,
	BAT_UNKNOWN
};
enum BAT_CHARG_STATE {
	CHARGING,
	DISCHARGING,
	UNKNOWN_STATE
};
enum BAT_STATE {
	BAT_NONE,
	BAT_WARN,
	BAT_LOW,
	BAT_CRIT,
	BAT_NORM,
	BAT_HAL_ERROR
};

#endif