npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

gpiobutton

v0.0.2

Published

provides higher level button events for a gpio button

Downloads

2

Readme

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.