gap/all: add Disconnect() to Driver

Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
deadprogram 2020-09-22 16:55:44 +02:00 committed by Ayke
parent 281d195e75
commit a2662956b8
4 changed files with 26 additions and 0 deletions

@ -73,6 +73,11 @@ func main() {
}
}
err = device.Disconnect()
if err != nil {
println(err)
}
done()
}

@ -128,6 +128,12 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
}
}
// Disconnect from the BLE device.
func (d *Device) Disconnect() error {
d.cm.CancelConnect(d.prph)
return nil
}
// Peripheral delegate functions
type peripheralDelegate struct {

@ -266,3 +266,8 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
device: dev,
}, nil
}
// Disconnect from the BLE device.
func (d *Device) Disconnect() error {
return d.device.Disconnect()
}

@ -252,3 +252,13 @@ func (a *Adapter) Connect(address Addresser, params ConnectionParams) (*Device,
connectionHandle: connectionHandle,
}, nil
}
// Disconnect from the BLE device.
func (d *Device) Disconnect() error {
errCode := C.sd_ble_gap_disconnect(d.connectionHandle, C.BLE_HCI_REMOTE_USER_TERMINATED_CONNECTION)
if errCode != 0 {
return Error(errCode)
}
return nil
}