Giter VIP home page Giter VIP logo

cordova-flic's Introduction

Cordova-Flic

A Cordova plugin providing access to the Flic SDK (Android and iOS)

Installation

$ cordova plugin add https://github.com/dukhanov/Cordova-Flic --variable URL_SCHEME=mycoolapp

Android

Set android:minSdkVersion="19" or higher in config.xml for the Android

	<preference name="android-minSdkVersion" value="19" />
$ cordova build android

iOS

Set deployment-target=8.0 or higher in config.xml for the iOS

	<preference name="deployment-target" value="8.0" />

Make sure, that you have installed node-xcode version 0.8.7 or higher on your Mac

$ npm i xcode
$ cordova build ios

Plugin API

It has been currently stripped to the minimum needed from a Javascript app.

The following functions are available:

  • Flic.init (config, success, error). Initialize Flic and register known buttons for receiving single click, double click and hold events
    • config:
      • appId: your app client ID
      • appSecret: your app client secret
      • appName: your app name
      • reloadOnFlicEvent: in case you want to start the App via Flic event (Android only, Boolean, default: false)
    • success: called on function success
    • error: called on function error
  • Flic.getKnownButtons(success, error). Get known buttons. Returns the list of buttons grabbed in a previous run of the app
    • success: called on function success
    • error: called on function error
  • Flic.grabButton(success, error). Grab a button and register it for receiving single click, double click and hold events. Returns the grabbed button
    • success: called on function success
    • error: called on function error
  • Flic.onButtonClick(onButtonPressed, onButtonPressedError)
    • onButtonPressed: called when flic button is pressed
    • onButtonPressedError: called when flic button is pressed, but some error has occured

Sample usage code

function successInit(result) {
    console.log('Flic init succeeded');

    // Get known buttons
    Flic.getKnownButtons(
        function(buttons) {
            console.log('Flic getKnownButtons succeeded');
            console.log('Flic known buttons: ' + JSON.stringify(buttons));
        },
        function(message) {
            console.log('Flic getKnownButtons failed: ' + message);
        });
}

function errorInit(message) {
    console.log('Flic init failed: ' + message);
}

function onFlicButtonPressed(result) {
    console.log(result.event); // (String) singleClick or doubleClick or hold
    console.log(result.button.buttonId); // (String)
    console.log(result.button.color); // (String) green
    console.log(result.wasQueued); // (Boolean) If the event was locally queued in the button because it was disconnected. After the connection is completed, the event will be sent with this parameter set to true.
    console.log(result.timeDiff); // (Number) If the event was queued, the timeDiff will be the number of seconds since the event happened.
}

function onFlicButtonPressedError(err){
    console.log(err);
}

var config = {
    appId: 'your app id',
    appSecret: 'your app client secret',
    appName: 'your app name',
    reloadOnFlicEvent: true,
}

// Init flic
Flic.init(config, successInit, errorInit);

// Subscription to button events
Flic.onButtonClick(onFlicButtonPressed, onFlicButtonPressedError)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.