From 1b51e75ff0f14ed86d42746f9081824a18678f5b Mon Sep 17 00:00:00 2001 From: a2nr Date: Fri, 17 Jul 2026 08:03:42 +0700 Subject: [PATCH] feat: add HardwareDeployer interface, BLEHardwareDeployer implements it --- frontend/src/lib/services/ble-deployer.ts | 7 ++++++- frontend/src/lib/types/deployer.ts | 20 ++++++++++++++++++++ 2 files changed, 26 insertions(+), 1 deletion(-) diff --git a/frontend/src/lib/services/ble-deployer.ts b/frontend/src/lib/services/ble-deployer.ts index 064048b..a53eec0 100644 --- a/frontend/src/lib/services/ble-deployer.ts +++ b/frontend/src/lib/services/ble-deployer.ts @@ -4,6 +4,7 @@ import { BLE_CHAR_SERIAL_UUID, CMD_INIT, CMD_DATA, CMD_END, CMD_ACK, CMD_ERR, CMD_SET_BAUD, CMD_RESET, CHUNK_SIZE, BLE_TIMEOUT_MS, END_TIMEOUT_MS, END_ACK_INDEX, INIT_ACK_INDEX, MAX_RETRIES, + type HardwareDeployer, type DeployProgress, type BLEACKResponse } from '$types/deployer'; @@ -12,7 +13,7 @@ function logAck(tag: string, msg: string) { console.log(`[BLE-ACK#${++_ackNotificationCount}] ${tag}: ${msg}`); } -export class BLEHardwareDeployer { +export class BLEHardwareDeployer implements HardwareDeployer { private server: BluetoothRemoteGATTServer | null = null; private service: BluetoothRemoteGATTService | null = null; private flashingChar: BluetoothRemoteGATTCharacteristic | null = null; @@ -46,6 +47,10 @@ export class BLEHardwareDeployer { return this.server?.connected ?? false; } + get deviceName(): string | null { + return this.device?.name ?? null; + } + private withTimeout(promise: Promise, ms: number, label: string): Promise { return Promise.race([ promise, diff --git a/frontend/src/lib/types/deployer.ts b/frontend/src/lib/types/deployer.ts index 59dc918..26f0142 100644 --- a/frontend/src/lib/types/deployer.ts +++ b/frontend/src/lib/types/deployer.ts @@ -16,6 +16,26 @@ export interface DeployProgress { bytesPerSecond?: number; } +/** + * Abstraction untuk hardware deployer (BLE atau USB). + * DeployTab menggunakan interface ini, switching instance berdasarkan mode. + */ +export interface HardwareDeployer { + checkSupport(): boolean; + readonly isConnected: boolean; + readonly deviceName: string | null; + pair(): Promise; + deployHex(hexContent: string, onProgress: (p: DeployProgress) => void): Promise; + deployBinary?(base64Binary: string, onProgress: (p: DeployProgress) => void): Promise; + startSerialMonitor(onData: (text: string) => void): Promise; + stopSerialMonitor(): void; + sendSerialInput(text: string): Promise; + setBaudRate(baud: number): Promise; + resetArduino(): Promise; + disconnect(): void; + onDisconnected(cb: () => void): void; +} + export interface BLEACKResponse { command: number; index: number;