From 92653778dc89b8155cdd7a400730d9f355c4661c Mon Sep 17 00:00:00 2001 From: Baku Hashimoto Date: Mon, 10 Jun 2024 13:02:01 +0900 Subject: [PATCH] Fix types for ExposureComp --- src/Tethr.ts | 2 +- src/TethrPTPUSB/TethrPTPUSB.ts | 7 ++++--- src/TethrPTPUSB/TethrPanasonic.ts | 9 +++++---- src/TethrPTPUSB/TethrSigma.ts | 7 ++++--- 4 files changed, 14 insertions(+), 11 deletions(-) diff --git a/src/Tethr.ts b/src/Tethr.ts index 2934bfe..77b2f92 100644 --- a/src/Tethr.ts +++ b/src/Tethr.ts @@ -428,7 +428,7 @@ export abstract class Tethr async getExposureComp() { return (await this.getExposureCompDesc()).value } - async getExposureCompDesc(): Promise> { + async getExposureCompDesc(): Promise> { return UnsupportedConfigDesc } diff --git a/src/TethrPTPUSB/TethrPTPUSB.ts b/src/TethrPTPUSB/TethrPTPUSB.ts index f4bf0c3..208f54d 100644 --- a/src/TethrPTPUSB/TethrPTPUSB.ts +++ b/src/TethrPTPUSB/TethrPTPUSB.ts @@ -4,6 +4,7 @@ import { Aperture, BatteryLevel, DriveMode, + ExposureComp, ExposureMode, ISO, WhiteBalance, @@ -249,9 +250,9 @@ export class TethrPTPUSB extends Tethr { break } - if (integer === 0) return `${sign}${fraction}` - if (fraction === '') return `${sign}${integer}` - return `${sign}${integer} ${fraction}` + if (integer === 0) return `${sign}${fraction}` as ExposureComp + if (fraction === '') return `${sign}${integer}` as ExposureComp + return `${sign}${integer} ${fraction}` as ExposureComp }, }) } diff --git a/src/TethrPTPUSB/TethrPanasonic.ts b/src/TethrPTPUSB/TethrPanasonic.ts index 8f0bb6d..6cbde60 100644 --- a/src/TethrPTPUSB/TethrPanasonic.ts +++ b/src/TethrPTPUSB/TethrPanasonic.ts @@ -4,6 +4,7 @@ import {times} from 'lodash' import { Aperture, ConfigName, + ExposureComp, ExposureMode, ISO, ManualFocusOption, @@ -233,7 +234,7 @@ export class TethrPanasonic extends TethrPTPUSB { return this.getDevicePropDescPanasonic({ devicePropCode: DevicePropCodePanasonic.Exposure, decode: v => { - if (v === 0x0) return '0' + if (v === 0x0) return '0' as ExposureComp const steps = v & 0xf const digits = Math.floor(steps / 3) @@ -243,10 +244,10 @@ export class TethrPanasonic extends TethrPTPUSB { const sign = negative ? '-' : '+' const thirdsSymbol = thirds === 1 ? '1/3' : thirds === 2 ? '2/3' : '' - if (digits === 0) return sign + thirdsSymbol - if (thirds === 0) return sign + digits + if (digits === 0) return (sign + thirdsSymbol) as ExposureComp + if (thirds === 0) return (sign + digits) as ExposureComp - return sign + digits + ' ' + thirdsSymbol + return (sign + digits + ' ' + thirdsSymbol) as ExposureComp }, valueSize: 2, }) diff --git a/src/TethrPTPUSB/TethrSigma.ts b/src/TethrPTPUSB/TethrSigma.ts index 838de96..0e93153 100644 --- a/src/TethrPTPUSB/TethrSigma.ts +++ b/src/TethrPTPUSB/TethrSigma.ts @@ -11,6 +11,7 @@ import { CameraStatus, ConfigName, DriveMode, + ExposureComp, ExposureMode, FocusMeteringMode, FocusPeaking, @@ -599,14 +600,14 @@ export class TethrSigma extends TethrPTPUSB { return this.compensationOneThirdTable.get(exposureComp) ?? null } - async setExposureComp(value: string): Promise { + async setExposureComp(value: ExposureComp): Promise { const id = this.compensationOneThirdTable.getKey(value) if (id === undefined) return {status: 'invalid parameter'} return this.setCamData(OpCodeSigma.SetCamDataGroup1, 5, id) } - async getExposureCompDesc(): Promise> { + async getExposureCompDesc(): Promise> { const {exposureComp: range} = await this.getCamCanSetInfo5() const value = await this.getExposureComp() @@ -1965,7 +1966,7 @@ export class TethrSigma extends TethrPTPUSB { [0b01110000, 102400], ]) - private compensationOneThirdTable = new BiMap([ + private compensationOneThirdTable = new BiMap([ [0b00000000, '0'], [0b00000011, '+1/3'], [0b00000101, '+2/3'],