1 // Copyright (c) 2008-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
25 // FORWARD DECLARATIONS
28 class MHWRMBatteryPowerObserver;
30 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
31 class MHWRMBatteryChargingStatusObserver;
32 class MHWRMBatteryChargingCurrentObserver;
33 class MHWRMBatteryFullChargingTimeObserver;
34 #endif //SYMBIAN_HWRM_EXTPOWERINFO
37 * HW Resource Manager Power API is a library API providing the
38 * ability to request detailed information regarding the battery
39 * capacity, voltage and current consumption.
41 * The API consists of the classes CHWRMPower, MHWRMBatteryConsumptionObserver
42 * and MHWRMBatteryVoltageObserver. If the client requires periodical measurements
43 * of the Average Voltage and/or Average Consumption, it should also provide callback pointer
44 * of the MHWRMBatteryConsumptionObserver and/or MHWRMBatteryVoltageObserver
45 * implementing class for the NewL() method.
50 * #include <hwrmpower.h>
52 * // A CHWRMPower instance can be created by using NewL() or NewLC() methods.
53 * // Periodical measurements are required so callbacks are provided. Assume
54 * // the calling object implements both interfaces.
55 * CHWRMPower* power = CHWRMPower::NewL(this, this);
57 * // Get battery info.
58 * TRequestStatus& status;
59 * TBatteryConsumptionData batteryConsumptionData;
60 * power->GetBatteryInfo(status, batteryConsumptionData);
62 * User::WaitForRequest(status);
63 * User::LeaveIfError(status.Int());
65 * // Start receiving periodical voltage measurements.
66 * TRequestStatus& statusStart;
67 * TIntervalMultiple intervalMultiple = EThreeTimesBaseTimeInterval;
68 * power->StartAverageVoltageReporting(statusStart, intervalMultiple);
70 * User::WaitForRequest(statusStart);
71 * User::LeaveIfError(statusStart.Int());
73 * // Measurements are being when the ProcessVoltageMeasurement() method
74 * // of the MHWRMBatteryVoltageObserver interface is called.
76 * // Stop receiving measurements when done
77 * power->StopAverageVoltageReportingL();
79 * // To clean up, delete the created object:
86 NONSHARABLE_CLASS(CHWRMPower) : public CBase
91 * Data structure used to retreive data from a call to GetBatteryVoltageInfo
93 struct TBatteryVoltageData
95 TInt iRemainingVoltage;
101 * Data structure used to retreive data from a call to GetBatteryInfo
103 struct TBatteryConsumptionData
105 TInt iNominalCapacity;
106 TInt iRemainingCapacity;
107 TInt iRemainingPercentageCapacity;
111 * Data structure used to retreive data from a call to GetBatteryInfo
113 struct TBatteryPowerMeasurementData
115 TInt iAverageVoltage;
116 TInt iAverageCurrent;
120 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
122 /* The type of charger connected to the device.*/
123 enum TBatteryChargerType
125 EBatteryChargerUnKnown = 0,
126 EBatteryChargerDedicated = 1,
127 EBatteryChargerUsbDedicated = 2,
128 EBatteryChargerUsbHost = 3
131 /* The current charging status of the device. */
132 enum TBatteryChargingStatus
134 EChargingStatusError = -1,
135 EChargingStatusNotConnected = 0,
136 EChargingStatusCharging = 1,
137 EChargingStatusNotCharging = 2,
138 EChargingStatusAlmostComplete = 3,
139 EChargingStatusChargingComplete = 4,
140 EChargingStatusChargingContinued = 5
143 /* Used to stop the ongoing charging notification.
144 * EChargingNotifierAll used to stop charging current and charging
145 * time notifications. */
147 enum TBatteryChargingNotifier
149 EChargingNotifierAll = 0,
150 EChargingNotifierChargingCurrent = 1,
151 EChargingNotifierBatteryFullChargingTime = 2
154 #endif //SYMBIAN_HWRM_EXTPOWERINFO
158 IMPORT_C ~CHWRMPower();
159 IMPORT_C static CHWRMPower* NewL();
160 IMPORT_C static CHWRMPower* NewLC();
162 public: // New functions
164 IMPORT_C void GetBatteryInfo(TRequestStatus& aStatus, TBatteryConsumptionData& aBatteryConsumptionData);
165 IMPORT_C void GetBatteryVoltageInfo(TRequestStatus& aStatus, TBatteryVoltageData& aBatteryVoltageData);
166 IMPORT_C void GetBaseTimeIntervalL(TInt &aBaseTimeInterval);
167 IMPORT_C TInt SetPowerReportObserver(MHWRMBatteryPowerObserver* aPowerReportCallback);
168 IMPORT_C TInt StartAveragePowerReporting(TRequestStatus& aStatus, const TUint& aInterval);
169 IMPORT_C void StopAveragePowerReportingL();
171 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
173 IMPORT_C TInt GetBatteryChargerType(TBatteryChargerType& aChargerType);
174 IMPORT_C TInt GetBatteryChargingStatus(TBatteryChargingStatus& aChargingStatus);
175 IMPORT_C TInt SetBatteryChargingObserver(
176 MHWRMBatteryChargingStatusObserver* aChargingStatusCallback,
177 MHWRMBatteryChargingCurrentObserver* aChrgCurrentCallback,
178 MHWRMBatteryFullChargingTimeObserver* aChrgTimeCallback);
179 IMPORT_C TInt NotifyAverageChargingCurrent(TRequestStatus& aStatus, const TUint& aInterval);
180 IMPORT_C TInt NotifyBatteryFullChargingTime(TRequestStatus& aStatus);
181 IMPORT_C void StopChargingNotificationL(TBatteryChargingNotifier aNotifier);
182 #endif //SYMBIAN_HWRM_EXTPOWERINFO
190 CHWRMPowerImpl* iPowerImpl;
194 * A callback interface for power measurements reporting.
196 * If the client requires periodical measurements of the Average Power,
197 * it needs to derive a class from the MHWRMBatteryPowerObserver interface
198 * and implement the PowerMeasurement() method.
200 * A callback object header example:
204 * #include <hwrmpower.h> // Link against HWRMPowerClient.lib.
206 * class CTest : public CBase,
207 * public MHWRMBatteryPowerObserver
214 * static CTest* NewL();
216 * // from MHWRMBatteryPowerObserver
217 * virtual void PowerMeasurement(TInt aErr, CHWRMPower::TBatteryPowerMeasurementData& aMeasurement);
220 * CHWRMPower* iPower;
224 * A callback method implementation example:
227 * void CTest::PowerMeasurement(TInt aErr, CHWRMPower::TBatteryPowerMeasurementData& aMeasurement);
229 * if (aErrorCode == KErrNone)
231 * INFO_PRINTF2(_L("INFO: Power Measurement Received, averageVolatge=%d, averageCurrent=%d"),aMeasurement.iAverageVoltage, aMeasurement.iAverageCurrent);
235 * INFO_PRINTF2(_L("INFO: Power Measurement Measurement Error, error=%d"),aErr);
244 class MHWRMBatteryPowerObserver
248 * Called when a Power(Voltage and Current) consumption measurement value is received.
250 * @param aErr Error code.
251 * @param aMeasurement The Average Power value calculated by the plugin. Valid only when aErr == KErrNone.
254 virtual void PowerMeasurement(TInt aErr, CHWRMPower::TBatteryPowerMeasurementData& aMeasurement)=0;
258 #ifdef SYMBIAN_HWRM_EXTPOWERINFO
260 * A callback interface for charging status change.
262 * If the client requires charging status change notofication,
263 * it needs to derive a class from the MHWRMBatteryChargingStatusObserver interface
264 * and implement the ChargingStatusChange() method.
266 * A callback object header example:
270 class CTest : public CBase,
271 public MHWRMBatteryChargingStatusObserver
278 static CTest* NewL();
280 // from MHWRMBatteryChargingStatusObserver
281 virtual void ChargingStatusChange( Tint aErrCode,
282 CHWRMPower::TBatteryChargingStatus aChrgStatus);
285 * A callback method implementation example:
289 void CTest:: ChargingStatusChange(TInt aErrorCode,
290 CHWRMPower::TBatteryChargingStatus aChrgStatus);
292 if (aErrorCode == KErrNone)
294 INFO_PRINTF2(_L("Charging status = %d"), aChrgStatus);
298 INFO_PRINTF2(_L("Error, error=%d"),aErrorCode);
306 class MHWRMBatteryChargingStatusObserver
310 * Called when a charging status is changed.
312 * @param aErrCode Error code.
313 * @param aChrgStatus Charging status.
316 virtual void ChargingStatusChange( TInt aErrCode,
317 CHWRMPower::TBatteryChargingStatus aChrgStatus)=0;
321 * A callback interface for charging current measurements reporting.
323 * If the client requires periodical measurements of the charging current measurements,
324 * it needs to derive a class from the MHWRMBatteryChargingCurrentObserver interface
325 * and implement the AverageChargingCurrentChange() method.
327 * A callback object header example:
331 class CTest : public CBase,
332 public MHWRMBatteryChargingStatusObserver
339 static CTest* NewL();
341 // from MHWRMBatteryChargingStatusObserver
342 virtual void AverageChargingCurrentRateChange(
343 TInt aErrCode, TInt aMeasurement);
347 * A callback method implementation example:
351 // Notification handler
352 void CTest::ChargingCurrentChange(
353 TInt aErrorCode, TInt aMeasurement)
355 if (aErrorCode == KErrNone)
357 INFO_PRINTF2(_L("Charging current = %d"), aMeasurement);
361 INFO_PRINTF2(_L("Error, error=%d"),aErrorCode);
372 class MHWRMBatteryChargingCurrentObserver
375 * Called when a charging current measurement value is received.
377 * @param aErrCode Error code.
378 * @param aMeasurement The Average Charging current value calculated by the plugin.
379 Valid only when aErr == KErrNone.
382 virtual void AverageChargingCurrentChange(TInt aErrCode, TInt aMeasurement)=0;
386 * A callback interface for remaining charging time notification.
388 * If the client requires remaining charging time notification,
389 * it needs to derive a class from the MHWRMBatteryFullChargingTimeObserver interface
390 * and implement the BatteryFullChargingTimeChange() method.
392 * A callback object header example:
396 class CTest : public CBase,
397 public MHWRMBatteryFullChargingTimeObserver
404 static CTest* NewL();
406 // from MHWRMBatteryChargingStatusObserver
407 virtual void BatteryFullChargingTimeChange(
408 TInt aErrCode, TInt aMeasurement);
412 * A callback method implementation example:
416 // Notification handler
417 void CTest::BatteryFullChargingTimeChange(
418 TInt aErrorCode, TUint aTime)
420 if (aErrorCode == KErrNone)
422 INFO_PRINTF2(_L("Remaining charging time = %d"), aTime);
426 INFO_PRINTF2(_L("Error, error=%d"),aErrorCode);
437 class MHWRMBatteryFullChargingTimeObserver
440 * Called when a full charging current time measurement value is received.
442 * @param aErrCode Error code.
443 * @param aTime Time required for full charging of Battery.
444 Valid only when aErrCode == KErrNone.
448 virtual void BatteryFullChargingTimeChange(TInt aErrCode, TUint aTime)=0;
450 #endif //SYMBIAN_HWRM_EXTPOWERINFO
452 #endif /*HWRMPOWER_H_*/