class Artoo::Drivers::Neopixel

Constants

COMMANDS

Attributes

count[R]
registered[R]

Public Class Methods

new(params = {}) click to toggle source
Calls superclass method
# 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

Public Instance Methods

off(index) click to toggle source
# File lib/artoo/drivers/neopixel.rb, line 31
def off(index)
  change_state(index, 0, 0, 0)
  @is_on[index] = false
end
off?(index) click to toggle source
# File lib/artoo/drivers/neopixel.rb, line 22
def off?(index)
  !on?(index)
end
on(index, red, green, blue) click to toggle source
# 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) click to toggle source
# File lib/artoo/drivers/neopixel.rb, line 18
def on?(index)
  @is_on[index]
end

Private Instance Methods

change_state(index, red, green, blue) click to toggle source
# File lib/artoo/drivers/neopixel.rb, line 38
def change_state(index, red, green, blue)
  ensure_registered
  connection.neopixel(index, red, green, blue)
end
ensure_registered() click to toggle source
# File lib/artoo/drivers/neopixel.rb, line 43
def ensure_registered
  unless registered
    connection.register_neopixel(pin, count)
    @registered = true
  end
end