Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions gap.go
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ type Connection uint16
type GAPDevice interface {
DiscoverServices(uuids []UUID) ([]DeviceService, error)
RequestConnectionParams(params ConnectionParams) error
Connected() (bool, error)
Disconnect() error
}

Expand Down
5 changes: 5 additions & 0 deletions gap_darwin.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,11 @@ func (d Device) Disconnect() error {
return nil
}

// Connected returns whether the device is currently connected.
func (d Device) Connected() (bool, error) {
return d.prph.State() == cbgo.PeripheralStateConnected, nil
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection. Fields that are unset will be left alone.
// Whether or not the device will actually honor this, depends on the device and
Expand Down
4 changes: 4 additions & 0 deletions gap_hci.go
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,10 @@ func (d Device) Disconnect() error {
return nil
}

func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection. Fields that are unset will be left alone.
// Whether or not the device will actually honor this, depends on the device and
Expand Down
9 changes: 9 additions & 0 deletions gap_linux.go
Original file line number Diff line number Diff line change
Expand Up @@ -540,6 +540,15 @@ func (d Device) Disconnect() error {
return d.device.Call("org.bluez.Device1.Disconnect", 0).Err
}

// Connected returns whether the device is currently connected.
func (d Device) Connected() (bool, error) {
val, err := d.device.GetProperty("org.bluez.Device1.Connected")
if err != nil {
return false, err
}
return val.Value().(bool), nil
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection. Fields that are unset will be left alone.
// Whether or not the device will actually honor this, depends on the device and
Expand Down
4 changes: 4 additions & 0 deletions gap_nrf51.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,4 +125,8 @@ func (d Device) RequestConnectionParams(params ConnectionParams) error {
return errNotYetImplmented
}

func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}

type DeviceService struct{}
4 changes: 4 additions & 0 deletions gap_nrf528xx-central.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,3 +237,7 @@ func (d Device) RequestConnectionParams(params ConnectionParams) error {
errCode := C.sd_ble_gap_conn_param_update(d.connectionHandle, &connParams)
return makeError(errCode)
}

func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}
4 changes: 4 additions & 0 deletions gap_s113v7.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,8 @@ func (d Device) RequestConnectionParams(params ConnectionParams) error {
return errNotYetImplmented
}

func (d Device) Connected() (bool, error) {
return false, errNotYetImplmented
}

type DeviceService struct{}
12 changes: 12 additions & 0 deletions gap_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -430,6 +430,18 @@ func (d Device) Disconnect() error {
return nil
}

// Connected returns whether the device is currently connected.
func (d Device) Connected() (bool, error) {
if d.device == nil {
return false, nil
}
status, err := d.device.GetConnectionStatus()
if err != nil {
return false, err
}
return status == bluetooth.BluetoothConnectionStatusConnected, nil
}

// RequestConnectionParams requests a different connection latency and timeout
// of the given device connection. Fields that are unset will be left alone.
// Whether or not the device will actually honor this, depends on the device and
Expand Down
Loading