Skip to content

Commit

Permalink
Fix types for ExposureComp
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Jun 10, 2024
1 parent a98f424 commit 9265377
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Tethr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -428,7 +428,7 @@ export abstract class Tethr
async getExposureComp() {
return (await this.getExposureCompDesc()).value
}
async getExposureCompDesc(): Promise<ConfigDesc<string>> {
async getExposureCompDesc(): Promise<ConfigDesc<ExposureComp>> {
return UnsupportedConfigDesc
}

Expand Down
7 changes: 4 additions & 3 deletions src/TethrPTPUSB/TethrPTPUSB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {
Aperture,
BatteryLevel,
DriveMode,
ExposureComp,
ExposureMode,
ISO,
WhiteBalance,
Expand Down Expand Up @@ -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
},
})
}
Expand Down
9 changes: 5 additions & 4 deletions src/TethrPTPUSB/TethrPanasonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import {times} from 'lodash'
import {
Aperture,
ConfigName,
ExposureComp,
ExposureMode,
ISO,
ManualFocusOption,
Expand Down Expand Up @@ -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)
Expand All @@ -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,
})
Expand Down
7 changes: 4 additions & 3 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ import {
CameraStatus,
ConfigName,
DriveMode,
ExposureComp,
ExposureMode,
FocusMeteringMode,
FocusPeaking,
Expand Down Expand Up @@ -599,14 +600,14 @@ export class TethrSigma extends TethrPTPUSB {
return this.compensationOneThirdTable.get(exposureComp) ?? null
}

async setExposureComp(value: string): Promise<OperationResult> {
async setExposureComp(value: ExposureComp): Promise<OperationResult> {
const id = this.compensationOneThirdTable.getKey(value)
if (id === undefined) return {status: 'invalid parameter'}

return this.setCamData(OpCodeSigma.SetCamDataGroup1, 5, id)
}

async getExposureCompDesc(): Promise<ConfigDesc<string>> {
async getExposureCompDesc(): Promise<ConfigDesc<ExposureComp>> {
const {exposureComp: range} = await this.getCamCanSetInfo5()
const value = await this.getExposureComp()

Expand Down Expand Up @@ -1965,7 +1966,7 @@ export class TethrSigma extends TethrPTPUSB {
[0b01110000, 102400],
])

private compensationOneThirdTable = new BiMap<number, string>([
private compensationOneThirdTable = new BiMap<number, ExposureComp>([
[0b00000000, '0'],
[0b00000011, '+1/3'],
[0b00000101, '+2/3'],
Expand Down

0 comments on commit 9265377

Please sign in to comment.