cordova-plugin-flic2
v0.0.2
Published
Cordova Flic2 Plugin
Downloads
9
Maintainers
Readme
cordova-plugin-flic2
This plugin provides the ability to interact with Flic2 buttons.
Although in the global scope, it is not available until after the deviceready
event.
document.addEventListener("deviceready", onDeviceReady, false);
function onDeviceReady() {
console.log(flic2);
}
Installation
cordova plugin add cordova-plugin-flic2
Supported Platforms
- Android
How to use
First initialize the plugin
flic2.init()
Scan for new buttons
flic2.startScan(success, error)
Parameters
- success: A callback to be called for each step of the scan. Takes an object argument. The properties on the object are
statusCode
andbutton
. Thebutton
will only be set on success. SeeConstants
for all status codes. - error: A callback for errors. Will always be an integer. See
Constants
for all failures;
Stop scan for buttons
flic2.stopScan()
Get buttons
flic2.getButtons(success, error)
Parameters
- success: A callback called when successful. It takes a list of buttons as argument.
- error: A callback for errors.
Buttons
getButtons
and startScan
returns buttons. Each buttons has some properties and methods.
Properties
name
: NamebdAddr
: Bluetooth addressconnectionState
: Connection statefirmwareVersion
: Firmware versiongetLastKnownBatteryLevel
: Last known battery levelpressCount
: Press countreadyTimestamp
: Timestamp when the button was readyserialNumber
: Serial numberuuid
: Unique button id
Methods
connect
: Connects the buttondisconnectOrAbortPendingConnection
: Disconnects the buttonsetName
: Set the name of the buttonsetAutoDisconnectTime
: Set auto disconnect timeonButtonSingleOrDoubleClickOrHold
: Add event listener for single, double, click or hold eventsonAllQueuedButtonEventsProcessed
: Add event listener for when all button events are processedonBatteryLevelUpdated
: Add event listener for battery level updatedonButtonClickOrHold
: Add event listener for click or hold eventsonButtonSingleOrDoubleClick
: Add event listener for single or double click eventsonButtonUpOrDown
:' Add event listener for button up or button down eventsonConnect
: Add event listener for connect eventsonDisconnect
: Add event listener for disconnect eventsonFailure
: Add event listener for failure eventsonReady
: Add event listener for ready eventsonFirmwareVersionUpdated
: Add event listener for firmware version updates eventsonNameUpdated
: Add event listener for name update eventsonUnpaired
: Add event listener for unpaired events
Every event listener can be removed by calling the un
instead of on
method, example unButtonClickOrHold
Constants
The following constants are reported as part of the callback for
startScan
:
flic2.SCAN_RESULT.ALREADY_PAIRED
= 0;flic2.SCAN_RESULT.DISCOVERED
= 1;flic2.SCAN_RESULT.CONNECTED
= 2;flic2.SCAN_RESULT.COMPLETE
= 3;flic2.SCAN_RESULT.FAILED_ALREADY_RUNNING
= 1;flic2.SCAN_RESULT.FAILED_BLUETOOTH_OFF
= 2;flic2.SCAN_RESULT.FAILED_SCAN_ERROR
= 3;flic2.SCAN_RESULT.FAILED_NO_NEW_BUTTONS_FOUND
= 4;flic2.SCAN_RESULT.FAILED_BUTTON_ALREADY_CONNECTED_TO_OTHER_DEVICE
= 5;flic2.SCAN_RESULT.FAILED_CONNECT_TIMED_OUT
= 6;flic2.SCAN_RESULT.FAILED_VERIFY_TIMED_OUT
= 7;