[Gambas-user] Gambas class to read a joystick
Benoit Minisini
gambas at ...1...
Mon Mar 3 14:29:57 CET 2008
On lundi 3 mars 2008, Rob wrote:
> On Sunday 02 March 2008 18:00, Benoit Minisini wrote:
> > Having no joystick, I opened "/dev/input/mouse0" with FOR READ
> > WATCH, the Read event is fired when I move the mouse, and I don't
> > get such an error. So this is strange... Where do you get the error
> > exactly?
>
> On the first "READ #jsdev" line. I've attached a small project to
> recreate the error (on my system, with a USB gamepad plugged in)
> along with a screenshot so you can see the error.
>
> Rob
After having looked in Linux sources, I understood:
The joystick input device driver can only be read by chunks whose size is the
size of a structure documented in the Documentation/input/joystick-api.txt
file in the Linux sources.
Alas the driver hacker didn't implement the FIONREAD ioctl that allows the
user space to dynamically know how many bytes it can read when the joystick
file descriptor is ready to be read. You must encode it in your program.
Berk...
Now, the question is why 'cat' works? Because it does not read the file byte
by byte, but by big blocks, so the device driver returns as many joystick
events as possible until the requested number of bytes is reached.
So, in File_Read, you must read the file descriptor by blocks:
--8<--------------------------------------
DIM sBuffer AS String
READ #jsdev, sBuffer, -256
PRINT Len(sBuffer)
' Now interprets the buffer contents
--8<--------------------------------------
Regards,
--
Benoit Minisini
More information about the User
mailing list