File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -176,6 +176,11 @@ func (d Device) Disconnect() error {
176176 return nil
177177}
178178
179+ // Connected returns whether the device is currently connected.
180+ func (d Device ) Connected () (bool , error ) {
181+ return d .prph .State () == cbgo .PeripheralStateConnected , nil
182+ }
183+
179184// RequestConnectionParams requests a different connection latency and timeout
180185// of the given device connection. Fields that are unset will be left alone.
181186// Whether or not the device will actually honor this, depends on the device and
Original file line number Diff line number Diff line change @@ -538,6 +538,15 @@ func (d Device) Disconnect() error {
538538 return d .device .Call ("org.bluez.Device1.Disconnect" , 0 ).Err
539539}
540540
541+ // Connected returns whether the device is currently connected.
542+ func (d Device ) Connected () (bool , error ) {
543+ val , err := d .device .GetProperty ("org.bluez.Device1.Connected" )
544+ if err != nil {
545+ return false , err
546+ }
547+ return val .Value ().(bool ), nil
548+ }
549+
541550// RequestConnectionParams requests a different connection latency and timeout
542551// of the given device connection. Fields that are unset will be left alone.
543552// Whether or not the device will actually honor this, depends on the device and
Original file line number Diff line number Diff line change @@ -428,6 +428,18 @@ func (d Device) Disconnect() error {
428428 return nil
429429}
430430
431+ // Connected returns whether the device is currently connected.
432+ func (d Device ) Connected () (bool , error ) {
433+ if d .device == nil {
434+ return false , nil
435+ }
436+ status , err := d .device .GetConnectionStatus ()
437+ if err != nil {
438+ return false , err
439+ }
440+ return status == bluetooth .BluetoothConnectionStatusConnected , nil
441+ }
442+
431443// RequestConnectionParams requests a different connection latency and timeout
432444// of the given device connection. Fields that are unset will be left alone.
433445// Whether or not the device will actually honor this, depends on the device and
You can’t perform that action at this time.
0 commit comments