littlewire 0.9.4 → 0.9.5
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/lib/littlewire.rb +15 -16
- data/lib/ws2811.rb +72 -5
- metadata +11 -17
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b02ec3c25311d8cf29a0e34fbf14a9e12f7c1d7a
|
4
|
+
data.tar.gz: 139849c4608ae5ddc03e79c01b830ff9e0ec720d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 843864b20dc637f517247ba49982a8c5fafd28c019cd8e4c63c0eb411c145f611b4a00bac21b890cfffa247d6fdeb207ad510173fc369b66531f78250ff372e6
|
7
|
+
data.tar.gz: 72a4af2222770d54a155caf7a07ac27fbb64b48c7d84534f2e34105f6c238ed87f54b446bf0a925e1afeb44506f794c6d2559297f8adeed862cd828785bde1f9
|
data/lib/littlewire.rb
CHANGED
@@ -204,7 +204,21 @@ class LittleWire
|
|
204
204
|
self.send "#{pin[0]}_write", pin[1], value
|
205
205
|
end
|
206
206
|
|
207
|
-
|
207
|
+
|
208
|
+
# lookup a pin name in a map and return it's raw identifier
|
209
|
+
def get_pin map, value #:nodoc:
|
210
|
+
value = value.to_sym if value.is_a? String
|
211
|
+
value = map[value] if map.has_key? value
|
212
|
+
value
|
213
|
+
end
|
214
|
+
|
215
|
+
# translate possible literal values in to a boolean true or false (meaning high or low)
|
216
|
+
def get_boolean value #:nodoc:
|
217
|
+
# some exceptions
|
218
|
+
value = false if value == :low or value == 0 or value == nil or value == :off or value == :ground or value == :gnd
|
219
|
+
!! value # double invert value in to boolean form
|
220
|
+
end
|
221
|
+
|
208
222
|
# raw opened device
|
209
223
|
def io #:nodoc:
|
210
224
|
unless @io
|
@@ -297,19 +311,4 @@ class LittleWire
|
|
297
311
|
value |= LIBUSB::ENDPOINT_IN if opts.has_key? :dataIn
|
298
312
|
return value
|
299
313
|
end
|
300
|
-
|
301
|
-
|
302
|
-
# lookup a pin name in a map and return it's raw identifier
|
303
|
-
def get_pin map, value #:nodoc:
|
304
|
-
value = value.to_sym if value.is_a? String
|
305
|
-
value = map[value] if map.has_key? value
|
306
|
-
value
|
307
|
-
end
|
308
|
-
|
309
|
-
# translate possible literal values in to a boolean true or false (meaning high or low)
|
310
|
-
def get_boolean value #:nodoc:
|
311
|
-
# some exceptions
|
312
|
-
value = false if value == :low or value == 0 or value == nil or value == :off or value == :ground or value == :gnd
|
313
|
-
!! value # double invert value in to boolean form
|
314
|
-
end
|
315
314
|
end
|
data/lib/ws2811.rb
CHANGED
@@ -12,18 +12,81 @@ require 'colorist'
|
|
12
12
|
class LittleWire::WS2811
|
13
13
|
attr_accessor :colors
|
14
14
|
attr_accessor :pin
|
15
|
-
|
15
|
+
attr_reader :wiring
|
16
|
+
ColorTransformer = {
|
17
|
+
rgb: ->(input) {
|
18
|
+
input # passthrough
|
19
|
+
},
|
20
|
+
grb: ->(input) {
|
21
|
+
Colorist::Color.from_rgb(input.g, input.r, input.b)
|
22
|
+
},
|
23
|
+
bgr: ->(input) {
|
24
|
+
Colorist::Color.from_rgb(input.b, input.r, input.g)
|
25
|
+
},
|
26
|
+
gbr: ->(input) {
|
27
|
+
Colorist::Color.from_rgb(input.g, input.b, input.r)
|
28
|
+
},
|
29
|
+
rbg: ->(input) {
|
30
|
+
Colorist::Color.from_rgb(input.r, input.b, input.g)
|
31
|
+
},
|
32
|
+
greyscale: ->(input) {
|
33
|
+
grey = (input.r + input.g + input.b) / 3 # average the colours
|
34
|
+
Colorist::Color.from_rgb(grey, grey, grey)
|
35
|
+
},
|
36
|
+
# lookup chart
|
37
|
+
florapixel_v1: :rbg,
|
38
|
+
florapixels_v1: :florapixel_v1,
|
39
|
+
ws2812: :rgb,
|
40
|
+
florapixel_v2: :ws2812,
|
41
|
+
florapixels_v2: :florapixel_v2,
|
42
|
+
grayscale: :greyscale, # Woo English!
|
43
|
+
white: :greyscale,
|
44
|
+
}
|
45
|
+
ChannelSize = 64 # LittleWire can store 64 values
|
16
46
|
|
17
47
|
def initialize wire, default_pin = false # :nodoc:
|
18
48
|
@wire = wire
|
19
49
|
@pin = default_pin
|
20
50
|
@colors = []
|
51
|
+
@wiring = :rgb
|
52
|
+
@wiring_map = ColorTransformer[:rgb]
|
53
|
+
end
|
54
|
+
|
55
|
+
# Set the pixel wiring style. The default :rgb is great for the little ws2812 LEDs
|
56
|
+
# which have the chips built in as a little black cube inside the LED. This setting is for
|
57
|
+
# other LEDs where the controller chip is outside the LED. In some of these LEDs the red,
|
58
|
+
# green, and blue outputs of the controller chip connect to different colours of LEDs!
|
59
|
+
#
|
60
|
+
# Of particular note, the original Adafruit Florapixels (now called version 1) can be modified
|
61
|
+
# to run at the 800khz speed instead of 400khz by breaking off this leg on the chip on the back:
|
62
|
+
#
|
63
|
+
# ______
|
64
|
+
# -|o |-
|
65
|
+
# -| |- <--- this one!
|
66
|
+
# -| |-
|
67
|
+
# -|______|-
|
68
|
+
#
|
69
|
+
# This makes them compatible with LittleWire and cheap LED strips, but these florapixels are
|
70
|
+
# wired bizarrely in RBG order. I rebuke thee, adafruit industries!! Also supposedly some
|
71
|
+
# other version of the v1 florapixels used another different wiring and I don't think they're
|
72
|
+
# labeled differently, so try it and see what works for you, or just give up and buy some
|
73
|
+
# ws2812 strip from aliexpress - it's only like 30¢ per LED including shipping anyway!
|
74
|
+
def wiring=(style)
|
75
|
+
@wiring_map = style.to_sym
|
76
|
+
# loop till we resolve symbol chain in to a real proc we can map colours through
|
77
|
+
@wiring_map = ColorTransformer[@wiring_map] while @wiring_map.is_a? Symbol
|
78
|
+
# if never exhausted lookup, you all get errors!!! ERRORS FOR EVERYONE!!!
|
79
|
+
raise "Unknown Wiring Style #{style.inspect}! Must be one of " +
|
80
|
+
"#{ColorTransformer.keys.map { |x| x.inspect }.join(', ')}" +
|
81
|
+
" or a Proc which transforms a Colorist::Color" if @wiring_map == nil
|
82
|
+
@wiring = style
|
21
83
|
end
|
22
84
|
|
23
85
|
# send colours to strip, optionally specifying a pin if not specified via
|
24
|
-
#
|
86
|
+
#
|
87
|
+
# littlewire.ws2811(pin).output
|
25
88
|
def output pin = nil
|
26
|
-
colors_buffer = @colors.map { |i| i.is_a?(Colorist::Color) ? i : i.to_color }
|
89
|
+
colors_buffer = @colors.map { |i| @wiring_map[i.is_a?(Colorist::Color) ? i : i.to_color] }
|
27
90
|
output_pin = @wire.get_pin(LittleWire::DigitalPinMap, pin || @pin)
|
28
91
|
raise "Must specify output pin for ws2811 strip" unless output_pin.is_a? Integer
|
29
92
|
|
@@ -39,15 +102,19 @@ class LittleWire::WS2811
|
|
39
102
|
end
|
40
103
|
end
|
41
104
|
|
105
|
+
# Set strip to an array of colours, automatically outputting them to the strip immediately
|
42
106
|
def send *colors
|
43
107
|
@colors = colors.flatten
|
44
108
|
output
|
45
109
|
end
|
46
110
|
alias_method :set, :send
|
47
111
|
|
112
|
+
# Set the whole strip to be black! This can be nice at the start of your program, because
|
113
|
+
# the strip starts out being whatever colours it was when it was powered up, which can be
|
114
|
+
# random - this makes sure everything is black, at least up to the max 64 LEDs littlewire
|
115
|
+
# supports per channel
|
48
116
|
def black!
|
49
|
-
|
50
|
-
output
|
117
|
+
send(['black'] * ChannelSize)
|
51
118
|
end
|
52
119
|
|
53
120
|
private
|
metadata
CHANGED
@@ -1,46 +1,41 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: littlewire
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.9.
|
5
|
-
prerelease:
|
4
|
+
version: 0.9.5
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Bluebie
|
9
8
|
autorequire:
|
10
9
|
bindir: bin
|
11
10
|
cert_chain: []
|
12
|
-
date: 2013-05
|
11
|
+
date: 2013-06-05 00:00:00.000000000 Z
|
13
12
|
dependencies:
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: libusb
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - '>='
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 0.2.0
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - '>='
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 0.2.0
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: colorist
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - '>='
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 0.0.2
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - '>='
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 0.0.2
|
46
41
|
description: A little library for a little wire. Providing a pure ruby interface (via
|
@@ -70,6 +65,7 @@ files:
|
|
70
65
|
- examples/led pixel.rb
|
71
66
|
homepage: http://creativepony.com/littlewire/
|
72
67
|
licenses: []
|
68
|
+
metadata: {}
|
73
69
|
post_install_message:
|
74
70
|
rdoc_options:
|
75
71
|
- --main
|
@@ -77,21 +73,19 @@ rdoc_options:
|
|
77
73
|
require_paths:
|
78
74
|
- lib
|
79
75
|
required_ruby_version: !ruby/object:Gem::Requirement
|
80
|
-
none: false
|
81
76
|
requirements:
|
82
|
-
- -
|
77
|
+
- - '>='
|
83
78
|
- !ruby/object:Gem::Version
|
84
79
|
version: '0'
|
85
80
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
86
|
-
none: false
|
87
81
|
requirements:
|
88
|
-
- -
|
82
|
+
- - '>='
|
89
83
|
- !ruby/object:Gem::Version
|
90
84
|
version: '0'
|
91
85
|
requirements: []
|
92
86
|
rubyforge_project:
|
93
|
-
rubygems_version:
|
87
|
+
rubygems_version: 2.0.0
|
94
88
|
signing_key:
|
95
|
-
specification_version:
|
89
|
+
specification_version: 4
|
96
90
|
summary: A tiny library for littlewire.cc usb devices
|
97
91
|
test_files: []
|