Skip to content

Commit

Permalink
Adjust range for valid RSSI filter to -127..20
Browse files Browse the repository at this point in the history
  • Loading branch information
weliem committed Dec 30, 2021
1 parent d9285c9 commit 331b5f4
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -373,13 +373,25 @@ public void stopScan() {
stopScanning();
}

public void setRssiThreshold(final short threshold) {
if (threshold > 20 || threshold < -200) {
throw new IllegalArgumentException("RSSI threshold value outside range (-200 to +20");
/**
* Set the RSSI threshold while scanning.
*
* The new value will be used when a new scan is started
*
* @param threshold must be between -127 and +20
*/
public void setRssiThreshold(final int threshold) {
if (threshold > 20 || threshold < -127) {
throw new IllegalArgumentException("RSSI threshold value outside range (-127 to +20");
}
this.discoveryRssiThreshold = threshold;
this.discoveryRssiThreshold = (short) threshold;
}

/**
* Get the currently set RSSI threshold for scanning
*
* @return the current stored RSSI threshold
*/
public short getRssiThreshold() {
return this.discoveryRssiThreshold;
}
Expand Down
1 change: 1 addition & 0 deletions src/main/java/testapp/BluetoothHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,7 @@ public BluetoothHandler() {
logger.info("initializing BluetoothCentral");
central = new BluetoothCentralManager(bluetoothCentralManagerCallback, new HashSet<>(Collections.singletonList(SCANOPTION_NO_NULL_NAMES)));
central.setPinCodeForPeripheral("B0:49:5F:01:20:8F", "635227");
central.setRssiThreshold(-120);
startScanning();
}

Expand Down

0 comments on commit 331b5f4

Please sign in to comment.