Code Monkey home page Code Monkey logo

blink_stick's Introduction

BlinkStick

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.

Prerequisites

Libusb

Installation of the libusb package under Debian/Ubuntu: sudo apt-get install libusb-1.0-0-dev

Udev access

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.

Installation

Add this line to your application's Gemfile:

gem 'blink_stick'

And then execute:

$ bundle

Usage

# 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

Rake console

You can also run it standalone (good for further gem development) by clonig the repository, and running the following in your shell:

$ rake console

TODO

  • Finish tests (I'm still learning!)
  • Cleanup code
  • Make sure Color module isn't polluting namespace
  • Validation when setting colors
  • Error handling
  • World domination

Contributing

  1. Fork it
  2. Create your feature branch (git checkout -b my-new-feature)
  3. Commit your changes (git commit -am 'Add some feature')
  4. Push to the branch (git push origin my-new-feature)
  5. Create new Pull Request

Do not change version number or CHANGELOG.

Thanks

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!

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.