|
|
@ -198,13 +198,8 @@ class IConsole : ActiveDriver() { |
|
|
|
override fun onDisconnectedPeripheral(peripheral: BluetoothPeripheral, status: BluetoothCommandStatus) { |
|
|
|
if (peripheral.address == current?.address) { |
|
|
|
if (wantsConnection) { |
|
|
|
logger.info("Will try restarting in 10 seconds (disconnection)") |
|
|
|
runBlocking { |
|
|
|
updateBonus() |
|
|
|
output.emit(Stopped) |
|
|
|
delay(timeMillis = 10_000) |
|
|
|
connect(connectionString, output) |
|
|
|
} |
|
|
|
logger.warn("Will try restarting in 10 seconds (disconnection)") |
|
|
|
prepareReconnect(connectionString, output) |
|
|
|
} else { |
|
|
|
current = null |
|
|
|
output.emitBlocking(Disconnected) |
|
|
@ -217,13 +212,8 @@ class IConsole : ActiveDriver() { |
|
|
|
|
|
|
|
runBlocking { |
|
|
|
if (health > 1) { |
|
|
|
logger.info("Will try restarting in 10 seconds (connection failed)") |
|
|
|
runBlocking { |
|
|
|
updateBonus() |
|
|
|
output.emit(Stopped) |
|
|
|
delay(timeMillis = 10_000) |
|
|
|
connect(connectionString, output) |
|
|
|
} |
|
|
|
logger.warn("Will try restarting in 10 seconds (connection error)") |
|
|
|
prepareReconnect(connectionString, output) |
|
|
|
} else { |
|
|
|
output.emit(ErrorOccurred("Failure: $status")) |
|
|
|
output.emit(Disconnected) |
|
|
@ -336,7 +326,10 @@ class IConsole : ActiveDriver() { |
|
|
|
delay(pollDuration) |
|
|
|
} |
|
|
|
|
|
|
|
private fun updateBonus() { |
|
|
|
private fun prepareReconnect(connectionString: String, output: FlowBus<Event>) { |
|
|
|
running = false |
|
|
|
connected = false |
|
|
|
|
|
|
|
bonusLevel = lastLevel |
|
|
|
bonusTime += lastTime |
|
|
|
bonusCals += lastCals |
|
|
@ -345,6 +338,12 @@ class IConsole : ActiveDriver() { |
|
|
|
lastTime = 0 |
|
|
|
lastCals = 0 |
|
|
|
lastMeters = 0 |
|
|
|
|
|
|
|
runBlocking { |
|
|
|
output.emit(Stopped) |
|
|
|
delay(timeMillis = 10_000) |
|
|
|
connect(connectionString, output) |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
companion object { |
|
|
|