diff options
author | Sven Gothel <[email protected]> | 2020-10-16 18:29:47 +0200 |
---|---|---|
committer | Sven Gothel <[email protected]> | 2020-10-16 18:29:47 +0200 |
commit | 09839e0e62ed81cd2c1ac5421d0acc0a85b09d5e (patch) | |
tree | f90527780e3a30224a00e0a634a5ee6444505e78 /examples | |
parent | cfcb3b8f1112e564e9c8bb813fb027d3e30e2b22 (diff) |
Cleanup warnings
Diffstat (limited to 'examples')
-rw-r--r-- | examples/java/AsyncTinyB.java | 4 | ||||
-rw-r--r-- | examples/java/CMakeLists.txt | 1 | ||||
-rw-r--r-- | examples/java/HelloTinyB.java | 2 | ||||
-rw-r--r-- | examples/java/Notification.java | 6 | ||||
-rw-r--r-- | examples/java/ScannerTinyB01.java | 2 | ||||
-rw-r--r-- | examples/java/ScannerTinyB02.java | 73 |
6 files changed, 23 insertions, 65 deletions
diff --git a/examples/java/AsyncTinyB.java b/examples/java/AsyncTinyB.java index cb9a305c..ed0d49be 100644 --- a/examples/java/AsyncTinyB.java +++ b/examples/java/AsyncTinyB.java @@ -12,7 +12,7 @@ import java.lang.reflect.InvocationTargetException; import java.util.concurrent.TimeUnit; public class AsyncTinyB { - private static final float SCALE_LSB = 0.03125f; + // private static final float SCALE_LSB = 0.03125f; static boolean running = true; static void printDevice(final BluetoothDevice device) { @@ -61,6 +61,7 @@ public class AsyncTinyB { * The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize * discovery we can call startDiscovery, which will put the default adapter in discovery mode. */ + @SuppressWarnings("deprecation") final boolean discoveryStarted = manager.startDiscovery(); System.out.println("The discovery started: " + (discoveryStarted ? "true" : "false")); @@ -99,6 +100,7 @@ public class AsyncTinyB { final Condition cv = lock.newCondition(); Runtime.getRuntime().addShutdownHook(new Thread() { + @Override public void run() { running = false; lock.lock(); diff --git a/examples/java/CMakeLists.txt b/examples/java/CMakeLists.txt index d7a374aa..e6cee8b2 100644 --- a/examples/java/CMakeLists.txt +++ b/examples/java/CMakeLists.txt @@ -1,3 +1,4 @@ +# examples/java/CMakeLists.txt find_package(Java REQUIRED) include(UseJava) diff --git a/examples/java/HelloTinyB.java b/examples/java/HelloTinyB.java index 6008e721..6ea6a493 100644 --- a/examples/java/HelloTinyB.java +++ b/examples/java/HelloTinyB.java @@ -128,6 +128,7 @@ public class HelloTinyB { * The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize * discovery we can call startDiscovery, which will put the default adapter in discovery mode. */ + @SuppressWarnings("deprecation") final boolean discoveryStarted = manager.startDiscovery(); System.out.println("The discovery started: " + (discoveryStarted ? "true" : "false")); @@ -161,6 +162,7 @@ public class HelloTinyB { final Condition cv = lock.newCondition(); Runtime.getRuntime().addShutdownHook(new Thread() { + @Override public void run() { running = false; lock.lock(); diff --git a/examples/java/Notification.java b/examples/java/Notification.java index 68e2a1b1..8d54017d 100644 --- a/examples/java/Notification.java +++ b/examples/java/Notification.java @@ -38,6 +38,7 @@ import org.tinyb.HCIStatusCode; class ValueNotification implements BluetoothNotification<byte[]> { + @Override public void run(final byte[] tempRaw) { System.out.print("Temp raw = {"); for (final byte b : tempRaw) { @@ -66,6 +67,7 @@ class ValueNotification implements BluetoothNotification<byte[]> { class ConnectedNotification implements BluetoothNotification<Boolean> { + @Override public void run(final Boolean connected) { System.out.println("Connected"); } @@ -73,7 +75,7 @@ class ConnectedNotification implements BluetoothNotification<Boolean> { } public class Notification { - private static final float SCALE_LSB = 0.03125f; + // private static final float SCALE_LSB = 0.03125f; static boolean running = true; static void printDevice(final BluetoothDevice device) { @@ -122,6 +124,7 @@ public class Notification { * The manager will try to initialize a BluetoothAdapter if any adapter is present in the system. To initialize * discovery we can call startDiscovery, which will put the default adapter in discovery mode. */ + @SuppressWarnings("deprecation") final boolean discoveryStarted = manager.startDiscovery(); System.out.println("The discovery started: " + (discoveryStarted ? "true" : "false")); @@ -158,6 +161,7 @@ public class Notification { final Condition cv = lock.newCondition(); Runtime.getRuntime().addShutdownHook(new Thread() { + @Override public void run() { running = false; lock.lock(); diff --git a/examples/java/ScannerTinyB01.java b/examples/java/ScannerTinyB01.java index d2a03ffb..cfd45ec9 100644 --- a/examples/java/ScannerTinyB01.java +++ b/examples/java/ScannerTinyB01.java @@ -332,7 +332,7 @@ public class ScannerTinyB01 { final BluetoothGattCharacteristic char2 = (BluetoothGattCharacteristic) manager.find(BluetoothType.GATT_CHARACTERISTIC, null, characteristic, sensor, 1000); System.err.println("Char UUID "+characteristic); - //System.err.println(" over manager: "+char0); + System.err.println(" over manager: "+char0); System.err.println(" over adapter: "+char1); System.err.println(" over device : "+char2); } diff --git a/examples/java/ScannerTinyB02.java b/examples/java/ScannerTinyB02.java index 75245920..815d5876 100644 --- a/examples/java/ScannerTinyB02.java +++ b/examples/java/ScannerTinyB02.java @@ -316,70 +316,19 @@ public class ScannerTinyB02 { // System.exit(-1); } - if( true ) { - final BluetoothDevice _sensor = sensor; - final Thread lalaTask = new Thread( new Runnable() { - @Override - public void run() { - _sensor.disconnect(); - } - }, "lala"); - lalaTask.setDaemon(true); // detach thread - lalaTask.start(); - - // Thread.sleep(60); - // sensor.connect(); - continue; - } else { - final List<BluetoothGattService> primServices = sensor.getServices(); - if ( null == primServices || primServices.isEmpty() ) { - System.err.println("No BluetoothGattService found!"); - } else { - final GATTCharacteristicListener myCharacteristicListener = new GATTCharacteristicListener(null) { - @Override - public void notificationReceived(final BluetoothGattCharacteristic charDecl, - final byte[] value, final long timestamp) { - System.err.println("****** GATT notificationReceived: "+charDecl+ - ", value "+BluetoothUtils.bytesHexString(value, true, true)); - } - - @Override - public void indicationReceived(final BluetoothGattCharacteristic charDecl, - final byte[] value, final long timestamp, final boolean confirmationSent) { - System.err.println("****** GATT indicationReceived: "+charDecl+ - ", value "+BluetoothUtils.bytesHexString(value, true, true)); - } - }; - final boolean addedCharacteristicListenerRes = - BluetoothGattService.addCharacteristicListenerToAll(sensor, primServices, myCharacteristicListener); - System.err.println("Added GATTCharacteristicListener: "+addedCharacteristicListenerRes); - - int i=0, j=0; - for(final Iterator<BluetoothGattService> srvIter = primServices.iterator(); srvIter.hasNext(); i++) { - final BluetoothGattService primService = srvIter.next(); - System.err.printf(" [%02d] Service %s\n", i, primService.toString()); - System.err.printf(" [%02d] Service Characteristics\n", i); - final List<BluetoothGattCharacteristic> serviceCharacteristics = primService.getCharacteristics(); - for(final Iterator<BluetoothGattCharacteristic> charIter = serviceCharacteristics.iterator(); charIter.hasNext(); j++) { - final BluetoothGattCharacteristic serviceChar = charIter.next(); - System.err.printf(" [%02d.%02d] Decla: %s\n", i, j, serviceChar.toString()); - final List<String> properties = Arrays.asList(serviceChar.getFlags()); - if( properties.contains("read") ) { - final byte[] value = serviceChar.readValue(); - final String svalue = BluetoothUtils.decodeUTF8String(value, 0, value.length); - System.err.printf(" [%02d.%02d] Value: %s ('%s')\n", - i, j, BluetoothUtils.bytesHexString(value, true, true), svalue); - } - } + final BluetoothDevice _sensor = sensor; + final Thread lalaTask = new Thread( new Runnable() { + @Override + public void run() { + _sensor.disconnect(); } - Thread.sleep(1000); // FIXME: Wait for notifications + }, "lala"); + lalaTask.setDaemon(true); // detach thread + lalaTask.start(); - final boolean remRes = BluetoothGattService.removeCharacteristicListenerFromAll(sensor, primServices, myCharacteristicListener); - System.err.println("Removed GATTCharacteristicListener: "+remRes); - } - sensor.disconnect(); - System.err.println("ScannerTinyB01 04 ...: "+adapter); - } + // Thread.sleep(60); + // sensor.connect(); + continue; } } catch (final Throwable t) { System.err.println("Caught: "+t.getMessage()); |