module BlinkStick::ColorHandler
Public Instance Methods
color()
click to toggle source
# File lib/blink_stick/color_handler.rb, line 12 def color result = @handle.control_transfer(bmRequestType: 0x80 | 0x20, bRequest: 0x1, wValue: 0x1, wIndex: 0x0000, dataIn: 4) [result[1].ord, result[2].ord, result[3].ord] end
color=(value)
click to toggle source
# File lib/blink_stick/color_handler.rb, line 2 def color=(value) data_out = transform_color_to_hex(Color.parse(value)) @handle.control_transfer(bmRequestType: 0x20, bRequest: 0x9, wValue: 0x1, wIndex: 0x0000, dataOut: data_out) end
off()
click to toggle source
# File lib/blink_stick/color_handler.rb, line 22 def off self.color = [0, 0, 0] end
random_color()
click to toggle source
# File lib/blink_stick/color_handler.rb, line 26 def random_color r = Random.new self.color = [r.rand(255), r.rand(255), r.rand(255)] end
Private Instance Methods
transform_color_to_hex(value)
click to toggle source
# File lib/blink_stick/color_handler.rb, line 33 def transform_color_to_hex(value) 1.chr + value[0].chr + value[1].chr + value[2].chr end