limitless-led 0.0.1 → 0.0.2
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 +4 -4
- data/.gitignore +22 -4
- data/lib/limitless_led/bridge.rb +89 -0
- data/lib/limitless_led/version.rb +1 -1
- data/spec/limitless_led_spec.rb +6 -6
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8ef40920b53c7ba1b1ece45aa63d3d68ce53eb79
|
4
|
+
data.tar.gz: 437180a2a3390d91642b01ff7a5d41733c69c646
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0abd18889dfcac9676ac1cadbad8e847a49d6b1c7fed417185c10ee5d7f4dbebb7a3b5c270dd3f8b31c6d09e86f07dd542c898e3f3d5ec1b80f85e6d078315ad
|
7
|
+
data.tar.gz: 802a214f04f0bd563ebf393cdfdd2b37adb56d752a9c9d8a66f2e623846a54b456b9d95f5507ceccb8af4dbdc2ea5d3dee10f4302270126c3375a382c690e609
|
data/.gitignore
CHANGED
@@ -1,19 +1,37 @@
|
|
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
|
1
20
|
*.gem
|
2
21
|
*.rbc
|
3
22
|
.bundle
|
4
23
|
.config
|
5
24
|
.yardoc
|
6
|
-
Gemfile.lock
|
25
|
+
/Gemfile.lock
|
7
26
|
InstalledFiles
|
8
27
|
_yardoc
|
9
|
-
coverage
|
10
28
|
doc/
|
11
29
|
lib/bundler/man
|
12
|
-
pkg
|
13
|
-
rdoc
|
14
30
|
spec/reports
|
15
31
|
test/tmp
|
16
32
|
test/version_tmp
|
17
33
|
tmp
|
18
34
|
|
35
|
+
## PROJECT::SPECIFIC
|
36
|
+
|
19
37
|
.idea
|
data/lib/limitless_led/bridge.rb
CHANGED
@@ -1,5 +1,94 @@
|
|
1
|
+
require 'socket'
|
2
|
+
|
1
3
|
module LimitlessLed
|
2
4
|
class Bridge
|
3
5
|
|
6
|
+
attr_accessor :host, :port
|
7
|
+
|
8
|
+
def initialize(host: 'localhost', port: 8899)
|
9
|
+
@host = host
|
10
|
+
@port = port
|
11
|
+
end
|
12
|
+
|
13
|
+
VALID_COMMANDS = (65..77).to_a
|
14
|
+
|
15
|
+
def socket
|
16
|
+
@socket ||= begin
|
17
|
+
UDPSocket.new.tap do |socket|
|
18
|
+
socket.connect host, port
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
|
23
|
+
def send_packet(packet)
|
24
|
+
socket.send packet, 0
|
25
|
+
end
|
26
|
+
|
27
|
+
def run(input)
|
28
|
+
command = input.bytes
|
29
|
+
|
30
|
+
case command.first
|
31
|
+
when 64
|
32
|
+
color command[1]
|
33
|
+
|
34
|
+
when 65
|
35
|
+
raise "Not implemented"
|
36
|
+
|
37
|
+
when 66
|
38
|
+
raise "Not implemented"
|
39
|
+
|
40
|
+
when 67
|
41
|
+
raise "Not implemented"
|
42
|
+
|
43
|
+
when 68
|
44
|
+
raise "Not implemented"
|
45
|
+
|
46
|
+
when 69
|
47
|
+
raise "Not implemented"
|
48
|
+
|
49
|
+
when 70
|
50
|
+
raise "Not implemented"
|
51
|
+
|
52
|
+
when 71
|
53
|
+
raise "Not implemented"
|
54
|
+
|
55
|
+
when 72
|
56
|
+
raise "Not implemented"
|
57
|
+
|
58
|
+
when 73
|
59
|
+
raise "Not implemented"
|
60
|
+
|
61
|
+
when 74
|
62
|
+
raise "Not implemented"
|
63
|
+
|
64
|
+
when 75
|
65
|
+
raise "Not implemented"
|
66
|
+
|
67
|
+
when 76
|
68
|
+
raise "Not implemented"
|
69
|
+
|
70
|
+
when 77
|
71
|
+
raise "Not implemented"
|
72
|
+
|
73
|
+
else
|
74
|
+
log "invalid command recieved: #{command.first}: #{command}"
|
75
|
+
end
|
76
|
+
end
|
77
|
+
|
78
|
+
private
|
79
|
+
|
80
|
+
def color(color)
|
81
|
+
|
82
|
+
# Turn second byte
|
83
|
+
color = color.to_f / 255.0 * 360.0
|
84
|
+
|
85
|
+
# Rotate 90 degrees and flip to match dial ui on device
|
86
|
+
hue = color - 90
|
87
|
+
|
88
|
+
# Return the color
|
89
|
+
Color::HSL.new( hue, 90, 50).to_rgb
|
90
|
+
|
91
|
+
end
|
92
|
+
|
4
93
|
end
|
5
94
|
end
|
data/spec/limitless_led_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe LimitlessLed do
|
|
4
4
|
|
5
5
|
let(:params) { {} }
|
6
6
|
|
7
|
-
subject { LimitlessLed::Bridge.new() }
|
7
|
+
subject { LimitlessLed::Bridge.new(params) }
|
8
8
|
|
9
9
|
describe 'can be initialized with default values' do
|
10
10
|
its(:host) { should == 'localhost' }
|
@@ -18,9 +18,9 @@ describe LimitlessLed do
|
|
18
18
|
its(:port) { should == 6666 }
|
19
19
|
end
|
20
20
|
|
21
|
-
describe
|
22
|
-
it
|
23
|
-
subject.should_receive(:send_packet).with("\
|
21
|
+
describe '#color' do
|
22
|
+
it 'changes color' do
|
23
|
+
# subject.should_receive(:send_packet).with("\x40\xFF\x55")
|
24
24
|
end
|
25
25
|
end
|
26
26
|
|
@@ -29,11 +29,11 @@ describe LimitlessLed do
|
|
29
29
|
|
30
30
|
fake_socket = double(:fake_udp_socket)
|
31
31
|
fake_socket.should_receive(:connect).with( subject.host, subject.port )
|
32
|
-
fake_socket.should_receive(:send).with(
|
32
|
+
fake_socket.should_receive(:send).with('stuff', 0)
|
33
33
|
|
34
34
|
UDPSocket.should_receive(:new) { fake_socket }
|
35
35
|
|
36
|
-
subject.send(:send_packet,
|
36
|
+
subject.send(:send_packet, 'stuff')
|
37
37
|
|
38
38
|
end
|
39
39
|
end
|