0

I am trying to compare the last value from a joystick file driver located at

/dev/input/js0

Just for testing, in the linux shell I am using xxd to make the hex dump:

xxd -c1 -p /dev/input/js0

And I see the value I am looking for, until here everything is ok!

I want to make a c code that prints a message when the last byte of that file is 1. But i don't know how to assign that byte to a variable, since the file js0 changes it's value with every key pressed.

Here is my code,

    #include<stdio.h>
#include<stdlib.h>
#include<unistd.h>



int main(int argc, char **argv){


system("sudo chmod 777 /dev/input/js0");
system("xxd -c1 -p /dev/input/js0");




return 0;
}

but I don't know how to proceed. Should I save the xxd in another file and read at the same time it's being saved? How?

HoldOffHunger
  • 18,769
  • 10
  • 104
  • 133
  • 2
    Given that a joystick device never reaches the end of the stream in normal operation, your question doesn't really make much sense... There's no such a thing as "the last byte", it's a continuous flow. – Matteo Italia Jul 16 '17 at 17:45
  • 1
    Now, if you want to actually do anything meaningful with the joystick device, read [its documentation](https://www.kernel.org/doc/Documentation/input/joystick-api.txt). It's actually really simple, the data produced by the joystick device is just a sequence of events encoded in a struct that you can read straight from the device file. – Matteo Italia Jul 16 '17 at 17:47
  • Is it xdd or xxd? Title, code and tags disagree on that. Still, is that anyhow relevant? That said, there is no such thing as "the linux shell". There are various shells that run on Linux, like `zsh` and `fish`. – Ulrich Eckhardt Oct 23 '20 at 16:33

0 Answers0