Git Product home page Git Product logo

joystick's Introduction

joystick++

A minimal C++ object-oriented API onto joystick devices under Linux.

usage

Create an instance of Joystick:

Joystick joystick;

Ensure that it was found and that we can use it:

if (!joystick.isFound())
{
  printf("open failed.\n");
  // hmm
}

Sample events from the Joystick:

JoystickEvent event;
if (joystick.sample(&event))
{
  // use 'event'
}

example

You might run this in a loop:

while (true)
{
  // Restrict rate
  usleep(1000);

  // Attempt to sample an event from the joystick
  JoystickEvent event;
  if (joystick.sample(&event))
  {
    if (event.isButton())
    {
      printf("Button %u is %s\n", event.number, event.value == 0 ? "up" : "down");
    }
    else if (event.isAxis())
    {
      printf("Axis %u is at position %d\n", event.number, event.value);
    }
  }
}

This produces something similar to:

Button 1 is up
Button 2 is down
Axis 0 is at position 122
Axis 1 is at position -11
Axis 2 is at position 9796
Axis 3 is at position -13850

options

You can specify the particular joystick by id:

Joystick js0(0);
Joystick js1(1);

Or provide a specific device name:

Joystick js0("/dev/input/js0");

license

Released under Apache License 2.0.

Copyright Drew Noakes 2013-2017.

joystick's People

Contributors

drewnoakes avatar jacobperron avatar kvanvel avatar romainreignier avatar sgvandijk avatar

Stargazers

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

Watchers

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

joystick's Issues

Test won't find /dev/input/js0

Hey man, sorry if it's a dumb issue report, I'm trying to run your test and no matter what I do I just get "open failed". I got an Xbox One controller plugged on my raspberry pi and
I can run jstest /dev/input/js0 and it runs fine.

I do run the build-test script fine. I'm not a pro with C and C++ so I know I might be doing something wrong. Any help will be appreciated.

Thanks

Missing axis events

Hey there,

I have a weird issue with the joystick. i'm using an APEM joystick inside my application which is design to run at 25Hz but when I try to sample an axis event from the joystick in that speed sometimes I got a false value of 0 when the stick is in my hand (why is that?!) if I work at 10Hz everything works fine with the joystick.
It's not a general load issue since i'm checking this on a stand alone application.

What could be the problem?

/dev/input/js0 file hangs with Beaglebone Black

Platform:
Beaglebone black

root@beaglebone:~# uname -a
Linux beaglebone 3.8.13-bone79 #1 SMP Tue Oct 13 20:44:55 UTC 2015 armv7l GNU/Linux

root@beaglebone:~# lsb_release -a
No LSB modules are available.
Distributor ID:	Debian
Description:	Debian GNU/Linux 7.9 (wheezy)
Release:	7.9
Codename:	wheezy

js0 file hangs whenever DC motor stalls momentarily (controlled using UART pin) in beaglebone black. It stops updating value in js0 and had to reboot it every time to be able to use joystick (PS3) again.

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.