Skip to content

Instantly share code, notes, and snippets.

@drew-wallace
Created June 3, 2017 16:55
Show Gist options
  • Save drew-wallace/4c91806e13dfa4ce3fa2fe8d437d9833 to your computer and use it in GitHub Desktop.
Save drew-wallace/4c91806e13dfa4ce3fa2fe8d437d9833 to your computer and use it in GitHub Desktop.
SDL Joystick GUID finder
#!/usr/bin/env ruby
class JoystickGUID
EVIOCGID = 0x80084502
# Derive an SDL-style GUID from bus type, vendor, product, version
def JoystickGUID::ReadGUID(filename)
input = [0,0,0,0].pack('SSSS')
success = 0
File.open(filename, File::RDONLY|File::NONBLOCK){ |file|
success = file.ioctl(EVIOCGID, input)
}
bustype, vendor, product, version = input.unpack('SSSS')
if(0 != success || 0 == vendor || 0 == product || 0 == version) then return nil end
return format('%02x%02x0000%02x%02x0000%02x%02x0000%02x%02x0000', bustype & 0xFF, bustype >> 8,
vendor & 0xFF, vendor >> 8,
product & 0xFF, product >> 8,
version & 0xFF, version >> 8);
end
end
if(__FILE__ == $0)
if(1 != ARGV.length)
puts("Usage: #{$0} path to device event")
exit
end
puts("#{ARGV[0]}: #{JoystickGUID::ReadGUID(ARGV[0])}")
end
@patroza
Copy link

patroza commented Jul 19, 2023

things appear to have changed since.. :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment