Sha256: 50be5da7f1f98fabf9a7459e4a42be071033ad9f92eb5dd6679fdf52bea94c7d

Contents?: true

Size: 883 Bytes

Versions: 21

Compression:

Stored size: 883 Bytes

Contents

class ProconBypassMan::DeviceProconFinder
  HID_NAME = "Nintendo Co., Ltd. Pro Controller"

  def self.find
    new.find
  end

  # @return [String, NilClass]
  def find
    find_device_path
  end

  private

  # @return [String , NilClass]
  def find_device_path
    if(line = device_from_shell) && (hidraw_name = line.match(/(hidraw\d+)\s+/)[1])
      "/dev/#{hidraw_name}"
    end
  end

  # @return [String , NilClass]
  def device_from_shell
    shell_output.split("\n").detect { |o| o.include?(HID_NAME) }
  end

  # @return [String]
  def shell_output
    `bash -c '#{get_list_shell}'`
  end

  def get_list_shell
    <<~SHELL
      FILES=/dev/hidraw*
      for f in $FILES
      do
        FILE=${f##*/}
        DEVICE="$(cat /sys/class/hidraw/${FILE}/device/uevent | grep HID_NAME | cut -d '=' -f2)"
        printf "%s   %s\n" $FILE "$DEVICE"
      done
    SHELL
  end
end

Version data entries

21 entries across 21 versions & 1 rubygems

Version Path
procon_bypass_man-0.3.12 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.11 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.10 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.9 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.8.1 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.8 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.7 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.6 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.5 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.4 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.3.1 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.3 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.2 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.1 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.3.0 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.2.3 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.2.2 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.2.1 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.2.0 lib/procon_bypass_man/support/device_procon_finder.rb
procon_bypass_man-0.1.23 lib/procon_bypass_man/support/device_procon_finder.rb