battery

Provides access to various properties of the battery. Each of these properties is a cp.prop, so it can be watched for changes. For example:

local battery = require("cp.battery")
battery.powerSupply:watch(function(value)
print("Now using "..value)
end)

This will print "Now using AC Power" or "Now using Battery Power" whenever the power supply changes.

API Overview

API Documentation

Constants

amperage

Signature

cp.battery.amperage <cp.prop: number; read-only>

Type

Constant

Description

Returns the amount of current flowing through the battery, in mAh.

Notes

capacity

Signature

cp.battery.capacity <cp.prop: number; read-only>

Type

Constant

Description

Returns the current capacity of the battery in mAh.

Notes

cycles

Signature

cp.battery.cycles <cp.prop: number; read-only>

Type

Constant

Description

Returns the number of discharge cycles of the battery.

Notes

Signature

cp.battery.designCapacity <cp.prop: number; read-only>

Type

Constant

Description

Returns the design capacity of the battery in mAh.

health

Signature

cp.battery.health <cp.prop: string; read-only>

Type

Constant

Description

Returns the health status of the battery; either "Good", "Fair" or "Poor",

Signature

cp.battery.healthCondition <cp.prop: string; read-only>

Type

Constant

Description

Returns the health condition status of the battery:

isCharged

Signature

cp.battery.isCharged <cp.prop: boolean; read-only>

Type

Constant

Description

Checks if the battery is fully charged.

Signature

cp.battery.isCharging <cp.prop: boolean; read-only>

Type

Constant

Description

Checks if the battery is currently charging.

Signature

`cp.battery.isFinishingCharge <cp.prop: boolean

string; read-only>` </span>

Type

Constant

Description

Checks if the battery is trickle charging;

Signature

cp.battery.maxCapacity <cp.prop; number; read-only>

Type

Constant

Description

Returns the maximum capacity of the battery in mAh.

Notes

Signature

`cp.battery.otherBatteryInfo <cp.prop: table

nil; read-only>` </span>

Type

Constant

Description

Returns information about non-PSU batteries (e.g. bluetooth accessories). If none are found, nil is returned.

Signature

cp.battery.percentage <cp.prop; string; read-only>

Type

Constant

Description

Returns the current source of power; either "AC Power", "Battery Power" or "Off Line".

psuSerial

Signature

cp.battery.psuSerial <cp.prop: number; read-only>

Type

Constant

Description

Returns the serial number of the attached power supply, or 0 if not present.

Signature

cp.battery.timeRemaining <cp.prop: number; read-only>

Type

Constant

Description

The amount of battery life remaining, in minuges.

Notes

Signature

cp.battery.timeToFullCharge <cp.prop; number; read-only>

Type

Constant

Description

Returns the time remaining for the battery to be fully charged, in minutes, or `-`` if still being calculated.

voltage

Signature

cp.battery.voltage <cp.prop: number; read-only>

Type

Constant

Description

Returns the current voltage of the battery in mV.

watts

Signature

cp.battery.watts <cp.prop: number; read-only>

Type

Constant

Description

Returns the power entering or leaving the battery, in W.