lib/artoo/drivers/button.rb in artoo-0.4.0 vs lib/artoo/drivers/button.rb in artoo-0.4.1

- old
+ new

@@ -2,17 +2,22 @@ module Artoo module Drivers # Button driver behaviors for Firmata class Button < Driver + COMMANDS = [:is_pressed?].freeze + DOWN = 1 UP = 0 + # @return [Boolean] True if pressed def is_pressed? (@is_pressed ||= false) == true end + # Sets values to read and write from button + # and starts driver def start_driver listener = ->(value) { update(value) } connection.on("digital-read-#{pin}", listener) connection.set_pin_mode(pin, Firmata::Board::INPUT) connection.toggle_pin_reporting(pin) @@ -22,10 +27,11 @@ end super end + # Publishes events according to the button feedback def update(value) if value == DOWN @is_pressed = true publish(event_topic_name("update"), "push", value) publish(event_topic_name("push"), value) @@ -35,6 +41,6 @@ publish(event_topic_name("release"), value) end end end end -end \ No newline at end of file +end