Skip to content

Commit

Permalink
[Sigma] Fix clearImageDB
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Nov 2, 2023
1 parent 0902a3f commit 19753f3
Showing 1 changed file with 13 additions and 9 deletions.
22 changes: 13 additions & 9 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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[] = []

Expand Down Expand Up @@ -1676,8 +1674,6 @@ export class TethrSigma extends TethrPTPUSB {
captureMode: number,
captureAmount = 1
): Promise<boolean> {
const {imageDBTail: captId} = await this.getCamCaptStatus()

const snapState = new Uint8Array([captureMode, captureAmount]).buffer

await this.device.sendData({
Expand All @@ -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
Expand All @@ -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),
})
}
}
Expand Down

0 comments on commit 19753f3

Please sign in to comment.