Skip to content

Commit a266295

Browse files
deadprogramaykevl
authored andcommitted
gap/all: add Disconnect() to Driver
Signed-off-by: deadprogram <ron@hybridgroup.com>
1 parent 281d195 commit a266295

File tree

4 files changed

+26
-0
lines changed

4 files changed

+26
-0
lines changed

examples/discover/main.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,11 @@ func main() {
7373
}
7474
}
7575

76+
err = device.Disconnect()
77+
if err != nil {
78+
println(err)
79+
}
80+
7681
done()
7782
}
7883

gap_darwin.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,12 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
128128
}
129129
}
130130

131+
// Disconnect from the BLE device.
132+
func (d *Device) Disconnect() error {
133+
d.cm.CancelConnect(d.prph)
134+
return nil
135+
}
136+
131137
// Peripheral delegate functions
132138

133139
type peripheralDelegate struct {

gap_linux.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -266,3 +266,8 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
266266
device: dev,
267267
}, nil
268268
}
269+
270+
// Disconnect from the BLE device.
271+
func (d *Device) Disconnect() error {
272+
return d.device.Disconnect()
273+
}

gap_nrf528xx.go

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -252,3 +252,13 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
252252
connectionHandle: connectionHandle,
253253
}, nil
254254
}
255+
256+
// Disconnect from the BLE device.
257+
func (d *Device) Disconnect() error {
258+
errCode := C.sd_ble_gap_disconnect(d.connectionHandle, C.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)
259+
if errCode != 0 {
260+
return Error(errCode)
261+
}
262+
263+
return nil
264+
}

0 commit comments

Comments
 (0)