1.1.0 • Published 4 years ago

flic-module v1.1.0

Weekly downloads
2
License
MIT
Repository
github
Last release
4 years ago

Flic Module

Overview

We have configured our Flic buttons to populate a firebase database whenever they are pressed. This module provides a convenience function to listen for those events and output an RxJS stream.

Installation

npm install flic-module

Usage

import FlicListener, {MODE} from "flic-module";

const flic = new FlicListener();

// Listen for the three different types of events from button 1
// In all cases `command` is the object in the firebase database
// ie. command = {button: <number>, mode: <number>, timestamp: <seconds since epoch>}
flic.button$(1, MODE.SINGLE_CLICK).subscribe(command => { ... });
flic.button$(1, MODE.DOUBLE_CLICK).subscribe(command => { ... });
flic.button$(1, MODE.LONG_PRESS).subscribe(command => { ... });

// Listen for events associated with the first 2 buttons pressed
// Note that you do not need to specify the button numbers
// - the n-th `buttonStreams` object corresponds to the n-th button
// that fired an event since the `FlicListener` was created
flic.nextButtonStreams$(2).pipe(map(buttonStreams => {
    console.log(buttonStreams.button) // the button number
    buttonsStreams.SINGLE_CLICK.subscribe(command => { ... });
    buttonsStreams.DOUBLE_CLICK.subscribe(command => { ... });
    buttonsStreams.LONG_PRESS.subscribe(command => { ... });
}))
1.1.0

4 years ago

1.0.1

4 years ago

1.0.0

4 years ago