gpiobutton
provides higher level button events for a gpio button
Last updated 6 years ago by steven-gardiner .
MIT · Repository · Bugs · Original npm · Tarball · package.json
$ cnpm install gpiobutton 
SYNC missed versions from official npm registry.

gpiobutton

get higher level button events from a gpio button

This package provides specialized handling of signals from buttons attached to GPIO ports of a Raspberry Pi. Rather than programming around low-level events like signal change, you can use higher-level events like a button press or multiple presses.

Installation

npm install gpiobutton

Initialization

var gpiobutton = require('gpiobutton');
var buttonSpec = {gpiono:4};
var button4 = new gpiobutton.button(buttonSpec);

The button's initialization spec includes the gpiono, which uses the same numbering scheme as the gpio package. It may also optionally include

  1. an "interval" property indicating the period (in milliseconds) of polling.
  2. a "DOWN" property indicating which signal indicates the button being down, or pressed.

API Methods

button4.deactivate();

Temporarily ignore signals from the button. Buttons start out activated but may be deactivated (which translates to being unexported from the gpio package) to decrease the amount of polling.

button4.activate();

Use the pin information from the instantiation to resume listening for changes on the pin.

Events

button4.on("buttondown", function(event) {
  // button was pressed down
});

Most buttons seem to rest in the "up" or open position, sending a signal of 1. When the button is pushed down, the signal goes to 0 and this event is emitted.

You can change the semantics of "up" and "down" for a particular button by explicitly passing a "DOWN" property in the button's instantiation spec.

button4.on("buttonup", function(event) {
  // button was released
});

The opposite of the buttondown.

button4.on("buttonpress", function(event) {
  // The button was pressed and then subsequently released
});

Analogue of the "mouseclick" event in web programming. Will not fire unless and until the button is released.

button4.on("longpress", function(event) {
  // The button was pressed and held.
});

Fired after the button has been down for awhile (defaults to 1000 milliseconds; can be altered by setting the "longTimeout" property of the instantiation spec of the button). Note that this event fires regardless of when or whether the button is released.

button4.on("multipress", function(event) {
  var presses = event.count;
  // Button was pressed several times
});

Fired after the button has been pressed (and released) multiple times, as for example a double click on a mouse. The event includes a "count" property indicating how many times the button was pressed. Finer-grained information about how long each press (and times between presses) can be found from the "wave" property of the event; each button state is described in terms of the number of "beats" the button state lasted. This package relies on the polling provided by the gpio package, so state changes occurring between polls are ignored.

Current Tags

  • 0.0.2                                ...           latest (6 years ago)

2 Versions

  • 0.0.2                                ...           6 years ago
  • 0.0.1                                ...           6 years ago
Maintainers (1)
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 3
Dependencies (1)
Dev Dependencies (0)
None
Dependents (1)

Copyright 2014 - 2017 © taobao.org |