Class: HIDAPI::SetupTaskHelper
- Inherits:
-
Object
- Object
- HIDAPI::SetupTaskHelper
- Defined in:
- lib/hidapi/setup_task_helper.rb
Instance Attribute Summary collapse
-
#interface ⇒ Object
readonly
Returns the value of attribute interface.
-
#product_id ⇒ Object
readonly
Returns the value of attribute product_id.
-
#simple_name ⇒ Object
readonly
Returns the value of attribute simple_name.
-
#vendor_id ⇒ Object
readonly
Returns the value of attribute vendor_id.
Instance Method Summary collapse
-
#initialize(vendor_id, product_id, simple_name, interface) ⇒ SetupTaskHelper
constructor
A new instance of SetupTaskHelper.
- #run ⇒ Object
- #usage ⇒ Object
- #valid_options? ⇒ Boolean
Constructor Details
#initialize(vendor_id, product_id, simple_name, interface) ⇒ SetupTaskHelper
Returns a new instance of SetupTaskHelper.
10 11 12 13 14 15 16 17 |
# File 'lib/hidapi/setup_task_helper.rb', line 10 def initialize(vendor_id, product_id, simple_name, interface) @vendor_id = vendor_id.to_s.strip.to_i(16) @product_id = product_id.to_s.strip.to_i(16) @simple_name = simple_name.to_s.strip.gsub(' ', '_').gsub(/[^A-Za-z0-9_\-]/, '') @interface = interface.to_s.strip.to_i @temp_dir = Dir.mktmpdir('hidapi_setup') ObjectSpace.define_finalizer(self, ->{ FileUtils.rm_rf(@temp_dir) }) end |
Instance Attribute Details
#interface ⇒ Object (readonly)
Returns the value of attribute interface.
8 9 10 |
# File 'lib/hidapi/setup_task_helper.rb', line 8 def interface @interface end |
#product_id ⇒ Object (readonly)
Returns the value of attribute product_id.
8 9 10 |
# File 'lib/hidapi/setup_task_helper.rb', line 8 def product_id @product_id end |
#simple_name ⇒ Object (readonly)
Returns the value of attribute simple_name.
8 9 10 |
# File 'lib/hidapi/setup_task_helper.rb', line 8 def simple_name @simple_name end |
#vendor_id ⇒ Object (readonly)
Returns the value of attribute vendor_id.
8 9 10 |
# File 'lib/hidapi/setup_task_helper.rb', line 8 def vendor_id @vendor_id end |
Instance Method Details
#run ⇒ Object
19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/hidapi/setup_task_helper.rb', line 19 def run if if == :osx run_osx elsif == :linux run_linux elsif == :windows run_windows else puts "Your operating system was detected as '#{}', but I don't have a setup routine for that." false end else usage end end |
#usage ⇒ Object
40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
# File 'lib/hidapi/setup_task_helper.rb', line 40 def usage() puts <<-USAGE Usage: bundle exec rake setup_hid_device[vendor_id,product_id,simple_name,interface] -OR- #{File.basename(__FILE__)} vendor_id product_id simple_name interface vendor_id should be the 16-bit identifier assigned to the device vendor in hex format. product_id should be the 16-bit identifier assigned by the manufacturer in hex format. simple_name should be a fairly short name for the device. interface is optional and defaults to 0. ie - bundle exec rake setup_hid_device[04d8,c002,pico-lcd-graphic] ie - #{File.basename(__FILE__)} 04d8 c002 pico-lcd-graphic USAGE false end |
#valid_options? ⇒ Boolean
36 37 38 |
# File 'lib/hidapi/setup_task_helper.rb', line 36 def vendor_id != 0 && product_id != 0 && simple_name != '' end |