Skip to content

Commit

Permalink
[Sigma] Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Oct 4, 2023
1 parent b98bfa7 commit 01e9b01
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 17 deletions.
5 changes: 4 additions & 1 deletion src/TethrPTPUSB/TethrPTPUSB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,10 @@ export class TethrPTPUSB extends Tethr {
EventCode.DevicePropChanged,
this.onDevicePropChanged
)
this.device.on('disconnect', () => this.emit('disconnect'))
this.device.on('disconnect', () => {
this._opened = false
this.emit('disconnect')
})

window.addEventListener('beforeunload', async () => {
await this.close()
Expand Down
37 changes: 21 additions & 16 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -132,9 +132,8 @@ const SigmaExpirationMs = 16
const SigmaCheckConfigIntervalMs = 1000

export class TethrSigma extends TethrPTPUSB {
private liveviewEnabled = false
private isCapturing = false
private checkPropChangedTimerId!: ReturnType<typeof setInterval>
#liveviewEnabled = false
#isCapturing = false

async open() {
await super.open()
Expand All @@ -151,16 +150,22 @@ export class TethrSigma extends TethrPTPUSB {
firmwareVersion: {tag: 3, type: IFDType.Ascii},
communiationVersion: {tag: 5, type: IFDType.Float},
})
this.checkPropChangedTimerId = setInterval(() => {
if (this.isCapturing) return
this.checkConfigChanged()
}, SigmaCheckConfigIntervalMs)

const checkPropChangedInterval = () => {
if (!this.opened) return

if (!this.#isCapturing) {
this.checkConfigChanged()
}

setTimeout(checkPropChangedInterval, SigmaCheckConfigIntervalMs)
}

checkPropChangedInterval()
}

async close(): Promise<void> {
await this.stopLiveview()
clearInterval(this.checkPropChangedTimerId)

await super.close()
}

Expand Down Expand Up @@ -800,7 +805,7 @@ export class TethrSigma extends TethrPTPUSB {
async getLiveviewEnabledDesc(): Promise<ConfigDesc<boolean>> {
return {
writable: false,
value: this.liveviewEnabled,
value: this.#liveviewEnabled,
}
}

Expand Down Expand Up @@ -959,7 +964,7 @@ export class TethrSigma extends TethrPTPUSB {
async takePhoto({doDownload = true}: TakePhotoOption = {}): Promise<
OperationResult<TethrObject[]>
> {
this.isCapturing = true
this.#isCapturing = true

const captureId = await this.executeSnapCommand(
SnapCaptureMode.NonAFCapture,
Expand Down Expand Up @@ -1011,7 +1016,7 @@ export class TethrSigma extends TethrPTPUSB {

await this.clearImageDBAll()

this.isCapturing = false
this.#isCapturing = false

return {status: 'ok', value: picts}
}
Expand Down Expand Up @@ -1056,14 +1061,14 @@ export class TethrSigma extends TethrPTPUSB {
const canvas = this.#ctx.canvas
const ctx = this.#ctx

this.liveviewEnabled = true
this.#liveviewEnabled = true
this.emit('liveviewEnabledChanged', await this.getDesc('liveviewEnabled'))

const updateFrame = async () => {
if (!this.liveviewEnabled) return
if (!this.#liveviewEnabled || !this.opened) return

try {
if (this.isCapturing) return
if (this.#isCapturing) return

const lvImage = await this.getLiveViewImage()

Expand Down Expand Up @@ -1093,7 +1098,7 @@ export class TethrSigma extends TethrPTPUSB {
}

async stopLiveview(): Promise<OperationResult> {
this.liveviewEnabled = false
this.#liveviewEnabled = false
this.emit('liveviewStreamUpdate', null)
this.emit('liveviewEnabledChanged', await this.getDesc('liveviewEnabled'))

Expand Down

0 comments on commit 01e9b01

Please sign in to comment.