C

BatteryInfoScriptInterface Class

The BatteryInfoScriptInterface class enables you to emulate changes in battery level and power state. More...

Header: #include <BatteryInfoScriptInterface>

Public Types

enum BatteryLevelWrap { BatteryLevelUnknown, BatteryLevelEmpty, BatteryLevelLow, BatteryLevelOk, BatteryLevelFull }
enum ChargerTypeWrap { UnknownCharger, WallCharger, USBCharger, VariableCurrentCharger }
enum ChargingStateWrap { UnknownChargingState, IdleChargingState, Charging, Discharging }

Properties

Public Functions

BatteryLevelWrap batteryLevel() const
ChargerTypeWrap chargerType() const
ChargingStateWrap chargingState() const
int currentFlow() const
int maximumCapacity() const
int remainingCapacity() const
int remainingChargingTime() const
int voltage() const

Public Slots

void setBatteryLevel(BatteryLevelWrap )
void setChargerType(ChargerTypeWrap )
void setChargingState(ChargingStateWrap )
void setCurrentFlow(int )
void setMaximumCapacity(int )
void setRemainingCapacity(int )
void setRemainingChargingTime(int )
void setVoltage(int )

Detailed Description

The BatteryInfoScriptInterface class enables you to emulate changes in battery level and power state.

The BatteryInfoScriptInterface class is exposed as sysinfo.battery.

For example, the following script decreases the battery level over 15 seconds until the battery is empty. The remainingCapacity variable sets the initial battery level to the value of the remainingCapacity property. The drainTime variable specifies the time in seconds to drain the battery, and the steps variable specifies how many times the battery level is reduced.

var remainingCapacity = sysinfo.battery.remainingCapacity;
var drainTime = 15;
var steps = 15;

The following code uses the chargingState property to set the power state to Discharging:

sysinfo.battery.chargingState = sysinfo.battery.Discharging;

Because running this script does not make sense if the battery is already drained, the following code uses the remainingCapacity property to check that the battery level is set between 1 and the maximum battery capacity:

if (remainingCapacity <= 1)
    remainingCapacity = sysinfo.battery.maximumCapacity;

The following code slowly drains the battery:

for (var i = 0; i < steps; ++i) {
    sysinfo.battery.remainingCapacity = remainingCapacity * (1 - i/(steps-1));
    yield(drainTime/steps * 1000);
}

Member Type Documentation

enum BatteryInfoScriptInterface::BatteryLevelWrap

ConstantValueDescription
BatteryInfoScriptInterface::BatteryLevelUnknownQBatteryInfo::LevelUnknownBattery level is not known.
BatteryInfoScriptInterface::BatteryLevelEmptyQBatteryInfo::LevelEmptyBattery level is reported as 0. The device will shut down.
BatteryInfoScriptInterface::BatteryLevelLowQBatteryInfo::LevelLowBattery level is below 40%.
BatteryInfoScriptInterface::BatteryLevelOkQBatteryInfo::LevelOkBattery level is above 40%.
BatteryInfoScriptInterface::BatteryLevelFullQBatteryInfo::LevelFullBattery level is at 100%.

enum BatteryInfoScriptInterface::ChargerTypeWrap

ConstantValueDescription
BatteryInfoScriptInterface::UnknownChargerQBatteryInfo::UnknownChargerCharger type is not known, or an error occurred.
BatteryInfoScriptInterface::WallChargerQBatteryInfo::WallChargerUsing a charger to connect to a power outlet.
BatteryInfoScriptInterface::USBChargerQBatteryInfo::USBChargerUsing a USB charger.
BatteryInfoScriptInterface::VariableCurrentChargerQBatteryInfo::VariableCurrentChargerUsing a charger that produces a variable current, such as a bicycle or solar charger.

enum BatteryInfoScriptInterface::ChargingStateWrap

ConstantValueDescription
BatteryInfoScriptInterface::UnknownChargingStateQBatteryInfo::UnknownChargingStateCharging state is not known.
BatteryInfoScriptInterface::IdleChargingStateQBatteryInfo::IdleChargingStateBattery is not charging.
BatteryInfoScriptInterface::ChargingQBatteryInfo::ChargingBattery is charging.
BatteryInfoScriptInterface::DischargingQBatteryInfo::DischargingBattery is discharging.

Property Documentation

batteryLevel : BatteryLevelWrap

This property holds the battery level.

Access functions:

BatteryLevelWrap batteryLevel() const
void setBatteryLevel(BatteryLevelWrap )

chargerType : ChargerTypeWrap

This property holds the charger type.

Access functions:

ChargerTypeWrap chargerType() const
void setChargerType(ChargerTypeWrap )

chargingState : ChargingStateWrap

This property holds the charging state.

Access functions:

ChargingStateWrap chargingState() const
void setChargingState(ChargingStateWrap )

currentFlow : int

This property holds the battery current flow.

Returns the amount of current flowing out of the battery in milliamperes (mA). A positive flow means discharging, a negative flow means charging, and 0 is returned if an error occurs or if the information is not available.

Access functions:

int currentFlow() const
void setCurrentFlow(int )

maximumCapacity : int

This property holds the maximum battery capacity measured as mAh.

If no battery is found, or if an error occurs, returns -1.

Access functions:

int maximumCapacity() const
void setMaximumCapacity(int )

remainingCapacity : int

This property holds the battery level measured as mAh.

If no battery is found, or if an error occurs, returns -1.

Access functions:

int remainingCapacity() const
void setRemainingCapacity(int )

remainingChargingTime : int

This property holds the remaining time of charging in seconds.

Returns 0 if the battery is full or not charging. If no battery is found, or if an error occurs, returns -1.

Access functions:

int remainingChargingTime() const
void setRemainingChargingTime(int )

voltage : int

This property holds the battery voltage in millivolts (mV).

If no battery is found, or if an error occurs, returns -1.

Access functions:

int voltage() const
void setVoltage(int )

Available under certain Qt licenses.
Find out more.