class LimitlessLed::Bridge

Constants

COMMANDS

Attributes

host[RW]
port[RW]

Public Class Methods

new(host: 'localhost', port: 8899) click to toggle source
# File lib/limitless_led/bridge.rb, line 25
def initialize(host: 'localhost', port: 8899)
  @host = host
  @port = port
end

Public Instance Methods

brightness(amount) click to toggle source
# File lib/limitless_led/bridge.rb, line 62
def brightness(amount)
  raise(ArgumentError.new('Brightness must be within 2 - 27')) unless (2..27).include?(amount)
  command :brightness, amount
end
color(color) click to toggle source
# File lib/limitless_led/bridge.rb, line 50
def color(color)
  color_code = if color.is_a?(Color::RGB)
     color_code_from_color(color)
   elsif color.is_a?(Integer)
     color
   elsif color.is_a?(String)
     color_code_from_color Color::RGB.const_get(color.camelize)
   end

  command :color, color_code
end
command(command_key, command_param = 0) click to toggle source
# File lib/limitless_led/bridge.rb, line 71
def command(command_key, command_param = 0)
  send_packet COMMANDS[command_key].chr + command_param.chr + 85.chr
end
go_crazy() click to toggle source
# File lib/limitless_led/bridge.rb, line 75
def go_crazy
  while true
    color rand(256)
  end
end
group(number) click to toggle source
# File lib/limitless_led/bridge.rb, line 30
def group(number)
  LimitlessLed::Group.new(number, self)
end
send_packet(packet) click to toggle source
# File lib/limitless_led/bridge.rb, line 67
def send_packet(packet)
  socket.send packet, 0
end
smooth_and_fast() click to toggle source
# File lib/limitless_led/bridge.rb, line 81
def smooth_and_fast
  0..255.cycle do |color_code|
    color color_code
    sleep 1/100.0
  end
end
socket() click to toggle source
# File lib/limitless_led/bridge.rb, line 34
def socket
  @socket ||= begin
    UDPSocket.new.tap do |socket|
      socket.connect host, port
    end
  end
end
white() click to toggle source
# File lib/limitless_led/bridge.rb, line 46
def white
  send_packet "\xc2\x00\x55"
end