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

pim447-trackball

v1.0.0

Published

Library to use and control the pimoroni trackball breakout.

Downloads

11

Readme

trackball - N76E003AQ20

Node.js module for reading the Pimoroni trackball powered by a Nuvoton N76E003AQ20 MCU.

pipeline status coverage report Quality Gate

Prerequisites

Wiring

| Device pin |Raspberry Pi pin|Raspberry Pi GPIO| |----------------|:---------------|:----------------| | GND | 6 | | | INT | | | | SCL (SPI_CLK) | 3 | 2 | | SDA (SPI_MOSI) | 5 | 3 | | 3-5V | 1 | |

Installation

npm install pim447-trackball

Available Properties

Colour

Returns the current colour of the trackball using the rgbw colour code.

Usage:

trackball.setColour(0,1,2,3);
trackball.Colour // Returns { r: 0, g: 1, b: 2, w: 3 } 

Contrast

Returns the current contrast of the trackball.

Usage:

await trackball.setContrast(0x0A);
trackball.Contrast // Returns 10

RefreshInterval

Returns the current refresh interval in milliseconds of the cursor and click events.

Usage:

trackball.RefreshInterval = 50;
trackball.RefreshInterval // Returns 50

Available Methods

convertHexColourToRgb(hexcolour) - static

Converts hexadecimal colour code to a rgb colour code.

Usage:

Trackball.convertHexColourToRgb('#FF530D'); // Returns { r: 255, g: 83, b: 13 }

convertHexColourToRgbw(hexcolour) - static

Converts hexadecimal colour code to a rgbw colour code.

Usage:

Trackball.convertHexColourToRgbw('#FF530D'); // Returns { r: 242, g: 70, b: 0, w:13 }

convertRgbToRgbw(r,g,b) - static

Converts rgb colour code to a rgbw colour code. The colour range is [0x00,0xFF] for each component.

Usage:

Trackball.convertRgbToRgbw(255, 83 ,13); // Returns { r: 242, g: 70, b: 0, w:13 }

setColour(r,g,b,w)

Sets the colour of the trackball. The colour range is [0x00,0xFF] for each component.

Usage:

await trackball.setColour(0xF0,0xF1,0xF2,0xF3); //sets the colour to (r:0xF0,g:0xF1,b:0xF2,w:0xF2)

setContrast(value)

Sets the contrast of the trackball . The contrast range is [0x00,0xFF].

Usage:

await trackball.setContrast(0xFF); //sets the contrast to (r:0xFF)

turnOn(refreshRate)

Enables the trackball. Status events will be sent per event. The defaut refresh rate 50 milliseconds

Usage:

const trackball = new Trackball();
await trackball.turnOn(100); //sets the refresh rate to 100 milliseconds.

turnOff

Disables the tracking of the cursor position and turn off the lighting of the trackball.

Usage:

await trackball.turnOff();

Available Events

stateUpdate

Returns the cursor movements and the click events.

Event format:

    {
        left: 0, //trackball movement
        right: 0, //trackball movement
        up: 0, //trackball movement
        down: 1, //trackball movement
        clicked: false, //current click state
        clickStateUpdate: 1, //the click state changed between this event and the previous one
        stateUpdate: true //a movement or click event occured
    }

Usage:

function handleStateUpdate(inputs) {
    console.info(inputs);
}

async function initialize() {
    trackball = new Trackball();
    await trackball.turnOn(); 

    trackball.on('stateUpdate', handleStateUpdate); //enable the event listening

    console.info('Click or move the cursor to trigger some events');

    setTimeout(()=>{  trackball.off("stateUpdate", handleStateUpdate);},300000);
}

error

Catches any trackball error(s). The catched errors can be processed by a custom error handler. The error is of type 'TrackballError'.

Event format:

    {
        message: 'message', //trackball error message
        code: 'code', //trackball error code
        innerError: TrackballError, //trackball error that caused the current error (optional)
    }

Usage:

function handleError(trackballError) {
    console.error(trackballError);
}

async function initialize() {
    trackball = new Trackball();
    await trackball.turnOn(); 

    trackball.once('error', handleError); //enable the event listening

    console.info('Click or move the cursor to trigger some events');

}

Credits