Class: Domotics::Core::Button
- Defined in:
- lib/domotics/core/element/button.rb
Instance Attribute Summary
Attributes inherited from Element
Instance Method Summary collapse
-
#initialize(args = {}) ⇒ Button
constructor
A new instance of Button.
- #set_state(*_args) ⇒ Object
- #state_changed(value) ⇒ Object
Methods inherited from Element
data=, #image, #info, #load_driver, #state, #to_s, #verbose_state
Constructor Details
#initialize(args = {}) ⇒ Button
Returns a new instance of Button.
3 4 5 6 7 8 9 10 |
# File 'lib/domotics/core/element/button.rb', line 3 def initialize(args = {}) @type = args[:type] || :button @touch = args[:touch] @last_on = nil args[:driver] = @touch ? "DigitalSensor" : "NOSensor" load_driver args super end |
Instance Method Details
#set_state(*_args) ⇒ Object
12 13 14 |
# File 'lib/domotics/core/element/button.rb', line 12 def set_state(*_args) nil end |
#state_changed(value) ⇒ Object
16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/domotics/core/element/button.rb', line 16 def state_changed(value) case value when :on @last_on = Time.now when :off case Time.now - (@last_on || Time.now) when 0...0.03 then nil # debounce when 0.03...0.3 then super :tap when 0.3...1 then super :long_tap when 1...2 then super :long_tap_x2 end end end |