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("/dev/[PORT_FILE]")

Your port file can be found using the Arduino IDE.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(port_file = nil, baud: 921_600, num_leds: 30, debug: false) ⇒ Receiver

Initializes a new receiver.

Examples:

kitchen_arduino = Rustle::Receiver.new("/deb/tty.usbmodem411", 
  num_leds: 30, baud: 921_600, debug: false)

Parameters:

  • port_file (String) (defaults to: nil)

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

  • baud (Fixnum) (defaults to: 921_600)

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

  • num_leds (Fixnum) (defaults to: 30)

    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.

  • debug (Boolean) (defaults to: false)

    whether or not to enable debug mode. See DebugPort.



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

def initialize(port_file = nil, baud: 921_600, num_leds: 30, debug: false)
  @port_file = port_file
  @baud = baud
  @debug = debug
  @strip = Strip.new(self, num_leds)

  init_serialport

  # Sending a blank frame upon initialization seems to fix all timing 
  # constraint problems.
  @strip.off!
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



21
22
23
# File 'lib/rustle/receiver.rb', line 21

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



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

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