knipper 0.0.1.dev3 → 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +2 -0
- data/knipper.gemspec +5 -2
- data/lib/knipper/blink1_lib.rb +5 -0
- data/lib/knipper/device.rb +53 -5
- data/lib/knipper/pattern/pattern.rb +28 -0
- data/lib/knipper/pattern/pattern_line.rb +29 -0
- data/lib/knipper/pattern.rb +2 -0
- data/lib/knipper/version.rb +1 -1
- data/lib/knipper.rb +3 -2
- data/spec/device_spec.rb +38 -0
- data/spec/pattern_line_spec.rb +19 -0
- data/spec/pattern_spec.rb +23 -0
- data/spec/spec_helper.rb +43 -0
- metadata +57 -10
data/.rspec
ADDED
data/knipper.gemspec
CHANGED
@@ -8,7 +8,7 @@ Gem::Specification.new do |gem|
|
|
8
8
|
gem.version = Knipper::VERSION
|
9
9
|
gem.authors = ["Erwin Boskma"]
|
10
10
|
gem.email = ["erwin@datarift.nl"]
|
11
|
-
gem.description = %q{Ruby wrapper for the blink(1) library}
|
11
|
+
gem.description = %q{Ruby wrapper for the blink(1) C-library}
|
12
12
|
gem.summary = %q{Wraps the C-library that is available for the blink(1) USB status lights}
|
13
13
|
gem.homepage = "http://github.com/eboskma/knipper"
|
14
14
|
|
@@ -17,5 +17,8 @@ Gem::Specification.new do |gem|
|
|
17
17
|
gem.test_files = gem.files.grep(%r{^(test|spec|features)/})
|
18
18
|
gem.require_paths = ["lib"]
|
19
19
|
|
20
|
-
gem.add_runtime_dependency "ffi", ['
|
20
|
+
gem.add_runtime_dependency "ffi", ['~> 1.2.0']
|
21
|
+
|
22
|
+
gem.add_development_dependency "rspec", ['~> 2.12.0']
|
23
|
+
gem.add_development_dependency "knipper", ['>= 0.0.1.dev3']
|
21
24
|
end
|
data/lib/knipper/blink1_lib.rb
CHANGED
@@ -17,8 +17,13 @@ module Knipper
|
|
17
17
|
attach_function :blink1_open, [], :pointer
|
18
18
|
attach_function :blink1_openByPath, [:string], :pointer
|
19
19
|
attach_function :blink1_close, [:pointer], :void
|
20
|
+
attach_function :blink1_play, [:pointer, :uchar, :uchar], :int
|
21
|
+
attach_function :blink1_writePatternLine, [:pointer, :ushort, :uchar, :uchar, :uchar, :uchar], :int
|
22
|
+
attach_function :blink1_readPatternLine, [:pointer, :pointer, :pointer, :pointer, :pointer, :uchar], :int
|
23
|
+
attach_function :blink1_degamma, [:int], :int
|
20
24
|
|
21
25
|
attach_function :blink1_setRGB, [:pointer, :uchar, :uchar, :uchar], :int
|
22
26
|
attach_function :blink1_fadeToRGB, [:pointer, :ushort, :uchar, :uchar, :uchar], :int
|
27
|
+
|
23
28
|
end
|
24
29
|
end
|
data/lib/knipper/device.rb
CHANGED
@@ -8,7 +8,6 @@ module Knipper
|
|
8
8
|
|
9
9
|
num_devices = @@lib.blink1_enumerate
|
10
10
|
devices = []
|
11
|
-
puts "#{num_devices} blink(1) devices found"
|
12
11
|
num_devices.times do |i|
|
13
12
|
devices << @@lib.blink1_getCachedPath(i)
|
14
13
|
end unless num_devices < 1
|
@@ -16,8 +15,8 @@ module Knipper
|
|
16
15
|
devices
|
17
16
|
end
|
18
17
|
|
19
|
-
def self.
|
20
|
-
|
18
|
+
def self.device_present?
|
19
|
+
devices.length > 0
|
21
20
|
end
|
22
21
|
|
23
22
|
def initialize(path = nil, &block)
|
@@ -32,8 +31,10 @@ module Knipper
|
|
32
31
|
@@lib.blink1_close @device
|
33
32
|
return
|
34
33
|
end
|
35
|
-
|
36
|
-
|
34
|
+
end
|
35
|
+
|
36
|
+
def close
|
37
|
+
@@lib.blink1_close @device
|
37
38
|
end
|
38
39
|
|
39
40
|
def fade_to_rgb(millis, red, green, blue)
|
@@ -43,5 +44,52 @@ module Knipper
|
|
43
44
|
def set_rgb(red, green, blue)
|
44
45
|
@@lib.blink1_setRGB(@device, red, green, blue)
|
45
46
|
end
|
47
|
+
|
48
|
+
def write_pattern_line(millis, red, green, blue, pos)
|
49
|
+
@@lib.blink1_writePatternLine(@device, millis, red, green, blue, pos)
|
50
|
+
end
|
51
|
+
|
52
|
+
def read_pattern_line(pos)
|
53
|
+
millis = FFI::MemoryPointer.new(:ushort)
|
54
|
+
r = FFI::MemoryPointer.new(:uchar)
|
55
|
+
g = FFI::MemoryPointer.new(:uchar)
|
56
|
+
b = FFI::MemoryPointer.new(:uchar)
|
57
|
+
@@lib.blink1_readPatternLine(@device, millis, r, g, b, pos)
|
58
|
+
|
59
|
+
Knipper::Pattern::PatternLine.new({
|
60
|
+
millis: millis.read_uint16,
|
61
|
+
red: r.read_uint8,
|
62
|
+
green: g.read_uint8,
|
63
|
+
blue: b.read_uint8
|
64
|
+
})
|
65
|
+
end
|
66
|
+
|
67
|
+
def clear_pattern
|
68
|
+
12.times do |i|
|
69
|
+
write_pattern_line 0, 0, 0, 0, i
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
def write_pattern(pattern, clear=true)
|
74
|
+
if pattern.is_a? String
|
75
|
+
pattern = Knipper::Pattern::Pattern.parse(pattern)
|
76
|
+
end
|
77
|
+
|
78
|
+
if pattern.is_a? Knipper::Pattern::Pattern
|
79
|
+
clear_pattern if clear
|
80
|
+
|
81
|
+
pattern.pattern.each do |pattern_line|
|
82
|
+
write_pattern_line pattern_line.millis, pattern_line.red, pattern_line.green, pattern_line.blue, pattern.pattern.index(pattern_line)
|
83
|
+
end
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def start_pattern(pos)
|
88
|
+
@@lib.blink1_play(@device, 1, pos)
|
89
|
+
end
|
90
|
+
|
91
|
+
def stop_pattern
|
92
|
+
@@lib.blink1_play(@device, 0, 0)
|
93
|
+
end
|
46
94
|
end
|
47
95
|
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
module Knipper
|
2
|
+
module Pattern
|
3
|
+
class Pattern
|
4
|
+
attr_accessor :lines
|
5
|
+
|
6
|
+
def self.parse(s)
|
7
|
+
pattern = Pattern.new
|
8
|
+
s.lines do |l|
|
9
|
+
pattern.lines << PatternLine.parse(l.chomp)
|
10
|
+
end
|
11
|
+
|
12
|
+
pattern
|
13
|
+
end
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@lines = []
|
17
|
+
end
|
18
|
+
|
19
|
+
def <<(pattern_line)
|
20
|
+
if pattern_line.is_a? PatternLine
|
21
|
+
lines << pattern_line
|
22
|
+
elsif pattern_line.is_a? String
|
23
|
+
lines << PatternLine.parse(pattern_line)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Knipper
|
2
|
+
module Pattern
|
3
|
+
class PatternLine
|
4
|
+
attr_accessor :millis, :red, :green, :blue
|
5
|
+
|
6
|
+
PATTERN = /\A(\d+),(\d+),(\d+),(\d+)\z/
|
7
|
+
|
8
|
+
def self.parse(s)
|
9
|
+
parts = PATTERN.match(s)
|
10
|
+
raise "Unrecognized pattern -- #{s}" unless parts
|
11
|
+
|
12
|
+
pattern_line = PatternLine.new
|
13
|
+
pattern_line.millis = parts[1].to_i
|
14
|
+
pattern_line.red = parts[2].to_i
|
15
|
+
pattern_line.green = parts[3].to_i
|
16
|
+
pattern_line.blue = parts[4].to_i
|
17
|
+
|
18
|
+
pattern_line
|
19
|
+
end
|
20
|
+
|
21
|
+
def initialize(attributes = {})
|
22
|
+
attributes.each do |name, value|
|
23
|
+
send("#{name}=", value)
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/knipper/version.rb
CHANGED
data/lib/knipper.rb
CHANGED
data/spec/device_spec.rb
ADDED
@@ -0,0 +1,38 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Knipper::Device do
|
4
|
+
it "opens a device" do
|
5
|
+
d = Knipper::Device.new
|
6
|
+
d.should_not be_nil
|
7
|
+
d.close
|
8
|
+
d = nil
|
9
|
+
end
|
10
|
+
|
11
|
+
it "sets a color" do
|
12
|
+
device = Knipper::Device.new
|
13
|
+
result = device.set_rgb(255, 0, 0)
|
14
|
+
result.should be >= 0
|
15
|
+
device.close
|
16
|
+
end
|
17
|
+
|
18
|
+
it "fades to a color" do
|
19
|
+
device = Knipper::Device.new
|
20
|
+
result = device.fade_to_rgb(100, 0, 255, 0)
|
21
|
+
result.should be >= 0
|
22
|
+
device.close
|
23
|
+
end
|
24
|
+
|
25
|
+
it "writes a pattern" do
|
26
|
+
device = Knipper::Device.new
|
27
|
+
lib = Knipper::Blink1Lib.new
|
28
|
+
device.clear_pattern
|
29
|
+
result = device.write_pattern_line 500, 100, 150, 200, 0
|
30
|
+
result.should be >= 0
|
31
|
+
pattern = device.read_pattern_line 0
|
32
|
+
pattern.millis.should eq 500
|
33
|
+
pattern.red.should eq lib.blink1_degamma(100)
|
34
|
+
pattern.green.should eq lib.blink1_degamma(150)
|
35
|
+
pattern.blue.should eq lib.blink1_degamma(200)
|
36
|
+
device.close
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,19 @@
|
|
1
|
+
require "spec_helper"
|
2
|
+
|
3
|
+
describe Knipper::Pattern::PatternLine do
|
4
|
+
it "parses a valid string" do
|
5
|
+
pattern_str = "500,128,65,233"
|
6
|
+
pattern = Knipper::Pattern::PatternLine.parse(pattern_str)
|
7
|
+
|
8
|
+
pattern.should_not be_nil
|
9
|
+
pattern.millis.should eq 500
|
10
|
+
pattern.red.should eq 128
|
11
|
+
pattern.green.should eq 65
|
12
|
+
pattern.blue.should eq 233
|
13
|
+
end
|
14
|
+
|
15
|
+
it "raises an error when parsing an invalid string" do
|
16
|
+
pattern_str = "asdf"
|
17
|
+
expect { Knipper::Pattern::PatternLine.parse(pattern_str) }.to raise_error("Unrecognized pattern -- #{pattern_str}")
|
18
|
+
end
|
19
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Knipper::Pattern::Pattern do
|
4
|
+
it "parses a series of pattern lines" do
|
5
|
+
pattern_str = <<EOF
|
6
|
+
0,1,2,3
|
7
|
+
1,2,3,4
|
8
|
+
2,3,4,5
|
9
|
+
3,4,5,6
|
10
|
+
4,5,6,7
|
11
|
+
EOF
|
12
|
+
pattern = Knipper::Pattern::Pattern.parse(pattern_str)
|
13
|
+
|
14
|
+
pattern.lines.should_not be_nil
|
15
|
+
pattern.lines.length.should eq 5
|
16
|
+
pattern.lines.length.times do |i|
|
17
|
+
pattern.lines[i].millis.should eq i
|
18
|
+
pattern.lines[i].red.should eq i + 1
|
19
|
+
pattern.lines[i].green.should eq i + 2
|
20
|
+
pattern.lines[i].blue.should eq i + 3
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,43 @@
|
|
1
|
+
require 'knipper'
|
2
|
+
|
3
|
+
class BlinkFormatter < RSpec::Core::Formatters::BaseFormatter
|
4
|
+
def initialize(output)
|
5
|
+
super(output)
|
6
|
+
end
|
7
|
+
|
8
|
+
# def start(count)
|
9
|
+
# super(count)
|
10
|
+
# Knipper::Device.new { |d| d.fade_to_rgb 100, 0, 0, 0 }
|
11
|
+
# end
|
12
|
+
|
13
|
+
def stop
|
14
|
+
return unless Knipper::Device.device_present?
|
15
|
+
|
16
|
+
if @failed_examples.length > 0
|
17
|
+
Knipper::Device.new { |d| d.fade_to_rgb 500, 255, 0, 0 }
|
18
|
+
else
|
19
|
+
Knipper::Device.new { |d| d.fade_to_rgb 500, 0, 255, 0 }
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
# This file was generated by the `rspec --init` command. Conventionally, all
|
25
|
+
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
26
|
+
# Require this file using `require "spec_helper"` to ensure that it is only
|
27
|
+
# loaded once.
|
28
|
+
#
|
29
|
+
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
30
|
+
RSpec.configure do |config|
|
31
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
32
|
+
config.run_all_when_everything_filtered = true
|
33
|
+
config.filter_run :focus
|
34
|
+
config.filter_run_excluding :skip
|
35
|
+
|
36
|
+
config.add_formatter BlinkFormatter
|
37
|
+
# Run specs in random order to surface order dependencies. If you find an
|
38
|
+
# order dependency and want to debug it, you can fix the order by providing
|
39
|
+
# the seed, which is printed after each run.
|
40
|
+
# --seed 1234
|
41
|
+
config.order = 'random'
|
42
|
+
end
|
43
|
+
|
metadata
CHANGED
@@ -1,22 +1,22 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: knipper
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.1
|
5
|
-
prerelease:
|
4
|
+
version: 0.0.1
|
5
|
+
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
8
8
|
- Erwin Boskma
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2013-01-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: ffi
|
16
16
|
requirement: !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
|
-
- -
|
19
|
+
- - ~>
|
20
20
|
- !ruby/object:Gem::Version
|
21
21
|
version: 1.2.0
|
22
22
|
type: :runtime
|
@@ -24,10 +24,42 @@ dependencies:
|
|
24
24
|
version_requirements: !ruby/object:Gem::Requirement
|
25
25
|
none: false
|
26
26
|
requirements:
|
27
|
-
- -
|
27
|
+
- - ~>
|
28
28
|
- !ruby/object:Gem::Version
|
29
29
|
version: 1.2.0
|
30
|
-
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rspec
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 2.12.0
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
version_requirements: !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ~>
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: 2.12.0
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: knipper
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ! '>='
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 0.0.1.dev3
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ! '>='
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 0.0.1.dev3
|
62
|
+
description: Ruby wrapper for the blink(1) C-library
|
31
63
|
email:
|
32
64
|
- erwin@datarift.nl
|
33
65
|
executables: []
|
@@ -35,6 +67,7 @@ extensions: []
|
|
35
67
|
extra_rdoc_files: []
|
36
68
|
files:
|
37
69
|
- .gitignore
|
70
|
+
- .rspec
|
38
71
|
- Gemfile
|
39
72
|
- LICENSE.txt
|
40
73
|
- README.md
|
@@ -43,7 +76,14 @@ files:
|
|
43
76
|
- lib/knipper.rb
|
44
77
|
- lib/knipper/blink1_lib.rb
|
45
78
|
- lib/knipper/device.rb
|
79
|
+
- lib/knipper/pattern.rb
|
80
|
+
- lib/knipper/pattern/pattern.rb
|
81
|
+
- lib/knipper/pattern/pattern_line.rb
|
46
82
|
- lib/knipper/version.rb
|
83
|
+
- spec/device_spec.rb
|
84
|
+
- spec/pattern_line_spec.rb
|
85
|
+
- spec/pattern_spec.rb
|
86
|
+
- spec/spec_helper.rb
|
47
87
|
homepage: http://github.com/eboskma/knipper
|
48
88
|
licenses: []
|
49
89
|
post_install_message:
|
@@ -58,17 +98,24 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
58
98
|
version: '0'
|
59
99
|
segments:
|
60
100
|
- 0
|
61
|
-
hash:
|
101
|
+
hash: -2175147279034420234
|
62
102
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
63
103
|
none: false
|
64
104
|
requirements:
|
65
|
-
- - ! '
|
105
|
+
- - ! '>='
|
66
106
|
- !ruby/object:Gem::Version
|
67
|
-
version:
|
107
|
+
version: '0'
|
108
|
+
segments:
|
109
|
+
- 0
|
110
|
+
hash: -2175147279034420234
|
68
111
|
requirements: []
|
69
112
|
rubyforge_project:
|
70
113
|
rubygems_version: 1.8.23
|
71
114
|
signing_key:
|
72
115
|
specification_version: 3
|
73
116
|
summary: Wraps the C-library that is available for the blink(1) USB status lights
|
74
|
-
test_files:
|
117
|
+
test_files:
|
118
|
+
- spec/device_spec.rb
|
119
|
+
- spec/pattern_line_spec.rb
|
120
|
+
- spec/pattern_spec.rb
|
121
|
+
- spec/spec_helper.rb
|