Skip to content

Commit b2d10c5

Browse files
attempt at updating disconnection method
1 parent ef185be commit b2d10c5

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

kernel/src/services/DeviceService.ts

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -98,14 +98,15 @@ export class DeviceService {
9898
});
9999
document.dispatchEvent(event)
100100

101-
// Contiuously check the port status every 2 seconds to update the connection status/card
102-
setInterval(() => {
103-
console.log('[DeviceService]: Checking port status...');
104-
if (this.port && !this.port.readable && !this.port.writable) {
105-
console.log('[DeviceService]: Port is not readable or writable, disconnecting...');
106-
this.disconnect();
107-
}
108-
}, 2000);
101+
// Listen for physical disconnect event
102+
this.port.addEventListener('disconnect', () => {
103+
console.log('[DeviceService]: Serial port physically disconnected.');
104+
this.isDeviceConnected = false;
105+
const event = new CustomEvent("deviceDisconnected", {
106+
detail: { msg: "Not connected" }
107+
});
108+
document.dispatchEvent(event);
109+
});
109110
}
110111

111112
async disconnect(): Promise<void> {

0 commit comments

Comments
 (0)