class AnimationSender
Attributes
address[RW]
port[RW]
running_animations[RW]
sections[RW]
strip_info[RW]
supported_animations[RW]
Public Class Methods
new(address, port)
click to toggle source
# File lib/animatedledstrip/animation_sender.rb, line 34 def initialize(address, port) @address = address @port = port @running_animations = {} @supported_animations = {} @sections = {} end
Public Instance Methods
end()
click to toggle source
noinspection RubyUnusedLocalVariable
# File lib/animatedledstrip/animation_sender.rb, line 77 def end @socket.close @receive_thread.join strip_info = nil running_animations = {} supported_animations = {} sections = {} end
send_animation(animation)
click to toggle source
# File lib/animatedledstrip/animation_sender.rb, line 86 def send_animation(animation) raise TypeError unless animation.is_a? AnimationData @socket.write(animation.json + ";;;") end
send_end_animation(end_animation)
click to toggle source
# File lib/animatedledstrip/animation_sender.rb, line 92 def send_end_animation(end_animation) raise TypeError unless end_animation.is_a? EndAnimation @socket.write(end_animation.json + ";;;") end
send_section(section)
click to toggle source
# File lib/animatedledstrip/animation_sender.rb, line 98 def send_section(section) raise TypeError unless section.is_a? Section @socket.write(section.json + ";;;") end
start()
click to toggle source
# File lib/animatedledstrip/animation_sender.rb, line 42 def start @socket = TCPSocket.new @address, @port @receive_thread = Thread.new { begin while (line = @socket.gets ";;;") puts line if line.start_with? "DATA:" json = JSON.parse (line.delete_prefix "DATA:").delete_suffix(";;;") data = AnimationData::new_from_json json @running_animations[data.id] = data elsif line.start_with? "AINF:" json = JSON.parse (line.delete_prefix "AINF:").delete_suffix(";;;") info = AnimationInfo.new_from_json json @supported_animations[info.name] = info elsif line.start_with? "END :" json = JSON.parse (line.delete_prefix "END :").delete_suffix(";;;") anim = EndAnimation.new_from_json json @running_animations.delete anim.id elsif line.start_with? "SECT:" json = JSON.parse (line.delete_prefix "SECT:").delete_suffix(";;;") sect = Section.new_from_json json @sections[sect.name] = sect elsif line.start_with? "SINF:" json = JSON.parse (line.delete_prefix "SINF:").delete_suffix(";;;") info = StripInfo.new_from_json json @strip_info = info end end rescue IOError # ignored end } end