Module: siteKiosk.system.battery

This module provides information about the system's battery status and offers means to attach listeners to some battery related events. These events include the battery value falling below a certain threshold, the change of battery level and a rise of the battery level above a certain threshold.

Example

//some simple battery functions

var batteryStatus = siteKiosk.system.battery.getStatus();

//log the current energy level
console.log("You have "+batteryStatus.percentage+" % energy left.");

siteKiosk.system.battery.onLow(function() {
   //notify when battery is low
   console.log("Oh no, not much energy left! You should find a power source and recharge the device!");
});

Methods

<static> getIsLow() → {boolean}

Returns true, if battery level is low.
Returns:
True, if battery level is low
Type
boolean

<static> getIsOkay() → {boolean}

Returns true, if battery level is okay.
Returns:
True, if battery level is okay
Type
boolean

<static> getStatus() → {siteKiosk.system.battery~batteryStatus}

Returns a battery status object.
Returns:
The battery status object
Type
siteKiosk.system.battery~batteryStatus

<static> onChanged(callback)

Provided callback function will be called when battery status has changed.
Parameters:
Name Type Description
callback siteKiosk.system.battery~changedCallback A callback function that is called when battery status changed

<static> onLow(callback) → {siteKiosk.system.battery~eventSubscription}

Registers a callback to be called when battery level falls below a certain value (15%).
Parameters:
Name Type Description
callback siteKiosk.system.battery~lowCallback The callback function
Returns:
An event subscription
Type
siteKiosk.system.battery~eventSubscription

<static> onOkay(callback) → {siteKiosk.system.battery~eventSubscription}

Registers a callback to be called when battery level is again above a certain value (20%).
Parameters:
Name Type Description
callback siteKiosk.system.battery~okayCallback The callback function
Returns:
An event subscription
Type
siteKiosk.system.battery~eventSubscription

Type Definitions

batteryStatus

An object providing information about the battery status.
Type:
  • Object
Properties:
Name Type Description
percentage number The Battery level in percentage
plugged boolean Whether the device is plugged into a power supply
status string Either "charging", "discharging", "full", "not-charging" or "unknown"

changedCallback(status)

A callback function that is called when battery status changed.
Parameters:
Name Type Description
status siteKiosk.system.battery~batteryStatus The battery status object

eventSubscription

An event subscription, used to unsubscribe the event.
Type:
  • Object
Properties:
Name Type Description
listenerCount number An Integer, indicating how many listeners this event had at the moment it has been subscribed
unbind function A function to unsubscribe the event

lowCallback()

A callback function that is called when the battery level is low.

okayCallback()

A callback function that is called when the battery level is okay.