Skip to content

Commit

Permalink
Fix typings
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Jun 12, 2024
1 parent 295835a commit 2c5bbdb
Show file tree
Hide file tree
Showing 7 changed files with 189 additions and 66 deletions.
52 changes: 40 additions & 12 deletions src/Tethr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
ConfigNameList,
ConfigType,
DriveMode,
ExposureComp,
ExposureMeteringMode,
ExposureMode,
FlashMode,
Expand All @@ -16,8 +17,12 @@ import {
FocusMode,
FocusPeaking,
FunctionalMode,
ImageAspect,
ImageQuality,
ImageSize,
ISO,
ManualFocusOption,
ShutterSpeed,
WhiteBalance,
} from './configs'
import {TethrObject} from './TethrObject'
Expand Down Expand Up @@ -412,18 +417,20 @@ export abstract class Tethr
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setExposureComp(value: string): Promise<OperationResult> {
async setExposureComp(value: ExposureComp): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getExposureComp() {
return (await this.getExposureCompDesc()).value
}
async getExposureCompDesc(): Promise<ConfigDesc<string>> {
async getExposureCompDesc(): Promise<ConfigDesc<ExposureComp>> {
return UnsupportedConfigDesc
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setExposureMeteringMode(value: string): Promise<OperationResult> {
async setExposureMeteringMode(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
value: ExposureMeteringMode
): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getExposureMeteringMode() {
Expand Down Expand Up @@ -537,18 +544,18 @@ export abstract class Tethr
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setImageAspect(value: string): Promise<OperationResult> {
async setImageAspect(value: ImageAspect): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getImageAspect() {
return (await this.getImageAspectDesc()).value
}
async getImageAspectDesc(): Promise<ConfigDesc<string>> {
async getImageAspectDesc(): Promise<ConfigDesc<ImageAspect>> {
return UnsupportedConfigDesc
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setImageQuality(value: string): Promise<OperationResult> {
async setImageQuality(value: ImageQuality): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getImageQuality() {
Expand All @@ -559,13 +566,13 @@ export abstract class Tethr
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setImageSize(value: string): Promise<OperationResult> {
async setImageSize(value: ImageSize): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getImageSize() {
return (await this.getImageSizeDesc()).value
}
async getImageSizeDesc(): Promise<ConfigDesc<string>> {
async getImageSizeDesc(): Promise<ConfigDesc<ImageSize>> {
return UnsupportedConfigDesc
}

Expand Down Expand Up @@ -671,13 +678,13 @@ export abstract class Tethr
}

// eslint-disable-next-line @typescript-eslint/no-unused-vars
async setShutterSpeed(value: string): Promise<OperationResult> {
async setShutterSpeed(value: ShutterSpeed): Promise<OperationResult> {
return UnsupportedOperationResult
}
async getShutterSpeed() {
return (await this.getShutterSpeedDesc()).value
}
async getShutterSpeedDesc(): Promise<ConfigDesc<string>> {
async getShutterSpeedDesc(): Promise<ConfigDesc<ShutterSpeed>> {
return UnsupportedConfigDesc
}

Expand Down Expand Up @@ -726,31 +733,52 @@ export abstract class Tethr
}

/**
* Runs auto focus.
* Runs auto focus. Use {@link getCanRunAutoFocus} to check if the camera supports this action.
* @category Action
*/
async runAutoFocus(): Promise<OperationResult> {
return UnsupportedOperationResult
}

/**
* Runs manual focus. Use {@link getCanRunAutoFocus} to check if the camera supports this action.
* @category Action
*/
// eslint-disable-next-line @typescript-eslint/no-unused-vars
async runManualFocus(option: ManualFocusOption): Promise<OperationResult> {
return UnsupportedOperationResult
}

/**
* Takes a photo. Use {@link getCanTakePhoto} to check if the camera supports this action.
* @category Action
*/
async takePhoto(
// eslint-disable-next-line @typescript-eslint/no-unused-vars
option?: TakePhotoOption
): Promise<OperationResult<TethrObject[]>> {
return UnsupportedOperationResult
}

/**
* Starts liveview. Use {@link getCanStartLiveview} to check if the camera supports this action.
* @category Action
*/
async startLiveview(): Promise<OperationResult<MediaStream>> {
return UnsupportedOperationResult
}

/**
* Stops liveview.
* @category Action
*/
async stopLiveview(): Promise<OperationResult> {
return UnsupportedOperationResult
}

/**
* Gets a liveview image.
*/
async getLiveViewImage(): Promise<OperationResult<Blob>> {
return UnsupportedOperationResult
}
Expand Down
3 changes: 2 additions & 1 deletion src/TethrPTPUSB/TethrPTPUSB.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import {
DriveModeTable,
ExposureMode,
ExposureModeTable,
ImageSize,
ISO,
WhiteBalance,
WhiteBalanceTable,
Expand Down Expand Up @@ -290,7 +291,7 @@ export class TethrPTPUSB extends Tethr {
})
}

setImageSizeValue(value: string) {
setImageSize(value: ImageSize) {
return this.setDevicePropValue({
devicePropCode: DevicePropCode.ImageSize,
datatypeCode: DatatypeCode.String,
Expand Down
24 changes: 14 additions & 10 deletions src/TethrPTPUSB/TethrPanasonic.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@ import {times} from 'lodash'

import {
Aperture,
ColorMode,
ConfigName,
ExposureComp,
ExposureMode,
ImageAspect,
ISO,
ManualFocusOption,
ShutterSpeed,
WhiteBalance,
} from '../configs'
import {ObjectFormatCode, ResCode} from '../PTPDatacode'
Expand Down Expand Up @@ -166,7 +170,7 @@ export class TethrPanasonic extends TethrPTPUSB {
})
}

setColorModeDesc(value: string) {
setColorMode(value: ColorMode) {
return this.setDevicePropValuePanasonic({
devicePropCode: DevicePropCodePanasonic.PhotoStyle_Param,

Expand Down Expand Up @@ -198,7 +202,7 @@ export class TethrPanasonic extends TethrPTPUSB {
})
}

setExposureComp(value: string) {
setExposureComp(value: ExposureComp) {
return this.setDevicePropValuePanasonic({
devicePropCode: DevicePropCodePanasonic.Exposure_Param,
encode: v => {
Expand Down Expand Up @@ -258,12 +262,12 @@ export class TethrPanasonic extends TethrPTPUSB {
}

async getManualFocusOptionsDesc() {
return readonlyConfigDesc([
return readonlyConfigDesc<ManualFocusOption[]>([
'near:2',
'near:1',
'far:1',
'far:2',
] as ManualFocusOption[])
])
}

async getCanTakePhotoDesc() {
Expand Down Expand Up @@ -299,10 +303,10 @@ export class TethrPanasonic extends TethrPTPUSB {
})
}

setImageAspect(value: string) {
setImageAspect(value: ImageAspect) {
return this.setDevicePropValuePanasonic({
devicePropCode: DevicePropCodePanasonic.ImageMode_ImageAspect,
encode: (value: string) => {
encode: (value: ImageAspect) => {
return this.imageAspectTable.getKey(value) ?? null
},
valueSize: 2,
Expand Down Expand Up @@ -469,7 +473,7 @@ export class TethrPanasonic extends TethrPTPUSB {
}
}

setShutterSpeed(value: string) {
setShutterSpeed(value: ShutterSpeed) {
return this.setDevicePropValuePanasonic({
devicePropCode: DevicePropCodePanasonic.ShutterSpeed_Param,
encode: (value: string) => {
Expand Down Expand Up @@ -506,9 +510,9 @@ export class TethrPanasonic extends TethrPTPUSB {
return null
}
if ((value & 0x80000000) === 0x00000000) {
return '1/' + value / 1000
return `1/${value / 1000}` as const
} else {
return ((value & 0x7fffffff) / 1000).toString()
return `${(value & 0x7fffffff) / 1000}` as const
}
},
valueSize: 4,
Expand Down Expand Up @@ -948,7 +952,7 @@ export class TethrPanasonic extends TethrPTPUSB {
[22, 'MY PHOTOSTYLE 4'],
])

protected imageAspectTable = new BiMap<number, string>([
protected imageAspectTable = new BiMap<number, ImageAspect>([
[1, '4:3'],
[2, '3:2'],
[3, '16:9'],
Expand Down
4 changes: 2 additions & 2 deletions src/TethrPTPUSB/TethrRicohTheta.ts
Original file line number Diff line number Diff line change
Expand Up @@ -97,10 +97,10 @@ export class TethrRicohTheta extends TethrPTPUSB {
const fraction = Number(num & BigInt(0xffffffff))

if (denominator === 1 || denominator === 10) {
return (fraction / denominator).toString()
return `${fraction / denominator}` as const
}

return fraction + '/' + denominator
return `${fraction}/${denominator}` as const
},
})
}
Expand Down
23 changes: 12 additions & 11 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,13 @@ import {FocalLength} from '..'
import {
Aperture,
BatteryLevel,
computeShutterSpeedSeconds,
ConfigName,
ExposureMode,
FocusMeteringMode,
FocusPeaking,
ImageAspect,
ISO,
ShutterSpeed,
WhiteBalance,
} from '../configs'
import {decodeIFD, encodeIFD, IFDType} from '../IFD'
Expand All @@ -29,7 +30,7 @@ import {
} from '../Tethr'
import {TethrObject} from '../TethrObject'
import {TethrStorage} from '../TethrStorage'
import {isntNil} from '../util'
import {computeShutterSpeedSeconds, isntNil} from '../util'
import {TethrPTPUSB} from '.'

enum OpCodeSigma {
Expand Down Expand Up @@ -782,14 +783,14 @@ export class TethrSigma extends TethrPTPUSB {
return {status: 'ok'}
}*/

async setImageAspect(imageAspect: string): Promise<OperationResult> {
async setImageAspect(imageAspect: ImageAspect): Promise<OperationResult> {
const id = this.imageAspectTable.getKey(imageAspect)
if (id === undefined) return {status: 'invalid parameter'}

return this.setCamData(OpCodeSigma.SetCamDataGroup5, 3, id)
}

async getImageAspectDesc(): Promise<ConfigDesc<string>> {
async getImageAspectDesc(): Promise<ConfigDesc<ImageAspect>> {
const {imageAspect} = await this.getCamStatus()

const value = this.imageAspectTable.get(imageAspect) ?? null
Expand All @@ -800,7 +801,7 @@ export class TethrSigma extends TethrPTPUSB {
value,
option: {
type: 'enum',
values: values.map(v => this.imageAspectTableIFD.get(v) ?? 'Unknown'),
values: values.map(v => this.imageAspectTableIFD.get(v)!),
},
}
}
Expand Down Expand Up @@ -1033,14 +1034,14 @@ export class TethrSigma extends TethrPTPUSB {
)
}

async setShutterSpeed(ss: string): Promise<OperationResult> {
async setShutterSpeed(ss: ShutterSpeed): Promise<OperationResult> {
const byte = this.shutterSpeedOneThirdTable.getKey(ss)
if (!byte) return {status: 'invalid parameter'}

return this.setCamData(OpCodeSigma.SetCamDataGroup1, 0, byte)
}

async getShutterSpeedDesc(): Promise<ConfigDesc<string>> {
async getShutterSpeedDesc(): Promise<ConfigDesc<ShutterSpeed>> {
const {shutterSpeed: range, notApexShutterSpeed} =
await this.getCamCanSetInfo5()

Expand Down Expand Up @@ -1805,7 +1806,7 @@ export class TethrSigma extends TethrPTPUSB {
[0x11, 'warm gold'],
])

private imageAspectTable = new BiMap<number, string>([
private imageAspectTable = new BiMap<number, ImageAspect>([
[1, '21:9'],
[2, '16:9'],
[3, '3:2'],
Expand All @@ -1815,7 +1816,7 @@ export class TethrSigma extends TethrPTPUSB {
[7, 'a size'],
])

private imageAspectTableIFD = new BiMap<number, string>([
private imageAspectTableIFD = new BiMap<number, ImageAspect>([
[1, '21:9'],
[2, '16:9'],
[3, '3:2'],
Expand Down Expand Up @@ -1913,7 +1914,7 @@ export class TethrSigma extends TethrPTPUSB {
[0b11111101, '-1/3'],
])

private shutterSpeedOneThirdTable = new BiMap<number, string>([
private shutterSpeedOneThirdTable = new BiMap<number, ShutterSpeed>([
[0b00001000, 'bulb'],
[0b00010000, '30'],
[0b00010011, '25'],
Expand Down Expand Up @@ -1985,7 +1986,7 @@ export class TethrSigma extends TethrPTPUSB {
[0b10110000, '1/32000'],
])

private shutterSpeedHalfTable = new BiMap<number, string>([
private shutterSpeedHalfTable = new BiMap<number, ShutterSpeed>([
[0b00001000, 'bulb'],
[0b00010001, '30'],
[0b00010100, '20'],
Expand Down
Loading

0 comments on commit 2c5bbdb

Please sign in to comment.