Skip to content

Commit

Permalink
[Sigma] make getLiveviewImage more robust
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Oct 24, 2023
1 parent 93c8750 commit e0f3d87
Showing 1 changed file with 16 additions and 4 deletions.
20 changes: 16 additions & 4 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,6 @@ const SigmaExpirationMs = 16
const SigmaCheckConfigIntervalMs = 1000

export class TethrSigma extends TethrPTPUSB {
#liveviewEnabled = false
#isCapturing = false

async open() {
Expand Down Expand Up @@ -1237,7 +1236,10 @@ export class TethrSigma extends TethrPTPUSB {
return {status: 'ok'}
}

async getLiveViewImage(): Promise<OperationResult<Blob>> {
#liveviewEnabled = false
#liveviewImageResult: OperationResult<Blob> = {status: 'busy'}

async #getLiveViewImage(): Promise<OperationResult<Blob>> {
const {resCode, data} = await this.device.receiveData({
label: 'SigmaFP GetViewFrame',
opcode: OpCodeSigma.GetViewFrame,
Expand All @@ -1249,8 +1251,18 @@ export class TethrSigma extends TethrPTPUSB {

// Might be quirky but somehow works
const jpegData = data.slice(10)
return (this.#liveviewImageResult = {
status: 'ok',
value: new Blob([jpegData], {type: 'image/jpg'}),
})
}

async getLiveViewImage(): Promise<OperationResult<Blob>> {
if (this.#liveviewEnabled) {
return this.#liveviewImageResult
}

return {status: 'ok', value: new Blob([jpegData], {type: 'image/jpg'})}
return await this.#getLiveViewImage()
}

#ctx: CanvasRenderingContext2D | null = null
Expand All @@ -1275,7 +1287,7 @@ export class TethrSigma extends TethrPTPUSB {
try {
if (this.#isCapturing) return

const lvImage = await this.getLiveViewImage()
const lvImage = await this.#getLiveViewImage()

if (lvImage.status !== 'ok') return

Expand Down

0 comments on commit e0f3d87

Please sign in to comment.