Sha256: 7ae97821087f3ddd33ce312fda071ea866473fbbb84dcd89fcc1d53c0881ff13

Contents?: true

Size: 1.11 KB

Versions: 1

Compression:

Stored size: 1.11 KB

Contents

require 'libusb'
require 'color'
require 'blink_stick/version'
require 'blink_stick/action_handler'
require 'blink_stick/color_handler'

class BlinkStick
  include BlinkStick::ActionHandler
  include BlinkStick::ColorHandler

  VENDOR_ID  = 0x20A0
  PRODUCT_ID = 0x41E5

  def self.usb
    @usb ||= LIBUSB::Context.new
  end

  def self.find_all
    usb = BlinkStick.usb

    usb_devices = usb.devices(idVendor: VENDOR_ID,
                              idProduct: PRODUCT_ID)

    usb_devices.map do |device|
      b = BlinkStick.new
      b.open(device)

      b
    end
  end

  def self.find_by_serial(serial)
    find_all.each do |b|
      return b if b.serial == serial
    end

    nil
  end

  def self.first
    find_all.first
  end

  def open(device = nil)
    usb = BlinkStick.usb

    if (device)
      @device = device
    else
      @device = usb.devices(idVendor: VENDOR_ID,
                            idProduct: PRODUCT_ID).first
    end

    @handle = @device.open
  end

  def serial
    @device.serial_number
  end

  def manufacturer
    @device.manufacturer
  end

  def description
    @device.product
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
blink_stick-0.1.1 lib/blink_stick.rb