public class LegoDeviceManagerImpl extends java.lang.Object implements LegoDeviceManager, LegoBluetoothDeviceManagerCallbackListener
DEFAULT_CONNECT_REQUEST_TIMEOUT
Modifier and Type | Method and Description |
---|---|
java.util.List<? extends LegoDevice> |
allDevices()
Returns a list with all known devices regardless of their current connect state.
|
void |
cancelDeviceConnection(LegoDevice device)
Disconnect from a LEGO Device.
|
void |
connectToDevice(android.content.Context context,
LegoDevice device)
Connect to a LEGO Device.
|
java.util.List<? extends LegoDevice> |
devicesInState(LegoDevice.DeviceState connectionState)
Returns a list of devices in the specified device state.
|
long |
getConnectRequestTimeoutInterval() |
static LegoDeviceManager |
getInstance() |
java.lang.String |
getSDKVersion() |
boolean |
isAutomaticReconnectOnConnectionLostEnabled() |
void |
onDeviceDidAppear(LegoBluetoothDevice device)
Invoked when a Bluetooth device advertising a LEGO Device service UUID is discovered.
|
void |
onDeviceDidDisappear(LegoBluetoothDevice device)
Invoked when a Bluetooth device stops advertising a LEGO Device service.
|
void |
onDidDisconnectFromDevice(LegoBluetoothDevice device,
boolean autoReconnect,
LDSDKError error)
Invoked when a device is disconnected.
|
void |
onDidFailToConnectToDevice(LegoBluetoothDevice device,
boolean autoReconnect,
LDSDKError error)
Invoked when a device fails to connect, of if a connection request times out.
|
void |
onDidFinishInterrogatingDevice(LegoBluetoothDevice device)
Invoked when a connection to a device is established and all required services has been discovered.
|
void |
onDidStartInterrogatingDevice(LegoBluetoothDevice device)
Invoked when a connection to a device is established, and the interrogation of the device for required services begins.
|
void |
onWillStartConnectingToDevice(LegoBluetoothDevice device)
Invoked when starting a device connect attempt.
|
void |
registerCallbackListener(DeviceManagerCallbackListener callbackListener)
Add a listener to receive device discovery and connection events
Note, that callbacks are not guaranteed to be delivered in the same order as the listeners are added.
|
void |
scan(android.content.Context context)
Start scanning for LEGO devices
|
void |
setAutomaticReconnectOnConnectionLostEnabled(boolean enabled)
If enabled, the LegoDeviceManager will attempt to reconnect in case of a connection loss, but only if the connection was not closed by the user,
the default value is false.
|
void |
setConnectRequestTimeoutInterval(long timeoutInterval)
If a connect request is not successful within this time interval the connection attempt is cancelled
and the
DeviceManagerCallbackListener.onDidFailToConnectToDevice(LegoDevice, boolean, dk.lego.devicesdk.LDSDKError) is invoked. |
void |
stopScanning()
Stop scanning for LEGO BLE devices
|
void |
unregisterCallbackListener(DeviceManagerCallbackListener callbackListener)
Remove a listener
|
public static LegoDeviceManager getInstance()
public void scan(android.content.Context context) throws java.lang.IllegalStateException
LegoDeviceManager
scan
in interface LegoDeviceManager
context
- The Android contextjava.lang.IllegalStateException
public void stopScanning()
LegoDeviceManager
stopScanning
in interface LegoDeviceManager
public void connectToDevice(android.content.Context context, LegoDevice device)
LegoDeviceManager
DeviceManagerCallbackListener.onDidFailToConnectToDevice(dk.lego.devicesdk.device.LegoDevice, boolean, dk.lego.devicesdk.LDSDKError)
is invoked.connectToDevice
in interface LegoDeviceManager
context
- The Android contextdevice
- The device to establish a connection topublic void setConnectRequestTimeoutInterval(long timeoutInterval)
LegoDeviceManager
DeviceManagerCallbackListener.onDidFailToConnectToDevice(LegoDevice, boolean, dk.lego.devicesdk.LDSDKError)
is invoked.
The default value is 10 seconds.setConnectRequestTimeoutInterval
in interface LegoDeviceManager
timeoutInterval
- The timeout interval in millisecondspublic long getConnectRequestTimeoutInterval()
getConnectRequestTimeoutInterval
in interface LegoDeviceManager
public void setAutomaticReconnectOnConnectionLostEnabled(boolean enabled)
LegoDeviceManager
LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_INTERROGATING
with an 'unexpected error' (e.g. not closed by user).
If the second connection attempt also fails, no further attempts are made to connect automatically.
If a connection is lost after successful connection (i.e. in state LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_INTERROGATION_FINISHED
)
If the connect-request does not succeed within the connectRequestTimeout no attempt is made to automatically reconnect.setAutomaticReconnectOnConnectionLostEnabled
in interface LegoDeviceManager
enabled
- Whether automatic reconnect should be enabled or notpublic boolean isAutomaticReconnectOnConnectionLostEnabled()
isAutomaticReconnectOnConnectionLostEnabled
in interface LegoDeviceManager
public void cancelDeviceConnection(LegoDevice device)
LegoDeviceManager
cancelDeviceConnection
in interface LegoDeviceManager
device
- The device to disconnect frompublic java.util.List<? extends LegoDevice> devicesInState(LegoDevice.DeviceState connectionState)
LegoDeviceManager
LegoDevice.DeviceState.DEVICE_CONNECTION_STATE_DISCONNECTED_ADVERTISING
.devicesInState
in interface LegoDeviceManager
connectionState
- The state of the devices.public java.util.List<? extends LegoDevice> allDevices()
LegoDeviceManager
allDevices
in interface LegoDeviceManager
public void registerCallbackListener(DeviceManagerCallbackListener callbackListener)
LegoDeviceManager
registerCallbackListener
in interface LegoDeviceManager
callbackListener
- The listener to addpublic void unregisterCallbackListener(DeviceManagerCallbackListener callbackListener)
LegoDeviceManager
unregisterCallbackListener
in interface LegoDeviceManager
callbackListener
- The listener to removepublic java.lang.String getSDKVersion()
getSDKVersion
in interface LegoDeviceManager
public void onDeviceDidAppear(LegoBluetoothDevice device)
LegoBluetoothDeviceManagerCallbackListener
onDeviceDidAppear
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The discovered devicepublic void onDeviceDidDisappear(LegoBluetoothDevice device)
LegoBluetoothDeviceManagerCallbackListener
onDeviceDidDisappear
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The device that stopped advertisingpublic void onWillStartConnectingToDevice(LegoBluetoothDevice device)
LegoBluetoothDeviceManagerCallbackListener
LegoDeviceManager.connectToDevice(android.content.Context, dk.lego.devicesdk.device.LegoDevice)
.
However, it may also happen in relation to an automatic reconnect attempt.onWillStartConnectingToDevice
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The device to establish a connection topublic void onDidFailToConnectToDevice(LegoBluetoothDevice device, boolean autoReconnect, LDSDKError error)
LegoBluetoothDeviceManagerCallbackListener
onDidFailToConnectToDevice
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The device that failed to connectautoReconnect
- true if an automatic reconnect will be attempted, see LegoDeviceManager.isAutomaticReconnectOnConnectionLostEnabled()
.error
- The cause of the failure.public void onDidDisconnectFromDevice(LegoBluetoothDevice device, boolean autoReconnect, LDSDKError error)
LegoBluetoothDeviceManagerCallbackListener
onDidDisconnectFromDevice
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The disconnected deviceautoReconnect
- true if an automatic reconnect will be attempted, see LegoDeviceManager.isAutomaticReconnectOnConnectionLostEnabled()
.error
- If an error occurred, the cause of the failure.public void onDidStartInterrogatingDevice(LegoBluetoothDevice device)
LegoBluetoothDeviceManagerCallbackListener
onDidStartInterrogatingDevice
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The connected devicepublic void onDidFinishInterrogatingDevice(LegoBluetoothDevice device)
LegoBluetoothDeviceManagerCallbackListener
onDidFinishInterrogatingDevice
in interface LegoBluetoothDeviceManagerCallbackListener
device
- The connected device