blink_stick 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/.gitignore +17 -0
- data/CHANGELOG.md +12 -0
- data/Gemfile +4 -0
- data/Guardfile +28 -0
- data/LICENSE.txt +22 -0
- data/README.md +122 -0
- data/Rakefile +20 -0
- data/blink_stick.gemspec +27 -0
- data/lib/blink_stick.rb +68 -0
- data/lib/blink_stick/action_handler.rb +33 -0
- data/lib/blink_stick/color_handler.rb +36 -0
- data/lib/blink_stick/version.rb +3 -0
- data/lib/color.rb +17 -0
- data/lib/color/hex.rb +13 -0
- data/lib/color/name.rb +148 -0
- data/test/lib/blink_stick/color_handler_test.rb +25 -0
- data/test/lib/blink_stick/version_test.rb +7 -0
- data/test/lib/blink_stick_test.rb +83 -0
- data/test/lib/color/hex_test.rb +17 -0
- data/test/lib/color/name_test.rb +15 -0
- data/test/lib/color_test.rb +13 -0
- data/test/test_helper.rb +7 -0
- metadata +157 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d3f7a8e8f93160aec650e9ce1ed246894c9690b
|
4
|
+
data.tar.gz: f91e8d43c492d268c0cd40f55d980df7a947c4f8
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c2d7473b3ff36c55f289868f10ea95ec7475d20d425ec8205c583cd1133040f6810e9abb2611b7ea69ad0d5f28adceb896cbcd70c27dd7fbfb0049c3a368a41f
|
7
|
+
data.tar.gz: 8403a3b1400551af29aa366017a2469446b07b991b0b0a78323271faae8344c5a65e945d86189bacf540a30f1df60e368ed66c89620b31be1a221a20b8a1f3cf
|
data/.gitignore
ADDED
data/CHANGELOG.md
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
# Change log
|
2
|
+
|
3
|
+
## 0.1.1
|
4
|
+
* code refactoring [bjoska] Thanks!
|
5
|
+
* first release into the wild (RubyGems)
|
6
|
+
|
7
|
+
## 0.1.0
|
8
|
+
* refactoring and more tests [bjoska] Thanks!
|
9
|
+
* blink method now takes color as first argument and options as second [danielthor]
|
10
|
+
|
11
|
+
## 0.0.1
|
12
|
+
* first staggering gem [danielthor]
|
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# A sample Guardfile
|
2
|
+
# More info at https://github.com/guard/guard#readme
|
3
|
+
|
4
|
+
guard :minitest do
|
5
|
+
# with Minitest::Unit
|
6
|
+
watch(%r{^test/(.*)\/?test_(.*)\.rb})
|
7
|
+
watch(%r{^lib/(.*/)?([^/]+)\.rb}) { |m| "test/#{m[1]}test_#{m[2]}.rb" }
|
8
|
+
watch(%r{^test/test_helper\.rb}) { 'test' }
|
9
|
+
|
10
|
+
# with Minitest::Spec
|
11
|
+
# watch(%r{^spec/(.*)_spec\.rb})
|
12
|
+
# watch(%r{^lib/(.+)\.rb}) { |m| "spec/#{m[1]}_spec.rb" }
|
13
|
+
# watch(%r{^spec/spec_helper\.rb}) { 'spec' }
|
14
|
+
|
15
|
+
# Rails 4
|
16
|
+
# watch(%r{^app/(.+)\.rb}) { |m| "test/#{m[1]}_test.rb" }
|
17
|
+
# watch(%r{^app/controllers/application_controller\.rb}) { 'test/controllers' }
|
18
|
+
# watch(%r{^app/controllers/(.+)_controller\.rb}) { |m| "test/integration/#{m[1]}_test.rb" }
|
19
|
+
# watch(%r{^app/views/(.+)_mailer/.+}) { |m| "test/mailers/#{m[1]}_mailer_test.rb" }
|
20
|
+
# watch(%r{^lib/(.+)\.rb}) { |m| "test/lib/#{m[1]}_test.rb" }
|
21
|
+
# watch(%r{^test/.+_test\.rb})
|
22
|
+
# watch(%r{^test/test_helper\.rb}) { 'test' }
|
23
|
+
|
24
|
+
# Rails < 4
|
25
|
+
# watch(%r{^app/controllers/(.*)\.rb}) { |m| "test/functional/#{m[1]}_test.rb" }
|
26
|
+
# watch(%r{^app/helpers/(.*)\.rb}) { |m| "test/helpers/#{m[1]}_test.rb" }
|
27
|
+
# watch(%r{^app/models/(.*)\.rb}) { |m| "test/unit/#{m[1]}_test.rb" }
|
28
|
+
end
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2013 Daniel Thor
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,122 @@
|
|
1
|
+
# BlinkStick
|
2
|
+
|
3
|
+
[BlinkStick](http://blinkstick.com) is a USB-controlled smart pixel. This gem will help you control it.
|
4
|
+
|
5
|
+
Note: This is a work in progress. It does not exist on rubygems.org, yet.
|
6
|
+
|
7
|
+
This code is heavily based on [Arvydas Juskevicius](https://github.com/arvydas/) [blinkstick-ruby](https://github.com/arvydas/blinkstick-ruby) code.
|
8
|
+
|
9
|
+
## Prerequisites
|
10
|
+
|
11
|
+
### Libusb
|
12
|
+
Installation of the libusb package under Debian/Ubuntu:
|
13
|
+
`sudo apt-get install libusb-1.0-0-dev`
|
14
|
+
|
15
|
+
### Udev access
|
16
|
+
You will also need to grant access to the device in question.
|
17
|
+
|
18
|
+
This can be done as follows:
|
19
|
+
|
20
|
+
```sh
|
21
|
+
echo "SUBSYSTEM==\"usb\", ATTR{idVendor}==\"20a0\", ATTR{idProduct}==\"41e5\", MODE:=\"0666\"" | sudo tee /etc/udev/rules.d/85-blinkstick.rules
|
22
|
+
```
|
23
|
+
|
24
|
+
Then reload the udev rules with:
|
25
|
+
|
26
|
+
```sh
|
27
|
+
sudo udevadm control --reload-rules
|
28
|
+
```
|
29
|
+
|
30
|
+
or just reboot your computer.
|
31
|
+
|
32
|
+
## Installation
|
33
|
+
|
34
|
+
Add this line to your application's Gemfile:
|
35
|
+
|
36
|
+
gem 'blink_stick', git: 'git://github.com/danielthor/blink_stick.git'
|
37
|
+
|
38
|
+
And then execute:
|
39
|
+
|
40
|
+
$ bundle
|
41
|
+
|
42
|
+
## Usage
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
# list all blink sticks
|
46
|
+
BlinkStick.find_all
|
47
|
+
|
48
|
+
# find by USB serial
|
49
|
+
BlinkStick.find_by_serial('BS000563-1.1')
|
50
|
+
|
51
|
+
# find first blink stick (you'll probably use this if you only have 1 blink stick connected)
|
52
|
+
bs = BlinkStick.first
|
53
|
+
|
54
|
+
# set color using rgb
|
55
|
+
bs.color = [255,255,255]
|
56
|
+
# or hex (with or without leading #)
|
57
|
+
bs.color = "#00FF00"
|
58
|
+
# or use css color names (see lib/color/name.rb for list)
|
59
|
+
bs.color = :blue
|
60
|
+
|
61
|
+
# make it blink (it's a BLINK stick, after all)
|
62
|
+
# blinks current color
|
63
|
+
bs.blink
|
64
|
+
# color to blink (see above for accepted color values)
|
65
|
+
bs.blink('abc123')
|
66
|
+
# number of times to blink (default: 1)
|
67
|
+
bs.blink('abc123', { blink: 5 })
|
68
|
+
# change the frequency/intensity of the blink (default: 0.2)
|
69
|
+
bs.blink('abc123', { blink: 5, frequency: 0.8 })
|
70
|
+
# turns the blink stick off after blink (default: previous color)
|
71
|
+
bs.blink('abc123', { turn_off: true })
|
72
|
+
|
73
|
+
# random color
|
74
|
+
bs.random_color
|
75
|
+
|
76
|
+
# turn it off
|
77
|
+
bs.off
|
78
|
+
|
79
|
+
# get serial
|
80
|
+
# ex: BS000563-1.1
|
81
|
+
bs.serial
|
82
|
+
|
83
|
+
# description (BlinkStick)
|
84
|
+
bs.description
|
85
|
+
|
86
|
+
# manufacturer (Agile Innovative Ltd)
|
87
|
+
bs.manufacturer
|
88
|
+
```
|
89
|
+
|
90
|
+
### Rake console
|
91
|
+
|
92
|
+
You can also run it standalone (good for further gem development) by clonig the repository, and running the following in your shell:
|
93
|
+
|
94
|
+
```sh
|
95
|
+
$ rake console
|
96
|
+
```
|
97
|
+
|
98
|
+
|
99
|
+
## TODO
|
100
|
+
|
101
|
+
- Finish tests (I'm still learning!)
|
102
|
+
- Cleanup code
|
103
|
+
- Make sure Color module isn't polluting namespace
|
104
|
+
- Validation when setting colors
|
105
|
+
- Error handling
|
106
|
+
- World domination
|
107
|
+
|
108
|
+
## Contributing
|
109
|
+
|
110
|
+
1. Fork it
|
111
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
112
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
113
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
114
|
+
5. Create new Pull Request
|
115
|
+
|
116
|
+
Do not change version number or CHANGELOG.
|
117
|
+
|
118
|
+
## Thanks
|
119
|
+
|
120
|
+
To [Arvydas Juskevicius](https://github.com/arvydas/) for making the [BlinkStick](http://blinkstick.com) and for providing [example code](https://github.com/arvydas/blinkstick-ruby/) to work from, Thanks!
|
121
|
+
|
122
|
+
And [Björn Skarner](https://github.com/bjoska/) for helping me taking the gem one step further and for teaching me how to make tests. Thanks!
|
data/Rakefile
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env rake
|
2
|
+
require "bundler/gem_tasks"
|
3
|
+
|
4
|
+
require 'rake/testtask'
|
5
|
+
|
6
|
+
Rake::TestTask.new do |t|
|
7
|
+
t.libs << 'lib/blink_stick'
|
8
|
+
t.test_files = FileList['test/lib/blink_stick/*_test.rb', 'test/lib/color/*_test.rb']
|
9
|
+
t.verbose = true
|
10
|
+
end
|
11
|
+
|
12
|
+
task :console do
|
13
|
+
require 'irb'
|
14
|
+
require 'irb/completion'
|
15
|
+
require 'blink_stick'
|
16
|
+
ARGV.clear
|
17
|
+
IRB.start
|
18
|
+
end
|
19
|
+
|
20
|
+
task :default => :test
|
data/blink_stick.gemspec
ADDED
@@ -0,0 +1,27 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'blink_stick/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "blink_stick"
|
8
|
+
spec.version = BlinkStick::VERSION
|
9
|
+
spec.authors = ["Daniel Thor"]
|
10
|
+
spec.email = ["daniel.thor@gmail.com"]
|
11
|
+
spec.description = %q{Control your BlinkStick}
|
12
|
+
spec.summary = %q{BlinkStick is a USB-controlled smart pixel}
|
13
|
+
spec.homepage = "https://github.com/danielthor/blink_stick/"
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files`.split($/)
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "libusb", "~> 0.4"
|
22
|
+
spec.add_development_dependency "bundler", "~> 1.3"
|
23
|
+
spec.add_development_dependency "rake"
|
24
|
+
spec.add_development_dependency "minitest"
|
25
|
+
spec.add_development_dependency "pry"
|
26
|
+
spec.add_development_dependency "guard-minitest"
|
27
|
+
end
|
data/lib/blink_stick.rb
ADDED
@@ -0,0 +1,68 @@
|
|
1
|
+
require 'libusb'
|
2
|
+
require 'color'
|
3
|
+
require 'blink_stick/version'
|
4
|
+
require 'blink_stick/action_handler'
|
5
|
+
require 'blink_stick/color_handler'
|
6
|
+
|
7
|
+
class BlinkStick
|
8
|
+
include BlinkStick::ActionHandler
|
9
|
+
include BlinkStick::ColorHandler
|
10
|
+
|
11
|
+
VENDOR_ID = 0x20A0
|
12
|
+
PRODUCT_ID = 0x41E5
|
13
|
+
|
14
|
+
def self.usb
|
15
|
+
@usb ||= LIBUSB::Context.new
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.find_all
|
19
|
+
usb = BlinkStick.usb
|
20
|
+
|
21
|
+
usb_devices = usb.devices(idVendor: VENDOR_ID,
|
22
|
+
idProduct: PRODUCT_ID)
|
23
|
+
|
24
|
+
usb_devices.map do |device|
|
25
|
+
b = BlinkStick.new
|
26
|
+
b.open(device)
|
27
|
+
|
28
|
+
b
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def self.find_by_serial(serial)
|
33
|
+
find_all.each do |b|
|
34
|
+
return b if b.serial == serial
|
35
|
+
end
|
36
|
+
|
37
|
+
nil
|
38
|
+
end
|
39
|
+
|
40
|
+
def self.first
|
41
|
+
find_all.first
|
42
|
+
end
|
43
|
+
|
44
|
+
def open(device = nil)
|
45
|
+
usb = BlinkStick.usb
|
46
|
+
|
47
|
+
if (device)
|
48
|
+
@device = device
|
49
|
+
else
|
50
|
+
@device = usb.devices(idVendor: VENDOR_ID,
|
51
|
+
idProduct: PRODUCT_ID).first
|
52
|
+
end
|
53
|
+
|
54
|
+
@handle = @device.open
|
55
|
+
end
|
56
|
+
|
57
|
+
def serial
|
58
|
+
@device.serial_number
|
59
|
+
end
|
60
|
+
|
61
|
+
def manufacturer
|
62
|
+
@device.manufacturer
|
63
|
+
end
|
64
|
+
|
65
|
+
def description
|
66
|
+
@device.product
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,33 @@
|
|
1
|
+
module BlinkStick::ActionHandler
|
2
|
+
def blink(blink_color = nil, options = {})
|
3
|
+
current_color = self.color
|
4
|
+
|
5
|
+
blink_color = [0, 0, 0] if blink_color.nil?
|
6
|
+
|
7
|
+
options = {
|
8
|
+
blink: 1,
|
9
|
+
frequency: 0.2,
|
10
|
+
turn_off: false
|
11
|
+
}.merge(options)
|
12
|
+
|
13
|
+
perform_blink(blink_color, current_color, options)
|
14
|
+
end
|
15
|
+
|
16
|
+
private
|
17
|
+
|
18
|
+
def perform_blink(blink_color, current_color, options)
|
19
|
+
options[:blink].times do
|
20
|
+
sleep options[:frequency]
|
21
|
+
|
22
|
+
self.color = blink_color
|
23
|
+
|
24
|
+
sleep options[:frequency]
|
25
|
+
|
26
|
+
if options[:turn_off]
|
27
|
+
self.off
|
28
|
+
else
|
29
|
+
self.color = current_color
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
33
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
module BlinkStick::ColorHandler
|
2
|
+
def color=(value)
|
3
|
+
data_out = transform_color_to_hex(Color.parse(value))
|
4
|
+
|
5
|
+
@handle.control_transfer(bmRequestType: 0x20,
|
6
|
+
bRequest: 0x9,
|
7
|
+
wValue: 0x1,
|
8
|
+
wIndex: 0x0000,
|
9
|
+
dataOut: data_out)
|
10
|
+
end
|
11
|
+
|
12
|
+
def color
|
13
|
+
result = @handle.control_transfer(bmRequestType: 0x80 | 0x20,
|
14
|
+
bRequest: 0x1,
|
15
|
+
wValue: 0x1,
|
16
|
+
wIndex: 0x0000,
|
17
|
+
dataIn: 4)
|
18
|
+
|
19
|
+
[result[1].ord, result[2].ord, result[3].ord]
|
20
|
+
end
|
21
|
+
|
22
|
+
def off
|
23
|
+
self.color = [0, 0, 0]
|
24
|
+
end
|
25
|
+
|
26
|
+
def random_color
|
27
|
+
r = Random.new
|
28
|
+
self.color = [r.rand(255), r.rand(255), r.rand(255)]
|
29
|
+
end
|
30
|
+
|
31
|
+
private
|
32
|
+
|
33
|
+
def transform_color_to_hex(value)
|
34
|
+
1.chr + value[0].chr + value[1].chr + value[2].chr
|
35
|
+
end
|
36
|
+
end
|
data/lib/color.rb
ADDED
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'color/name'
|
2
|
+
require 'color/hex'
|
3
|
+
|
4
|
+
module Color
|
5
|
+
def self.parse(value)
|
6
|
+
if value =~ /^\#{0,1}[a-f0-9]{6}$/i
|
7
|
+
Color.hex(value)
|
8
|
+
elsif value.is_a?(Array)
|
9
|
+
# TODO: Validate RGB color array
|
10
|
+
value
|
11
|
+
elsif Color::NAMES.has_key?(value.downcase.to_sym)
|
12
|
+
Color.name(value)
|
13
|
+
else
|
14
|
+
raise "Unknown color format"
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/color/hex.rb
ADDED
data/lib/color/name.rb
ADDED
@@ -0,0 +1,148 @@
|
|
1
|
+
module Color
|
2
|
+
NAMES = {
|
3
|
+
alice_blue: [240,248,255],
|
4
|
+
antique_white: [250,235,215],
|
5
|
+
aqua: [0,255,255],
|
6
|
+
aquamarine: [127,255,212],
|
7
|
+
azure: [240,255,255],
|
8
|
+
beige: [245,245,220],
|
9
|
+
bisque: [255,228,196],
|
10
|
+
black: [0,0,0],
|
11
|
+
blanched_almond: [255,235,205],
|
12
|
+
blue: [0,0,255],
|
13
|
+
blue_violet: [138,43,226],
|
14
|
+
brown: [165,42,42],
|
15
|
+
burly_wood: [222,184,135],
|
16
|
+
cadet_blue: [95,158,160],
|
17
|
+
chartreuse: [127,255,0],
|
18
|
+
chocolate: [210,105,30],
|
19
|
+
coral: [255,127,80],
|
20
|
+
cornflower_blue: [100,149,237],
|
21
|
+
cornsilk: [255,248,220],
|
22
|
+
crimson: [220,20,60],
|
23
|
+
cyan: [0,255,255],
|
24
|
+
dark_blue: [0,0,139],
|
25
|
+
dark_cyan: [0,139,139],
|
26
|
+
dark_golden_rod: [184,134,11],
|
27
|
+
dark_gray: [169,169,169],
|
28
|
+
dark_green: [0,100,0],
|
29
|
+
dark_khaki: [189,183,107],
|
30
|
+
dark_magenta: [139,0,139],
|
31
|
+
dark_olive_green: [85,107,47],
|
32
|
+
dark_orange: [255,140,0],
|
33
|
+
dark_orchid: [153,50,204],
|
34
|
+
dark_red: [139,0,0],
|
35
|
+
dark_salmon: [233,150,122],
|
36
|
+
dark_sea_green: [143,188,143],
|
37
|
+
dark_slate_blue: [72,61,139],
|
38
|
+
dark_slate_gray: [47,79,79],
|
39
|
+
dark_turquoise: [0,206,209],
|
40
|
+
dark_violet: [148,0,211],
|
41
|
+
deep_pink: [255,20,147],
|
42
|
+
deep_sky_blue: [0,191,255],
|
43
|
+
dim_gray: [105,105,105],
|
44
|
+
dodger_blue: [30,144,255],
|
45
|
+
fire_brick: [178,34,34],
|
46
|
+
floral_white: [255,250,240],
|
47
|
+
forest_green: [34,139,34],
|
48
|
+
fuchsia: [255,0,255],
|
49
|
+
gainsboro: [220,220,220],
|
50
|
+
ghost_white: [248,248,255],
|
51
|
+
gold: [255,215,0],
|
52
|
+
golden_rod: [218,165,32],
|
53
|
+
gray: [128,128,128],
|
54
|
+
green: [0,128,0],
|
55
|
+
green_yellow: [173,255,47],
|
56
|
+
honey_dew: [240,255,240],
|
57
|
+
hot_pink: [255,105,180],
|
58
|
+
indian_red: [205,92,92],
|
59
|
+
indigo: [75,0,130],
|
60
|
+
ivory: [255,255,240],
|
61
|
+
khaki: [240,230,140],
|
62
|
+
lavender: [230,230,250],
|
63
|
+
lavender_blush: [255,240,245],
|
64
|
+
lawn_green: [124,252,0],
|
65
|
+
lemon_chiffon: [255,250,205],
|
66
|
+
light_blue: [173,216,230],
|
67
|
+
light_coral: [240,128,128],
|
68
|
+
light_cyan: [224,255,255],
|
69
|
+
light_golden_rod_yellow: [250,250,210],
|
70
|
+
light_gray: [211,211,211],
|
71
|
+
light_green: [144,238,144],
|
72
|
+
light_pink: [255,182,193],
|
73
|
+
light_salmon: [255,160,122],
|
74
|
+
light_sea_green: [32,178,170],
|
75
|
+
light_sky_blue: [135,206,250],
|
76
|
+
light_slate_gray: [119,136,153],
|
77
|
+
light_steel_blue: [176,196,222],
|
78
|
+
light_yellow: [255,255,224],
|
79
|
+
lime: [0,255,0],
|
80
|
+
lime_green: [50,205,50],
|
81
|
+
linen: [250,240,230],
|
82
|
+
magenta: [255,0,255],
|
83
|
+
maroon: [128,0,0],
|
84
|
+
medium_aqua_marine: [102,205,170],
|
85
|
+
medium_blue: [0,0,205],
|
86
|
+
medium_orchid: [186,85,211],
|
87
|
+
medium_purple: [147,112,219],
|
88
|
+
medium_sea_green: [60,179,113],
|
89
|
+
medium_slate_blue: [123,104,238],
|
90
|
+
medium_spring_green: [0,250,154],
|
91
|
+
medium_turquoise: [72,209,204],
|
92
|
+
medium_violet_red: [199,21,133],
|
93
|
+
midnight_blue: [25,25,112],
|
94
|
+
mint_cream: [245,255,250],
|
95
|
+
misty_rose: [255,228,225],
|
96
|
+
moccasin: [255,228,181],
|
97
|
+
navajo_white: [255,222,173],
|
98
|
+
navy: [0,0,128],
|
99
|
+
old_lace: [253,245,230],
|
100
|
+
olive: [128,128,0],
|
101
|
+
olive_drab: [107,142,35],
|
102
|
+
orange: [255,165,0],
|
103
|
+
orange_red: [255,69,0],
|
104
|
+
orchid: [218,112,214],
|
105
|
+
pale_golden_rod: [238,232,170],
|
106
|
+
pale_green: [152,251,152],
|
107
|
+
pale_turquoise: [175,238,238],
|
108
|
+
pale_violet_red: [219,112,147],
|
109
|
+
papaya_whip: [255,239,213],
|
110
|
+
peach_puff: [255,218,185],
|
111
|
+
peru: [205,133,63],
|
112
|
+
pink: [255,192,203],
|
113
|
+
plum: [221,160,221],
|
114
|
+
powder_blue: [176,224,230],
|
115
|
+
purple: [128,0,128],
|
116
|
+
red: [255,0,0],
|
117
|
+
rosy_brown: [188,143,143],
|
118
|
+
royal_blue: [65,105,225],
|
119
|
+
saddle_brown: [139,69,19],
|
120
|
+
salmon: [250,128,114],
|
121
|
+
sandy_brown: [244,164,96],
|
122
|
+
sea_green: [46,139,87],
|
123
|
+
sea_shell: [255,245,238],
|
124
|
+
sienna: [160,82,45],
|
125
|
+
silver: [192,192,192],
|
126
|
+
sky_blue: [135,206,235],
|
127
|
+
slate_blue: [106,90,205],
|
128
|
+
slate_gray: [112,128,144],
|
129
|
+
snow: [255,250,250],
|
130
|
+
spring_green: [0,255,127],
|
131
|
+
steel_blue: [70,130,180],
|
132
|
+
tan: [210,180,140],
|
133
|
+
teal: [0,128,128],
|
134
|
+
thistle: [216,191,216],
|
135
|
+
tomato: [255,99,71],
|
136
|
+
turquoise: [64,224,208],
|
137
|
+
violet: [238,130,238],
|
138
|
+
wheat: [245,222,179],
|
139
|
+
white: [255,255,255],
|
140
|
+
white_smoke: [245,245,245],
|
141
|
+
yellow: [255,255,0],
|
142
|
+
yellow_green: [154,205,50]
|
143
|
+
}
|
144
|
+
|
145
|
+
def self.name(name)
|
146
|
+
NAMES[name.to_s.downcase.to_sym]
|
147
|
+
end
|
148
|
+
end
|
@@ -0,0 +1,25 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe BlinkStick::ColorHandler do
|
4
|
+
class ColorMock
|
5
|
+
include BlinkStick::ColorHandler
|
6
|
+
end
|
7
|
+
|
8
|
+
subject { ColorMock.new }
|
9
|
+
|
10
|
+
describe '#off' do
|
11
|
+
it 'will set the color to [0,0,0]' do
|
12
|
+
subject.stub :color=, [255, 255, 255] do
|
13
|
+
subject.off.must_equal [0, 0, 0]
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
describe '#random_color' do
|
19
|
+
it 'will return an array of 3 random numbers' do
|
20
|
+
subject.stub :color=, [255,255,255] do
|
21
|
+
subject.random_color.must_be_instance_of Array
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,83 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe BlinkStick do
|
4
|
+
subject { BlinkStick }
|
5
|
+
|
6
|
+
MockDevice = Struct.new :open
|
7
|
+
|
8
|
+
class BlinkStickMock
|
9
|
+
def serial
|
10
|
+
@serial ||= ('a'..'z').to_a.sample(5).join
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
it "must have constant VENDOR_ID 0x20A0" do
|
15
|
+
subject::VENDOR_ID.must_equal 0x20A0
|
16
|
+
end
|
17
|
+
|
18
|
+
it "must have constant PRODUCT_ID 0x41E5" do
|
19
|
+
subject::PRODUCT_ID.must_equal 0x41E5
|
20
|
+
end
|
21
|
+
|
22
|
+
describe 'self.usb' do
|
23
|
+
it 'must only instantiate one LIBUSB::Context' do
|
24
|
+
usb = subject.usb
|
25
|
+
|
26
|
+
subject.usb.must_equal usb
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
describe 'self.find_all' do
|
31
|
+
it 'will return the located devices instantiated' do
|
32
|
+
mock_usb = MiniTest::Mock.new
|
33
|
+
return_value = [MockDevice.new, MockDevice.new, MockDevice.new]
|
34
|
+
|
35
|
+
mock_usb.expect :devices, return_value,
|
36
|
+
[idVendor: subject::VENDOR_ID, idProduct: subject::PRODUCT_ID]
|
37
|
+
|
38
|
+
subject.stub :usb, mock_usb do
|
39
|
+
subject.find_all.length.must_equal 3
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe 'self.find_by_serial' do
|
45
|
+
it "must respond to find_by_serial" do
|
46
|
+
subject.must_respond_to :find_by_serial
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'must collect the specified serial number' do
|
50
|
+
bsm1 = BlinkStickMock.new
|
51
|
+
bsm2 = BlinkStickMock.new
|
52
|
+
device_array = [bsm1, bsm2]
|
53
|
+
|
54
|
+
serial = bsm2.serial
|
55
|
+
|
56
|
+
subject.stub :find_all, device_array do
|
57
|
+
subject.find_by_serial(serial).must_equal bsm2
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'must return nil when none is found' do
|
62
|
+
bsm1 = BlinkStickMock.new
|
63
|
+
bsm2 = BlinkStickMock.new
|
64
|
+
device_array = [bsm1, bsm2]
|
65
|
+
|
66
|
+
subject.stub :find_all, device_array do
|
67
|
+
subject.find_by_serial('12345').must_be_nil
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
72
|
+
describe 'self.first' do
|
73
|
+
it 'must return the first available device' do
|
74
|
+
bsm1 = BlinkStickMock.new
|
75
|
+
bsm2 = BlinkStickMock.new
|
76
|
+
device_array = [bsm1, bsm2]
|
77
|
+
|
78
|
+
subject.stub :find_all, device_array do
|
79
|
+
subject.first.must_equal bsm1
|
80
|
+
end
|
81
|
+
end
|
82
|
+
end
|
83
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Color do
|
4
|
+
|
5
|
+
it "must convert hex string to rgb array" do
|
6
|
+
Color.hex(COLOR_HEX_VALUE).must_equal COLOR_RGB_VALUE
|
7
|
+
end
|
8
|
+
|
9
|
+
it "must convert hex with hash string to rgb array" do
|
10
|
+
Color.hex('#' + COLOR_HEX_VALUE).must_equal COLOR_RGB_VALUE
|
11
|
+
end
|
12
|
+
|
13
|
+
it "must ignore hex case when converting" do
|
14
|
+
Color.hex(COLOR_HEX_VALUE.upcase).must_equal COLOR_RGB_VALUE
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
require_relative '../../test_helper'
|
2
|
+
|
3
|
+
describe Color do
|
4
|
+
|
5
|
+
it "must define Color::NAMES hash" do
|
6
|
+
Color::NAMES.must_be_kind_of Hash
|
7
|
+
end
|
8
|
+
|
9
|
+
it "must parse all named colors" do
|
10
|
+
Color::NAMES.each do |name, rgb|
|
11
|
+
Color.parse(name.to_s).must_equal rgb
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require_relative '../test_helper'
|
2
|
+
|
3
|
+
describe Color do
|
4
|
+
|
5
|
+
it "must parse hex value" do
|
6
|
+
Color.parse(COLOR_HEX_VALUE).must_equal COLOR_RGB_VALUE
|
7
|
+
end
|
8
|
+
|
9
|
+
it "must parse same rgb value" do
|
10
|
+
Color.parse(COLOR_RGB_VALUE).must_equal COLOR_RGB_VALUE
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
ADDED
@@ -0,0 +1,157 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: blink_stick
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Daniel Thor
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-02-07 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: libusb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ~>
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ~>
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.3'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ~>
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.3'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - '>='
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - '>='
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - '>='
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard-minitest
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - '>='
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - '>='
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '0'
|
97
|
+
description: Control your BlinkStick
|
98
|
+
email:
|
99
|
+
- daniel.thor@gmail.com
|
100
|
+
executables: []
|
101
|
+
extensions: []
|
102
|
+
extra_rdoc_files: []
|
103
|
+
files:
|
104
|
+
- .gitignore
|
105
|
+
- CHANGELOG.md
|
106
|
+
- Gemfile
|
107
|
+
- Guardfile
|
108
|
+
- LICENSE.txt
|
109
|
+
- README.md
|
110
|
+
- Rakefile
|
111
|
+
- blink_stick.gemspec
|
112
|
+
- lib/blink_stick.rb
|
113
|
+
- lib/blink_stick/action_handler.rb
|
114
|
+
- lib/blink_stick/color_handler.rb
|
115
|
+
- lib/blink_stick/version.rb
|
116
|
+
- lib/color.rb
|
117
|
+
- lib/color/hex.rb
|
118
|
+
- lib/color/name.rb
|
119
|
+
- test/lib/blink_stick/color_handler_test.rb
|
120
|
+
- test/lib/blink_stick/version_test.rb
|
121
|
+
- test/lib/blink_stick_test.rb
|
122
|
+
- test/lib/color/hex_test.rb
|
123
|
+
- test/lib/color/name_test.rb
|
124
|
+
- test/lib/color_test.rb
|
125
|
+
- test/test_helper.rb
|
126
|
+
homepage: https://github.com/danielthor/blink_stick/
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
metadata: {}
|
130
|
+
post_install_message:
|
131
|
+
rdoc_options: []
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - '>='
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
139
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
|
+
requirements:
|
141
|
+
- - '>='
|
142
|
+
- !ruby/object:Gem::Version
|
143
|
+
version: '0'
|
144
|
+
requirements: []
|
145
|
+
rubyforge_project:
|
146
|
+
rubygems_version: 2.1.9
|
147
|
+
signing_key:
|
148
|
+
specification_version: 4
|
149
|
+
summary: BlinkStick is a USB-controlled smart pixel
|
150
|
+
test_files:
|
151
|
+
- test/lib/blink_stick/color_handler_test.rb
|
152
|
+
- test/lib/blink_stick/version_test.rb
|
153
|
+
- test/lib/blink_stick_test.rb
|
154
|
+
- test/lib/color/hex_test.rb
|
155
|
+
- test/lib/color/name_test.rb
|
156
|
+
- test/lib/color_test.rb
|
157
|
+
- test/test_helper.rb
|