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
10
README.md
10
README.md
|
|
@ -12,10 +12,10 @@ De BLE-verbinding is beveiligd met **HMAC-SHA256 authenticatie** (application-le
|
||||||
|---|---|
|
|---|---|
|
||||||
| Relais 1 | Op **G1** |
|
| Relais 1 | Op **G1** |
|
||||||
| Relais 2 | Op **G2** |
|
| Relais 2 | Op **G2** |
|
||||||
| Touch sensor 1 | HS-S43A Digital Capacitive Switch Module op **G8** (actief HIGH) |
|
| Touch sensor 1 | HS-S43A Digital Capacitive Switch Module op **G8** (actief LOW) |
|
||||||
| Touch sensor 2 | HS-S43A Digital Capacitive Switch Module op **G6** (actief HIGH) |
|
| Touch sensor 2 | HS-S43A Digital Capacitive Switch Module op **G6** (actief LOW) |
|
||||||
| Knop | Op **G41** (active low) |
|
| Knop | Op **G41** (active low) |
|
||||||
| Status LED | Op **G46** (rood = geen verbinding, geel = verbinding <60s, uit = stabiel) |
|
| Status LED | Op **G35** (WS2812 RGB, rood = geen verbinding, geel = verbinding <60s, uit = stabiel) |
|
||||||
|
|
||||||
### Pinout
|
### Pinout
|
||||||
|
|
||||||
|
|
@ -25,7 +25,7 @@ G2 = RELAY2
|
||||||
G6 = TOUCH2 (INPUT)
|
G6 = TOUCH2 (INPUT)
|
||||||
G8 = TOUCH1 (INPUT)
|
G8 = TOUCH1 (INPUT)
|
||||||
G41 = BUTTON (INPUT, active low)
|
G41 = BUTTON (INPUT, active low)
|
||||||
G46 = LED (OUTPUT)
|
G35 = LED (WS2812 RGB, OUTPUT)
|
||||||
```
|
```
|
||||||
|
|
||||||
### Aansluiting
|
### Aansluiting
|
||||||
|
|
@ -39,7 +39,7 @@ Relais + → G1 / G2
|
||||||
Relais - → GND
|
Relais - → GND
|
||||||
```
|
```
|
||||||
|
|
||||||
> **HS-S43A touch sensor:** Digitale output (actief HIGH). Geen pullup nodig — de sensor geeft actief 0V of 3.3V.
|
> **HS-S43A touch sensor:** Digitale output (actief LOW — pin naar GND bij aanraking). Gebruik `INPUT_PULLUP` modus. De sensor trekt de pin actief laag bij detectie.
|
||||||
|
|
||||||
## LED-signalering
|
## LED-signalering
|
||||||
|
|
||||||
|
|
|
||||||
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.GCMParameterSpec
|
||||||
import javax.crypto.spec.SecretKeySpec
|
import javax.crypto.spec.SecretKeySpec
|
||||||
import kotlin.text.Charsets
|
import kotlin.text.Charsets
|
||||||
|
import kotlinx.coroutines.CompletableDeferred
|
||||||
|
|
||||||
class BleRelayManager(
|
class BleRelayManager(
|
||||||
private val context: Context,
|
private val context: Context,
|
||||||
|
|
@ -83,14 +84,6 @@ class BleRelayManager(
|
||||||
private var ecdhNotifyBuf: ByteArray = ByteArray(0)
|
private var ecdhNotifyBuf: ByteArray = ByteArray(0)
|
||||||
private var ecdhCccdPending = false
|
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 {
|
interface OtaNotifyCallback {
|
||||||
fun onOtaNotify(status: Int, seq: Int)
|
fun onOtaNotify(status: Int, seq: Int)
|
||||||
}
|
}
|
||||||
|
|
@ -290,6 +283,7 @@ class BleRelayManager(
|
||||||
private fun connectToDevice(device: android.bluetooth.BluetoothDevice) {
|
private fun connectToDevice(device: android.bluetooth.BluetoothDevice) {
|
||||||
handler.post { callbacks.onStatusChanged(BleStatus.Connecting) }
|
handler.post { callbacks.onStatusChanged(BleStatus.Connecting) }
|
||||||
Log.d(TAG, "Connecting to ${device.address}")
|
Log.d(TAG, "Connecting to ${device.address}")
|
||||||
|
bluetoothGatt?.close()
|
||||||
bluetoothGatt = device.connectGatt(context, false, gattCallback)
|
bluetoothGatt = device.connectGatt(context, false, gattCallback)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -500,10 +494,10 @@ class BleRelayManager(
|
||||||
|
|
||||||
Thread {
|
Thread {
|
||||||
val start = System.currentTimeMillis()
|
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)
|
Thread.sleep(50)
|
||||||
}
|
}
|
||||||
if (!ecdhDeferred!!.isDone()) {
|
if (!ecdhDeferred!!.isCompleted) {
|
||||||
Log.w(TAG, "ECDH: notify timeout")
|
Log.w(TAG, "ECDH: notify timeout")
|
||||||
handler.post {
|
handler.post {
|
||||||
callbacks.onStatusChanged(BleStatus.CommError)
|
callbacks.onStatusChanged(BleStatus.CommError)
|
||||||
|
|
|
||||||
|
|
@ -98,11 +98,7 @@ class OtaManager(
|
||||||
return@withContext false
|
return@withContext false
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
delay(500)
|
||||||
withTimeout(OTA_START_TIMEOUT_MS) {
|
|
||||||
while (true) { delay(100); ensureActive() }
|
|
||||||
}
|
|
||||||
} catch (_: kotlinx.coroutines.TimeoutCancellationException) {}
|
|
||||||
|
|
||||||
val totalChunks = (fw.size + chunkDataSize - 1) / chunkDataSize
|
val totalChunks = (fw.size + chunkDataSize - 1) / chunkDataSize
|
||||||
var seq = 0
|
var seq = 0
|
||||||
|
|
|
||||||
|
|
@ -66,10 +66,18 @@ mkdir -p "$RELEASE_DIR"
|
||||||
|
|
||||||
cp "$ANDROID_DIR/app/build/outputs/apk/release/app-release.apk" "$RELEASE_DIR/"
|
cp "$ANDROID_DIR/app/build/outputs/apk/release/app-release.apk" "$RELEASE_DIR/"
|
||||||
cp "$ANDROID_DIR/app/build/outputs/bundle/release/app-release.aab" "$RELEASE_DIR/"
|
cp "$ANDROID_DIR/app/build/outputs/bundle/release/app-release.aab" "$RELEASE_DIR/"
|
||||||
cp "$FIRMWARE_DIR/bootloader.bin" "$RELEASE_DIR/"
|
|
||||||
cp "$FIRMWARE_DIR/partitions.bin" "$RELEASE_DIR/"
|
# Server firmware
|
||||||
cp "$FIRMWARE_DIR/boot_app0.bin" "$RELEASE_DIR/"
|
cp "$FIRMWARE_DIR/server/bootloader.bin" "$RELEASE_DIR/server-bootloader.bin"
|
||||||
cp "$FIRMWARE_DIR/firmware.bin" "$RELEASE_DIR/"
|
cp "$FIRMWARE_DIR/server/partitions.bin" "$RELEASE_DIR/server-partitions.bin"
|
||||||
|
cp "$FIRMWARE_DIR/server/boot_app0.bin" "$RELEASE_DIR/server-boot_app0.bin"
|
||||||
|
cp "$FIRMWARE_DIR/server/firmware.bin" "$RELEASE_DIR/server-firmware.bin"
|
||||||
|
|
||||||
|
# Client firmware
|
||||||
|
cp "$FIRMWARE_DIR/client/bootloader.bin" "$RELEASE_DIR/client-bootloader.bin"
|
||||||
|
cp "$FIRMWARE_DIR/client/partitions.bin" "$RELEASE_DIR/client-partitions.bin"
|
||||||
|
cp "$FIRMWARE_DIR/client/boot_app0.bin" "$RELEASE_DIR/client-boot_app0.bin"
|
||||||
|
cp "$FIRMWARE_DIR/client/firmware.bin" "$RELEASE_DIR/client-firmware.bin"
|
||||||
|
|
||||||
log "Checksums..."
|
log "Checksums..."
|
||||||
cd "$RELEASE_DIR"
|
cd "$RELEASE_DIR"
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue