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 11 |
# File 'lib/domotics/core/element/button.rb', line 3 def initialize(args = {}) @type = args[:type] || :button @touch = args[:touch] @taped = true #@tap_lock = Mutex.new 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 29 30 31 32 33 34 35 36 37 |
# File 'lib/domotics/core/element/button.rb', line 16 def state_changed(value) case value when :on (@last_on = Time.now; @taped = false) if @taped when :off case Time.now - (@last_on || Time.now) when 0...0.01 then return # debounce when 0.01...0.3 then super :tap; @taped = true when 0.3...1 then super :long_tap; @taped = true #@tap_lock.synchronize do # if @tap and @tap.alive? # @tap.kill # @tap = nil # super :double_tap # else # @tap = Thread.new { sleep 0.25; super :tap } # end #end else super :long_tap_x2; @taped = true end end end |