animatedledstrip-client 0.0.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 8c23ae558840af80bfb0161f275df791382dc716934c261fc9dff7398a3a7c4d
4
+ data.tar.gz: a9ddabb34944385a0e252ce7367221c701859aeaaa6e1b8bbe469126a68d0557
5
+ SHA512:
6
+ metadata.gz: 14c61a66d1a36b55f56ed61b242b6040fe752d2b408be4ce5b364d0ba2f37280089760e94fd4467bca9dc73153717b5d20440ca6690e1f97c62d16a11f18432f
7
+ data.tar.gz: b8050a64d8ef24d47a0047f8edf4e55d1db80b43edba32d6eae4be8b901a0d94fe8bac89ab05fa5163526c326e6bd6cf946e3b6e90de39c5dae54ef5b8d060b4
data/lib/animation.rb ADDED
@@ -0,0 +1,80 @@
1
+ module Animation
2
+ COLOR = 0
3
+ CUSTOM_ANIMATION = 1
4
+ CUSTOM_REPETITIVE_ANIMATION = 2
5
+ ALTERNATE = 3
6
+ BOUNCE = 4
7
+ BOUNCE_TO_COLOR = 5
8
+ CAT_TOY = 6
9
+ METEOR = 7
10
+ MULTIPIXEL_RUN = 8
11
+ MULTIPIXEL_RUN_TO_COLOR = 9
12
+ RIPPLE = 10
13
+ PIXEL_MARATHON = 11
14
+ PIXEL_RUN = 12
15
+ SMOOTH_CHASE = 13
16
+ SMOOTH_FADE = 14
17
+ SPARKLE = 15
18
+ SPARKLE_FADE = 16
19
+ SPARKLE_TO_COLOR = 17
20
+ SPLAT = 18
21
+ STACK = 19
22
+ STACK_OVERFLOW = 20
23
+ WIPE = 21
24
+ END_ANIMATION = 22
25
+
26
+ # @return [String]
27
+ def self.string(animation)
28
+ case animation
29
+ when COLOR
30
+ 'COLOR'
31
+ when CUSTOM_ANIMATION
32
+ 'CUSTOMANIMATION'
33
+ when CUSTOM_REPETITIVE_ANIMATION
34
+ 'CUSTOMREPETITIVEANIMATION'
35
+ when ALTERNATE
36
+ 'ALTERNATE'
37
+ when BOUNCE
38
+ 'BOUNCE'
39
+ when BOUNCE_TO_COLOR
40
+ 'BOUNCETOCOLOR'
41
+ when CAT_TOY
42
+ 'CATTOY'
43
+ when METEOR
44
+ 'METEOR'
45
+ when MULTIPIXEL_RUN
46
+ 'MULTIPIXELRUN'
47
+ when MULTIPIXEL_RUN_TO_COLOR
48
+ 'MULTIPIXELRUNTOCOLOR'
49
+ when RIPPLE
50
+ 'RIPPLE'
51
+ when PIXEL_MARATHON
52
+ 'PIXELMARATHON'
53
+ when PIXEL_RUN
54
+ 'PIXELRUN'
55
+ when SMOOTH_CHASE
56
+ 'SMOOTHCHASE'
57
+ when SMOOTH_FADE
58
+ 'SMOOTHFADE'
59
+ when SPARKLE
60
+ 'SPARKLE'
61
+ when SPARKLE_FADE
62
+ 'SPARKLEFADE'
63
+ when SPARKLE_TO_COLOR
64
+ 'SPARKLETOCOLOR'
65
+ when SPLAT
66
+ 'SPLAT'
67
+ when STACK
68
+ 'STACK'
69
+ when STACK_OVERFLOW
70
+ 'STACKOVERFLOW'
71
+ when WIPE
72
+ 'WIPE'
73
+ when END_ANIMATION
74
+ 'ENDANIMATION'
75
+ else
76
+ 'COLOR'
77
+ end
78
+ end
79
+
80
+ end
@@ -0,0 +1,64 @@
1
+ require_relative './imation.rb'
2
+ require_relative './rection.rb'
3
+ require_relative './lor_container.rb'
4
+
5
+ class AnimationData
6
+ attr_accessor :animation, :colors, :center,
7
+ :continuous, :delay, :delay_mod,
8
+ :direction, :distance, :end_pixel,
9
+ :id, :spacing, :start_pixel
10
+
11
+ def initialize
12
+ @animation = Animation::COLOR
13
+ @colors = []
14
+ @center = -1
15
+ @continuous = nil
16
+ @delay = -1
17
+ @delay_mod = 1.0
18
+ @direction = Direction::FORWARD
19
+ @distance = -1
20
+ @end_pixel = -1
21
+ @id = ''
22
+ @spacing = -1
23
+ @start_pixel = 0
24
+ end
25
+
26
+ def add_color(color)
27
+ raise TypeError unless color.is_a? ColorContainer
28
+
29
+ colors.push(color)
30
+ end
31
+
32
+ # @return [String]
33
+ def json
34
+ raise TypeError unless @animation.is_a? Integer
35
+ raise TypeError unless @center.is_a? Integer
36
+ raise TypeError unless @continuous.is_a?(Integer) || @continuous.nil?
37
+ raise TypeError unless @delay.is_a? Integer
38
+ raise TypeError unless @delay_mod.is_a? Float
39
+ raise TypeError unless @direction.is_a? Integer
40
+ raise TypeError unless @distance.is_a? Integer
41
+ raise TypeError unless @end_pixel.is_a? Integer
42
+ raise TypeError unless @id.is_a? String
43
+ raise TypeError unless @spacing.is_a? Integer
44
+ raise TypeError unless @start_pixel.is_a? Integer
45
+
46
+ @colors.each { |cc| raise TypeError unless cc.is_a? ColorContainer }
47
+
48
+ str = "DATA:{\"animation\":\"#{Animation.string(@animation)}\","\
49
+ '"colors":['
50
+ @colors.each { |cc| str += "#{cc.json}," }
51
+ str.delete_suffix! ','
52
+ str + '],'\
53
+ "\"center\":#{@center},"\
54
+ "\"continuous\":#{@continuous.nil? ? 'null' : @continuous},"\
55
+ "\"delay\":#{@delay},"\
56
+ "\"delayMod\":#{delay_mod},"\
57
+ "\"direction\":\"#{Direction.string(@direction)}\","\
58
+ "\"distance\":#{@distance},"\
59
+ "\"endPixel\":#{@end_pixel},"\
60
+ "\"id\":\"#{@id}\","\
61
+ "\"spacing\":#{@spacing},"\
62
+ "\"startPixel\":#{@start_pixel}}"
63
+ end
64
+ end
@@ -0,0 +1,26 @@
1
+ require 'socket'
2
+ require_relative './animation_sender.rb'
3
+
4
+ class AnimationSender
5
+ attr_accessor :address, :port
6
+
7
+ def initialize(address, port)
8
+ @address = address
9
+ @port = port
10
+ end
11
+
12
+ def start
13
+ @socket = TCPSocket.new @address, @port
14
+ end
15
+
16
+ def end
17
+ @socket.close
18
+ end
19
+
20
+ def send_animation(animation)
21
+ raise TypeError unless animation.is_a? AnimationData
22
+
23
+ @socket.write animation.json
24
+ end
25
+
26
+ end
@@ -0,0 +1,25 @@
1
+ class ColorContainer
2
+ attr_accessor :colors
3
+
4
+ def initialize
5
+ @colors = []
6
+ end
7
+
8
+ # @return [String]
9
+ def json
10
+ @colors.each { |c| raise TypeError unless c.is_a? Integer }
11
+ str = '{"colors":['
12
+ @colors.each do |c|
13
+ str.concat(c.to_s, ',')
14
+ end
15
+ str.delete_suffix! ','
16
+ str + ']}'
17
+ end
18
+
19
+ def add_color(color)
20
+ raise TypeError unless color.is_a? Integer
21
+
22
+ @colors.push(color)
23
+ end
24
+
25
+ end
data/lib/direction.rb ADDED
@@ -0,0 +1,15 @@
1
+ module Direction
2
+ FORWARD = 0
3
+ BACKWARD = 1
4
+
5
+ def self.string(direction)
6
+ case direction
7
+ when FORWARD
8
+ 'FORWARD'
9
+ when BACKWARD
10
+ 'BACKWARD'
11
+ else
12
+ 'FORWARD'
13
+ end
14
+ end
15
+ end
metadata ADDED
@@ -0,0 +1,47 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: animatedledstrip-client
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Max Narvaez
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2019-11-05 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description:
14
+ email:
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/animation.rb
20
+ - lib/animation_data.rb
21
+ - lib/animation_sender.rb
22
+ - lib/color_container.rb
23
+ - lib/direction.rb
24
+ homepage:
25
+ licenses: []
26
+ metadata: {}
27
+ post_install_message:
28
+ rdoc_options: []
29
+ require_paths:
30
+ - lib
31
+ required_ruby_version: !ruby/object:Gem::Requirement
32
+ requirements:
33
+ - - ">="
34
+ - !ruby/object:Gem::Version
35
+ version: '0'
36
+ required_rubygems_version: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ requirements: []
42
+ rubyforge_project:
43
+ rubygems_version: 2.7.6
44
+ signing_key:
45
+ specification_version: 4
46
+ summary: Library for connecting to an AnimatedLEDStripServer
47
+ test_files: []