Handle operation on battery sensor.

Usage

battery keyword is needed to instanciate this sting.

var battery = require('battery');

Data accessors

Methods

Events

Full Example

var battery = require('battery');
var recorder = require('recorder');

var dataResult = battery.data();


recorder.save({
    'AC Connector' : battery.isConnector(battery.AC),
    'level' : battery.level(),
    'FULL State' : battery.isState(battery.FULL),
    'technology' : battery.technology(),
    'temperature' : battery.temperature(),
    'timestamp' : battery.timestamp(),
    'voltage' : battery.voltage(),
    'json' : battery.data()
});

battery.onLevelChanged(function(data) {
    recorder.save(data);
    recorder.sync();
});

battery.onStateChanged(function(data) {
    recorder.save(data);
    recorder.sync();
});

connector

Retrieve the Connector used to charge the battery.

connector();

Parameters

  • None.

Return

isConnector

Test the current connector value against the given one.

isConnector(value);

Parameters

Return

  • Boolean

isState

Test the current state value against the given one.

isState(value);

Parameters

Return

  • Boolean

level

Retrieve the Current battery level.

level();

Parameters

  • None.

Return

  • level : Double, Current battery level

state

Retrieve the Description of the current state.

state();

Parameters

  • None.

Return

technology

Retrieve the Technology of the battery.

technology();

Parameters

  • None.

Return

  • technology : String, Technology of the battery

temperature

Retrieve the Current temperature of the battery.

temperature();

Parameters

  • None.

Return

  • temperature : Double, Current temperature of the battery

timestamp

Retrieve the represents the time of the operation..

timestamp();

Parameters

  • None.

Return

  • timestamp : Long, represents the time of the operation.

voltage

Retrieve the Current voltage of the battery.

voltage();

Parameters

  • None.

Return

  • voltage : Double, Current voltage of the battery

data

Returns every available seed.

data();

Parameters

  • None.

Returns

onLevelChanged

Starts a listener on the battery level and executes some actions when it changes.

onLevelChanged(callback);

Parameters

Return

  • token : Token used for canceling event listener.

onStateChanged

Starts a listener on the battery state and executes some actions when it changes.

onStateChanged(callback);

Parameters

Return

  • token : Token used for canceling event listener.