lib/fusuma/plugin/detectors/hold_detector.rb in fusuma-3.0.0 vs lib/fusuma/plugin/detectors/hold_detector.rb in fusuma-3.1.0

- old
+ new

@@ -9,14 +9,18 @@ # Detect Hold gesture class HoldDetector < Detector SOURCES = %w[gesture timer].freeze BUFFER_TYPE = "gesture" GESTURE_RECORD_TYPE = "hold" - Timer = Inputs::TimerInput.instance BASE_THERESHOLD = 0.7 + def initialize(*args) + super(*args) + @timer = Inputs::TimerInput.instance + end + # @param buffers [Array<Buffers::Buffer>] # @return [Events::Event] if event is detected # @return [Array<Events::Event>] if hold end event is detected # @return [NilClass] if event is NOT detected def detect(buffers) @@ -48,14 +52,14 @@ end repeat_index = create_repeat_index(finger: finger, status: status) oneshot_index = create_oneshot_index(finger: finger) - if status == "begin" then + if status == "begin" @timeout = nil - if threshold(index: oneshot_index) < Timer.interval then - Timer.wake_early(Time.now + threshold(index: oneshot_index)) + if threshold(index: oneshot_index) < @timer.interval + @timer.wake_early(Time.now + threshold(index: oneshot_index)) end elsif status == "timer" return if @timeout return unless enough?(index: oneshot_index, holding_time: holding_time) @@ -113,13 +117,13 @@ last_time - hold_events.first.time end def enough?(index:, holding_time:) diff = threshold(index: index) - holding_time - if diff < 0 then + if diff < 0 true - elsif diff < Timer.interval - Timer.wake_early(Time.now + diff) + elsif diff < @timer.interval + @timer.wake_early(Time.now + diff) false end end def threshold(index:)