charger - 充电

示例代码

var charger = require('charger');

// start charging
charger.switch(1);

//stop charging
charger.switch(0);

// get charging current in mA
var charge_current = charger.getCurrent();
console.log('charge current is ' + charge_current + ' mA');

// get charge state
var charge_state = charger.getConnectState();
console.log('charge state is ' + charge_state);

方法

charger.switch(onoff)

开始/停止充电

入参

属性

类型

必填

描述

onff

bool

充电开关标识

返回值

Number类型。0 - 成功,其它 - 失败

charger.getCurrent()

获取充电电流大小,单位:mA

返回值

Number类型。电流值,单位mA

charger.getConnectState()

获取usb连接状态

返回值

Number类型。1 - usb连接,0 - usb未连接