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

node-glfw-joystick

v0.1.6

Published

Creates events for joysticks

Downloads

13

Readme

NodeJS binding to Joystick (Gamepad) via GLFW

In this project, we find and init joystick (gamepad) devices via GLFW (This is the work done by node-glfw), and wrap their polled states as NodeJS events for a generic Joystick (gamepad). We map the device buttons and axes to match our generic one.

We identify the device by the name attribute and button count returned from GLFW. GLFW doesn't provide vendorId nor productId attributes, making it hard to truly distinguish devices (e.g Device1 from CompanyX: name is Controller and has 10 buttons, Device2 from CompanyY: name is Controller and has 10 buttons)

We have provided button/axes maps for the XBox360, PS3, PS4 controllers. The PS4 controller, when connected via Bluetooth, seems to behave different and return 0 button count. We recommend using a PS3 Wireless Controller instead.

Also, this project uses a modified built for GLFW3, since it will segfault when connecting a controller in Maverics.

Dependencies

Installation

npm install node-glfw-joystick

Usage

First, we initialize our object

var JoystickManager = require('node-glfw-joystick');
var joystickMgr = new JoystickManager();
joystickMgr.init();

Then, there are two ways of getting events ::Animate([delay]) or ::Poll()

// With Animate

joystickMgr.animate();

joystickMgr.on('JOYSTICK_BUTTON_DOWN', function(deviceId, buttonId) { ... });

if you have a drawing function or some other loop function that updates your application, then you can use Poll

// With Polling

yourloopFunction() {
	joystickMgr.poll();
}

joystickMgr.on('JOYSTICK_BUTTON_DOWN', function(deviceId, buttonId) { ... });

Test

In the folder tests

node test.js

For a more visual test, use

node joystickTest.js

Pressed the home button to reset if the triangle gets lost!

Events

There are 5 type of events you can listen for

JOYSTICK_AXES_UPDATE			---> function(deviceId, axeId, value) {}
JOYSTICK_BUTTON_UP 				---> function(deviceId, buttonId) {}
JOYSTICK_BUTTON_DOWN			---> function(deviceId, buttonId) {}
JOYSTICK_BUTTON_RELEASED	---> function(deviceId, buttonId) {}
JOYSTICK_BUTTON_PRESSED		---> function(deviceId, buttonId) {}

ButtonIds

The buttonId is the name of a button found in our genericJoystick class. There are 31 generic buttons

JOYSTICK_UNDEFINED
JOYSTICK_BTN_UP
JOYSTICK_BTN_DOWN
JOYSTICK_BTN_LEFT
JOYSTICK_BTN_RIGHT
JOYSTICK_BTN_X_PS
JOYSTICK_BTN_Y
JOYSTICK_BTN_A
JOYSTICK_BTN_B
JOYSTICK_BTN_SQUARE
JOYSTICK_BTN_TRIANGLE
JOYSTICK_BTN_X_XBOX
JOYSTICK_BTN_CIRCLE
JOYSTICK_BTN_SELECT
JOYSTICK_BTN_START
JOYSTICK_BTN_HOME
JOYSTICK_BTN_JS_LEFT
JOYSTICK_BTN_JS_RIGHT
JOYSTICK_BTN_R1
JOYSTICK_BTN_R2
JOYSTICK_BTN_L1
JOYSTICK_BTN_L2
JOYSTICK_BTN_PAD_PS4

We have wrapped hat switches with events as well.

JOYSTICK_BTN_LEFT_ANALOG_UP
JOYSTICK_BTN_LEFT_ANALOG_DOWN
JOYSTICK_BTN_LEFT_ANALOG_LEFT
JOYSTICK_BTN_LEFT_ANALOG_RIGHT
JOYSTICK_BTN_RIGHT_ANALOG_UP
JOYSTICK_BTN_RIGHT_ANALOG_DOWN
JOYSTICK_BTN_RIGHT_ANALOG_LEFT
JOYSTICK_BTN_RIGHT_ANALOG_RIGHT

AxesIds

There are 6 axesIds

JOYSTICK_AXE_LEFTJS_UP
JOYSTICK_AXE_LEFTJS_LEFT
JOYSTICK_AXE_RIGHTJS_UP
JOYSTICK_AXE_RIGHTJS_LEFT
JOYSTICK_AXE_L2
JOYSTICK_AXE_R2