sniner / cleware

Ruby library for Cleware devices

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

sniner/cleware

Access library for some Cleware devices. It has been tested with these devices:

  • Ampel "traffic light" (0d50:0008 v29, v106)
  • Contact (0d50:0030 v3)
  • IO16 (0d50:0030 v14)

Dependencies

  • HIDAPI: Be sure to install the right hidapi library. It comes in two flavors: based on libusb and one called 'raw'. Get hidapi based on libusb if you have to choose one. On Arch Linux you will find one package with both flavors included.
  • libc: Needed for converting wide-strings.
  • FFI gem

Permissions

In order to grant users access to Cleware devices you have to give them write access on the corresponding device files /dev/usb/hiddev*. This can be accomplished by e.g. /etc/udev/rules.d/99-cleware.rules with following content:

ATTRS{idVendor}=="0d50", MODE="0666"

Building the gem

gem build cleware.gemspec
gem install cleware-0.1.0.gem

Example

require 'sniner/cleware'

include Sniner::Cleware::TrafficLight::Colors

tl = Sniner::Cleware.devices(:product => Sniner::Cleware::PRODUCT_LED).first

tl.open do |dev|
    # Setting colors individually
    dev.red = true
    dev.yellow = true
    sleep(1)

    # Using a bit mask
    dev.leds = RED|GREEN
    sleep(1)

    # Flipping on/off states
    dev.leds ^= ALL
    sleep(1)
end

HID API vs libusb

All Cleware gadgets are USB HID class devices. The USB human interface device (HID) class is an abstraction layer while libusb provides low-level access. As far as I know the HID API is the preferred way of accessing Cleware devices, but accessing via libusb does work too. A libusb version is included, but not used by default and is not maintained.

Further reading

About

Ruby library for Cleware devices

License:GNU Lesser General Public License v3.0


Languages

Language:Ruby 100.0%