@@ -16,7 +16,7 @@ var reportMap = []byte{
16
16
0x05 , 0x01 , // USAGE_PAGE (Generic Desktop)
17
17
0x09 , 0x06 , // USAGE (Keyboard)
18
18
0xa1 , 0x01 , // COLLECTION (Application)
19
- 0x85 , 0x01 , // REPORT_ID (1 )
19
+ 0x85 , 0x02 , // REPORT_ID (2 )
20
20
0x05 , 0x07 , // USAGE_PAGE (Keyboard)
21
21
0x19 , 0x01 , // USAGE_MINIMUM
22
22
0x29 , 0x7f , // USAGE_MAXIMUM
@@ -39,18 +39,19 @@ var reportMap = []byte{
39
39
0xc0 , // END_COLLECTION
40
40
}
41
41
42
- type Keyboard struct {
42
+ type bleKeyboard struct {
43
+ keyboard
43
44
Name string
44
45
report [9 ]byte
45
46
}
46
47
47
- func NewKeyboard (name string ) * Keyboard {
48
- return & Keyboard {
48
+ func NewKeyboard (name string ) * bleKeyboard {
49
+ return & bleKeyboard {
49
50
Name : name ,
50
51
}
51
52
}
52
53
53
- func (k * Keyboard ) Connect () error {
54
+ func (k * bleKeyboard ) Connect () error {
54
55
err := adapter .Enable ()
55
56
if err != nil {
56
57
return err
@@ -84,7 +85,7 @@ func (k *Keyboard) Connect() error {
84
85
return nil
85
86
}
86
87
87
- func (k * Keyboard ) registerHID () error {
88
+ func (k * bleKeyboard ) registerHID () error {
88
89
adapter .AddService (& bluetooth.Service {
89
90
UUID : bluetooth .ServiceUUIDDeviceInformation ,
90
91
Characteristics : []bluetooth.CharacteristicConfig {
@@ -201,30 +202,15 @@ func (k *Keyboard) registerHID() error {
201
202
return nil
202
203
}
203
204
204
- func (k * Keyboard ) Up (c k.Keycode ) error {
205
- k .report [0 ] = 0x01
206
- k .report [1 ] = 0x00
207
- k .report [2 ] = 0x00
208
- k .report [3 ] = 0x00
209
- k .report [4 ] = 0x00
210
- k .report [5 ] = 0x00
211
- k .report [6 ] = 0x00
212
- k .report [7 ] = 0x00
213
- k .report [8 ] = 0x00
214
- _ , err := reportIn .Write (k .report [:9 ])
215
- return err
205
+ func (k * bleKeyboard ) Up (c k.Keycode ) error {
206
+ return k .keyboard .Up (Keycode (c ))
207
+ }
208
+
209
+ func (k * bleKeyboard ) Down (c k.Keycode ) error {
210
+ return k .keyboard .Down (Keycode (c ))
216
211
}
217
212
218
- func (k * Keyboard ) Down (c k.Keycode ) error {
219
- k .report [0 ] = 0x01
220
- k .report [1 ] = 0x00
221
- k .report [2 ] = 0x00
222
- k .report [3 ] = uint8 (c )
223
- k .report [4 ] = 0x00
224
- k .report [5 ] = 0x00
225
- k .report [6 ] = 0x00
226
- k .report [7 ] = 0x00
227
- k .report [8 ] = 0x00
228
- _ , err := reportIn .Write (k .report [:9 ])
213
+ func sendBLEPacket (b []byte ) error {
214
+ _ , err := reportIn .Write (b )
229
215
return err
230
216
}
0 commit comments