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

gpiod-client

v1.7.2

Published

Intuitive, fun to use, object-oriented implementation.

Downloads

13

Readme

GPIO Controller for Node.js done right

Intuitive, fun to use, object-oriented implementation.

Thanks to C++ bindings this package is using kernel level GPIO access via libgpiod (see https://kernel.googlesource.com/pub/scm/libs/libgpiod/libgpiod/+/v0.2.x/README.md). The library offers accuracy and reliability. It can also register changes as quick as 1 microsecond or less and does not require extensive pooling.

Written in TypeScript.

Installation

sudo apt update
sudo apt-get install libgpiod-dev
yarn add gpiod-client

API Reference

https://kodmax.github.io/gpiod-client/classes/GPIOController.html

Digital Input

Features

  • reading current value
  • listening for input events: rising and/or falling edge
  • nanoseconds precision for each event provided by linux kernel
  • software input debouncer for ease of use with mechanical switches
  • configurable 'hold' event triggered after each hold time is reached

Polling interval

Linux kernel

The input events are collected at kernel level. Each event has a high resolution timer timestamp attached. The precision goes to nanoseconds level.

Input line configuration

Each input line can be configured with different pooling interval to read those events. Regardless of the pooling interval the precision remains the same and no events are lost. If edge events are not needed, no pooling is required.

Examples

Logging button events

import { GPIOController } from 'gpiod-client'

const gpio = new GPIOController('gpiochip0', 'input27')

// look for both falling and rising edges
// read the events queue from linux kernel every 100ms
const line2 = gpio.requestLineAsInput(2, 'both', 100) 

// debounce the mechanical switch noise for 50ms
// trigger a hold event after 300ms press and then after 1 second press
const button = line2.createDebouncer(50, 0, [300, 1000]) 

console.log('Hit the button!')

button.addListener('press', () => {
    console.log('press')
})

button.addListener('release', () => {
    console.log('release')
})

button.addListener('hold', ev => {
    console.log('hold', ev.time, 'ms')
})

Digital output

Features

  • setting a value
  • optionally pausing program execution after setings a value (sleep in microseconds). Convenient if the connected circuit needs some microseconds to process the input change
  • sending an impulse (trigger in microseconds) of 0 or 1. Convenient for triggering RST or other functions.

Examples

Classic, blink as led by settings 0 and 1 in interval of 50 miliseconds

import { GPIOController } from 'gpiod-client'

const gpio = new GPIOController('gpiochip0', 'blink17')
const led = gpio.requestLineAsOutput(17, 1)

let i = 0
setInterval(() => {
    led.setValue(++i % 2 ? 1 : 0)
}, 50)

Flash led for 10 miliseconds every second using trigger

import { GPIOController } from 'gpiod-client'

const gpio = new GPIOController('gpiochip0', 'blink17')
const led = gpio.requestLineAsOutput(17, 0)

setInterval(() => {
    led.trigger(1, 10000)
}, 1000)