Class: L8::Util
- Inherits:
-
Object
- Object
- L8::Util
- Defined in:
- lib/l8/util.rb
Constant Summary collapse
- HEADER =
[0xaa, 0x55]
Class Method Summary collapse
- .frame(payload) ⇒ Object
- .pixels_to_two_byte_array(pixels) ⇒ Object
- .to_two_byte_color(r, g, b) ⇒ Object
Class Method Details
.frame(payload) ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/l8/util.rb', line 17 def self.frame(payload) crc8 = Digest::CRC8.new crc8 << payload.pack('C*') frame = HEADER + [payload.size] + payload << crc8.checksum frame.pack('C*') end |
.pixels_to_two_byte_array(pixels) ⇒ Object
11 12 13 14 15 |
# File 'lib/l8/util.rb', line 11 def self.pixels_to_two_byte_array(pixels) data = [] pixels.each_slice(3) { |slice| data.concat to_two_byte_color(slice[0], slice[1], slice[2]) } data end |
.to_two_byte_color(r, g, b) ⇒ Object
7 8 9 |
# File 'lib/l8/util.rb', line 7 def self.to_two_byte_color(r, g, b) [(0.to_s(16) + b.to_s(16)).hex] + [(g.to_s(16) + r.to_s(16)).hex] end |