-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #100 from noahm/nm/config-display
Display current sensitivity settings
- Loading branch information
Showing
9 changed files
with
141 additions
and
82 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { useAtomValue, type Atom } from "jotai"; | ||
import type { SMXStage } from "../../sdk"; | ||
import { useConfig } from "./hooks"; | ||
|
||
export function ConfigValues(props: { stageAtom: Atom<SMXStage | undefined> }) { | ||
const stage = useAtomValue(props.stageAtom); | ||
const config = useConfig(stage); | ||
|
||
const ranges = config?.enabledSensors.flatMap((panel, idx) => { | ||
if (!panel.some((sensor) => sensor)) { | ||
return []; // skip panels will all disabled sensors | ||
} | ||
|
||
const { fsrHighThreshold: highs, fsrLowThreshold: lows } = config.panelSettings[idx]; | ||
|
||
return { | ||
idx, | ||
lows, | ||
highs, | ||
}; | ||
}); | ||
|
||
if (!ranges) { | ||
return null; | ||
} | ||
|
||
return ( | ||
<> | ||
<h3>Sensitivity settings</h3> | ||
<ul> | ||
{ranges.map((range) => ( | ||
<li key={range.idx}> | ||
Panel {range.idx + 1}: {range.lows[0]} - {range.highs[0]} | ||
</li> | ||
))} | ||
</ul> | ||
</> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
import { useAtomValue } from "jotai"; | ||
import { useState, useEffect, useRef } from "react"; | ||
import { type SMXStage, type SMXSensorTestData, SensorTestMode } from "../../sdk"; | ||
import { displayTestData$ } from "../state"; | ||
|
||
// UI Update Rate in Milliseconds | ||
const UI_UPDATE_RATE = 50; | ||
|
||
export function useInputState(stage: SMXStage | undefined) { | ||
const readTestData = useAtomValue(displayTestData$); | ||
const [panelStates, setPanelStates] = useState<Array<boolean> | null>(); | ||
useEffect(() => { | ||
return stage?.inputState$.throttle(UI_UPDATE_RATE).onValue(setPanelStates); | ||
}, [stage]); | ||
return panelStates; | ||
} | ||
|
||
export function useTestData(stage: SMXStage | undefined) { | ||
const testDataMode = useAtomValue(displayTestData$); | ||
const [testData, setTestData] = useState<SMXSensorTestData | null>(null); | ||
|
||
// request updates on an interval | ||
useEffect(() => { | ||
if (!stage || !testDataMode) { | ||
return; | ||
} | ||
let testMode = SensorTestMode.UncalibratedValues; | ||
switch (testDataMode) { | ||
case "calibrated": | ||
testMode = SensorTestMode.CalibratedValues; | ||
break; | ||
case "noise": | ||
testMode = SensorTestMode.Noise; | ||
break; | ||
case "tare": | ||
testMode = SensorTestMode.Tare; | ||
} | ||
const handle = setInterval(() => stage.updateTestData(testMode), UI_UPDATE_RATE); | ||
return () => clearInterval(handle); | ||
}, [stage, testDataMode]); | ||
|
||
// ingest responses and display in UI | ||
useEffect(() => { | ||
return stage?.testDataResponse$.onValue(setTestData); | ||
}, [stage]); | ||
|
||
return testData; | ||
} | ||
|
||
export function useConfig(stage: SMXStage | undefined) { | ||
const stageRef = useRef(stage); | ||
const [configData, setConfig] = useState(stage?.config); | ||
|
||
useEffect(() => { | ||
if (stageRef.current !== stage) { | ||
// detected the stage has changed, so keep the config in sync | ||
setConfig(stage?.config); | ||
stageRef.current = stage; | ||
} | ||
}, [stage]); | ||
|
||
useEffect(() => { | ||
return stage?.configResponse$.onValue((config) => setConfig(config.config)); | ||
}, [stage]); | ||
|
||
return configData; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters