ledenet_api 1.1.2 → 1.2.1

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: 9b2322ff3b2b79724713e5b7b620a1f3d160fc61
4
- data.tar.gz: 0313e482fccc8cd041f2440f802220e50d1151f1
3
+ metadata.gz: 6b35153c257762f08c7ddfe36ec752d8a31ab43a
4
+ data.tar.gz: 8db99c674a748d3ed59154a186f9591c7be052a0
5
5
  SHA512:
6
- metadata.gz: c5088d200d263359d2846de07822c1d3dbbc4f98fac1482677264d5c86dd28629127ccfebba560fc530fe1898d2a8f1ccf33db2dccaccdff365b484995d31c54
7
- data.tar.gz: f942c29bb3e5a98f945f1b9c258b46547300834687f2c0bacff6c497f1492a9ea35c5d0a41ae462c5a3374c1ec9be3c65230c8ddd58047f37dee4a20c121941b
6
+ metadata.gz: 3a41d1078922bdf008dc686a1c9f24fb19a5feb3c7cad107fb74fbf249926f94b66c43e56f529db4b75c6c5d635ca453e6dcaf8b5822a535e8ab7bc126479b3f
7
+ data.tar.gz: c20ff4d69afba7a115c750727399211c7c92a93a91147eff469a4ea760bb4a75bd1700b9e791e4e41e0909256229dabeb8de19069bc1c346aa10f5446ed59342
data/bin/ledenet-ufo CHANGED
@@ -53,7 +53,7 @@ opts = OptionParser.new do |opts|
53
53
  options[:on?] = false
54
54
  end
55
55
 
56
- opts.on("-l", "--list", Integer, "Prints a list of available devices and exits") do |v|
56
+ opts.on("-l", "--list", "Prints a list of available devices and exits") do |v|
57
57
  options[:list] = true
58
58
  end
59
59
 
@@ -64,6 +64,24 @@ opts = OptionParser.new do |opts|
64
64
  opts.on("-h", "--help", "Prints this help message") do
65
65
  options[:print_help?] = true
66
66
  end
67
+
68
+ opts.on("--function-id [VALUE]", Integer, "Set function id to VALUE") do |v|
69
+ options[:function] = v
70
+ end
71
+
72
+ opts.on("-f", "--function [VALUE]", "Set function to VALUE.") do |v|
73
+ if !LEDENET::Functions.const_defined?(v)
74
+ warn "Unknown function type: #{v}. Valid function types: \n\t" <<
75
+ "#{LEDENET::Functions.all_functions.join("\n\t")}"
76
+ exit 1
77
+ end
78
+
79
+ options[:function] = LEDENET::Functions.const_get(v)
80
+ end
81
+
82
+ opts.on("-p", "--speed [VALUE]", Integer, "Set function speed to VALUE") do |v|
83
+ options[:speed] = v
84
+ end
67
85
  end
68
86
 
69
87
  opts.parse!
@@ -73,14 +91,20 @@ if options[:print_help?] || options.empty?
73
91
  exit 0
74
92
  end
75
93
 
94
+ if options[:list] && options.count > 1
95
+ warn "--list is incompatible with other options!\n\n"
96
+ warn opts
97
+ exit 1
98
+ end
99
+
100
+ if options[:function].nil? != options[:speed].nil?
101
+ warn "--funciton and --speed must be specified together. You provide " <<
102
+ "one without also providing the other."
103
+ exit 1
104
+ end
105
+
76
106
  begin
77
107
  if options[:list]
78
- if options.count > 1
79
- warn "--list is incompatible with other options!\n\n"
80
- warn opts
81
- exit 1
82
- end
83
-
84
108
  devices = LEDENET.discover_devices(expected_devices: 1000)
85
109
 
86
110
  row_format = "%16s %18s %20s\n"
@@ -111,7 +135,15 @@ begin
111
135
  api = LEDENET::Api.new(ip)
112
136
 
113
137
  api.set_power(options[:on?]) unless options[:on?].nil?
114
- api.update_color_data(options.select { |k,_| %w{red green blue warm_white}.include?(k.to_s) })
138
+
139
+ color_params = options.select do |k,_|
140
+ %w{red green blue warm_white}.include?(k.to_s)
141
+ end
142
+ api.update_color_data(color_params) unless color_params.empty?
143
+
144
+ if options[:function] && options[:speed]
145
+ api.update_function(options[:function], options[:speed])
146
+ end
115
147
 
116
148
  if options[:print_status?]
117
149
  status = api.current_color_data
data/lib/ledenet/api.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  require 'ledenet/packets/set_power_request'
2
2
  require 'ledenet/packets/status_request'
3
3
  require 'ledenet/packets/update_color_request'
4
+ require 'ledenet/packets/set_function_request'
4
5
 
5
6
  module LEDENET
6
7
  class Api
@@ -60,6 +61,14 @@ module LEDENET
60
61
  Hash[color_data]
61
62
  end
62
63
 
64
+ def update_function(fn, speed)
65
+ if fn.is_a?(String) or fn.is_a?(Symbol)
66
+ fn = LEDENET::Functions.const_get(fn.upcase)
67
+ end
68
+
69
+ send_packet(LEDENET::Packets::SetFunctionRequest.new(function_id: fn, speed: speed))
70
+ end
71
+
63
72
  def reconnect!
64
73
  create_socket
65
74
  true
@@ -0,0 +1,30 @@
1
+ module LEDENET
2
+ module Functions
3
+ VALUES = [
4
+ SEVEN_COLOR_CROSS_FADE = 0x25,
5
+ RED_GRADUAL_CHANGE = 0x26,
6
+ GREEN_GRADUAL_CHANGE = 0x27,
7
+ BLUE_GRADUAL_CHANGE = 0x28,
8
+ YELLOW_GRADUAL_CHANGE = 0x29,
9
+ CYAN_GRADUAL_CHANGE = 0x2A,
10
+ PURPLE_GRADUAL_CHANGE = 0x2B,
11
+ WHITE_GRADUAL_CHANGE = 0x2C,
12
+ RED_GREEN_CROSS_FADE = 0x2D,
13
+ RED_BLUE_CROSS_FADE = 0x2E,
14
+ GREEN_BLUE_CROSS_FADE = 0x2F,
15
+ SEVEN_COLOR_STROBE_FLASH = 0x30,
16
+ RED_STROBE_FLASH = 0x31,
17
+ GREEN_STROBE_FLASH = 0x32,
18
+ BLUE_STROBE_FLASH = 0x33,
19
+ YELLOW_STROBE_FLASH = 0x34,
20
+ CYAN_STROBE_FLASH = 0x35,
21
+ PURPLE_STROBE_FLASH = 0x36,
22
+ WHITE_STROBE_FLASH = 0x37,
23
+ SEVEN_COLOR_JUMPING_CHANGE = 0x38
24
+ ]
25
+
26
+ def self.all_functions
27
+ LEDENET::Functions.constants.reject { |x| x == :VALUES }
28
+ end
29
+ end
30
+ end
@@ -1,6 +1,5 @@
1
1
  require 'bindata'
2
2
 
3
3
  module LEDENET::Packets
4
- class EmptyResponse < BinData::Record
5
- end
4
+ class EmptyResponse ; end
6
5
  end
@@ -0,0 +1,39 @@
1
+ require 'bindata'
2
+
3
+ require 'ledenet/packets/fields/checksum'
4
+ require 'ledenet/packets/empty_response'
5
+
6
+ module LEDENET::Packets
7
+ class SetFunctionRequest < BinData::Record
8
+ VALID_SPEED_RANGE = (0..100)
9
+
10
+ # Speed value is in [0x00, 0x20], with 0x00 being the fastest.
11
+ PACKET_SPEED_RANGE = (0x00..0x20)
12
+
13
+ hide :checksum
14
+ mandatory_parameter :function_id
15
+ mandatory_parameter :speed
16
+
17
+ uint8 :packet_id, value: 0x61
18
+ uint8 :function_id_val, value: ->() { function_id }
19
+
20
+ uint8 :speed_val, value: ->() do
21
+ if !VALID_SPEED_RANGE.include?(speed)
22
+ raise "Speed should be between #{VALID_SPEED_RANGE.min} and #{VALID_SPEED_RANGE.max}"
23
+ end
24
+
25
+ scaled_speed = (speed / (VALID_SPEED_RANGE.max / PACKET_SPEED_RANGE.max)).round
26
+ scaled_speed = [PACKET_SPEED_RANGE.min, scaled_speed].max
27
+ scaled_speed = [PACKET_SPEED_RANGE.max, scaled_speed].min
28
+
29
+ PACKET_SPEED_RANGE.max - scaled_speed
30
+ end
31
+
32
+ uint8 :remote_or_local, value: 0x0F
33
+ checksum :checksum, packet_data: ->() { snapshot }
34
+
35
+ def response_reader
36
+ LEDENET::Packets::EmptyResponse
37
+ end
38
+ end
39
+ end
@@ -4,7 +4,7 @@ require 'ledenet/packets/fields/checksum'
4
4
 
5
5
  module LEDENET::Packets
6
6
  class StatusResponse < BinData::Record
7
- hide :checksum, :unused_payload
7
+ hide :checksum
8
8
 
9
9
  uint8 :packet_id, value: 0x81
10
10
  uint8 :device_name
@@ -21,7 +21,7 @@ module LEDENET::Packets
21
21
  uint8 :blue
22
22
  uint8 :warm_white
23
23
 
24
- uint16be :unused_payload, value: 0x0000
24
+ uint16be :unused_payload
25
25
  uint8 :checksum
26
26
 
27
27
  def on?
@@ -1,3 +1,3 @@
1
1
  module LEDENET
2
- VERSION = '1.1.2'
2
+ VERSION = '1.2.1'
3
3
  end
data/lib/ledenet_api.rb CHANGED
@@ -1,3 +1,4 @@
1
1
  require 'ledenet/version'
2
2
  require 'ledenet/device_discovery'
3
3
  require 'ledenet/api'
4
+ require 'ledenet/functions'
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: 1.1.2
4
+ version: 1.2.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Christopher Mullins
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-04-30 00:00:00.000000000 Z
11
+ date: 2016-05-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bindata
@@ -98,8 +98,10 @@ files:
98
98
  - ledenet_api.gemspec
99
99
  - lib/ledenet/api.rb
100
100
  - lib/ledenet/device_discovery.rb
101
+ - lib/ledenet/functions.rb
101
102
  - lib/ledenet/packets/empty_response.rb
102
103
  - lib/ledenet/packets/fields/checksum.rb
104
+ - lib/ledenet/packets/set_function_request.rb
103
105
  - lib/ledenet/packets/set_power_request.rb
104
106
  - lib/ledenet/packets/status_request.rb
105
107
  - lib/ledenet/packets/status_response.rb