class Rustle::Receiver
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.
Attributes
When your receiver is instantiated, a {Strip} object is automatically created alongside it. @return [Strip] the strip associated with the Receiver
Public Class Methods
Initializes a new receiver.
@example
kitchen_arduino = Rustle::Receiver.new("/deb/tty.usbmodem411", num_leds: 30, baud: 921_600, debug: false)
@param [String] port_file the location of serial port file. It can be
found in the Arduino IDE (or via Ino).
@param [Fixnum] baud the serial baud rate (make sure it matches the one in
your sketch)
@param [Fixnum] num_leds 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.
@param [Boolean] debug whether or not to enable debug mode. See
{DebugPort}.
# 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
Public Instance Methods
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. @param [Frame] frame a frame object
# File lib/rustle/receiver.rb, line 56 def push_frame(frame) @port.write frame.serialize end
Private Instance Methods
Instantiates a new port
# File lib/rustle/receiver.rb, line 63 def init_serialport if @debug @port = DebugPort.new else raise PortFileNotSpecified if @debug == false @port = SerialPort.new @port_file, @baud, 8, 1, SerialPort::NONE end end