I don’t know if there is a Julia wrapper for ioctl already, but you can always @ccall it. You can do something like this
function get_axis_count(fd::Cint)::Csize_t
axes = Ref{UInt8}()
if @ccall(ioctl(fd::Cint, JSIOCGAXES::Cint; axes::Ref{UInt8})::Cint) == -1
return 0
end
return axes[]
end
const JSIOCGAXES=2147576337
function open_joystick(filename="/dev/input/js0")
file = open(filename,"r+")
Cint(fd(file))
end
function get_axis_count(fd::Cint)
axes = Ref{UInt8}()
if @ccall(ioctl(fd::Cint, JSIOCGAXES::Clong; axes::Ref{UInt8})::Cint) == -1
return -1
end
Int64(axes[])
end
using Pkg
pkg"add https://github.com/ufechner7/Joystick.jl"
using Joystick
fd=open_joystick()
axis_count = get_axis_count(fd)
println(axis_count)
But why do I have a different value for JSIOCGAXES than you have?
And is it correct to assume that the file descriptor is of type Cint, both on 64bit and 32bit systems?
So a signed integer. So you should use -2147390959, not 2147576337 (unless you convert the latter to unsigned). These integer literals are all signed as you’re writing them, so using the reinterpreted unsigned value is wrong.
You’re printing an unsigned value and getting a positive value… Again, the Julia literal 2147576337 is a signed value, which is completely different from the unsigned litearal value 0x80016a11. 2147576337 doesn’t even fit in a Int32.