Class: Fusuma::Plugin::Detectors::TapDetector
- Inherits:
-
Detector
- Object
- Detector
- Fusuma::Plugin::Detectors::TapDetector
- Defined in:
- lib/fusuma/plugin/detectors/tap_detector.rb
Overview
Detect tap event
Constant Summary collapse
- BUFFER_TYPE =
'tap'- GESTURE_RECORD_TYPE =
'tap'- BASE_INTERVAL =
0.5
- BASE_HOLDING_TIME =
0.1
- BASE_TAP_TIME =
1
Instance Method Summary collapse
- #create_index(finger:, direction:) ⇒ Config::Index
- #detect(buffers) ⇒ Event, NilClass
- #hold?(buffer, holding_time) ⇒ Boolean
- #tap?(buffer, holding_time) ⇒ Boolean
- #tap_released?(buffer) ⇒ Boolean
Instance Method Details
#create_index(finger:, direction:) ⇒ Config::Index
47 48 49 50 51 52 53 54 |
# File 'lib/fusuma/plugin/detectors/tap_detector.rb', line 47 def create_index(finger:, direction:) Config::Index.new( [ Config::Index::Key.new(direction), Config::Index::Key.new(finger.to_i) ] ) end |
#detect(buffers) ⇒ Event, NilClass
20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/fusuma/plugin/detectors/tap_detector.rb', line 20 def detect(buffers) buffer = buffers.find { |b| b.type == BUFFER_TYPE } return if buffer.empty? finger = buffer.finger holding_time = buffer.events.last.time - buffer.events.first.time direction = if hold?(buffer, holding_time) 'hold' elsif tap?(buffer, holding_time) 'tap' end return if direction.nil? buffer.clear index = create_index(finger: finger, direction: direction) return unless enough?(index: index, direction: direction) create_event(record: Events::Records::IndexRecord.new(index: index)) end |
#hold?(buffer, holding_time) ⇒ Boolean
56 57 58 59 60 61 62 |
# File 'lib/fusuma/plugin/detectors/tap_detector.rb', line 56 def hold?(buffer, holding_time) return false if holding_time < 1 return true if buffer.finger == 4 true if buffer.events.any? { |e| e.record.status == 'hold' } end |
#tap?(buffer, holding_time) ⇒ Boolean
64 65 66 67 68 |
# File 'lib/fusuma/plugin/detectors/tap_detector.rb', line 64 def tap?(buffer, holding_time) return false if holding_time > 0.15 tap_released?(buffer) end |
#tap_released?(buffer) ⇒ Boolean
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/fusuma/plugin/detectors/tap_detector.rb', line 70 def tap_released?(buffer) touch_num = buffer.events.count { |e| (e.record.status =~ /begin|touch/) } release_num = buffer.events.count { |e| e.record.status =~ /release|end/ } MultiLogger.debug(touch_num: touch_num, release_num: release_num) case buffer.finger when 1 touch_num == release_num when 2 touch_num == release_num + 1 when 3 touch_num == release_num + 1 when 4 touch_num > 0 && release_num > 0 else false end end |