Class: Rustle::Receiver

Inherits:
Object
  • Object
show all
Defined in:
lib/rustle/receiver.rb

Overview

Receivers

Your receiver is, effectively, your Arduino. The receiver class’s purpose is to manage the serial communication between Ruby and your Arduino, and to ensure that changes made to a Strip object are reflected immediately on the actual LED strip. This class, however, is not responsible for actual serialization; the Frame and Color classes serialize themselves.

The Receiver class is initialized using a block.

bedroom_arduino = Rustle::Receiver.new do
  port_file "/dev/[PORT_FILE]"
  num_leds 30
end

Your port file can be found using the Arduino IDE.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize {|port_file, baud, num_leds| ... } ⇒ Receiver

Initializes a new receiver.

Examples:

kitchen_arduino = Rustle::Receiver.new do
  port_file "/dev/tty.usbmodem411" # replace this
  num_leds 60
end

Yield Parameters:

  • port_file (String)

    the location of serial port file. It can be found in the Arduino IDE (or via Ino).

  • baud (Fixnum)

    (optional) the serial baud rate (make sure it matches the one in your sketch)

  • num_leds (Fixnum)

    (optional) the total number of LEDs connected to your receiver. Note that this attribute only affects how the Strip object is instantiated; the number of LEDs is not actually stored in the Receiver object.



42
43
44
45
46
47
48
49
# File 'lib/rustle/receiver.rb', line 42

def initialize(&block)
  # Default value
  @baud = 921_600

  instance_eval &block

  init_serialport
end

Instance Attribute Details

#stripStrip (readonly)

When your receiver is instantiated, a Strip object is automatically created alongside it.

Returns:

  • (Strip)

    the strip associated with the Receiver



24
25
26
# File 'lib/rustle/receiver.rb', line 24

def strip
  @strip
end

Instance Method Details

#push_frame(frame) ⇒ Object

Serializes frame and sends it off to the the serial port. push_frame is used internally, so its direct use is discouraged, but it would work in theory.

Parameters:

  • frame (Frame)

    a frame object



55
56
57
# File 'lib/rustle/receiver.rb', line 55

def push_frame(frame)
  @port.write frame.serialize
end