BlinkStick is a USB-controlled smart pixel. This gem will help you control it.
Note: This is a work in progress.
This code is based on Arvydas Juskevicius blinkstick-ruby code.
Installation of the libusb package under Debian/Ubuntu:
sudo apt-get install libusb-1.0-0-dev
You will also need to grant access to the device in question.
This can be done as follows:
echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"20a0\", ATTR{idProduct}==\"41e5\", MODE:=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick.rules
Then reload the udev rules with:
sudo udevadm control --reload-rules
or just reboot your computer.
Add this line to your application's Gemfile:
gem 'blink_stick'
And then execute:
$ bundle
# list all blink sticks
BlinkStick.find_all
# find by USB serial
BlinkStick.find_by_serial('BS000563-1.1')
# find first blink stick (you'll probably use this if you only have 1 blink stick connected)
bs = BlinkStick.first
# set color using rgb
bs.color = [255,255,255]
# or hex (with or without leading #)
bs.color = "#00FF00"
# or use css color names (see lib/color/name.rb for list)
bs.color = :blue
# make it blink (it's a BLINK stick, after all)
# blinks current color
bs.blink
# color to blink (see above for accepted color values)
bs.blink('abc123')
# number of times to blink (default: 1)
bs.blink('abc123', { blink: 5 })
# change the frequency/intensity of the blink (default: 0.2)
bs.blink('abc123', { blink: 5, frequency: 0.8 })
# turns the blink stick off after blink (default: previous color)
bs.blink('abc123', { turn_off: true })
# random color
bs.random_color
# turn it off
bs.off
# fade between two colors (see above for accepted color values)
bs.fade([255, 0, 0], [0, 255, 0])
# time it should take (default: 0.5)
bs.fade([255, 0, 0], [0, 255, 0], time: 2)
# pulse color (default: [255, 255, 255]) - think Apple sleep light
bs.pulse([1,2,3])
# number of times to pulsate (default: 2)
bs.pulse(:red, times: 1)
# get serial
# ex: BS000563-1.1
bs.serial
# description (BlinkStick)
bs.description
# manufacturer (Agile Innovative Ltd)
bs.manufacturer
You can also run it standalone (good for further gem development) by clonig the repository, and running the following in your shell:
$ rake console
git checkout -b my-new-feature
)git commit -am 'Add some feature'
)git push origin my-new-feature
)Do not change version number or CHANGELOG.
To Arvydas Juskevicius for making the BlinkStick and for providing example code to work from, Thanks!
And Björn Skarner for helping me taking the gem one step further and for teaching me how to make tests. Thanks!