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

nunchuck-js

v1.2.0

Published

Nunchuck.js library that provides a lot of nunchuck modules

Downloads

21

Readme

nunchuck.js

Node.js module for nunchuck controller device. Provides a device object and a decoder object. The device object enables to receive raw data. A typical usage could be:

  var nunchuckModules = require('nunchuck-js').nunchuck;
  var NunchuckDevice = nunchuckModules.device;
  var device = new NunchuckDevice(NUNCHUCK_ADDRESS, 10,[]);
  device.init();
  device.start(function(data){
      var x = data[0];
      var y= data[1];  
      var cBtn = data[2];
      var zBtn = data[3];
      var aX = data[4]; //accelerometer X axis values from 0-255;
      var aY = data[5]; //accelerometer Y axis values from 0-255;
      var aZ = data[6]; //accelerometer Z axis values from 0-255;
  });

The device object:

The NunchuckDevice constructor takes 3 parameters:

  • The address of the device (typically 0x52);
  • The request frequency in milliseconds ( 10 => request every 10 ms)
  • An array of values to calibrate the device, if empty will be used default values: [thresholdX, threshoholdY];

The start method takes a callback function in input. The callback will be invoked at the requested frequency, every time the callback is invoked new data are passed in a data object. The data object is an array of length = 7, the value mapping is:

  • data[0] X axis of the stick, contains a number value [min=0, max=255];
  • data[1] Y axis of the stick, contains a number value [min=0, max=255];
  • data[2] C button can be 0 or 1;
  • data[3] Z button can be 0 or 1;
  • data[4] X axis of the accelerometer contains a number value [min=0, max=255];
  • data[5] Y axis of the accelerometer contains a number value [min=0, max=255];
  • data[6] Z axis of the accelerometer contains a number value [min=0, max=255];

The decoder object:

The decoder object wraps a device object and decode raw data in an human readable way. Below a typical example usage:

  var nunchuckModules = require('nunchuck-js').nunchuck;
  var NunchuckDevice = nunchuckModules.device;
  var NunchuckDecoder = nunchuckModules.decoder;
  var nunchuck = new NunchuckDevice(NUNCHUCK_ADDRESS, 10,[]);
  nunchuck.init();
  var decoder = new NunchuckDecoder(nunchuck);
  decoder.start(function(stream){
    var hX = stream[0]; //possible values left, right, center
    console.log(hX);
  }

###Process values returned by the decoder: Decoder sends data in an array. The decoder has an utility method (asObject) to transform the array in a generic JSON object:

  decoder.start(function(stream){
    var obj = decoder.asObject(stream);
    console.log(obj.stick.x)
  }

Here is the spec of the returned JSON object:

var message = {
  stick: {
    xDirection: ,//['left','center','up']
    yDirection:: ,//['up','center','down']
    x: ,//single X stick direction value
    y: ,//single Y stick direction value
  }
  buttons:{
    C: ,//['idle','pressed']
    Z: ,//['idle','pressed']
  },
  accelerometer:{
    aX: ,//single X axis acceleration value
    aY: ,//single Y axis acceleration value
    aZ: ,//single Z axis acceleration value
  },
  motion:{
    accel: ,// total acceleration from 3 axes
    tilt: ,//['left', 'right', 'up', 'down']
  },
  rotation:{
    x: ,// x rotation angle in radians (roll)
    y: ,// y rotation angle in radians (pitch)
    z: ,// z rotation angle in radians (yaw)
  }
}