Class: Artoo::Drivers::BlinkM

Inherits:
Driver
  • Object
show all
Defined in:
lib/artoo/drivers/blink_m.rb

Overview

BlinkM LED driver behaviors for i2c

Constant Summary collapse

COMMANDS =
[:rgb, :fade, :color, :firmware_version].freeze

Instance Method Summary collapse

Instance Method Details

#addressObject



9
# File 'lib/artoo/drivers/blink_m.rb', line 9

def address; 0x09; end

#colorObject



42
43
44
45
46
47
# File 'lib/artoo/drivers/blink_m.rb', line 42

def color
  connection.i2c_write('g'.bytes.first)
  @data = connection.i2c_read(3)
  return nil if @data.nil? || @data.empty?
  return @data[0], @data[1], @data[2]
end

#fade(r = 0, g = 0, b = 0) ⇒ Object



30
31
32
33
# File 'lib/artoo/drivers/blink_m.rb', line 30

def fade(r=0, g=0, b=0)
  connection.i2c_write('c'.bytes.first)
  connection.i2c_write(r, g, b)
end

#firmware_versionObject



35
36
37
38
39
40
# File 'lib/artoo/drivers/blink_m.rb', line 35

def firmware_version
  connection.i2c_write('Z'.bytes.first)
  @data = connection.i2c_read(2)
  return nil if @data.nil? || @data.empty?
  return "#{@data[0]}.#{@data[1]}"
end

#rgb(r = 0, g = 0, b = 0) ⇒ Object



25
26
27
28
# File 'lib/artoo/drivers/blink_m.rb', line 25

def rgb(r=0, g=0, b=0)
  connection.i2c_write('n'.bytes.first)
  connection.i2c_write(r, g, b)
end

#start_driverObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/artoo/drivers/blink_m.rb', line 11

def start_driver
  begin
    connection.i2c_start(address)
    connection.i2c_write("o".bytes.first) # stops any scripts already running
    rgb(0, 0, 0)

    super
  rescue Exception => e
    Logger.error "Error starting BlinkM driver!"
    Logger.error e.message
    Logger.error e.backtrace.inspect
  end
end