Class: Artoo::Drivers::Button
- Defined in:
- lib/artoo/drivers/button.rb
Overview
Button driver behaviors for Firmata
Constant Summary collapse
- DOWN =
1- UP =
0
Instance Attribute Summary
Attributes inherited from Driver
Instance Method Summary collapse
Methods inherited from Driver
#connection, #event_topic_name, #initialize, #interval, #method_missing, #pin
Methods included from Celluloid
Constructor Details
This class inherits a constructor from Artoo::Drivers::Driver
Dynamic Method Handling
This class handles dynamic methods through the method_missing method in the class Artoo::Drivers::Driver
Instance Method Details
#is_pressed? ⇒ Boolean
10 11 12 |
# File 'lib/artoo/drivers/button.rb', line 10 def is_pressed? (@is_pressed ||= false) == true end |
#start_driver ⇒ Object
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/artoo/drivers/button.rb', line 14 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) every(interval) do connection.read_and_process end super end |
#update(value) ⇒ Object
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/artoo/drivers/button.rb', line 27 def update(value) if value == DOWN @is_pressed = true publish(event_topic_name("update"), "push", value) publish(event_topic_name("push"), value) else @is_pressed = false publish(event_topic_name("update"), "release", value) publish(event_topic_name("release"), value) end end |