ledenet_api 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/ledenet/api.rb +27 -16
- data/lib/ledenet/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: fc308b3bf1a99c0a67ef519e13f84fabece00fc6
|
4
|
+
data.tar.gz: dd9f6a4032283d24b2f82ca3a00f4ee9647e864c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 505fd9e3be7cfe496e4a3b1105145f7452a8df8e689f6b68e521ccbe37879bf381d66b2297e97409b5fbf6f0495d9d63865db294120bde6b6c5bbeaa599004e9
|
7
|
+
data.tar.gz: 001c8afd4e0f0228b8ace0517168992bcdb5dac57fe415fcd2044c0a0aba1fe1cd01d29e8606e2fb079b3414d90cbe2c5c995fa917e44dc885a9512d2001ba93
|
data/Gemfile.lock
CHANGED
data/lib/ledenet/api.rb
CHANGED
@@ -2,16 +2,21 @@ module LEDENET
|
|
2
2
|
class Api
|
3
3
|
API_PORT = 5577
|
4
4
|
|
5
|
-
|
5
|
+
DEFAULT_OPTIONS = {
|
6
|
+
reuse_connection: false
|
7
|
+
}
|
8
|
+
|
9
|
+
def initialize(device_address, options = {})
|
6
10
|
@device_address = device_address
|
11
|
+
@options = DEFAULT_OPTIONS.merge(options)
|
7
12
|
end
|
8
13
|
|
9
14
|
def on
|
10
|
-
|
15
|
+
send_bytes_action(0x71, 0x23, 0x0F, 0xA3)
|
11
16
|
end
|
12
17
|
|
13
18
|
def off
|
14
|
-
|
19
|
+
send_bytes_action(0x71, 0x24 ,0x0F, 0xA4)
|
15
20
|
end
|
16
21
|
|
17
22
|
def on?
|
@@ -21,7 +26,7 @@ module LEDENET
|
|
21
26
|
def update_color(r, g, b)
|
22
27
|
checksum = color_checksum(r, g, b)
|
23
28
|
|
24
|
-
|
29
|
+
send_bytes_action(0x31, r, g, b, 0xFF, 0, 0x0F, checksum)
|
25
30
|
end
|
26
31
|
|
27
32
|
def current_color
|
@@ -38,16 +43,13 @@ module LEDENET
|
|
38
43
|
end
|
39
44
|
|
40
45
|
def status
|
41
|
-
|
46
|
+
socket_action do
|
42
47
|
send_bytes(0x81, 0x8A, 0x8B, 0x96)
|
43
48
|
|
44
49
|
# Example response:
|
45
50
|
# [129, 4, 35, 97, 33, 9, 11, 22, 33, 255, 3, 0, 0, 119]
|
46
51
|
# R G B WW ^--- LSB indicates on/off
|
47
52
|
flush_response(14)
|
48
|
-
rescue Errno::EPIPE
|
49
|
-
reconnect!
|
50
|
-
retry
|
51
53
|
end
|
52
54
|
end
|
53
55
|
|
@@ -56,19 +58,28 @@ module LEDENET
|
|
56
58
|
end
|
57
59
|
|
58
60
|
def send_bytes(*b)
|
59
|
-
|
61
|
+
@socket.write(b.pack('c*'))
|
62
|
+
end
|
60
63
|
|
61
|
-
|
62
|
-
|
63
|
-
rescue Errno::EPIPE
|
64
|
-
reconnect!
|
65
|
-
retry
|
66
|
-
end
|
64
|
+
def send_bytes_action(*b)
|
65
|
+
socket_action { send_bytes(*b) }
|
67
66
|
end
|
68
67
|
|
69
68
|
def create_socket
|
70
|
-
@socket.close unless @socket.nil?
|
69
|
+
@socket.close unless @socket.nil? or @socket.closed?
|
71
70
|
@socket = TCPSocket.new(@device_address, API_PORT)
|
72
71
|
end
|
72
|
+
|
73
|
+
def socket_action
|
74
|
+
begin
|
75
|
+
create_socket if @socket.nil? or @socket.closed?
|
76
|
+
yield
|
77
|
+
rescue Errno::EPIPE, IOError
|
78
|
+
reconnect!
|
79
|
+
retry
|
80
|
+
ensure
|
81
|
+
@socket.close unless @socket.closed? or @options[:reuse_connection]
|
82
|
+
end
|
83
|
+
end
|
73
84
|
end
|
74
85
|
end
|
data/lib/ledenet/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ledenet_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Christopher Mullins
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2015-10-
|
11
|
+
date: 2015-10-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|