-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinput.go
63 lines (53 loc) · 1.37 KB
/
input.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
package libphonelabgo
import (
phonelab "github.com/shaseley/phonelab-go"
)
type InputProcessor struct {
TouchSlop int
Source phonelab.Processor
}
func (p *InputProcessor) Process() <-chan interface{} {
outChan := make(chan interface{})
inChan := p.Source.Process()
go func() {
detector := NewGestureDetector(p.TouchSlop)
for raw := range inChan {
if log, ok := raw.(*phonelab.Logline); ok && log != nil {
switch typed := log.Payload.(type) {
case *IFKeyEventLog:
{
// Just emit the key event if it is an up
if typed.Action == KEY_ACTION_UP {
event := &TouchScreenEvent{
What: TouchScreenEventKey,
Timestamp: typed.Timestamp,
TraceTime: log.TraceTime,
Code: typed.KeyCode,
}
outChan <- event
}
}
case *IFMotionEventLog:
{
// Update the detector state
if outEvent, err := detector.OnTouchEvent(log.TraceTime, typed); err != nil {
panic(err)
} else if outEvent != nil {
outChan <- outEvent
}
}
}
}
}
close(outChan)
}()
return outChan
}
type InputProcessorGenerator struct{}
func (ipg *InputProcessorGenerator) GenerateProcessor(source *phonelab.PipelineSourceInstance,
kwargs map[string]interface{}) phonelab.Processor {
return &InputProcessor{
TouchSlop: TouchSlopScaled,
Source: source.Processor,
}
}