battery - 电池

示例代码

var battery = require('battery');

// get battery connection state: 1 - connected, 0 - not connect
var batt_stat = battery.getConnectState();
console.log('batt state is ' + batt_stat);

// get battery voltage in mV
var batt_vol = battery.getVoltage();
console.log('batt voltage is ' + batt_vol + ' mV');

// get battery level
var batt_level = battery.getLevel();
console.log('battery level is ' + batt_level);

// get battery temperature
var batt_temp = battery.getTemperature();
console.log('battery temperature is ' + batt_temp);

方法

battery.getConnectState()

获取电池接通状态

返回值

Number类型。1 - 电池接通,0 - 没有接电池

battery.getVoltage()

获取电池电压

返回值

Number类型。电压值,单位mV

battery.getLevel()

获取电池电量

返回值

Number类型。电池电量,取值范围:0-100

battery.getTemperature()

获取电池温度

返回值

Number类型。电池温度值