Class: Rustle::Frame
- Inherits:
-
Object
- Object
- Rustle::Frame
- Defined in:
- lib/rustle/frame.rb
Overview
Frames
All strip changes are sent by serializing frames and sending them to the receiver. Serialization of a frame is done by serializing all Color objects in the leds
array (see Color#serialize), and then appending the char
255 to the end. Serialized frames are, thus, strings of chars
, where each char
is a single RGB color channel.
It is worth noting that, since 255 is our end-of-frame code, all color data sent as an integer in the range 0..254
. It is safe to assume that an approximate 1/255th drop in brightness is not noticeable. There is, however, the option of modifying the sketch to multiply each RGB channel by 1.004 and flooring the value.
Coercion of RGB values into the range 0..254
is handled in Color#serialize.
Instance Attribute Summary collapse
-
#leds ⇒ Array<Color>
readonly
LEDs in a frame are represented as an array of Color objects.
Instance Method Summary collapse
-
#initialize(leds) ⇒ Frame
constructor
Initializes a new frame.
-
#serialize ⇒ String
Serializes all LED Color objects (see Color#serialize) and appends the end-of-frame code (
255.chr
).
Constructor Details
#initialize(leds) ⇒ Frame
Initializes a new frame.
30 31 32 33 34 |
# File 'lib/rustle/frame.rb', line 30 def initialize(leds) validate_leds(leds) @leds = leds end |
Instance Attribute Details
Instance Method Details
#serialize ⇒ String
Serializes all LED Color objects (see Color#serialize) and appends the end-of-frame code (255.chr
)
40 41 42 |
# File 'lib/rustle/frame.rb', line 40 def serialize @leds.map(&:serialize).join + 255.chr end |