From 19753f3eec1b00d8c3aec263e8e169e080029d1f Mon Sep 17 00:00:00 2001 From: Baku Hashimoto Date: Thu, 2 Nov 2023 14:20:19 +0900 Subject: [PATCH] [Sigma] Fix clearImageDB --- src/TethrPTPUSB/TethrSigma.ts | 22 +++++++++++++--------- 1 file changed, 13 insertions(+), 9 deletions(-) diff --git a/src/TethrPTPUSB/TethrSigma.ts b/src/TethrPTPUSB/TethrSigma.ts index dc71444..acb129f 100644 --- a/src/TethrPTPUSB/TethrSigma.ts +++ b/src/TethrPTPUSB/TethrSigma.ts @@ -1161,14 +1161,12 @@ export class TethrSigma extends TethrPTPUSB { this.#isCapturing = true - await this.clearImageDBAll() - - const captureId = await this.executeSnapCommand( + const succeedSnapCommand = await this.executeSnapCommand( SnapCaptureMode.NonAFCapture, 1 ) - if (captureId === null) return {status: 'general error'} + if (!succeedSnapCommand) return {status: 'general error'} const picts: TethrObject[] = [] @@ -1676,8 +1674,6 @@ export class TethrSigma extends TethrPTPUSB { captureMode: number, captureAmount = 1 ): Promise { - const {imageDBTail: captId} = await this.getCamCaptStatus() - const snapState = new Uint8Array([captureMode, captureAmount]).buffer await this.device.sendData({ @@ -1686,8 +1682,10 @@ export class TethrSigma extends TethrPTPUSB { data: this.encodeParameter(snapState), }) + const {imageDBHead} = await this.getCamCaptStatus() + for (let restTries = 50; restTries > 0; restTries--) { - const {status} = await this.getCamCaptStatus(captId) + const {status} = await this.getCamCaptStatus(imageDBHead) const isFailure = (status & 0xf000) === 0x6000 if (isFailure) return false @@ -1706,12 +1704,18 @@ export class TethrSigma extends TethrPTPUSB { private async clearImageDBAll() { const {imageDBHead, imageDBTail} = await this.getCamCaptStatus() - for (let id = imageDBHead; id < imageDBTail; id++) { + const imageDBCount = 29 + + for ( + let id = imageDBHead; + id !== imageDBTail; + id = (id + 1) % imageDBCount + ) { await this.device.sendData({ label: 'SigmaFP ClearImageDBSingle', opcode: OpCodeSigma.ClearImageDBSingle, parameters: [id], - data: new ArrayBuffer(8), + data: new ArrayBuffer(16), }) } }