Skip to content

Commit

Permalink
[Sigma] Normalize the focusDistance
Browse files Browse the repository at this point in the history
  • Loading branch information
baku89 committed Oct 6, 2023
1 parent 6c20499 commit fd34a52
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 6 deletions.
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@
"eslint-plugin-unused-imports": "^2.0.0",
"eslint-plugin-vue": "^9.17.0",
"file-saver": "^2.0.5",
"linearly": "^0.12.1",
"npm-run-all": "^4.1.5",
"prettier": "^2.3.2",
"stylus": "^0.60.0",
Expand Down
24 changes: 18 additions & 6 deletions src/TethrPTPUSB/TethrSigma.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import {BiMap} from 'bim'
import {scalar} from 'linearly'
import {isEqual, minBy} from 'lodash'
import sleep from 'sleep-promise'
import {MemoizeExpiring} from 'typescript-memoize'
Expand Down Expand Up @@ -253,7 +254,8 @@ export class TethrSigma extends TethrPTPUSB {
}

async getCanStartLiveviewDesc() {
return createReadonlyConfigDesc(true)
const {lvImageTransfer} = await this.getCamCanSetInfo5()
return createReadonlyConfigDesc(lvImageTransfer.length > 0)
}

async setColorMode(colorMode: string): Promise<OperationResult> {
Expand Down Expand Up @@ -486,8 +488,12 @@ export class TethrSigma extends TethrPTPUSB {

async getFocusDistanceDesc(): Promise<ConfigDesc<number>> {
const {focusPosition: range} = await this.getCamCanSetInfo5()
const value = (await this.getCamStatus()).focusPosition[0]
const focusPosition = (await this.getCamStatus()).focusPosition[0]

// Small value means far direction, so invert the min/max and normalize it
const value = scalar.invlerp(range[1], range[0], focusPosition)

// Only writable when AF is on
const writable = range.length === 2 && !!(await this.getCanRunAutoFocus())

if (writable) {
Expand All @@ -496,9 +502,9 @@ export class TethrSigma extends TethrPTPUSB {
value,
option: {
type: 'range',
min: range[0],
max: range[1],
step: 1,
min: 0,
max: 1,
step: 0,
},
}
} else {
Expand All @@ -512,8 +518,14 @@ export class TethrSigma extends TethrPTPUSB {
async setFocusDistance(
value: number
): Promise<{status: OperationResultStatus}> {
const {focusPosition: range} = await this.getCamCanSetInfo5()

const focusPosition = scalar.round(scalar.lerp(range[1], range[0], value))

console.error(value, focusPosition)

const data = encodeIFD({
focusPosition: {tag: 81, type: IFDType.Short, value: [value]},
focusPosition: {tag: 81, type: IFDType.Short, value: [focusPosition]},
})

try {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1844,6 +1844,11 @@ levn@^0.4.1:
prelude-ls "^1.2.1"
type-check "~0.4.0"

linearly@^0.12.1:
version "0.12.1"
resolved "https://registry.yarnpkg.com/linearly/-/linearly-0.12.1.tgz#a58a14fdbfc7e419ac21fad5cd459b7dccff414f"
integrity sha512-mGdv/cSZENtaf0vJZiKwjOggOIhID8JZNJa8aIafsa0ipLvDuu+R01rPtk4oy8IQkcEcqVLnIeH5MHNG8SuYFA==

load-json-file@^4.0.0:
version "4.0.0"
resolved "https://registry.yarnpkg.com/load-json-file/-/load-json-file-4.0.0.tgz#2f5f45ab91e33216234fd53adab668eb4ec0993b"
Expand Down

0 comments on commit fd34a52

Please sign in to comment.