Class: Rustle::Receiver
- Inherits:
-
Object
- Object
- Rustle::Receiver
- 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
-
#strip ⇒ Strip
readonly
When your receiver is instantiated, a Strip object is automatically created alongside it.
Instance Method Summary collapse
-
#initialize(port_file = nil, baud: 921_600, num_leds: 30, debug: false) ⇒ Receiver
constructor
Initializes a new receiver.
-
#push_frame(frame) ⇒ Object
Serializes
frame
and sends it off to the the serial port.
Constructor Details
#initialize(port_file = nil, baud: 921_600, num_leds: 30, debug: false) ⇒ Receiver
Initializes a new receiver.
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
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.
56 57 58 |
# File 'lib/rustle/receiver.rb', line 56 def push_frame(frame) @port.write frame.serialize end |