class BlinkStick

Constants

PRODUCT_ID
VENDOR_ID
VERSION

Public Class Methods

find_all() click to toggle source
# File lib/blink_stick.rb, line 18
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
find_by_serial(serial) click to toggle source
# File lib/blink_stick.rb, line 32
def self.find_by_serial(serial)
  find_all.each do |b|
    return b if b.serial == serial
  end

  nil
end
first() click to toggle source
# File lib/blink_stick.rb, line 40
def self.first
  find_all.first
end
usb() click to toggle source
# File lib/blink_stick.rb, line 14
def self.usb
  @usb ||= LIBUSB::Context.new
end

Public Instance Methods

description() click to toggle source
# File lib/blink_stick.rb, line 65
def description
  @device.product
end
manufacturer() click to toggle source
# File lib/blink_stick.rb, line 61
def manufacturer
  @device.manufacturer
end
open(device = nil) click to toggle source
# File lib/blink_stick.rb, line 44
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
serial() click to toggle source
# File lib/blink_stick.rb, line 57
def serial
  @device.serial_number
end