summaryrefslogtreecommitdiffstats
path: root/examples/java
diff options
context:
space:
mode:
Diffstat (limited to 'examples/java')
-rw-r--r--examples/java/AsyncTinyB.java3
-rw-r--r--examples/java/HelloTinyB.java3
-rw-r--r--examples/java/Notification.java3
-rw-r--r--examples/java/ScannerTinyB00.java8
-rw-r--r--examples/java/ScannerTinyB01.java7
-rw-r--r--examples/java/ScannerTinyB02.java7
-rw-r--r--examples/java/ScannerTinyB10.java8
7 files changed, 24 insertions, 15 deletions
diff --git a/examples/java/AsyncTinyB.java b/examples/java/AsyncTinyB.java
index f70b890a..20313b33 100644
--- a/examples/java/AsyncTinyB.java
+++ b/examples/java/AsyncTinyB.java
@@ -6,6 +6,7 @@ import org.tinyb.BluetoothFactory;
import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
+import org.tinyb.HCIStatusCode;
import java.lang.reflect.InvocationTargetException;
import java.util.concurrent.TimeUnit;
@@ -87,7 +88,7 @@ public class AsyncTinyB {
System.out.print("Found device: ");
printDevice(sensor);
- if (sensor.connect())
+ if ( HCIStatusCode.SUCCESS == sensor.connect() )
System.out.println("Sensor with the provided address connected");
else {
System.out.println("Could not connect device.");
diff --git a/examples/java/HelloTinyB.java b/examples/java/HelloTinyB.java
index 77435de6..b6709b7f 100644
--- a/examples/java/HelloTinyB.java
+++ b/examples/java/HelloTinyB.java
@@ -11,6 +11,7 @@ import org.tinyb.BluetoothFactory;
import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
+import org.tinyb.HCIStatusCode;
public class HelloTinyB {
static boolean running = true;
@@ -149,7 +150,7 @@ public class HelloTinyB {
System.out.print("Found device: ");
printDevice(sensor);
- if (sensor.connect())
+ if ( HCIStatusCode.SUCCESS == sensor.connect() )
System.out.println("Sensor with the provided address connected");
else {
System.out.println("Could not connect device.");
diff --git a/examples/java/Notification.java b/examples/java/Notification.java
index c39a0a9e..5a2f5a8e 100644
--- a/examples/java/Notification.java
+++ b/examples/java/Notification.java
@@ -34,6 +34,7 @@ import org.tinyb.BluetoothGattCharacteristic;
import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothNotification;
+import org.tinyb.HCIStatusCode;
class ValueNotification implements BluetoothNotification<byte[]> {
@@ -141,7 +142,7 @@ public class Notification {
System.out.print("Found device: ");
printDevice(sensor);
- if (sensor.connect())
+ if ( HCIStatusCode.SUCCESS == sensor.connect() )
System.out.println("Sensor with the provided address connected");
else {
System.out.println("Could not connect device.");
diff --git a/examples/java/ScannerTinyB00.java b/examples/java/ScannerTinyB00.java
index 7a45729a..e3b00648 100644
--- a/examples/java/ScannerTinyB00.java
+++ b/examples/java/ScannerTinyB00.java
@@ -37,6 +37,7 @@ import org.tinyb.BluetoothGattService;
import org.tinyb.BluetoothManager;
import org.tinyb.BluetoothNotification;
import org.tinyb.BluetoothUtils;
+import org.tinyb.HCIStatusCode;
public class ScannerTinyB00 {
static {
@@ -165,13 +166,14 @@ public class ScannerTinyB00 {
sensor.enableServicesResolvedNotifications(servicesResolvedNotification);
final long t2;
- if ( sensor.connect() ) {
+ final HCIStatusCode res;
+ if ( ( res = sensor.connect() ) == HCIStatusCode.SUCCESS ) {
t2 = System.currentTimeMillis();
- System.err.println("Sensor connected in "+(t2-t1)+" ms");
+ System.err.println("Sensor connect command in "+(t2-t1)+" ms");
System.err.println("Sensor connectedNotification: "+connectedNotification.getValue());
} else {
t2=0;
- System.out.println("Could not connect device.");
+ System.out.println("Connect command failed, res "+res);
System.exit(-1);
}
diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java
index d6385167..4dda480c 100644
--- a/examples/java/ScannerTinyB01.java
+++ b/examples/java/ScannerTinyB01.java
@@ -275,13 +275,14 @@ public class ScannerTinyB01 {
final long t2 = BluetoothUtils.getCurrentMilliseconds();
final long t3;
- if ( sensor.connect() ) {
+ HCIStatusCode res;
+ if ( ( res = sensor.connect() ) == HCIStatusCode.SUCCESS ) {
t3 = BluetoothUtils.getCurrentMilliseconds();
- System.err.println("Sensor connected: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
+ System.err.println("Sensor connect issued: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
System.err.println("Sensor connectedNotification: "+connectedNotification.getValue());
} else {
t3 = BluetoothUtils.getCurrentMilliseconds();
- System.out.println("Could not connect device: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
+ System.out.println("connect command failed, res "+res+": "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
// we tolerate the failed immediate connect, as it might happen at a later time
}
diff --git a/examples/java/ScannerTinyB02.java b/examples/java/ScannerTinyB02.java
index d02ba9e7..a62c9742 100644
--- a/examples/java/ScannerTinyB02.java
+++ b/examples/java/ScannerTinyB02.java
@@ -282,13 +282,14 @@ public class ScannerTinyB02 {
final long t2 = BluetoothUtils.getCurrentMilliseconds();
final long t3;
- if ( sensor.connect() ) {
+ HCIStatusCode res;
+ if ( (res = sensor.connect() ) == HCIStatusCode.SUCCESS ) {
t3 = BluetoothUtils.getCurrentMilliseconds();
- System.err.println("Sensor connected: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
+ System.err.println("Sensor connect issued: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
System.err.println("Sensor connectedNotification: "+connectedNotification.getValue());
} else {
t3 = BluetoothUtils.getCurrentMilliseconds();
- System.out.println("Could not connect device: "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
+ System.out.println("connect command failed, res "+res+": "+(t3-t2)+" ms, total "+(t3-t0)+" ms");
// we tolerate the failed immediate connect, as it might happen at a later time
}
diff --git a/examples/java/ScannerTinyB10.java b/examples/java/ScannerTinyB10.java
index 1ec6afc3..730376d9 100644
--- a/examples/java/ScannerTinyB10.java
+++ b/examples/java/ScannerTinyB10.java
@@ -184,12 +184,14 @@ public class ScannerTinyB10 {
private void connectDiscoveredDevice(final BluetoothDevice device) {
println("****** Connecting Device: Start " + device.toString());
device.getAdapter().stopDiscovery();
- boolean res = false;
+ HCIStatusCode res;
if( !USE_WHITELIST ) {
res = device.connect();
+ } else {
+ res = HCIStatusCode.SUCCESS;
}
- println("****** Connecting Device: End result "+res+" of " + device.toString());
- if( !USE_WHITELIST && 0 == devicesInProcessing.size() && !res ) {
+ println("****** Connecting Device Command, res "+res+": End result "+res+" of " + device.toString());
+ if( !USE_WHITELIST && 0 == devicesInProcessing.size() && HCIStatusCode.SUCCESS != res ) {
device.getAdapter().startDiscovery( true );
}
}