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 }
enum HealthWrap { HealthUnknown, HealthOk, HealthBad }

Properties

Public Functions

BatteryInfoScriptInterface::BatteryLevelWrap batteryLevel() const
BatteryInfoScriptInterface::ChargerTypeWrap chargerType() const
BatteryInfoScriptInterface::ChargingStateWrap chargingState() const
int currentFlow() const
BatteryInfoScriptInterface::HealthWrap health() const
int maximumCapacity() const
int remainingCapacity() const
int remainingChargingTime() const
float temperature() const
int voltage() const

Public Slots

void setBatteryLevel(BatteryInfoScriptInterface::BatteryLevelWrap)
void setChargerType(BatteryInfoScriptInterface::ChargerTypeWrap)
void setChargingState(BatteryInfoScriptInterface::ChargingStateWrap)
void setCurrentFlow(int)
void setHealth(BatteryInfoScriptInterface::HealthWrap)
void setMaximumCapacity(int)
void setRemainingCapacity(int)
void setRemainingChargingTime(int)
void setTemperature(float)
void setVoltage(int)

Static Public Members

const QMetaObject staticMetaObject

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::BatteryLevelUnknown0Battery level is not known.
BatteryInfoScriptInterface::BatteryLevelEmpty1Battery level is reported as 0. The device will shut down.
BatteryInfoScriptInterface::BatteryLevelLow2Battery level is below 40%.
BatteryInfoScriptInterface::BatteryLevelOk3Battery level is above 40%.
BatteryInfoScriptInterface::BatteryLevelFull4Battery level is at 100%.

enum BatteryInfoScriptInterface::ChargerTypeWrap

ConstantValueDescription
BatteryInfoScriptInterface::UnknownCharger0Charger type is not known, or an error occurred.
BatteryInfoScriptInterface::WallCharger1Using a charger to connect to a power outlet.
BatteryInfoScriptInterface::USBCharger2Using a USB charger.
BatteryInfoScriptInterface::VariableCurrentCharger3Using a charger that produces a variable current, such as a bicycle or solar charger.

enum BatteryInfoScriptInterface::ChargingStateWrap

ConstantValueDescription
BatteryInfoScriptInterface::UnknownChargingState0Charging state is not known.
BatteryInfoScriptInterface::IdleChargingState2Battery is not charging.
BatteryInfoScriptInterface::Charging1Battery is charging.
BatteryInfoScriptInterface::Discharging3Battery is discharging.

enum BatteryInfoScriptInterface::HealthWrap

Property Documentation

batteryLevel : BatteryLevelWrap

This property holds the battery level.

Access functions:

BatteryInfoScriptInterface::BatteryLevelWrap batteryLevel() const
void setBatteryLevel(BatteryInfoScriptInterface::BatteryLevelWrap)

chargerType : ChargerTypeWrap

This property holds the charger type.

Access functions:

BatteryInfoScriptInterface::ChargerTypeWrap chargerType() const
void setChargerType(BatteryInfoScriptInterface::ChargerTypeWrap)

chargingState : ChargingStateWrap

This property holds the charging state.

Access functions:

BatteryInfoScriptInterface::ChargingStateWrap chargingState() const
void setChargingState(BatteryInfoScriptInterface::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)

health : HealthWrap

This property holds the health of the battery.

Access functions:

BatteryInfoScriptInterface::HealthWrap health() const
void setHealth(BatteryInfoScriptInterface::HealthWrap)

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)

temperature : float

This property holds the battery temperature in degree celsius.

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

Access functions:

float temperature() const
void setTemperature(float)

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)

Member Function Documentation

Member Variable Documentation

Related Non-Members

Macro Documentation

© 2018 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.