class Artoo::Drivers::Button
Button
driver behaviors
Constants
- COMMANDS
- DOWN
- UP
Public Instance Methods
is_pressed?()
click to toggle source
@return [Boolean] True if pressed
# File lib/artoo/drivers/button.rb, line 13 def is_pressed? (@pressed_val == 1) ? true : false end
start_driver()
click to toggle source
Calls superclass method
# File lib/artoo/drivers/button.rb, line 17 def start_driver @pressed_val = 0 every(interval) do new_value = connection.digital_read(pin) update(new_value) if !new_value.nil? && new_value != is_pressed? end super end
Private Instance Methods
update(new_val)
click to toggle source
Publishes events according to the button feedback
# File lib/artoo/drivers/button.rb, line 30 def update(new_val) if new_val == 1 @pressed_val = 1 publish(event_topic_name("update"), "push", new_val) publish(event_topic_name("push"), new_val) else @pressed_val = 0 publish(event_topic_name("update"), "release", new_val) publish(event_topic_name("release"), new_val) end end