feat(ble-deployer): add resetArduino() method for DTR pulse

This commit is contained in:
a2nr 2026-07-05 17:46:32 +07:00
parent a18d3f660c
commit c6c6daecbf
1 changed files with 17 additions and 1 deletions

View File

@ -2,7 +2,7 @@ import {
BLE_SERVICE_UUID,
BLE_CHAR_FLASHING_UUID,
BLE_CHAR_SERIAL_UUID,
CMD_INIT, CMD_DATA, CMD_END, CMD_ACK, CMD_ERR, CMD_SET_BAUD,
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 DeployProgress, type BLEACKResponse
} from '$types/deployer';
@ -533,6 +533,22 @@ export class BLEHardwareDeployer {
await this.serialChar.writeValueWithoutResponse(payload);
}
async resetArduino(): Promise<void> {
if (!this.serialChar) throw new Error('Belum terhubung ke perangkat');
console.log('[BLE-SERIAL] resetArduino: sending DTR pulse command...');
const payload = new Uint8Array(1);
payload[0] = CMD_RESET;
await this.serialChar.writeValueWithoutResponse(payload);
// Wait for firmware to complete DTR pulse (250ms delay via firmware DTR pulse timing)
await new Promise(resolve => setTimeout(resolve, 250));
console.log('[BLE-SERIAL] resetArduino: DTR pulse complete');
}
stopSerialMonitor(): void {
console.log('[BLE-SERIAL] stopSerialMonitor');
if (this.serialChar && this._onSerialNotification) {