class BBB::Components::Button

Attributes

press_callbacks[RW]
release_callbacks[RW]
status[R]

Public Class Methods

new(options={}) click to toggle source
# File lib/BBB/components/button.rb, line 11
def initialize(options={})
  @status = :released
  @release_callbacks = []
  @press_callbacks = []
end

Public Instance Methods

high?() click to toggle source
# File lib/BBB/components/button.rb, line 53
def high?
  pin.on?
end
Also aliased as: on?
low?() click to toggle source
# File lib/BBB/components/button.rb, line 58
def low?
  !high
end
Also aliased as: off?
off?()
Alias for: low?
on?()
Alias for: high?
on_press(&block) click to toggle source
# File lib/BBB/components/button.rb, line 45
def on_press(&block)
  if block_given?
    @press_callbacks << block
  else
    @press_callbacks.each{ |c| c.call(status) }
  end
end
on_release(&block) click to toggle source
# File lib/BBB/components/button.rb, line 41
def on_release(&block)
  @release_callbacks.each{ |c| c.call(status) }
end
press!() click to toggle source
# File lib/BBB/components/button.rb, line 25
def press!
  old_state = status
  @status = :pressed
  on_press if old_state != status
end
pressed?() click to toggle source
# File lib/BBB/components/button.rb, line 17
def pressed?
  status == :pressed
end
release!() click to toggle source
# File lib/BBB/components/button.rb, line 31
def release!
  old_state = status
  @status = :released
  on_release if old_state != status
end
released?() click to toggle source
# File lib/BBB/components/button.rb, line 21
def released?
  !pressed
end
update(value=pin.high?) click to toggle source
# File lib/BBB/components/button.rb, line 37
def update(value=pin.high?)
  value == true ? press! : release!
end