diff options
author | Trygve Laugstøl <trygvis@inamo.no> | 2014-12-31 16:31:49 +0100 |
---|---|---|
committer | Trygve Laugstøl <trygvis@inamo.no> | 2014-12-31 16:31:49 +0100 |
commit | ed559834ccddafa955df5b528f08fba964e57699 (patch) | |
tree | 3fcbcedaf49232de5c8fe8b6f67bd2fd8c52afa9 /app/src/main/java/io/trygvis/android/bt/BtDevice.java | |
download | io.trygvis.soilmoisture-android-ed559834ccddafa955df5b528f08fba964e57699.tar.gz io.trygvis.soilmoisture-android-ed559834ccddafa955df5b528f08fba964e57699.tar.bz2 io.trygvis.soilmoisture-android-ed559834ccddafa955df5b528f08fba964e57699.tar.xz io.trygvis.soilmoisture-android-ed559834ccddafa955df5b528f08fba964e57699.zip |
o Initial import of Soil Moisture app.
Diffstat (limited to 'app/src/main/java/io/trygvis/android/bt/BtDevice.java')
-rw-r--r-- | app/src/main/java/io/trygvis/android/bt/BtDevice.java | 68 |
1 files changed, 68 insertions, 0 deletions
diff --git a/app/src/main/java/io/trygvis/android/bt/BtDevice.java b/app/src/main/java/io/trygvis/android/bt/BtDevice.java new file mode 100644 index 0000000..ba10d2d --- /dev/null +++ b/app/src/main/java/io/trygvis/android/bt/BtDevice.java @@ -0,0 +1,68 @@ +package io.trygvis.android.bt; + +import android.bluetooth.BluetoothDevice; +import android.util.Log; + +public class BtDevice<A> { + private final static String TAG = BtDevice.class.getSimpleName(); + + private final DefaultBtService btService; + private final BluetoothDevice bluetoothDevice; + private Integer rssi; + private BtScanResult scanResult; + private A tag; + + private boolean seenNow; + + private BtDeviceListener l = null; + + private BtDeviceListener listener = new BtDeviceListener() { + }; + + public BtDevice(DefaultBtService btService, BluetoothDevice bluetoothDevice, A tag, Integer rssi, BtScanResult scanResult) { + this.btService = btService; + this.bluetoothDevice = bluetoothDevice; + this.tag = tag; + this.rssi = rssi; + this.scanResult = scanResult; + } + + public void addListener(BtDeviceListener listener) { + this.l = listener; + } + + public A getTag() { + return tag; + } + + public void setTag(A tag) { + this.tag = tag; + } + + public String getAddress() { + return bluetoothDevice.getAddress(); + } + + public String getName() { + return bluetoothDevice.getName(); + } + + public int getRssi() { + return rssi; + } + + public boolean connect(BtActionExecutor executor) { + Log.i(TAG, "connect(), address=" + bluetoothDevice.getAddress() + ", queue=" + executor); + bluetoothDevice.connectGatt(btService, false, executor.asCallback()); + return true; + } + + public BtScanResult getScanResult() { + return scanResult; + } + + @Override + public String toString() { + return "BtDevice{address=" + bluetoothDevice.getAddress() + '}'; + } +} |