-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathtypes.go
More file actions
78 lines (70 loc) · 1.68 KB
/
types.go
File metadata and controls
78 lines (70 loc) · 1.68 KB
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
package virtual_device
import (
"github.com/jbdemonte/virtual-device/linux"
"github.com/jbdemonte/virtual-device/utils"
"os"
)
// AbsAxis describes an absolute axis with its range and properties.
type AbsAxis struct {
Axis linux.AbsoluteAxis
Value int32
Min int32
Max int32
Flat int32
Fuzz int32
Resolution int32
IsUnidirectional bool
}
// Repeat holds the key repeat delay and period in milliseconds.
type Repeat struct {
delay int32
period int32
}
func (a AbsAxis) denormalizeUniDirectional(value float32) int32 {
if value < 0 {
value = 0
}
if value > 1 {
value = 1
}
return int32(float32(a.Min) + (value)*float32(a.Max-a.Min))
}
func (a AbsAxis) denormalizeBiDirectional(value float32) int32 {
if value < -1 {
value = -1
}
if value > 1 {
value = 1
}
return int32(float32(a.Min) + (value+1)*float32(a.Max-a.Min)/2)
}
func (a AbsAxis) Denormalize(value float32) int32 {
if a.IsUnidirectional {
return a.denormalizeUniDirectional(value)
}
return a.denormalizeBiDirectional(value)
}
// Config holds the input capabilities for a virtual device.
type Config struct {
keys []linux.Key
buttons []linux.Button
absoluteAxes []AbsAxis
relativeAxes []linux.RelativeAxis
repeat *Repeat
leds []linux.Led
properties []linux.InputProp
miscEvents []linux.MiscEvent
}
type virtualDevice struct {
fd *os.File
path string
eventPath string
mode os.FileMode
queueLen int
name string
id linux.InputID
config Config
isRegistered *utils.AtomicBool
queue chan *linux.InputEvent
pullDone chan struct{}
}