apple2ix/usb_hid_usages2plist
Aaron Culliney 7d64531b89 Squashed 'Apple2Mac/DDHidLib/' content from commit e6a9848
git-subtree-dir: Apple2Mac/DDHidLib
git-subtree-split: e6a9848859fc84e689afb85799658f4980651106
2014-11-09 17:08:23 -08:00

46 lines
1.3 KiB
Ruby
Executable File

#!/usr/bin/env ruby
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "vendor"))
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "lib"))
require 'pp'
require 'plist'
usb_hid_usages = ARGV[0]
usage_tables = {}
current_usage = 0;
current_usage_table = nil
File.open(usb_hid_usages).each_line do |line|
next if line =~ /^\s*#/
next if line =~ /^\s*$/
if (line =~ /^(\d+)\s+(.*)\s*$/)
current_usage = $1.to_i
usage_description = $2
current_usage_table = {'usages' => {}, 'ranges' => {}}
current_usage_table['description'] = usage_description
usage_tables[current_usage] = current_usage_table
elsif (line =~ /^\s+(\S+)\s+(.*)\s*$/)
usage_page = $1
usage_page_description = $2
if (usage_page =~ /^0x((?:\d|[a-fA-F])+)$/)
usage_page = $1.hex
current_usage_table['usages'][usage_page] = usage_page_description
elsif (usage_page =~ /^0x((?:\d|[a-fA-F])+)-((?:\d|[a-fA-F])+)$/)
range_start = $1.hex
range_end = $2.hex
range = "{#{range_start}, #{range_end}}";
current_usage_table['ranges'][range] = usage_page_description
elsif (usage_page == '*')
current_usage_table['default'] = usage_page_description
else
puts "Uknown page: #{usage_page}"
end
end
end
puts Plist.dump(usage_tables)