Class: Artoo::Drivers::Neopixel

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

Constant Summary collapse

COMMANDS =
[:on, :off, :on?, :off?].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(params = {}) ⇒ Neopixel

Returns a new instance of Neopixel.



10
11
12
13
14
15
16
# File 'lib/artoo/drivers/neopixel.rb', line 10

def initialize(params = {})
  @is_on = Hash.new(false)
  additional_params = params.fetch(:additional_params) { Hash.new }
  @count = additional_params.fetch(:count)
  @registered = false
  super
end

Instance Attribute Details

#countObject (readonly)

Returns the value of attribute count.



8
9
10
# File 'lib/artoo/drivers/neopixel.rb', line 8

def count
  @count
end

#registeredObject (readonly)

Returns the value of attribute registered.



8
9
10
# File 'lib/artoo/drivers/neopixel.rb', line 8

def registered
  @registered
end

Instance Method Details

#off(index) ⇒ Object



31
32
33
34
# File 'lib/artoo/drivers/neopixel.rb', line 31

def off(index)
  change_state(index, 0, 0, 0)
  @is_on[index] = false
end

#off?(index) ⇒ Boolean

Returns:

  • (Boolean)


22
23
24
# File 'lib/artoo/drivers/neopixel.rb', line 22

def off?(index)
  !on?(index)
end

#on(index, red, green, blue) ⇒ Object



26
27
28
29
# File 'lib/artoo/drivers/neopixel.rb', line 26

def on(index, red, green, blue)
  change_state(index, red, green, blue)
  @is_on[index] = true
end

#on?(index) ⇒ Boolean

Returns:

  • (Boolean)


18
19
20
# File 'lib/artoo/drivers/neopixel.rb', line 18

def on?(index)
  @is_on[index]
end