Added recorder to be able to stream the current LED data via network. That way you can create nice looking GIF images of the effects - and even develop effects without having to look at the actual LED panel.

This commit is contained in:
2019-09-04 06:05:45 +02:00
parent bf1666fb32
commit 33c2417534
8 changed files with 275 additions and 0 deletions

93
src/tools/recorder.rb Executable file
View File

@@ -0,0 +1,93 @@
#!/usr/bin/env ruby
require 'socket'
require 'pp'
require 'rmagick'
include Magick
IP = ARGV[0]
PORT = 2122
FILE = ARGV[1] or raise "No filename given"
EFFECT = ARGV[2]
FRAMES = 250
FACTOR = 1
delay = 50
puts "Connecting to #{IP}:#{PORT}..."
s = TCPSocket.new(IP, PORT)
puts "Connected."
init = s.recv(3).unpack("C*")
raise "Initial data packet wasn't usable!" if init[2] != 0xFF
puts "Got initial data packet."
dim_x, dim_y = *init
len = dim_x * dim_y * 3 + 3
puts "Size: #{dim_x}x#{dim_y}. Expecting packet length #{len}."
puts "Opening local UDP socket..."
udp = UDPSocket.new
udp.bind("10.10.2.1", 13330)
puts "Waiting for UDP packets on port 13330..."
s.sendmsg("P\x12\x34\x00")
s.sendmsg("E#{EFFECT}\x00") if EFFECT
gif = ImageList.new
last_id = 255
last_frame_time = nil
img = nil
last_diff = nil
while gif.length < FRAMES do
data = udp.recvfrom(1024)[0].unpack("C*")
if delay > 0
delay -= 1
next
end
#puts "Packet. ID: #{data[0]}, length: #{data.length}"
raise "Unexpected packet length" unless data.count == len
raise "Invalid data packet" unless data[len - 1]==0xFF
id = data.shift << 8 | data.shift
if last_id != id-1 && last_id != id-2
puts
gif = ImageList.new
end
last_id = id
if img && last_frame_time
last_diff = diff = Time.now.to_f * 100 - last_frame_time.to_f * 100
img.delay = diff
end
last_frame_time = Time.now
img = Image.new(dim_x, dim_y)
img.delay = 5
gc = Draw.new
#next
print "."
print "#{gif.length}" if gif.length%50==0
(0...dim_y).each do |y|
(0...dim_x).each do |x|
r, g, b = *data.shift(3)
gc.fill("rgb(#{r}, #{g}, #{b})")
gc.point(x, y)
#img.pixel_color(x, y, Pixel.new(r, g, b, 255))
end
end
gc.draw(img)
img.sample!(FACTOR)
gif << img
end
img.delay = last_diff
s.close
puts
puts "Generating gif..."
gif.write(FILE)
puts
puts