limitless-led 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0c3801fee2b64b49c2ffbf8ba011bd0d2a96311d
4
- data.tar.gz: c0a62f8e2616603ff7c3fc3b30172dcaa9bd6c05
3
+ metadata.gz: 2fec2000f5c11ff96ef95a8affe1b2b6e63aa695
4
+ data.tar.gz: 81075637c3c0c8444a55363fbf385e14922ca842
5
5
  SHA512:
6
- metadata.gz: 1f990a7b1175c171425493fcb59fb1846d207f92e42667e5cbe5a002021a77096efd47881d494ede1f3dd827142c7e0b9725c50a31f9e165c82202525202da83
7
- data.tar.gz: 42b39ed0c2e5f93373078eddc4bcc6ed8669e9da092ad1e198b0eff08c8b98b23a68a7027d5d76f57831835aa1b7d5d9945ea6d8aadbfc446a96ee128cad28fd
6
+ metadata.gz: 2e2dfbb0e453308b221cb79cbc6ea09609482bfa87f61350602d8427c1fa20afaad93a98573e56fb2567802397b0999d61a004684c57f1680d103049d0f30fa7
7
+ data.tar.gz: 795b47c620f78ebe29f2085bddab32b91c571cc554224716916e6585ecb694fae9f45f6d8eb3d84e7110977e9cfbbf63d734544c329bbfedcb31b1f5ba51724b
data/.gitignore CHANGED
@@ -1,37 +1,20 @@
1
- ## MAC OS
2
- .DS_Store
3
-
4
- ## TEXTMATE
5
- *.tmproj
6
- tmtags
7
-
8
- ## EMACS
9
- *~
10
- \#*
11
- .\#*
12
-
13
- ## VIM
14
- *.swp
15
-
16
- ## PROJECT::GENERAL
17
- coverage
18
- rdoc
19
- pkg
20
1
  *.gem
21
2
  *.rbc
22
3
  .bundle
23
4
  .config
24
- .yardoc
25
- /Gemfile.lock
5
+ .ruby-version
6
+ .ruby-gemset
7
+ coverage
26
8
  InstalledFiles
27
- _yardoc
28
- doc/
29
9
  lib/bundler/man
10
+ pkg
11
+ rdoc
30
12
  spec/reports
31
13
  test/tmp
32
14
  test/version_tmp
33
15
  tmp
34
16
 
35
- ## PROJECT::SPECIFIC
36
-
37
- .idea
17
+ # YARD artifacts
18
+ .yardoc
19
+ _yardoc
20
+ doc/
data/Gemfile CHANGED
@@ -1,4 +1,3 @@
1
1
  source 'https://rubygems.org'
2
2
 
3
- # Specify your gem's dependencies in limitless_led.gemspec
4
- gemspec
3
+ gemspec
@@ -0,0 +1,34 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ limitless-led (0.2.0)
5
+ active_support
6
+ color
7
+ rainbow
8
+
9
+ GEM
10
+ remote: https://rubygems.org/
11
+ specs:
12
+ active_support (3.0.0)
13
+ activesupport (= 3.0.0)
14
+ activesupport (3.0.0)
15
+ color (1.4.2)
16
+ diff-lcs (1.2.4)
17
+ rainbow (1.99.0)
18
+ rake (10.1.0)
19
+ rspec (2.14.1)
20
+ rspec-core (~> 2.14.0)
21
+ rspec-expectations (~> 2.14.0)
22
+ rspec-mocks (~> 2.14.0)
23
+ rspec-core (2.14.5)
24
+ rspec-expectations (2.14.3)
25
+ diff-lcs (>= 1.1.3, < 2.0)
26
+ rspec-mocks (2.14.3)
27
+
28
+ PLATFORMS
29
+ ruby
30
+
31
+ DEPENDENCIES
32
+ limitless-led!
33
+ rake
34
+ rspec
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2013 hired
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
6
+ this software and associated documentation files (the "Software"), to deal in
7
+ the Software without restriction, including without limitation the rights to
8
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
9
+ the Software, and to permit persons to whom the Software is furnished to do so,
10
+ subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
17
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
18
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
19
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
20
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.md CHANGED
@@ -1,81 +1,59 @@
1
- # LimitlessLed
1
+ limitless-led
2
+ =============
2
3
 
3
- [![Build Status](https://travis-ci.org/jpsilvashy/limitless-led.png?branch=master)](https://travis-ci.org/jpsilvashy/limitless-led)
4
- [![Dependency Status](https://gemnasium.com/jpsilvashy/limitless-led.png)](https://gemnasium.com/jpsilvashy/limitless-led)
5
- [![Code Climate](https://codeclimate.com/github/jpsilvashy/limitless-led.png)](https://codeclimate.com/github/jpsilvashy/limitless-led)
6
- [![Coverage Status](https://coveralls.io/repos/jpsilvashy/limitless-led/badge.png)](https://coveralls.io/r/jpsilvashy/limitless-led)
7
-
8
- A Ruby gem for controlling the [LimitlessLED v3.0 RGBW color-changing light bulbs](http://www.limitlessled.com/), based on the official [LimitlessLED API documentation](http://www.limitlessled.com/dev/).
9
-
10
- ## Installation
11
-
12
- Add this line to your application's Gemfile:
13
-
14
- ``` ruby
15
- gem 'limitless-led'
16
- ```
17
-
18
- And then execute:
19
-
20
- $ bundle
21
-
22
- Or install it yourself as:
23
-
24
- $ gem install limitless-led
4
+ A Ruby client library for controlling the [LimitlessLED v3.0 RGBW color-changing light bulbs](http://www.limitlessled.com/),
5
+ based on the official [LimitlessLED API documentation](http://www.limitlessled.com/dev/).
25
6
 
26
7
  ## Usage
27
8
 
28
- ``` ruby
29
- require 'limitless_led'
30
-
31
- # If you don't have a LimitlessLED handy you can start the development
32
- # server by running bin/server, it logs to stdout
33
- bridge = LimitlessLed::Bridge.new(host: 'localhost', port: 8899)
34
-
35
- # Send in hex like this:
36
- bridge.color "#ff0000"
37
-
38
- # You can send a triple
39
- bridge.color "#f00"
40
-
41
- # Send data straight to the bridge:
42
- bridge.send_packet "\x40\x00\x55"
43
-
44
- # Send a lot of data to the bridge very quickly:
45
- 10.times do
46
- (0..255).each do |int|
47
- bridge.send_packet "\x40#{ int.chr }\x55"
48
- sleep 0.005
49
- end
50
- end
51
-
52
- # Again if you don't have the LimitlessLED, you can create an instance
53
- # of the development server
54
- server = LimitlessLed::Server.new(host: 'localhost', port: 8899)
55
-
56
- # Then you can see what the server does when it receives messages
57
- server.receive_data("\x40\x00\xff")
58
- ```
59
-
60
- _View more demos in the [/examples](https://github.com/jpsilvashy/limitless-led/tree/master/examples) directory_
61
-
62
- If you are using the development server you should see this output:
63
-
64
- ![Output](https://www.evernote.com/shard/s5/sh/8d51bc75-7d2b-4e23-a3c8-05e5742ec333/89bd43c12107a6e2d69bad91a526220c/deep/0/server.jpg)
65
-
66
- **As a note,** since we are transforming the colors from RGB to HSL and then back for representing the color in the console (which additionally is more limiting than the true color space offered by the LED) some of the hex values may not exactly match, especially near the dark limit. Since we are controlling the the brightness of the LED separately, and do not have access to the saturation some colors maybe be harder to reproduce than others, especially dark colors.
67
-
68
- ## Contributors
69
-
70
- - [Nate Clark](https://github.com/heythisisnate)
71
- - [Curtis Gagliardi](https://github.com/cgag)
72
-
73
- *_This originally was a fork of [hired/limitless-led](https://github.com/hired/limitless-led) but quickly grew larger in scope so I decided to move it to a new repo._
74
-
75
- ## Contributing
76
- 1. Fork it ( http://github.com/jpsilvashy/limitless-led/fork )
77
- 2. Create your feature branch (`git checkout -b my-new-feature`)
78
- 3. Commit your changes (`git commit -am 'Add some feature'`)
79
- 4. Push to the branch (`git push origin my-new-feature`)
80
- 5. Create new Pull Request
81
-
9
+ bridge = LimitlessLed::Bridge.new(host: '192.168.1.100', port: 8899)
10
+
11
+ bridge.all_on # all lights are on
12
+ bridge.all_off # all lights are off
13
+ bridge.white # all lights are white
14
+ bridge.disco # disco mode!
15
+ bridge.disco_faster # disco mode faster
16
+ bridge.disco_slower # disco mode slower
17
+
18
+ # change the color by calling #color with either a color string, integer, or Color::RGB object
19
+ # see: https://github.com/halostatue/color/blob/master/lib/color/rgb-colors.rb for a list
20
+ # of all the named colors
21
+ bridge.color 'Red' # color is red
22
+ bridge.color Color::RGB::Red # color is red
23
+ bridge.color 170 # color is red
24
+
25
+ # adjust brightness on a scale from 2 - 27 (27 is full brightness)
26
+ bridge.brightness 27 # full brightness
27
+
28
+ # control a single group
29
+ group = bridge.group(1) # supports up to 4 groups (1 - 4)
30
+ group.color 'Blue'
31
+ group.brightness 25
32
+
33
+
34
+ ## Note
35
+
36
+ We are *not affiliated in any way* with the manufacturers of Limitless LED. We just think they are cool.
37
+
38
+ ## License
39
+
40
+ The MIT License (MIT)
41
+
42
+ Copyright (c) 2013 Hired, Inc.
43
+
44
+ Permission is hereby granted, free of charge, to any person obtaining a copy of
45
+ this software and associated documentation files (the "Software"), to deal in
46
+ the Software without restriction, including without limitation the rights to
47
+ use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
48
+ the Software, and to permit persons to whom the Software is furnished to do so,
49
+ subject to the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be included in all
52
+ copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
55
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
56
+ FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
57
+ COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
58
+ IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
59
+ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -1,11 +1,10 @@
1
- #!/usr/bin/ruby
2
- require "limitless_led/version"
1
+ lib = File.expand_path('../lib', File.dirname(__FILE__))
2
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
3
3
 
4
- require "limitless_led/logger"
5
- require "limitless_led/bridge"
6
- require "limitless_led/server"
7
-
8
- module LimitlessLed
9
- class CommandNotImplemented < StandardError; end
10
- class UnknownCommand < StandardError; end
11
- end
4
+ require 'socket'
5
+ require 'color'
6
+ require 'active_support/inflector'
7
+ require 'limitless_led/version'
8
+ require 'limitless_led/colors'
9
+ require 'limitless_led/group'
10
+ require 'limitless_led/bridge'
@@ -1,10 +1,25 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'socket'
4
-
5
1
  module LimitlessLed
6
2
  class Bridge
7
- include LimitlessLed::Logger
3
+ include Colors
4
+
5
+ COMMANDS = {
6
+ all_off: 65,
7
+ all_on: 66,
8
+ disco: 77,
9
+ disco_slower: 67,
10
+ disco_faster: 68,
11
+ color: 64,
12
+ brightness: 78,
13
+ group_1_on: 69,
14
+ group_1_off: 70,
15
+ group_2_on: 71,
16
+ group_2_off: 72,
17
+ group_3_on: 73,
18
+ group_3_off: 74,
19
+ group_4_on: 75,
20
+ group_4_off: 76
21
+ }
22
+
8
23
  attr_accessor :host, :port
9
24
 
10
25
  def initialize(host: 'localhost', port: 8899)
@@ -12,7 +27,9 @@ module LimitlessLed
12
27
  @port = port
13
28
  end
14
29
 
15
- VALID_COMMANDS = (65..77).to_a
30
+ def group(number)
31
+ LimitlessLed::Group.new(number, self)
32
+ end
16
33
 
17
34
  def socket
18
35
  @socket ||= begin
@@ -22,51 +39,50 @@ module LimitlessLed
22
39
  end
23
40
  end
24
41
 
25
- # Sends the actual bytes to the real bridge/led over the UDP socket method.
26
- #
27
- # Usage:
28
- #
29
- # # Default
30
- # send_packet "\x40\xff\x55"
31
- #
32
- # Options:
33
- #
34
- # +packet+:: the bytes to send to the device
35
- #
36
- def send_packet(packet)
37
- socket.send packet, 0
42
+ COMMANDS.each do |cmd, _|
43
+ define_method(cmd) { command cmd }
44
+ end
45
+
46
+ def white
47
+ send_packet "\xc2\x00\x55"
38
48
  end
39
49
 
40
- # This sets the color of the LED with a hex value for the color the packets
41
- # are sent to the socket for the command
42
- #
43
- # Usage:
44
- #
45
- # # Default
46
- # color '#ff0000'
47
- #
48
- # # Triplet
49
- # color '#f00'
50
- #
51
- # # Optional "#"
52
- # color 'ff0000'
53
- #
54
- # Options:
55
- #
56
- # +color+:: The color in the hex format rrggbb or rgb
57
- #
58
50
  def color(color)
51
+ color_code = if color.is_a?(Color::RGB)
52
+ color_code_from_color(color)
53
+ elsif color.is_a?(Integer)
54
+ color
55
+ elsif color.is_a?(String)
56
+ color_code_from_color Color::RGB.const_get(color.camelize)
57
+ end
58
+
59
+ command :color, color_code
60
+ end
61
+
62
+ def brightness(amount)
63
+ raise(ArgumentError.new('Brightness must be within 2 - 27')) unless (2..27).include?(amount)
64
+ command :brightness, amount
65
+ end
59
66
 
60
- # receive color as string like #ff0000 or a triplet
61
- # transform to HSL color
62
- # color = Color::RGB.from_html(color).to_hsl
67
+ def send_packet(packet)
68
+ socket.send packet, 0
69
+ end
63
70
 
64
- # Transform color into value out of 255
65
- # hue = ((-(color.to_hsl.hue - 240) % 360) / 360.0 * 255.0).to_i
71
+ def command(command_key, command_param = 0)
72
+ send_packet COMMANDS[command_key].chr + command_param.chr + 85.chr
73
+ end
66
74
 
67
- # send command
68
- send_packet "\x40#{ color.to_i.chr }\x55"
75
+ def go_crazy
76
+ while true
77
+ color rand(256)
78
+ end
69
79
  end
70
80
 
81
+ def smooth_and_fast
82
+ 0..255.cycle do |color_code|
83
+ color color_code
84
+ sleep 1/100.0
85
+ end
86
+ end
71
87
  end
72
88
  end
@@ -0,0 +1,11 @@
1
+ module Colors
2
+
3
+ def color_code_from_color(color)
4
+ ((-(color.to_hsl.hue - 240) % 360) / 360.0 * 255.0).to_i
5
+ end
6
+
7
+ def color_from_hex(hex)
8
+ Color::RGB.from_html(hex)
9
+ end
10
+
11
+ end
@@ -0,0 +1,27 @@
1
+ module LimitlessLed
2
+ class Group
3
+ attr_reader :bridge
4
+
5
+ def initialize(number, bridge)
6
+ raise(ArgumentError.new('Group number must be 1, 2, 3 or 4')) unless (1..4).include?(number)
7
+ @number = number
8
+ @bridge = bridge
9
+ end
10
+
11
+ def on
12
+ bridge.command "group_#{@number}_on".to_sym
13
+ end
14
+
15
+ def off
16
+ bridge.command "group_#{@number}_off".to_sym
17
+ end
18
+
19
+ %w{ color brightness white }.each do |cmd|
20
+ define_method cmd do |arg = nil|
21
+ on
22
+ sleep(0.1)
23
+ bridge.send(*[cmd, arg].compact)
24
+ end
25
+ end
26
+ end
27
+ end
@@ -1,5 +1,3 @@
1
- #!/usr/bin/ruby
2
-
3
1
  module LimitlessLed
4
- VERSION = "0.1.4"
5
- end
2
+ VERSION = "0.2.0"
3
+ end
@@ -4,14 +4,13 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
  require 'limitless_led/version'
5
5
 
6
6
  Gem::Specification.new do |spec|
7
-
8
7
  spec.name = "limitless-led"
9
8
  spec.version = LimitlessLed::VERSION
10
- spec.authors = ["Joseph Silvashy"]
11
- spec.email = ["jpsilvashy@gmail.com"]
9
+ spec.authors = ["Hired, Inc", "Joseph Silvashy"]
10
+ spec.email = ["opensource@hired.com", "jpsilvashy@gmail.com"]
12
11
  spec.summary = %q{A Ruby gem for controlling the LimitlessLED v3.0 RGBW color-changing light bulbs.}
13
12
  spec.description = %q{A Ruby gem for controlling the LimitlessLED v3.0 RGBW color-changing light bulbs, based on the official LimitlessLED API documentation.}
14
- spec.homepage = "https://github.com/jpsilvashy/limitless-led"
13
+ spec.homepage = "https://github.com/hired/limitless-led"
15
14
  spec.license = "MIT"
16
15
 
17
16
  spec.files = `git ls-files`.split($/)
@@ -22,8 +21,8 @@ Gem::Specification.new do |spec|
22
21
  spec.add_development_dependency "rake"
23
22
  spec.add_development_dependency "rspec"
24
23
 
25
- spec.add_dependency "eventmachine"
24
+ spec.add_dependency "active_support"
26
25
  spec.add_dependency "color"
27
26
  spec.add_dependency "rainbow"
28
27
 
29
- end
28
+ end
@@ -1,40 +1,9 @@
1
- # Tests should cover these commands, which can also be found here:
2
- # http://www.limitlessled.com/dev/
3
-
4
- # All UDP Commands are 3 Bytes. First byte is from the list below, plus a fixed 2 byte suffix of 0x00 (decimal: 0) and 0x55 (decimal: 85)
5
- # i.e. to turn all RGBW COLOR LimitlessLED Smart lights to ON then send the TCP/IP UDP packet of: 0x42 0x00 0x55
6
- #
7
- # Hexidecimal (byte) Decimal (integer)
8
- #
9
- # RGBW COLOR LED ALL OFF 0x41 65
10
- # RGBW COLOR LED ALL ON 0x42 66
11
- #
12
- # DISCO SPEED SLOWER 0x43 67
13
- # DISCO SPEED FASTER 0x44 68
14
- #
15
- # GROUP 1 ALL ON 0x45 69 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
16
- # GROUP 1 ALL OFF 0x46 70
17
- # GROUP 2 ALL ON 0x47 71 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
18
- # GROUP 2 ALL OFF 0x48 72
19
- # GROUP 3 ALL ON 0x49 73 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
20
- # GROUP 3 ALL OFF 0x4A 74
21
- # GROUP 4 ALL ON 0x4B 75 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
22
- # GROUP 4 ALL OFF 0x4C 76
23
- #
24
- # DISCO MODE 0x4D 77
25
- #
26
- # SET COLOR TO WHITE (GROUP ALL) 0x42 100ms followed by: 0xC2
27
- # SET COLOR TO WHITE (GROUP 1) 0x45 100ms followed by: 0xC5
28
- # SET COLOR TO WHITE (GROUP 2) 0x47 100ms followed by: 0xC7
29
- # SET COLOR TO WHITE (GROUP 3) 0x49 100ms followed by: 0xC9
30
- # SET COLOR TO WHITE (GROUP 4) 0x4B 100ms followed by: 0xCB
31
-
32
-
33
1
  require 'spec_helper'
34
2
 
35
3
  describe LimitlessLed::Bridge do
36
4
 
37
5
  let(:params) { {} }
6
+
38
7
  subject { LimitlessLed::Bridge.new(params) }
39
8
 
40
9
  describe 'can be initialized with default values' do
@@ -49,27 +18,109 @@ describe LimitlessLed::Bridge do
49
18
  its(:port) { should == 6666 }
50
19
  end
51
20
 
21
+ describe '#all_on' do
22
+ it 'turns on all groups' do
23
+ subject.should_receive(:send_packet).with("\x42\x00\x55")
24
+ subject.all_on
25
+ end
26
+ end
27
+
28
+ describe '#all_off' do
29
+ it 'turns off all groups' do
30
+ subject.should_receive(:send_packet).with("\x41\x00\x55")
31
+ subject.all_off
32
+ end
33
+ end
34
+
35
+ describe '#white' do
36
+ it 'should set the color to white' do
37
+ subject.should_receive(:send_packet).with("\xc2\x00\x55")
38
+ subject.white
39
+ end
40
+ end
41
+
52
42
  describe '#color' do
53
- it 'changes color' do
54
- subject.send(:send_packet, "\x40\xFF\x55")
43
+ context 'when given an integer 0 - 255' do
44
+ it 'changes the color to 255 (blue)' do
45
+ subject.should_receive(:send_packet).with("\x40" + 255.chr + "\x55")
46
+ subject.color(255)
47
+ end
48
+
49
+ it 'changes the color to 89' do
50
+ subject.should_receive(:send_packet).with("\x40" + 89.chr + "\x55")
51
+ subject.color(89)
52
+ end
53
+ end
54
+
55
+ context 'when given a ruby Color object' do
56
+ it 'it changes the color to 0 (blue)' do
57
+ subject.should_receive(:send_packet).with("\x40" + 0.chr + "\x55")
58
+ subject.color(Color::RGB::Blue)
59
+ end
55
60
 
56
- # true.should be_true
57
- # subject.should_receive(:send_packet).with("\x40\xFF\x55")
61
+ it 'it changes the color to 170 (red)' do
62
+ subject.should_receive(:send_packet).with("\x40" + 170.chr + "\x55")
63
+ subject.color(Color::RGB::Red)
64
+ end
65
+ end
66
+
67
+ context 'when given a string' do
68
+ it 'it changes the color to 0 (blue)' do
69
+ subject.should_receive(:send_packet).with("\x40" + 0.chr + "\x55")
70
+ subject.color('blue')
71
+ end
72
+
73
+ it 'it changes the color to 192 (pink)' do
74
+ subject.should_receive(:send_packet).with("\x40" + 192.chr + "\x55")
75
+ subject.color('DeepPink')
76
+ end
77
+
78
+ it 'it changes the color to 85 (green)' do
79
+ subject.should_receive(:send_packet).with("\x40" + 85.chr + "\x55")
80
+ subject.color('green')
81
+ end
82
+
83
+ it 'it changes the color to 170 (red)' do
84
+ subject.should_receive(:send_packet).with("\x40" + 170.chr + "\x55")
85
+ subject.color('red')
86
+ end
87
+ end
88
+ end
89
+
90
+ describe '#brightness' do
91
+ it 'sends the brightness command' do
92
+ subject.should_receive(:send_packet).with(78.chr + 2.chr + 85.chr)
93
+ subject.brightness(2)
94
+ end
95
+
96
+ it 'raises an exception if giving an invalid brightness amount' do
97
+ expect { subject.brightness(1)}.to raise_error(ArgumentError)
98
+ expect { subject.brightness(28)}.to raise_error(ArgumentError)
99
+ expect { subject.brightness(0)}.to raise_error(ArgumentError)
58
100
  end
59
101
  end
60
102
 
61
103
  describe '#send_packet' do
62
104
  it 'should create a new socket and send the packet' do
63
-
64
105
  fake_socket = double(:fake_udp_socket)
65
106
  fake_socket.should_receive(:connect).with( subject.host, subject.port )
66
- fake_socket.should_receive(:send).with("\x40\xFF\x55", 0)
67
-
107
+ fake_socket.should_receive(:send).with("stuff", 0)
68
108
  UDPSocket.should_receive(:new) { fake_socket }
109
+ subject.send(:send_packet, "stuff")
110
+ end
111
+ end
69
112
 
70
- subject.send(:send_packet, "\x40\xFF\x55")
113
+ describe '#groups' do
114
+ it 'returns a object representing a group' do
115
+ group1 = subject.group(1)
116
+ group1.should be_a(LimitlessLed::Group)
117
+ end
71
118
 
119
+ it 'raises an exception if given an invalid group number' do
120
+ expect { subject.group(5) }.to raise_error(ArgumentError)
121
+ expect { subject.group(0) }.to raise_error(ArgumentError)
72
122
  end
73
123
  end
74
124
 
75
125
  end
126
+
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe LimitlessLed::Group do
4
+ let(:group_number) { 1 }
5
+
6
+ subject { LimitlessLed::Group.new(group_number, LimitlessLed::Bridge.new) }
7
+
8
+ its(:bridge) { should be_a(LimitlessLed::Bridge) }
9
+
10
+ describe '#on' do
11
+ [[1, "\x45"], [2, "\x47"], [3, "\x49"], [4, "\x4B"]].each do |pair|
12
+ it "turns on group #{pair[0]}" do
13
+ group = LimitlessLed::Group.new(pair[0], LimitlessLed::Bridge.new)
14
+ group.bridge.should_receive(:send_packet).with(pair[1] + "\x00\x55")
15
+ group.on
16
+ end
17
+ end
18
+ end
19
+
20
+ describe '#off' do
21
+ [[1, "\x46"], [2, "\x48"], [3, "\x4A"], [4, "\x4C"]].each do |pair|
22
+ it "turns off group #{pair[0]}" do
23
+ group = LimitlessLed::Group.new(pair[0], LimitlessLed::Bridge.new)
24
+ group.bridge.should_receive(:send_packet).with(pair[1] + "\x00\x55")
25
+ group.off
26
+ end
27
+ end
28
+ end
29
+
30
+ describe '#color' do
31
+ it 'turns on the group and change its color' do
32
+ subject.should_receive(:on)
33
+ subject.should_receive(:sleep).with(0.1)
34
+ subject.bridge.should_receive(:color).with(255)
35
+ subject.color(255)
36
+ end
37
+ end
38
+
39
+ describe '#brightness' do
40
+ it 'turns on the group and change its brightness' do
41
+ subject.should_receive(:on)
42
+ subject.should_receive(:sleep).with(0.1)
43
+ subject.bridge.should_receive(:brightness).with(255)
44
+ subject.brightness(255)
45
+ end
46
+ end
47
+
48
+ describe '#white' do
49
+ it 'turns on the group and changes it to white' do
50
+ subject.should_receive(:on)
51
+ subject.should_receive(:sleep).with(0.1)
52
+ subject.bridge.should_receive(:send_packet).with("\xc2\x00\x55")
53
+ subject.white
54
+ end
55
+ end
56
+
57
+ end
58
+
@@ -1,8 +1,4 @@
1
- require 'rubygems'
2
- require 'bundler/setup'
1
+ require 'rspec/autorun'
2
+ require 'color'
3
3
 
4
- require 'limitless_led'
5
-
6
- RSpec.configure do |config|
7
- # some (optional) config here
8
- end
4
+ require File.expand_path(File.join(File.dirname(__FILE__), '../lib/limitless_led'))
metadata CHANGED
@@ -1,14 +1,15 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: limitless-led
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.4
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
+ - Hired, Inc
7
8
  - Joseph Silvashy
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2014-01-15 00:00:00.000000000 Z
12
+ date: 2014-01-31 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
@@ -39,7 +40,7 @@ dependencies:
39
40
  - !ruby/object:Gem::Version
40
41
  version: '0'
41
42
  - !ruby/object:Gem::Dependency
42
- name: eventmachine
43
+ name: active_support
43
44
  requirement: !ruby/object:Gem::Requirement
44
45
  requirements:
45
46
  - - '>='
@@ -83,33 +84,28 @@ dependencies:
83
84
  description: A Ruby gem for controlling the LimitlessLED v3.0 RGBW color-changing
84
85
  light bulbs, based on the official LimitlessLED API documentation.
85
86
  email:
87
+ - opensource@hired.com
86
88
  - jpsilvashy@gmail.com
87
- executables:
88
- - server
89
+ executables: []
89
90
  extensions: []
90
91
  extra_rdoc_files: []
91
92
  files:
92
93
  - .gitignore
93
94
  - .rspec
94
- - .travis.yml
95
95
  - Gemfile
96
- - LICENSE.txt
96
+ - Gemfile.lock
97
+ - LICENSE
97
98
  - README.md
98
- - Rakefile
99
- - bin/server
100
- - examples/demo.rb
101
- - examples/skycolor.rb
102
99
  - lib/limitless_led.rb
103
100
  - lib/limitless_led/bridge.rb
104
- - lib/limitless_led/logger.rb
105
- - lib/limitless_led/server.rb
101
+ - lib/limitless_led/colors.rb
102
+ - lib/limitless_led/group.rb
106
103
  - lib/limitless_led/version.rb
107
104
  - limitless_led.gemspec
108
105
  - spec/bridge_spec.rb
109
- - spec/logger_spec.rb
110
- - spec/server_spec.rb
106
+ - spec/group_spec.rb
111
107
  - spec/spec_helper.rb
112
- homepage: https://github.com/jpsilvashy/limitless-led
108
+ homepage: https://github.com/hired/limitless-led
113
109
  licenses:
114
110
  - MIT
115
111
  metadata: {}
@@ -129,14 +125,12 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
125
  version: '0'
130
126
  requirements: []
131
127
  rubyforge_project:
132
- rubygems_version: 2.1.1
128
+ rubygems_version: 2.1.8
133
129
  signing_key:
134
130
  specification_version: 4
135
131
  summary: A Ruby gem for controlling the LimitlessLED v3.0 RGBW color-changing light
136
132
  bulbs.
137
133
  test_files:
138
134
  - spec/bridge_spec.rb
139
- - spec/logger_spec.rb
140
- - spec/server_spec.rb
135
+ - spec/group_spec.rb
141
136
  - spec/spec_helper.rb
142
- has_rdoc:
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- # - 1.9.3
4
- # - 1.9.2
5
- # - jruby-18mode
6
- # - jruby-19mode
7
- # - rbx-2.1.1
8
- - ruby-head
9
- - jruby-head
10
- # - 1.8.7
11
- # - ree
@@ -1,22 +0,0 @@
1
- Copyright (c) 2013 Joseph Silvashy
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/Rakefile DELETED
@@ -1,7 +0,0 @@
1
- require "bundler/gem_tasks"
2
- require "rspec/core/rake_task"
3
-
4
- RSpec::Core::RakeTask.new
5
-
6
- task :default => :spec
7
- task :test => :spec
data/bin/server DELETED
@@ -1,22 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'optparse'
4
- require 'eventmachine'
5
- require 'limitless_led'
6
-
7
- options = { port: 8899 }
8
-
9
- optparse = OptionParser.new do |opts|
10
- opts.banner = "Usage: server [options]"
11
- opts.on('-p', '--port [PORT]', "Optional port") do |port|
12
- options[:port] = port
13
- end
14
- end
15
-
16
- optparse.parse!
17
-
18
- puts ">> Starting Limitless LED Server running on port: #{options[:port]}"
19
-
20
- EM.run do
21
- EM.open_datagram_socket('localhost', options[:port], LimitlessLed::Server)
22
- end
@@ -1,32 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- require 'limitless_led'
4
-
5
- # If you don't have a LimitlessLED handy you can start the development
6
- # server by running bin/server, it logs to stdout
7
- bridge = LimitlessLed::Bridge.new(host: "107.3.148.126", port: 8899)
8
-
9
- # Send in hex like this:
10
- bridge.color "#ff0000"
11
-
12
- # You can send a triple
13
- bridge.color "#f00"
14
-
15
- # Send data straight to the bridge:
16
- bridge.send_packet "\x40\x00\x55"
17
-
18
- # Send a lot of data to the bridge very quickly:
19
- 10.times do
20
- (0..255).each do |int|
21
- bridge.send_packet "\x40#{ int.chr }\x55"
22
- sleep 0.005
23
- end
24
- end
25
-
26
-
27
- # Again if you don't have the LimitlessLED, you can create an instance
28
- # of the development server
29
- server = LimitlessLed::Server.new(host: 'localhost', port: 8899)
30
-
31
- # Then you can see what the server does when it receives messages
32
- server.receive_data("\x40\x00\xff")
@@ -1,19 +0,0 @@
1
- #!/usr/bin/env ruby
2
-
3
- # This example takes a photo and approximates the most dominant color in the image and changes
4
- # the LED to match. Our example is using a remote image from a webcam, but you can put any
5
- # image source uri.
6
-
7
- # Install miro gem first
8
- # https://github.com/jonbuda/miro
9
- require 'miro'
10
- require 'limitless_led'
11
-
12
- # Source of image
13
- colors = Miro::DominantColors.new('http://cdn.abclocal.go.com/three/kgo/webcam/tahoecam.jpg')
14
-
15
- # Connect to bridge
16
- bridge = LimitlessLed::Bridge.new(host: 'localhost', port: 8899)
17
-
18
- # Send send most dominant color from image to the LED
19
- bridge.color colors.to_hex[0]
@@ -1,62 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- module LimitlessLed
4
- module Logger
5
-
6
- # Logs timestamp and message
7
- #
8
- # Usage:
9
- #
10
- # # Default
11
- # log "something happend"
12
- #
13
- # Options:
14
- #
15
- # +message+:: any string for the message you want to log
16
- #
17
- def log(message)
18
- puts "#{DateTime.now.to_s} : #{message}"
19
- end
20
-
21
- # This receives and integer as the color value from 0-255, this value
22
- # maps directly to the dial on the limitless-led controller and app where
23
- # the color at 12 o'clock is 0, the colors are mapped clockwise around
24
- # the dial with 255 being almost the same color as 0, this is because the
25
- # color space we are using is HSL.
26
- #
27
- # Usage:
28
- #
29
- # # Default
30
- # log_color 0
31
- #
32
- # # Different color
33
- # log_color 120
34
- #
35
- # # HSL hue is radial so 255 is the same as 0
36
- # log_color 255
37
- #
38
- # Options:
39
- #
40
- # +color+:: color 0-255
41
- #
42
- def log_color(color)
43
-
44
- # Turn second byte int a value out of 360, this is because HSL color maps
45
- # the hue on a radial scale so the first and last values are the same color
46
- hue= color.to_f / 255.0 * 360.0
47
-
48
- # Return the color
49
- color = Color::HSL.new( hue, 100, 50).to_rgb
50
-
51
- # Get each channel and prepare for loggers output
52
- red = color.r * 255
53
- green = color.g * 255
54
- blue = color.b * 255
55
-
56
- # Log the color and the hex of the color
57
- log '████████ '.color(red, green, blue) + color.html
58
-
59
- end
60
-
61
- end
62
- end
@@ -1,46 +0,0 @@
1
- #!/usr/bin/ruby
2
-
3
- require 'eventmachine'
4
-
5
- require 'date'
6
- require 'rainbow'
7
- require 'color'
8
-
9
- module LimitlessLed
10
- class Server < EM::Connection
11
- include LimitlessLed::Logger
12
-
13
- def initialize(host: 'localhost', port: 8899)
14
- @bridge = LimitlessLed::Bridge.new(host: host, port: port)
15
- end
16
-
17
- # This method dispatches the raw command in bytes to the proper method used
18
- # to run commands for the led the first byte in the command code tells the
19
- # real led which command to expect, most commands are 3 bytes long total
20
- # and always end with 0x55
21
- #
22
- # Usage:
23
- #
24
- # # Default
25
- # receive_data "\x40\xff\x55"
26
- #
27
- # Options:
28
- #
29
- # +input+:: bytes used to run the commands
30
- #
31
- def receive_data(input)
32
- command = input.bytes
33
-
34
- case command.first
35
- when 64
36
- log_color command[1]
37
- when 65..77
38
- raise LimitlessLed::CommandNotImplemented
39
- else
40
- raise LimitlessLed::UnknownCommand
41
- end
42
-
43
- end
44
-
45
- end
46
- end
@@ -1,5 +0,0 @@
1
- require 'spec_helper'
2
-
3
- describe LimitlessLed::Logger do
4
-
5
- end
@@ -1,46 +0,0 @@
1
- # Tests should cover these commands, which can also be found here:
2
- # http://www.limitlessled.com/dev/
3
-
4
- # All UDP Commands are 3 Bytes. First byte is from the list below, plus a fixed 2 byte suffix of 0x00 (decimal: 0) and 0x55 (decimal: 85)
5
- # i.e. to turn all RGBW COLOR LimitlessLED Smart lights to ON then send the TCP/IP UDP packet of: 0x42 0x00 0x55
6
- #
7
- # Hexidecimal (byte) Decimal (integer)
8
- #
9
- # RGBW COLOR LED ALL OFF 0x41 65
10
- # RGBW COLOR LED ALL ON 0x42 66
11
- #
12
- # DISCO SPEED SLOWER 0x43 67
13
- # DISCO SPEED FASTER 0x44 68
14
- #
15
- # GROUP 1 ALL ON 0x45 69 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
16
- # GROUP 1 ALL OFF 0x46 70
17
- # GROUP 2 ALL ON 0x47 71 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
18
- # GROUP 2 ALL OFF 0x48 72
19
- # GROUP 3 ALL ON 0x49 73 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
20
- # GROUP 3 ALL OFF 0x4A 74
21
- # GROUP 4 ALL ON 0x4B 75 (SYNC/PAIR RGB+W Bulb within 2 seconds of Wall Switch Power being turned ON)
22
- # GROUP 4 ALL OFF 0x4C 76
23
- #
24
- # DISCO MODE 0x4D 77
25
- #
26
- # SET COLOR TO WHITE (GROUP ALL) 0x42 100ms followed by: 0xC2
27
- # SET COLOR TO WHITE (GROUP 1) 0x45 100ms followed by: 0xC5
28
- # SET COLOR TO WHITE (GROUP 2) 0x47 100ms followed by: 0xC7
29
- # SET COLOR TO WHITE (GROUP 3) 0x49 100ms followed by: 0xC9
30
- # SET COLOR TO WHITE (GROUP 4) 0x4B 100ms followed by: 0xCB
31
-
32
- require 'spec_helper'
33
-
34
- describe LimitlessLed::Server do
35
-
36
- let(:params) { { host: 'localhost', port: 6666 } }
37
- subject { LimitlessLed::Server.new(params) }
38
-
39
- describe '#receive_data' do
40
- it 'should raise an exception when improperly formed commands are sent' do
41
- #subject.send(:receive_data, "\xFF\x55")
42
- #subject.should raise_error(LimitlessLed::CommandNotImplemented)
43
- end
44
- end
45
-
46
- end