-
Notifications
You must be signed in to change notification settings - Fork 16
Expand file tree
/
Copy pathtty_hid_manager.go
More file actions
93 lines (86 loc) · 2.92 KB
/
Copy pathtty_hid_manager.go
File metadata and controls
93 lines (86 loc) · 2.92 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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
package main
import (
"encoding/binary"
"go.bug.st/serial"
)
func handel_touch_using_hid_manager(port serial.Port) touch_control_func {
var buf [16]byte
buf[0] = 0x55
buf[1] = 0xaa
buf[2] = 0x0c
buf[3] = 0x03
setReport := func(action uint8, id uint8, x, y uint32) {
buf[4] = action
buf[5] = id
binary.LittleEndian.PutUint32(buf[6:10], x)
binary.LittleEndian.PutUint32(buf[10:14], y)
buf[14] = 0
buf[15] = buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7] ^ buf[8] ^ buf[9] ^ buf[10] ^ buf[11] ^ buf[12] ^ buf[13] ^ buf[14]
}
return func(control_data touch_control_pack) {
switch control_data.action {
case TouchActionRequire, TouchActionMove:
x, y := rotateAbsoluteXY(control_data.x, control_data.y)
// 应用外接屏幕缩放
if global_external_screen_scale_enabled && global_external_screen_scale_func != nil {
x, y = global_external_screen_scale_func(x, y)
}
setReport(0x01, uint8(control_data.id), uint32(x), uint32(y))
port.Write(buf[:])
case TouchActionRelease:
setReport(0x00, uint8(control_data.id), 0, 0)
port.Write(buf[:])
case TouchActionResetResolution:
setReport(0x03, uint8(control_data.id), uint32(control_data.x), uint32(control_data.y))
port.Write(buf[:])
}
}
}
// func handel_touch_using_hid_manager(port serial.Port) touch_control_func {
// var buf [16]byte
// buf[0] = 0x55
// buf[1] = 0xaa
// buf[2] = 0x0c
// buf[3] = 0x03
// setReport := func(action uint8, id uint8, x, y uint32) {
// buf[4] = action
// buf[5] = id
// binary.LittleEndian.PutUint32(buf[6:10], x)
// binary.LittleEndian.PutUint32(buf[10:14], y)
// buf[14] = 0
// buf[15] = buf[2] ^ buf[3] ^ buf[4] ^ buf[5] ^ buf[6] ^ buf[7] ^ buf[8] ^ buf[9] ^ buf[10] ^ buf[11] ^ buf[12] ^ buf[13] ^ buf[14]
// logger.Errorf("buf: %x", buf)
// }
// // 创建UDP连接
// udpAddr, err := net.ResolveUDPAddr("udp", "192.168.3.255:61068")
// if err != nil {
// logger.Errorf("Error resolving UDP address: %v", err)
// }
// conn, err := net.DialUDP("udp", nil, udpAddr)
// if err != nil {
// logger.Errorf("Error creating UDP connection: %v", err)
// }
// return func(control_data touch_control_pack) {
// switch control_data.action {
// case TouchActionRequire, TouchActionMove:
// x, y := rotateAbsoluteXY(control_data.x, control_data.y)
// setReport(0x01, uint8(control_data.id), uint32(x), uint32(y))
// _, err := conn.Write(buf[:])
// if err != nil {
// logger.Errorf("Error sending UDP data: %v", err)
// }
// case TouchActionRelease:
// setReport(0x00, uint8(control_data.id), 0, 0)
// _, err := conn.Write(buf[:])
// if err != nil {
// logger.Errorf("Error sending UDP data: %v", err)
// }
// case TouchActionResetResolution:
// setReport(0x03, uint8(control_data.id), uint32(control_data.x), uint32(control_data.y))
// _, err := conn.Write(buf[:])
// if err != nil {
// logger.Errorf("Error sending UDP data: %v", err)
// }
// }
// }
// }