Created
June 3, 2017 16:55
-
-
Save drew-wallace/4c91806e13dfa4ce3fa2fe8d437d9833 to your computer and use it in GitHub Desktop.
SDL Joystick GUID finder
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
things appear to have changed since.. :)