fix: critical issues from code review
All checks were successful
CI / build (pull_request) Successful in 1m20s
All checks were successful
CI / build (pull_request) Successful in 1m20s
- Fix README touch sensor docs (active LOW, INPUT_PULLUP) - Fix README LED pin (G46 -> G35 WS2812) - Fix release.sh to copy server/ and client/ firmware - Remove stale firmware.bin from root assets - Reduce OTA START wait from 10s to 500ms - Close bluetoothGatt before new connection - Use kotlinx.coroutines.CompletableDeferred
This commit is contained in:
parent
e03067c5f4
commit
64ade7ff10
6 changed files with 22 additions and 24 deletions
Binary file not shown.
Binary file not shown.
|
|
@ -32,6 +32,7 @@ import javax.crypto.Mac
|
|||
import javax.crypto.spec.GCMParameterSpec
|
||||
import javax.crypto.spec.SecretKeySpec
|
||||
import kotlin.text.Charsets
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
|
||||
class BleRelayManager(
|
||||
private val context: Context,
|
||||
|
|
@ -83,14 +84,6 @@ class BleRelayManager(
|
|||
private var ecdhNotifyBuf: ByteArray = ByteArray(0)
|
||||
private var ecdhCccdPending = false
|
||||
|
||||
private class CompletableDeferred<T> {
|
||||
private var result: T? = null
|
||||
private var completed = false
|
||||
@Synchronized fun complete(value: T) { result = value; completed = true }
|
||||
@Synchronized fun isDone(): Boolean = completed
|
||||
@Synchronized fun get(): T? = result
|
||||
}
|
||||
|
||||
interface OtaNotifyCallback {
|
||||
fun onOtaNotify(status: Int, seq: Int)
|
||||
}
|
||||
|
|
@ -290,6 +283,7 @@ class BleRelayManager(
|
|||
private fun connectToDevice(device: android.bluetooth.BluetoothDevice) {
|
||||
handler.post { callbacks.onStatusChanged(BleStatus.Connecting) }
|
||||
Log.d(TAG, "Connecting to ${device.address}")
|
||||
bluetoothGatt?.close()
|
||||
bluetoothGatt = device.connectGatt(context, false, gattCallback)
|
||||
}
|
||||
|
||||
|
|
@ -500,10 +494,10 @@ class BleRelayManager(
|
|||
|
||||
Thread {
|
||||
val start = System.currentTimeMillis()
|
||||
while (!ecdhDeferred!!.isDone() && System.currentTimeMillis() - start < ECDH_TIMEOUT_MS) {
|
||||
while (!ecdhDeferred!!.isCompleted && System.currentTimeMillis() - start < ECDH_TIMEOUT_MS) {
|
||||
Thread.sleep(50)
|
||||
}
|
||||
if (!ecdhDeferred!!.isDone()) {
|
||||
if (!ecdhDeferred!!.isCompleted) {
|
||||
Log.w(TAG, "ECDH: notify timeout")
|
||||
handler.post {
|
||||
callbacks.onStatusChanged(BleStatus.CommError)
|
||||
|
|
|
|||
|
|
@ -98,11 +98,7 @@ class OtaManager(
|
|||
return@withContext false
|
||||
}
|
||||
|
||||
try {
|
||||
withTimeout(OTA_START_TIMEOUT_MS) {
|
||||
while (true) { delay(100); ensureActive() }
|
||||
}
|
||||
} catch (_: kotlinx.coroutines.TimeoutCancellationException) {}
|
||||
delay(500)
|
||||
|
||||
val totalChunks = (fw.size + chunkDataSize - 1) / chunkDataSize
|
||||
var seq = 0
|
||||
|
|
|
|||
Loading…
Reference in a new issue