expand interface options beyond BLE

This commit is contained in:
andrekir 2022-05-16 23:32:49 -03:00
parent 5fb2be0591
commit 841ea515ba
5 changed files with 127 additions and 168 deletions

View file

@ -50,8 +50,13 @@ class BluetoothRepository @Inject constructor(
}
}
/** @return true for a valid Bluetooth address, false otherwise */
fun isValid(bleAddress: String): Boolean {
return BluetoothAdapter.checkBluetoothAddress(bleAddress)
}
fun getRemoteDevice(address: String): BluetoothDevice? {
return bluetoothAdapterLazy.get()?.getRemoteDevice(address)
return bluetoothAdapterLazy.get()?.takeIf { isValid(address) }?.getRemoteDevice(address)
}
fun getBluetoothLeScanner(): BluetoothLeScanner? {

View file

@ -77,7 +77,7 @@ class RadioInterfaceService @Inject constructor(
bluetoothRepository.state.collect { state ->
if (state.enabled) {
startInterface()
} else {
} else if (radioIf is BluetoothInterface) {
stopInterface()
}
}
@ -281,7 +281,7 @@ class RadioInterfaceService @Inject constructor(
debug("Setting bonded device to ${address.anonymize}")
getPrefs(context).edit(commit = true) {
getPrefs(context).edit {
if (address == null)
this.remove(DEVADDR_KEY)
else

View file

@ -59,9 +59,6 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
}
override fun connect() {
//here you must put your computer's IP address.
//here you must put your computer's IP address.
// No need to keep a reference to this thread - it will exit when we close inStream
thread(start = true, isDaemon = true, name = "TCP reader") {
try {
@ -90,6 +87,7 @@ class TCPInterface(service: RadioInterfaceService, private val address: String)
} else
readChar(c.toByte())
} catch (ex: SocketTimeoutException) {
errormsg("SocketTimeoutException in TCP reader: $ex")
// Ignore and start another read
}
}