Skip to content

Commit ba1a1ab

Browse files
committed
Update
1 parent 28a9b0d commit ba1a1ab

File tree

1 file changed

+15
-29
lines changed

1 file changed

+15
-29
lines changed

ble/ble.go

Lines changed: 15 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ var reportMap = []byte{
1616
0x05, 0x01, // USAGE_PAGE (Generic Desktop)
1717
0x09, 0x06, // USAGE (Keyboard)
1818
0xa1, 0x01, // COLLECTION (Application)
19-
0x85, 0x01, // REPORT_ID (1)
19+
0x85, 0x02, // REPORT_ID (2)
2020
0x05, 0x07, // USAGE_PAGE (Keyboard)
2121
0x19, 0x01, // USAGE_MINIMUM
2222
0x29, 0x7f, // USAGE_MAXIMUM
@@ -39,18 +39,19 @@ var reportMap = []byte{
3939
0xc0, // END_COLLECTION
4040
}
4141

42-
type Keyboard struct {
42+
type bleKeyboard struct {
43+
keyboard
4344
Name string
4445
report [9]byte
4546
}
4647

47-
func NewKeyboard(name string) *Keyboard {
48-
return &Keyboard{
48+
func NewKeyboard(name string) *bleKeyboard {
49+
return &bleKeyboard{
4950
Name: name,
5051
}
5152
}
5253

53-
func (k *Keyboard) Connect() error {
54+
func (k *bleKeyboard) Connect() error {
5455
err := adapter.Enable()
5556
if err != nil {
5657
return err
@@ -84,7 +85,7 @@ func (k *Keyboard) Connect() error {
8485
return nil
8586
}
8687

87-
func (k *Keyboard) registerHID() error {
88+
func (k *bleKeyboard) registerHID() error {
8889
adapter.AddService(&bluetooth.Service{
8990
UUID: bluetooth.ServiceUUIDDeviceInformation,
9091
Characteristics: []bluetooth.CharacteristicConfig{
@@ -201,30 +202,15 @@ func (k *Keyboard) registerHID() error {
201202
return nil
202203
}
203204

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))
216211
}
217212

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)
229215
return err
230216
}

0 commit comments

Comments
 (0)