We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e8f77e2 commit 20f9e8bCopy full SHA for 20f9e8b
1 file changed
Transmission/src/main/java/org/operatorfoundation/transmission/SerialConnectionFactory.kt
@@ -231,6 +231,19 @@ class SerialConnectionFactory(context: Context)
231
_connectionState.value = ConnectionState.Disconnected
232
}
233
234
+ /**
235
+ * Closes the current connection and resets state to Disconnected.
236
+ * Does not cancel the connection scope, so reconnection remains possible.
237
+ * Call this when a USB device detach event is received.
238
+ */
239
+ fun onDeviceDetached() {
240
+ val currentState = _connectionState.value
241
+ if (currentState is ConnectionState.Connected) {
242
+ currentState.connection.close()
243
+ }
244
+ _connectionState.value = ConnectionState.Disconnected
245
246
+
247
/**
248
* Creates the actual SerialConnection instance from a permitted USB device.
249
*
0 commit comments