...
Users have a means to also specify VictorDeviceScanParameters when scanning for VictoR devices. Options include specifying the scan time, the string query for victor device names, and whether the case of the device name is important.
Code Block | ||
---|---|---|
| ||
import com.fn.victorcore.VictorDeviceInfo; import com.fn.victorcore.VictorDeviceScanParameters; import com.fn.victorcommunications.VictorBleDeviceManager; public class MainActivity extends Activity { @Override public void onCreate(Bundle savedInstanceState) { deviceManager = new VictorBleDeviceManager(this); } public void Scan() { deviceManager = new VictorBleDeviceManager(this); VictorDeviceScanParameters scanParameters = new VictorDeviceScanParameters(); scanParameters.setScanTime(3000L); CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(scanParameters); } } |
...
Additionally, users can choose to receive a callback during the act of scanning for devices, rather than having to wait for the scan to complete. Callbacks can be set by passing a VictorDeviceCallback object that defines the onDeviceFound method.
Code Block | ||
---|---|---|
| ||
import com.fn.victorcore.VictorDeviceInfo; import com.fn.victorcore.VictorDeviceCallback; import com.fn.victorcommunications.VictorBleDeviceManager; public class MainActivity extends Activity { private final VictorDeviceCallback deviceCallback = new VictorDeviceCallback() { @Override public void onDeviceFound(VictorDeviceInfo deviceInfo) { System.out.printf("Found " + deviceInfo + "\n")); } @Override public void onConnectionStateChange(VictorDeviceInfo deviceInfo, boolean connected) { System.out.printf("Got a connection state change from %s.\n", deviceInfo))); } @Override public void onAttributeChange(VictorDeviceInfo deviceInfo, UUID attribute, byte[] data) { System.out.printf("Got an attribute change for attribute %s from %s.\n", attribute, deviceInfo))); } }; @Override public void onCreate(Bundle savedInstanceState) { deviceManager = new VictorBleDeviceManager(this); } public void Scan() { deviceManager = new VictorBleDeviceManager(this); CompletableFuture<Set<VictorDeviceInfo>> futureScannedDevices = deviceManager.scanForDevices(deviceCallback); } } |
...
It is also possible to subscribe to the connection state of a VictoR device. This results in callbacks being triggered whenever the device is connected to or disconnected from.
Code Block | ||
---|---|---|
| ||
private final VictorDeviceCallback deviceCallback = new VictorDeviceCallback() { @Override public void onDeviceFound(VictorDeviceInfo deviceInfo) { System.out.printf("Found " + deviceInfo + "\n")); } @Override public void onConnectionStateChange(VictorDeviceInfo deviceInfo, boolean connected) { System.out.printf("Got a connection state change from %s.\n", deviceInfo))); } @Override public void onAttributeChange(VictorDeviceInfo deviceInfo, UUID attribute, byte[] data) { System.out.printf("Got an attribute change for attribute %s from %s.\n", attribute, deviceInfo))); } }; deviceManager.subscribeConnectionStateChange(deviceInfo.getAddress(), deviceCallback); |
...
Deserialization of the data from the VictoR device is handled by the service objects, resulting in either a primitive data type or a custom made class defined in the SDK where appropriate. For example, when reading the serial number for the device through the DeviceInformationService class, the CompletableFuture returns a string.
Code Block | ||
---|---|---|
| ||
String serialNumber = deviceInfoService.getSerialNumber().get(); |
...
However, when reading the General System Parameters for the device through the DeviceConfigurationService class, the CompletableFutrue returns a GeneralSystemParameters object (defined in the SDK) that provides accessors for the various pieces of data inside of the General System Parameters attribute.
Code Block | ||
---|---|---|
| ||
GeneralSystemParameters generalSystemParameters = deviceConfigService.getGeneralSystemParameters().get(); boolean bluetoothEnabled = generalSystemParameters.isBluetoothLinkEnabled(); PowerProfileOption powerProfileOption = generalSystemParameters.getPowerProfile(); short minimumInactivityInterval = generalSystemParameters.getMinimumInactivityInterval(); |
NOTE: When reading from a device, please reference the supported ICD document specified above to ensure the attribute itself, as well as reading from the attribute, is supported.
...
Similar to reading from a VictoR device, writing to a VictoR device requires an established connection with a powered on device through a device manager and a service object that contains the data to be written. Serialization of data when writing to the VictoR device is handled by the service objects, converting the data into a byte array before being sent to the device.
Code Block | ||
---|---|---|
| ||
VideoParameters newVideoParameters = new VideoParameters(); newVideoParameters.getFrameSize().setRows((short)128); newVideoParameters.getFrameSize().setColumns((short)64); newVideoParameters.setFrameRate((short)24); newVideoParameters.setOpticalPath(VideoParameters.OpticalPathOptions.Auto); deviceConfigService.setVideoParameters(newVideoParameters); |
NOTE: When writing to a device, please reference the supported ICD document specified above to ensure the attribute itself, as well as writing to the attribute, is supported.
...
Attributes on the VictoR device, when supported, can be subscribed to through the usage of the VictorDeviceCallback class and the service containing the data to be subscribed to.
Code Block | ||
---|---|---|
| ||
private final DeviceInformationService.DeviceInformationCallback deviceInformationCallback = new DeviceInformationService.DeviceInformationCallback() { public void onCurrentBatteryLevelChanged(VictorDeviceInfo deviceInfo, short currentBatteryLevel) { debugTextView.post(() -> debugTextView.append("Current Battery Level: " + currentBatteryLevel + "\n")); } }; deviceInfoService.subscribeToCurrentBatteryLevel(deviceInfo.getAddress(), deviceInformationCallback); |