Git Product home page Git Product logo

node-evdev's Introduction

Evdev reader for nodeJS

An Evdev events reader.

Quick test : see index.js. Will open any plugged joystick and display events as they come.

node index.js event-<your_event_type>
#Example with joysticks/gamepads :
node index.js "event-joystick"
# If you have multiple similar devices, you can select by index with a third argument :
node index.js "event-joystick" 1

This app is dead simple on purpose to be easily customizable without having to read tons of source code. Please note that this module's main purpose is to provide an easy programming interface for nodejs modules, not a full-featured command line interface.

How it works

Internals

Basics are simple : find event devices, open them and listen for events.

Events are parsed in plain js. C++ native code is only used to make queries.

Options

Example :

{
  raw:false
}

Options Explained

Raw

get raw events or parsed (with string instead of uints).

Opening streams

You can specify evdev files to open in options. Or call the search method.

var reader = new EvdevReader();
reader.search("/dev/input/by-path","event-joystick",function(err){
  //Err should be null.
});

Events

Raw events

When in raw mode, events are emitted under the name "event" with the structure : { time : {tv_sec: , tv_usec: }, type : , code : , value : }

Parsed events

Events are emitted under an "event_type" name, with this structure : { time : {tv_sec: , tv_usec: }, code : , value : }

TODO

  • Add more tests
  • The app require the running user to be a member of the "input" group. A VM should be provided to allow for easy testing without risking to compromise the system. Alternatively, I'd be best to find a lightweight solution to safely provide inputs when testing.
  • Need a way to discover input capabilities and vendor infos like libevdev's libevdev_has_event_code().

Useful resources

Importing event codes

Event codes are found here

Use this regex : .#define (\w)\s*(0?x?[0-9a-f]{1,3}) replace with : $2:"$1",

node-evdev's People

Contributors

anbraten avatar christophgysin avatar ediskandarov avatar pixnbits avatar sdumetz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

node-evdev's Issues

DeviceReader error events are not forwarded to EvdevReader

The following code throws Unhandled 'error' event error.

const EvdevReader = require("evdev");

const reader = new EvdevReader();
reader.on("error", (error) => console.log(error))

reader.open("/dev/null");

There is as expected a TypeError: Inappropriate ioctl for device error emitted by DeviceReader.init, but I would expect this error to be captured by the EvdevReader which in turn would emit an error event of its own.

Error: ESPIPE: invalid seek

This is likely not a library issue, but user error. I'm really not sure what I'm missing here, though.

I'm trying to recognize events coming from a simple USB gamepad under linux. I've got things working with the legacy, "jsdev" method via the node-joystick package, but I'm trying to switch to the evdev method.

I can cat /dev/input/by-id/usb-0810_usb_gamepad-event-joystick and see output as I press buttons, so it seems that the kernel is functioning properly, but when I run the index.js in this package, the output is as follows:

root@DietPi ~/t/n/evdev# ./index.js
searching for event streams matching undefined in : /dev/input/by-path
found 4 inputs
{ bustype: 3, vendor: 2064, product: 58625, version: 272 }
reader error :  { Error: ESPIPE: invalid seek, read errno: -29, code: 'ESPIPE', syscall: 'read' }
root@DietPi ~/t/n/evdev#

I would love a hint on this. What might be going wrong and what can I do about it?

Any help would be very much appreciated! Thanks!

multiple inputs same events

How can is isolate an event to a specific input? I'm monitoring events on multiple inputs with the same events so need to get a handle on both the event and the input that made it.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.