You can use ccall()
to directly call the underlying functions yourself. Since (I guess) you only need to open, close and read from the joystick device file something like this would do it:
O_RDONLY = 0
O_NONBLOCK = 2048
jfd = ccall(:open, Cint, (Cstring, Cint), "/dev/input/js0", O_RDONLY|O_NONBLOCK)
println("fd = $(jfd)")
N = 100
buf = Vector{UInt8}(undef, N)
# Loop until we read succesfully 5 times
count = 0
while count < 5
# ssize_t read(int fd, void *buf, size_t count)
res = ccall(:read, Cssize_t, (Cint, Ptr{Cuchar}, Csize_t), jfd, buf, N)
if res != -1
println("read() returned $(res) bytes")
println(buf[1:res])
global count += 1
end
end
ccall(:close, Cint, (Cint,), jfd)
With a gamepad attached to my system I get output like this:
melis@juggle 15:06:~$ julia t.jl
fd = 18
# Initial joystick data returned
read() returned 96 bytes
UInt8[0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x00, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x01, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x02, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x03, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x04, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x05, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x06, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x07, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x08, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x09, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x81, 0x0a, 0xcb, 0x6d, 0xc0, 0x55, 0x00, 0x00, 0x82, 0x00, 0x00]
read() returned 56 bytes
UInt8[0x43, 0x6e, 0xc0, 0x55, 0xfe, 0xff, 0x82, 0x01, 0x43, 0x6e, 0xc0, 0x55, 0x01, 0x80, 0x82, 0x02, 0x43, 0x6e, 0xc0, 0x55, 0x00, 0x00, 0x82, 0x03, 0x43, 0x6e, 0xc0, 0x55, 0xfe, 0xff, 0x82, 0x04, 0x43, 0x6e, 0xc0, 0x55, 0x01, 0x80, 0x82, 0x05, 0x43, 0x6e, 0xc0, 0x55, 0x00, 0x00, 0x82, 0x06, 0x43, 0x6e, 0xc0, 0x55, 0x00, 0x00, 0x82, 0x07, 0xcb]
# read() continuously returns -1 within the loop, until I trigger the joystick again
read() returned 8 bytes
UInt8[0x5a, 0x73, 0xc0, 0x55, 0xdd, 0xf4, 0x02, 0x00, 0x43]
read() returned 8 bytes
UInt8[0x61, 0x73, 0xc0, 0x55, 0xb0, 0xe5, 0x02, 0x00, 0x43]
read() returned 8 bytes
UInt8[0x68, 0x73, 0xc0, 0x55, 0x80, 0xd5, 0x02, 0x00, 0x43]
You would then have to map the returned bytes to the actual joystick data you need, but hopefully this is a start.
Edit: and to verify that this indeed opens the device file with the correct options:
melis@juggle 15:10:~$ strace julia t.jl 2>&1 | grep js0
openat(AT_FDCWD, "/dev/input/js0", O_RDONLY|O_NONBLOCK) = 16
Edit 2: fixed off-by-one in indexing buf
, due to my Python habits