mirror of
https://github.com/SlimeVR/SlimeVR-Server.git
synced 2026-11-23 18:41:24 -08:00
Compare commits
6
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
c1c2133127 | ||
|
|
4a39726fbb | ||
|
|
49dc68886d | ||
|
|
de8757c09f | ||
|
|
b57390e92b | ||
|
|
6cbfb3b34d |
No files matched your search
@@ -66,7 +66,7 @@ function BasicResetButton(options: UseResetOptions & { customName?: string }) {
|
||||
const name = options.customName || resetName;
|
||||
|
||||
const skiReset =
|
||||
options.type === ResetType.Mounting && options.group === 'default';
|
||||
options.type === ResetType.MOUNTING && options.group === 'default';
|
||||
|
||||
return (
|
||||
<Tooltip
|
||||
@@ -175,8 +175,8 @@ export function Toolbar() {
|
||||
<div className="flex-col flex gap-1 md:w-[60%]">
|
||||
<Typography variant="section-title" id="toolbar-drift_reset" />
|
||||
<div className="gap-2 md:h-[72px] h-[62px] w-full grid-cols-2 grid">
|
||||
<BasicResetButton type={ResetType.Full} />
|
||||
<BasicResetButton type={ResetType.Yaw} />
|
||||
<BasicResetButton type={ResetType.FULL} />
|
||||
<BasicResetButton type={ResetType.YAW} />
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex-col flex gap-1 md:flex-grow">
|
||||
@@ -191,18 +191,18 @@ export function Toolbar() {
|
||||
}}
|
||||
>
|
||||
<BasicResetButton
|
||||
type={ResetType.Mounting}
|
||||
type={ResetType.MOUNTING}
|
||||
group={'default'}
|
||||
customName="toolbar-mounting_calibration-default"
|
||||
/>
|
||||
<BasicResetButton
|
||||
type={ResetType.Mounting}
|
||||
type={ResetType.MOUNTING}
|
||||
group={'feet'}
|
||||
customName="toolbar-mounting_calibration-feet"
|
||||
/>
|
||||
{groupVisibility['fingers'] && (
|
||||
<BasicResetButton
|
||||
type={ResetType.Mounting}
|
||||
type={ResetType.MOUNTING}
|
||||
group={'fingers'}
|
||||
customName="toolbar-mounting_calibration-fingers"
|
||||
/>
|
||||
|
||||
@@ -27,7 +27,7 @@ export function Home() {
|
||||
|
||||
const sendToSettings = (tracker: TrackerDataT) => {
|
||||
navigate(
|
||||
`/tracker/${tracker.trackerId?.trackerNum}/${tracker.trackerId?.deviceId?.id}`
|
||||
`/tracker/${tracker.trackerId}/${tracker.deviceId}`
|
||||
);
|
||||
};
|
||||
|
||||
@@ -86,8 +86,8 @@ export function Home() {
|
||||
warning={
|
||||
!!highlightedTrackers?.trackers.find(
|
||||
(t) =>
|
||||
t?.deviceId?.id === tracker.trackerId?.deviceId?.id &&
|
||||
t?.trackerNum === tracker.trackerId?.trackerNum
|
||||
t?.deviceId?.id === tracker.deviceId &&
|
||||
t?.trackerNum === tracker.trackerId
|
||||
) && highlightedTrackers.step
|
||||
}
|
||||
/>
|
||||
@@ -128,8 +128,8 @@ export function Home() {
|
||||
warning={
|
||||
!!highlightedTrackers?.trackers.find(
|
||||
(t) =>
|
||||
t?.deviceId?.id === tracker.trackerId?.deviceId?.id &&
|
||||
t?.trackerNum === tracker.trackerId?.trackerNum
|
||||
t?.deviceId?.id === tracker.deviceId &&
|
||||
t?.trackerNum === tracker.trackerId
|
||||
) && highlightedTrackers.step
|
||||
}
|
||||
/>
|
||||
|
||||
@@ -15,12 +15,12 @@ import { Tooltip } from '@/components/commons/Tooltip';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
|
||||
export function ResetButtonIcon(options: UseResetOptions) {
|
||||
if (options.type === ResetType.Mounting && !options.group)
|
||||
if (options.type === ResetType.MOUNTING && !options.group)
|
||||
options.group = 'default';
|
||||
|
||||
if (options.type === ResetType.Yaw) return <YawResetIcon width={18} />;
|
||||
if (options.type === ResetType.Full) return <FullResetIcon width={18} />;
|
||||
if (options.type === ResetType.Mounting) {
|
||||
if (options.type === ResetType.YAW) return <YawResetIcon width={18} />;
|
||||
if (options.type === ResetType.FULL) return <FullResetIcon width={18} />;
|
||||
if (options.type === ResetType.MOUNTING) {
|
||||
if (options.group === 'default') return <SkiIcon />;
|
||||
if (options.group === 'feet') return <FootIcon />;
|
||||
if (options.group === 'fingers') return <FingersIcon width={16} />;
|
||||
@@ -83,7 +83,7 @@ export function ResetButton({
|
||||
<div className="opacity-0 h-0">
|
||||
{children || <Localized id={name} />}
|
||||
</div>
|
||||
{status !== 'counting' || options.type === ResetType.Yaw
|
||||
{status !== 'counting' || options.type === ResetType.YAW
|
||||
? children || <Localized id={name} />
|
||||
: String(timer)}
|
||||
</div>
|
||||
|
||||
@@ -200,7 +200,7 @@ export const RIGHT_LEG_PARTS = [
|
||||
];
|
||||
|
||||
export const RESET_TYPE_ORDER = [
|
||||
ResetType.Yaw,
|
||||
ResetType.Full,
|
||||
ResetType.Mounting,
|
||||
ResetType.YAW,
|
||||
ResetType.FULL,
|
||||
ResetType.MOUNTING,
|
||||
];
|
||||
@@ -1,12 +1,9 @@
|
||||
import { Control, Controller, useForm } from 'react-hook-form';
|
||||
import {
|
||||
ChangeSkeletonConfigRequestT,
|
||||
ChangeSkeletonProportionsRequestT,
|
||||
ResetType,
|
||||
RpcMessage,
|
||||
SkeletonBone,
|
||||
SkeletonConfigRequestT,
|
||||
SkeletonConfigResponseT,
|
||||
SkeletonResetAllRequestT,
|
||||
SkeletonBone, SkeletonProportionsRequestT, SkeletonProportionsResetAllRequestT, SkeletonProportionsResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useOnboarding } from '@/hooks/onboarding';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
@@ -85,7 +82,7 @@ function IconButton({
|
||||
|
||||
function parseConfigImport(
|
||||
config: SkeletonConfigExport
|
||||
): ChangeSkeletonConfigRequestT[] {
|
||||
): ChangeSkeletonProportionsRequestT[] {
|
||||
if (!config.version) config.version = 1;
|
||||
if (config.version < 1) {
|
||||
// Add config migration stuff here, this one is just an example.
|
||||
@@ -95,7 +92,7 @@ function parseConfigImport(
|
||||
const bone =
|
||||
typeof part.bone === 'string' ? SkeletonBone[part.bone] : part.bone;
|
||||
|
||||
return new ChangeSkeletonConfigRequestT(bone, part.value);
|
||||
return new ChangeSkeletonProportionsRequestT(bone, part.value);
|
||||
});
|
||||
}
|
||||
|
||||
@@ -121,7 +118,7 @@ function ImportExportButtons() {
|
||||
const exporting = useRef(false);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.SkeletonConfigResponse,
|
||||
RpcMessage.SkeletonProportionsResponse,
|
||||
(data: SkeletonConfigExport) => {
|
||||
if (!exporting.current) return;
|
||||
exporting.current = false;
|
||||
@@ -183,11 +180,11 @@ function ImportExportButtons() {
|
||||
}
|
||||
|
||||
parseConfigImport(config).forEach((req) =>
|
||||
sendRPCPacket(RpcMessage.ChangeSkeletonConfigRequest, req)
|
||||
sendRPCPacket(RpcMessage.ChangeSkeletonProportionsRequest, req)
|
||||
);
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonConfigRequest,
|
||||
new SkeletonConfigRequestT()
|
||||
RpcMessage.SkeletonProportionsRequest,
|
||||
new SkeletonProportionsRequestT()
|
||||
);
|
||||
setImportState(ImportStatus.SUCCESS);
|
||||
setTimeout(() => {
|
||||
@@ -219,8 +216,8 @@ function ImportExportButtons() {
|
||||
exporting.current = true;
|
||||
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonConfigRequest,
|
||||
new SkeletonConfigRequestT()
|
||||
RpcMessage.SkeletonProportionsRequest,
|
||||
new SkeletonProportionsRequestT()
|
||||
);
|
||||
}}
|
||||
>
|
||||
@@ -311,16 +308,17 @@ function ButtonsControl({ control }: { control: ManualProportionControls }) {
|
||||
const [showWarning, setShowWarning] = useState(false);
|
||||
const resetAll = () => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonResetAllRequest,
|
||||
new SkeletonResetAllRequestT()
|
||||
RpcMessage.SkeletonProportionsResetAllRequest,
|
||||
new SkeletonProportionsResetAllRequestT()
|
||||
);
|
||||
};
|
||||
|
||||
const beneathFloor = useMemo(() => {
|
||||
// TODO I think this needs to be rewritten with rewrite but it also just may be unneeded
|
||||
const hmd = computedTrackers.find(
|
||||
(tracker) =>
|
||||
tracker.tracker.trackerId?.trackerNum === 1 &&
|
||||
tracker.tracker.trackerId.deviceId?.id === undefined
|
||||
tracker.tracker.trackerId === 1 &&
|
||||
tracker.tracker.deviceId === undefined
|
||||
);
|
||||
return !(hmd?.tracker.position && hmd.tracker.position.y >= MIN_HEIGHT);
|
||||
}, [computedTrackers]);
|
||||
@@ -418,8 +416,8 @@ export function ManualProportionsPage() {
|
||||
}, [ratio]);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.SkeletonConfigResponse,
|
||||
(data: SkeletonConfigResponseT) => {
|
||||
RpcMessage.SkeletonProportionsResponse,
|
||||
(data: SkeletonProportionsResponseT) => {
|
||||
if (data.userHeight) setUserHeight(data.userHeight);
|
||||
}
|
||||
);
|
||||
@@ -470,7 +468,7 @@ export function ManualProportionsPage() {
|
||||
<div className="top-4 w-full px-4 absolute flex gap-2 flex-col lg:flex-row md:flex-wrap">
|
||||
<div className="h-14 flex flex-grow items-center">
|
||||
<ResetButton
|
||||
type={ResetType.Full}
|
||||
type={ResetType.FULL}
|
||||
className="w-full h-full bg-background-50 hover:bg-background-40 text-background-10"
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -7,14 +7,12 @@ import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
CancelUserHeightCalibrationT,
|
||||
ChangeSettingsRequestT,
|
||||
ModelSettingsT,
|
||||
ResetType,
|
||||
RpcMessage,
|
||||
SkeletonConfigRequestT,
|
||||
SkeletonConfigResponseT,
|
||||
SkeletonHeightT,
|
||||
SkeletonResetAllRequestT,
|
||||
SkeletonProportionsRequestT,
|
||||
SkeletonProportionsResetAllRequestT,
|
||||
SkeletonProportionsResponseT,
|
||||
StartUserHeightCalibrationT,
|
||||
UserHeightCalibrationStatus,
|
||||
UserHeightRecordingStatusResponseT,
|
||||
@@ -265,7 +263,7 @@ export function ScaledProportionsPage() {
|
||||
);
|
||||
};
|
||||
|
||||
// Makes it so you dont get spammed by sounds if multiple status complete at once
|
||||
// Makes it so you don't get spammed by sounds if multiple status complete at once
|
||||
useDebouncedEffect(
|
||||
() => {
|
||||
if (!config || !config.feedbackSound) return;
|
||||
@@ -295,8 +293,8 @@ export function ScaledProportionsPage() {
|
||||
);
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settingsRequest);
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonResetAllRequest,
|
||||
new SkeletonResetAllRequestT()
|
||||
RpcMessage.SkeletonProportionsResetAllRequest,
|
||||
new SkeletonProportionsResetAllRequestT()
|
||||
);
|
||||
setConfig({ lastUsedProportions: 'scaled' });
|
||||
setLastUsed('manual');
|
||||
@@ -320,8 +318,8 @@ export function ScaledProportionsPage() {
|
||||
);
|
||||
|
||||
useRPCPacket(
|
||||
RpcMessage.SkeletonConfigResponse,
|
||||
(res: SkeletonConfigResponseT) => {
|
||||
RpcMessage.SkeletonProportionsResponse,
|
||||
(res: SkeletonProportionsResponseT) => {
|
||||
setHmdHeight(res.userHeight);
|
||||
}
|
||||
);
|
||||
@@ -336,8 +334,8 @@ export function ScaledProportionsPage() {
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonConfigRequest,
|
||||
new SkeletonConfigRequestT()
|
||||
RpcMessage.SkeletonProportionsRequest,
|
||||
new SkeletonProportionsRequestT()
|
||||
);
|
||||
|
||||
return () => {
|
||||
@@ -356,8 +354,8 @@ export function ScaledProportionsPage() {
|
||||
if (status && checkNotAuto(status.status)) {
|
||||
setAuto(false);
|
||||
sendRPCPacket(
|
||||
RpcMessage.SkeletonConfigRequest,
|
||||
new SkeletonConfigRequestT()
|
||||
RpcMessage.SkeletonProportionsRequest,
|
||||
new SkeletonProportionsRequestT()
|
||||
); // Re ask the user height so it resets back to the correct value
|
||||
}
|
||||
},
|
||||
@@ -469,7 +467,7 @@ export function ScaledProportionsPage() {
|
||||
state={{ alonePage: state.alonePage }}
|
||||
/>
|
||||
<ResetButton
|
||||
type={ResetType.Full}
|
||||
type={ResetType.FULL}
|
||||
className="bg-background-50 hover:bg-background-40 text-background-10"
|
||||
/>
|
||||
</>
|
||||
|
||||
@@ -69,7 +69,7 @@ export function PreparationStep({
|
||||
>
|
||||
{l10n.getString('onboarding-automatic_mounting-prev_step')}
|
||||
</Button>
|
||||
<ResetButton type={ResetType.Full} onReseted={nextStep} />
|
||||
<ResetButton type={ResetType.FULL} onReseted={nextStep} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -58,7 +58,7 @@ export function MountingResetStep({
|
||||
{l10n.getString('onboarding-automatic_mounting-prev_step')}
|
||||
</Button>
|
||||
<ResetButton
|
||||
type={ResetType.Mounting}
|
||||
type={ResetType.MOUNTING}
|
||||
group="default"
|
||||
onReseted={nextStep}
|
||||
/>
|
||||
|
||||
@@ -69,7 +69,7 @@ export function PreparationStep({
|
||||
>
|
||||
{l10n.getString('onboarding-automatic_mounting-prev_step')}
|
||||
</Button>
|
||||
<ResetButton type={ResetType.Full} onReseted={nextStep} />
|
||||
<ResetButton type={ResetType.FULL} onReseted={nextStep} />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,7 +5,7 @@ import { HumanIcon } from '@/components/commons/icon/HumanIcon';
|
||||
import { HeadsetIcon } from '@/components/commons/icon/HeadsetIcon';
|
||||
import { useState } from 'react';
|
||||
import { SittingIcon } from '@/components/commons/icon/SittingIcon';
|
||||
import { VMCFileUpload } from '@/components/settings/pages/VMCSettings';
|
||||
import { VRMFileUpload } from '@/components/settings/pages/VMCSettings';
|
||||
import { QuizButton } from './SlimeSetQuestion';
|
||||
import { useNavigate } from 'react-router-dom';
|
||||
|
||||
@@ -81,7 +81,7 @@ export function QuizMocapPosQuestion() {
|
||||
/>
|
||||
<Typography id="onboarding-quiz-mocap_preferences-vrm_model-desc" />
|
||||
</div>
|
||||
<VMCFileUpload />
|
||||
<VRMFileUpload />
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
@@ -3,18 +3,11 @@ import { useEffect, useRef, useState } from 'react';
|
||||
import { DefaultValues, useForm } from 'react-hook-form';
|
||||
import {
|
||||
ChangeSettingsRequestT,
|
||||
FilteringSettingsT,
|
||||
FilteringType,
|
||||
LegTweaksSettingsT,
|
||||
ModelRatiosT,
|
||||
ModelSettingsT,
|
||||
ModelTogglesT,
|
||||
RpcMessage,
|
||||
SettingsRequestT,
|
||||
SettingsResponseT,
|
||||
TapDetectionSettingsT,
|
||||
HIDSettingsT,
|
||||
VelocitySettingsT,
|
||||
BodyPart,
|
||||
OutputTrackersSettingT,
|
||||
} from 'solarxr-protocol';
|
||||
@@ -54,19 +47,6 @@ import { TouchDoubleIcon } from '@/components/commons/icon/TouchDoubleIcon';
|
||||
import { MartialArtsIcon } from '@/components/commons/icon/MartialArtsIcon';
|
||||
|
||||
export type SettingsForm = {
|
||||
trackers: {
|
||||
automaticTrackerToggle: boolean;
|
||||
waist: boolean;
|
||||
chest: boolean;
|
||||
leftFoot: boolean;
|
||||
rightFoot: boolean;
|
||||
leftKnee: boolean;
|
||||
rightKnee: boolean;
|
||||
leftElbow: boolean;
|
||||
rightElbow: boolean;
|
||||
leftHand: boolean;
|
||||
rightHand: boolean;
|
||||
};
|
||||
filtering: {
|
||||
type: number;
|
||||
amount: number;
|
||||
@@ -83,7 +63,7 @@ export type SettingsForm = {
|
||||
correctConstraints: boolean;
|
||||
};
|
||||
ratios: {
|
||||
imputeSpineFromTopDown: number;
|
||||
imputeSpineFromUpperLower: number;
|
||||
imputeSpineCurvature: number;
|
||||
interpHipLegs: number;
|
||||
interpKneeTrackerAnkle: number;
|
||||
@@ -112,25 +92,9 @@ export type SettingsForm = {
|
||||
hidSettings: {
|
||||
trackersOverHID: boolean;
|
||||
};
|
||||
velocitySettings: {
|
||||
sendDerivedVelocity: boolean;
|
||||
};
|
||||
};
|
||||
|
||||
const defaultValues: SettingsForm = {
|
||||
trackers: {
|
||||
automaticTrackerToggle: true,
|
||||
waist: false,
|
||||
chest: false,
|
||||
leftFoot: false,
|
||||
rightFoot: false,
|
||||
leftElbow: false,
|
||||
rightElbow: false,
|
||||
leftHand: false,
|
||||
rightHand: false,
|
||||
leftKnee: false,
|
||||
rightKnee: false,
|
||||
},
|
||||
toggles: {
|
||||
forceArmsFromHmd: false,
|
||||
floorClip: false,
|
||||
@@ -143,7 +107,7 @@ const defaultValues: SettingsForm = {
|
||||
correctConstraints: true,
|
||||
},
|
||||
ratios: {
|
||||
imputeSpineFromTopDown: 0.5,
|
||||
imputeSpineFromUpperLower: 0.5,
|
||||
imputeSpineCurvature: 0.5,
|
||||
interpHipLegs: 0.25,
|
||||
interpKneeTrackerAnkle: 0.85,
|
||||
@@ -169,7 +133,6 @@ const defaultValues: SettingsForm = {
|
||||
resetsSettings: defaultResetSettings,
|
||||
stayAligned: defaultStayAlignedSettings,
|
||||
hidSettings: { trackersOverHID: false },
|
||||
velocitySettings: { sendDerivedVelocity: false },
|
||||
};
|
||||
|
||||
const settingsAtom = atom(new SettingsResponseT());
|
||||
@@ -193,12 +156,6 @@ export function GeneralSettings() {
|
||||
value: String(value),
|
||||
label: l10n.getString(`body_part-${BodyPart[value]}`),
|
||||
}));
|
||||
const blockHandsWarning = useRef(false);
|
||||
// If not null, warning will be shown, and showHandsWarning will
|
||||
// hold which hands should be toggled ([leftHand, rightHand])
|
||||
const [showHandsWarning, setShowHandsWarning] = useState<
|
||||
[boolean, boolean] | null
|
||||
>(null);
|
||||
|
||||
const percentageFormat = new Intl.NumberFormat(currentLocales, {
|
||||
style: 'percent',
|
||||
@@ -219,67 +176,10 @@ export function GeneralSettings() {
|
||||
reValidateMode: 'onChange',
|
||||
});
|
||||
|
||||
const {
|
||||
trackers: { automaticTrackerToggle },
|
||||
} = watch();
|
||||
|
||||
|
||||
const onSubmit = (values: SettingsForm) => {
|
||||
const settingsReq = new ChangeSettingsRequestT();
|
||||
|
||||
if (values.trackers) {
|
||||
const outputTrackers = new OutputTrackersSettingT();
|
||||
|
||||
// The tracker is at the tail of the bone.
|
||||
// Example, the waist tracker is at the tail of the hip bone so we use the hip BodyPart
|
||||
const enabledBodyParts: [boolean, BodyPart][] = [
|
||||
[values.trackers.waist, BodyPart.HIP],
|
||||
[values.trackers.chest, BodyPart.CHEST],
|
||||
[values.trackers.leftFoot, BodyPart.LEFT_FOOT],
|
||||
[values.trackers.rightFoot, BodyPart.RIGHT_FOOT],
|
||||
[values.trackers.leftKnee, BodyPart.LEFT_UPPER_LEG],
|
||||
[values.trackers.rightKnee, BodyPart.RIGHT_UPPER_LEG],
|
||||
[values.trackers.leftElbow, BodyPart.LEFT_UPPER_ARM],
|
||||
[values.trackers.rightElbow, BodyPart.RIGHT_UPPER_ARM],
|
||||
[values.trackers.leftHand, BodyPart.LEFT_HAND],
|
||||
[values.trackers.rightHand, BodyPart.RIGHT_HAND],
|
||||
];
|
||||
outputTrackers.trackers = enabledBodyParts
|
||||
.filter(([enabled]) => enabled)
|
||||
.map(([, part]) => part);
|
||||
|
||||
const leftHandEnabled = outputTrackers.trackers.includes(
|
||||
BodyPart.LEFT_HAND
|
||||
);
|
||||
const rightHandEnabled = outputTrackers.trackers.includes(
|
||||
BodyPart.RIGHT_HAND
|
||||
);
|
||||
if (
|
||||
!blockHandsWarning.current &&
|
||||
!showHandsWarning &&
|
||||
!settings?.outputTrackers?.trackers.includes(BodyPart.LEFT_HAND) &&
|
||||
!settings?.outputTrackers?.trackers.includes(BodyPart.RIGHT_HAND) &&
|
||||
(leftHandEnabled || rightHandEnabled)
|
||||
) {
|
||||
// We have just toggled on one of the hand trackers, show the user a warning
|
||||
setShowHandsWarning([leftHandEnabled, rightHandEnabled]);
|
||||
outputTrackers.trackers = outputTrackers.trackers.filter(
|
||||
(tracker) =>
|
||||
tracker != BodyPart.LEFT_HAND && tracker != BodyPart.RIGHT_HAND
|
||||
);
|
||||
} else if (
|
||||
blockHandsWarning.current &&
|
||||
!outputTrackers.trackers.includes(BodyPart.LEFT_HAND) &&
|
||||
!outputTrackers.trackers.includes(BodyPart.RIGHT_HAND)
|
||||
) {
|
||||
// Both hand trackers have just been disabled, make sure the warning shows up
|
||||
// again next time the user toggles one back on
|
||||
blockHandsWarning.current = false;
|
||||
}
|
||||
|
||||
outputTrackers.automaticTrackerToggle =
|
||||
values.trackers.automaticTrackerToggle;
|
||||
settingsReq.outputTrackers = outputTrackers;
|
||||
}
|
||||
const req = new ChangeSettingsRequestT();
|
||||
|
||||
const modelSettings = new ModelSettingsT();
|
||||
|
||||
@@ -299,8 +199,8 @@ export function GeneralSettings() {
|
||||
|
||||
if (values.ratios) {
|
||||
const ratios = new ModelRatiosT();
|
||||
ratios.imputeSpineFromTopDown =
|
||||
values.ratios.imputeSpineFromTopDown || -1;
|
||||
ratios.imputeSpineFromUpperLower =
|
||||
values.ratios.imputeSpineFromUpperLower || -1;
|
||||
ratios.imputeSpineCurvature = values.ratios.imputeSpineCurvature || -1;
|
||||
ratios.interpHipLegs = values.ratios.interpHipLegs || -1;
|
||||
ratios.interpKneeTrackerAnkle =
|
||||
@@ -315,7 +215,7 @@ export function GeneralSettings() {
|
||||
modelSettings.legTweaks = legTweaks;
|
||||
}
|
||||
|
||||
settingsReq.modelSettings = modelSettings;
|
||||
req.modelSettings = modelSettings;
|
||||
|
||||
const tapDetection = new TapDetectionSettingsT();
|
||||
tapDetection.fullResetDelay = values.tapDetection.fullResetDelay;
|
||||
@@ -338,29 +238,29 @@ export function GeneralSettings() {
|
||||
tapDetection.numberTrackersOverThreshold =
|
||||
values.tapDetection.numberTrackersOverThreshold;
|
||||
tapDetection.setupMode = false;
|
||||
settingsReq.tapDetectionSettings = tapDetection;
|
||||
req.tapDetectionSettings = tapDetection;
|
||||
|
||||
const filtering = new FilteringSettingsT();
|
||||
filtering.type = values.filtering.type;
|
||||
filtering.amount = values.filtering.amount;
|
||||
settingsReq.filtering = filtering;
|
||||
req.filtering = filtering;
|
||||
|
||||
settingsReq.stayAligned = serializeStayAlignedSettings(values.stayAligned);
|
||||
req.stayAligned = serializeStayAlignedSettings(values.stayAligned);
|
||||
|
||||
const hidSettings = new HIDSettingsT();
|
||||
hidSettings.trackersOverHid = values.hidSettings.trackersOverHID;
|
||||
settingsReq.hidSettings = hidSettings;
|
||||
req.hidSettings = hidSettings;
|
||||
|
||||
const velocitySettings = new VelocitySettingsT();
|
||||
velocitySettings.sendDerivedVelocity =
|
||||
values.velocitySettings.sendDerivedVelocity;
|
||||
settingsReq.velocitySettings = velocitySettings;
|
||||
req.velocitySettings = velocitySettings;
|
||||
|
||||
if (values.resetsSettings) {
|
||||
settingsReq.resetsSettings = loadResetSettings(values.resetsSettings);
|
||||
req.resetsSettings = loadResetSettings(values.resetsSettings);
|
||||
}
|
||||
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settingsReq);
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, req);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -1001,7 +901,7 @@ export function GeneralSettings() {
|
||||
<div className="grid md:grid-cols-2 flex-col gap-3 pt-2 pb-3">
|
||||
<Radio
|
||||
control={control}
|
||||
name="resetsSettings.armsMountingResetMode"
|
||||
name="resetsSettings.armsResetMode"
|
||||
label={l10n.getString(
|
||||
'settings-general-fk_settings-arm_fk-back'
|
||||
)}
|
||||
@@ -1012,7 +912,7 @@ export function GeneralSettings() {
|
||||
/>
|
||||
<Radio
|
||||
control={control}
|
||||
name="resetsSettings.armsMountingResetMode"
|
||||
name="resetsSettings.armsResetMode"
|
||||
label={l10n.getString(
|
||||
'settings-general-fk_settings-arm_fk-forward'
|
||||
)}
|
||||
@@ -1023,7 +923,7 @@ export function GeneralSettings() {
|
||||
/>
|
||||
<Radio
|
||||
control={control}
|
||||
name="resetsSettings.armsMountingResetMode"
|
||||
name="resetsSettings.armsResetMode"
|
||||
label={l10n.getString(
|
||||
'settings-general-fk_settings-arm_fk-tpose_up'
|
||||
)}
|
||||
@@ -1034,7 +934,7 @@ export function GeneralSettings() {
|
||||
/>
|
||||
<Radio
|
||||
control={control}
|
||||
name="resetsSettings.armsMountingResetMode"
|
||||
name="resetsSettings.armsResetMode"
|
||||
label={l10n.getString(
|
||||
'settings-general-fk_settings-arm_fk-tpose_down'
|
||||
)}
|
||||
@@ -1112,7 +1012,7 @@ export function GeneralSettings() {
|
||||
<div className="grid sm:grid-cols-2 gap-3 pb-3">
|
||||
<NumberSelector
|
||||
control={control}
|
||||
name="ratios.imputeSpineFromTopDown"
|
||||
name="ratios.imputeSpineFromUpperLower"
|
||||
label={l10n.getString(
|
||||
'settings-general-fk_settings-skeleton_settings-impute_spine_from_top_down'
|
||||
)}
|
||||
|
||||
@@ -6,11 +6,9 @@ import { useCallback, useEffect, useRef, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import {
|
||||
ChangeMagToggleRequestT,
|
||||
DeviceIdT,
|
||||
MagToggleRequestT,
|
||||
MagToggleResponseT,
|
||||
RpcMessage,
|
||||
TrackerIdT,
|
||||
} from 'solarxr-protocol';
|
||||
import { Link } from 'react-router-dom';
|
||||
|
||||
@@ -19,13 +17,11 @@ interface MagnetometerToggleForm {
|
||||
}
|
||||
|
||||
export function MagnetometerToggleSetting({
|
||||
trackerNum,
|
||||
deviceId,
|
||||
trackerId,
|
||||
settingType,
|
||||
id,
|
||||
}: {
|
||||
trackerNum?: number;
|
||||
deviceId?: number;
|
||||
trackerId?: number;
|
||||
settingType: 'general' | 'tracker';
|
||||
id?: string;
|
||||
}) {
|
||||
@@ -45,18 +41,14 @@ export function MagnetometerToggleSetting({
|
||||
if (originalValue.current === values.magToggle) return;
|
||||
setWaitingMag(true);
|
||||
const req = new ChangeMagToggleRequestT();
|
||||
if (trackerNum !== undefined) {
|
||||
const id = new TrackerIdT(
|
||||
deviceId ? new DeviceIdT(deviceId) : undefined,
|
||||
trackerNum
|
||||
);
|
||||
req.trackerId = id;
|
||||
if (trackerId !== undefined) {
|
||||
req.trackerId = trackerId;
|
||||
}
|
||||
|
||||
req.enable = values.magToggle;
|
||||
sendRPCPacket(RpcMessage.ChangeMagToggleRequest, req);
|
||||
},
|
||||
[trackerNum, deviceId]
|
||||
[trackerId]
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
@@ -66,25 +58,18 @@ export function MagnetometerToggleSetting({
|
||||
|
||||
useEffect(() => {
|
||||
const req = new MagToggleRequestT();
|
||||
if (trackerNum !== undefined) {
|
||||
const id = new TrackerIdT(
|
||||
deviceId ? new DeviceIdT(deviceId) : undefined,
|
||||
trackerNum
|
||||
);
|
||||
req.trackerId = id;
|
||||
if (trackerId !== undefined) {
|
||||
req.trackerId = trackerId;
|
||||
sendRPCPacket(RpcMessage.MagToggleRequest, new MagToggleRequestT());
|
||||
}
|
||||
sendRPCPacket(RpcMessage.MagToggleRequest, req);
|
||||
}, [trackerNum, deviceId]);
|
||||
}, [trackerId]);
|
||||
|
||||
useRPCPacket(RpcMessage.MagToggleResponse, (mag: MagToggleResponseT) => {
|
||||
if (trackerNum !== undefined && mag.trackerId?.trackerNum === undefined) {
|
||||
if (trackerId !== undefined && mag.trackerId === undefined) {
|
||||
setGlobalToggle(mag.enable);
|
||||
}
|
||||
if (
|
||||
mag.trackerId?.trackerNum !== trackerNum ||
|
||||
mag.trackerId?.deviceId?.id !== deviceId
|
||||
) {
|
||||
if (mag.trackerId !== trackerId) {
|
||||
return;
|
||||
}
|
||||
originalValue.current = mag.enable;
|
||||
|
||||
@@ -0,0 +1,311 @@
|
||||
import { Localized, useLocalization } from '@fluent/react';
|
||||
import {useEffect, useRef, useState} from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import {
|
||||
BodyPart,
|
||||
ChangeOutputTrackersSettingsRequestT, OutputTrackersSettingsResponseT,
|
||||
RpcMessage, SettingsResponseT, TapDetectionSettingsT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import { CheckBox } from '@/components/commons/Checkbox';
|
||||
import { FileInput } from '@/components/commons/FileInput';
|
||||
import { OutputTrackersIcon } from '@/components/commons/icon/OutputTrackersIcon';
|
||||
import { Input } from '@/components/commons/Input';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
import { magic } from '@/utils/formatting';
|
||||
import {
|
||||
SettingsPageLayout,
|
||||
SettingsPagePaneLayout,
|
||||
} from '@/components/settings/SettingsPageLayout';
|
||||
import { error } from '@/utils/logging';
|
||||
import {
|
||||
OSCPortsAddress,
|
||||
useOscPortsAddressValidator,
|
||||
} from '@/hooks/osc-setting-validator';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { boolean, object } from 'yup';
|
||||
import {atom, useAtomValue, useSetAtom} from "jotai";
|
||||
import {selectAtom} from "jotai/utils";
|
||||
import {isEqual} from "@react-hookz/deep-equal";
|
||||
|
||||
interface OutputTrackersSettingsForm {
|
||||
automaticTrackerToggle: boolean;
|
||||
waist: boolean;
|
||||
chest: boolean;
|
||||
leftFoot: boolean;
|
||||
rightFoot: boolean;
|
||||
leftKnee: boolean;
|
||||
rightKnee: boolean;
|
||||
leftElbow: boolean;
|
||||
rightElbow: boolean;
|
||||
leftHand: boolean;
|
||||
rightHand: boolean;
|
||||
sendDerivedVelocity: boolean;
|
||||
}
|
||||
|
||||
const defaultOutputTrackersSettings: OutputTrackersSettingsForm = {
|
||||
automaticTrackerToggle: true,
|
||||
waist: false,
|
||||
chest: false,
|
||||
leftFoot: false,
|
||||
rightFoot: false,
|
||||
leftElbow: false,
|
||||
rightElbow: false,
|
||||
leftHand: false,
|
||||
rightHand: false,
|
||||
leftKnee: false,
|
||||
rightKnee: false,
|
||||
sendDerivedVelocity: false,
|
||||
};
|
||||
|
||||
const settingsAtom = atom(new OutputTrackersSettingsResponseT());
|
||||
const settingsValueAtom = selectAtom(
|
||||
settingsAtom,
|
||||
(settings) => settings,
|
||||
isEqual
|
||||
);
|
||||
|
||||
export function OutputTrackersSettings() {
|
||||
const setSettings = useSetAtom(settingsAtom);
|
||||
const settings = useAtomValue(settingsValueAtom);
|
||||
const { l10n } = useLocalization();
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
|
||||
const { reset, control, watch, handleSubmit } = useForm<OutputTrackersSettingsForm>({
|
||||
defaultValues: defaultOutputTrackersSettings,
|
||||
reValidateMode: 'onChange',
|
||||
mode: 'onChange',
|
||||
resolver: yupResolver(
|
||||
object({
|
||||
automaticTrackerToggle: boolean().required(),
|
||||
waist: boolean().required(),
|
||||
chest: boolean().required(),
|
||||
leftFoot: boolean().required(),
|
||||
rightFoot: boolean().required(),
|
||||
leftKnee: boolean().required(),
|
||||
rightKnee: boolean().required(),
|
||||
leftElbow: boolean().required(),
|
||||
rightElbow: boolean().required(),
|
||||
leftHand: boolean().required(),
|
||||
rightHand: boolean().required(),
|
||||
sendDerivedVelocity: boolean().required(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
const blockHandsWarning = useRef(false);
|
||||
// If not null, warning will be shown, and showHandsWarning will
|
||||
// hold which hands should be toggled ([leftHand, rightHand])
|
||||
const [showHandsWarning, setShowHandsWarning] = useState<
|
||||
[boolean, boolean] | null
|
||||
>(null);
|
||||
|
||||
const {
|
||||
trackers: { automaticTrackerToggle },
|
||||
} = watch();
|
||||
|
||||
const onSubmit = async (values: OutputTrackersSettingsForm) => {
|
||||
const req = new ChangeOutputTrackersSettingsRequestT();
|
||||
|
||||
// The tracker is at the tail of the bone.
|
||||
// Example, the waist tracker is at the tail of the hip bone so we use the hip BodyPart
|
||||
const enabledBodyParts: [boolean, BodyPart][] = [
|
||||
[values.waist, BodyPart.HIP],
|
||||
[values.chest, BodyPart.CHEST],
|
||||
[values.leftFoot, BodyPart.LEFT_FOOT],
|
||||
[values.rightFoot, BodyPart.RIGHT_FOOT],
|
||||
[values.leftKnee, BodyPart.LEFT_UPPER_LEG],
|
||||
[values.rightKnee, BodyPart.RIGHT_UPPER_LEG],
|
||||
[values.leftElbow, BodyPart.LEFT_UPPER_ARM],
|
||||
[values.rightElbow, BodyPart.RIGHT_UPPER_ARM],
|
||||
[values.leftHand, BodyPart.LEFT_HAND],
|
||||
[values.rightHand, BodyPart.RIGHT_HAND],
|
||||
];
|
||||
req.trackers = enabledBodyParts
|
||||
.filter(([enabled]) => enabled)
|
||||
.map(([, part]) => part);
|
||||
|
||||
// Hand warning
|
||||
if (
|
||||
!blockHandsWarning.current &&
|
||||
!showHandsWarning &&
|
||||
!settings?.trackers.includes(BodyPart.LEFT_HAND) &&
|
||||
!settings?.trackers.includes(BodyPart.RIGHT_HAND) &&
|
||||
(values.leftHand || values.rightHand)
|
||||
) {
|
||||
// We have just toggled on one of the hand trackers, show the user a warning
|
||||
setShowHandsWarning([values.leftHand, values.rightHand]);
|
||||
values.leftHand = false;
|
||||
values.rightHand = false;
|
||||
} else if (
|
||||
blockHandsWarning.current &&
|
||||
!values.leftHand && !values.rightHand
|
||||
) {
|
||||
// Both hand trackers have just been disabled, make sure the warning shows up
|
||||
// again next time the user toggles one back on
|
||||
blockHandsWarning.current = false;
|
||||
}
|
||||
|
||||
req.automaticTrackerToggle = values.automaticTrackerToggle;
|
||||
req.sendDerivedVelocity = values.sendDerivedVelocity;
|
||||
|
||||
sendRPCPacket(RpcMessage.ChangeOutputTrackersSettingsRequest, req);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch(() => handleSubmit(onSubmit)());
|
||||
return () => subscription.unsubscribe();
|
||||
}, []);
|
||||
|
||||
useRPCPacket(RpcMessage.OutputTrackersSettingsResponse, (settings: OutputTrackersSettingsResponseT) => {
|
||||
const formData: OutputTrackersSettingsForm = defaultOutputTrackersSettings;
|
||||
formData.automaticTrackerToggle = settings.automaticTrackerToggle;
|
||||
formData.sendDerivedVelocity = settings.sendDerivedVelocity;
|
||||
|
||||
reset(formData);
|
||||
});
|
||||
|
||||
return (
|
||||
<SettingsPageLayout>
|
||||
<form className="flex flex-col gap-2 w-full">
|
||||
<SettingsPagePaneLayout icon={<OutputTrackersIcon />} id="vmc">
|
||||
<>
|
||||
<Typography variant="main-title">
|
||||
{l10n.getString('settings-osc-vmc')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pt-2 pb-4">
|
||||
<>
|
||||
{l10n
|
||||
.getString('settings-osc-vmc-description')
|
||||
.split('\n')
|
||||
.map((line, i) => (
|
||||
<Typography key={i}>{line}</Typography>
|
||||
))}
|
||||
</>
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-enable')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography>
|
||||
{l10n.getString('settings-osc-vmc-enable-description')}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3 pb-5">
|
||||
<CheckBox
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="enabled"
|
||||
label={l10n.getString('settings-osc-vmc-enable-label')}
|
||||
/>
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-network')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<>
|
||||
{l10n
|
||||
.getString('settings-osc-vmc-network-description')
|
||||
.split('\n')
|
||||
.map((line, i) => (
|
||||
<Typography key={i}>{line}</Typography>
|
||||
))}
|
||||
</>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3 pb-5">
|
||||
<Localized
|
||||
id="settings-osc-vmc-network-port_in"
|
||||
attrs={{ placeholder: true, label: true }}
|
||||
>
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="portsAddress.portIn"
|
||||
placeholder="9002"
|
||||
label=""
|
||||
/>
|
||||
</Localized>
|
||||
<Localized
|
||||
id="settings-osc-vmc-network-port_out"
|
||||
attrs={{ placeholder: true, label: true }}
|
||||
>
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="portsAddress.portOut"
|
||||
placeholder="9000"
|
||||
label=""
|
||||
/>
|
||||
</Localized>
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-network-address')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography>
|
||||
{l10n.getString('settings-osc-vmc-network-address-description')}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid gap-3 pb-5">
|
||||
<Input
|
||||
type="text"
|
||||
control={control}
|
||||
name="portsAddress.address"
|
||||
placeholder={l10n.getString(
|
||||
'settings-osc-vmc-network-address-placeholder'
|
||||
)}
|
||||
label=""
|
||||
/>
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-vrm')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography>
|
||||
{l10n.getString('settings-osc-vmc-vrm-description')}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid gap-3 pb-5">
|
||||
<OutputTrackersFileUpload />
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-anchor_hip')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography>
|
||||
{l10n.getString('settings-osc-vmc-anchor_hip-description')}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3 pb-5">
|
||||
<CheckBox
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="anchorHip"
|
||||
label={l10n.getString('settings-osc-vmc-anchor_hip-label')}
|
||||
/>
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-mirror_tracking')}
|
||||
</Typography>
|
||||
<div className="flex flex-col pb-2">
|
||||
<Typography>
|
||||
{l10n.getString('settings-osc-vmc-mirror_tracking-description')}
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid grid-cols-2 gap-3 pb-5">
|
||||
<CheckBox
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="mirrorTracking"
|
||||
label={l10n.getString('settings-osc-vmc-mirror_tracking-label')}
|
||||
/>
|
||||
</div>
|
||||
</>
|
||||
</SettingsPagePaneLayout>
|
||||
</form>
|
||||
</SettingsPageLayout>
|
||||
);
|
||||
}
|
||||
@@ -2,13 +2,13 @@ import { Localized, useLocalization } from '@fluent/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import {
|
||||
ChangeSettingsRequestT,
|
||||
ChangeVMCOSCSettingsRequestT,
|
||||
ChangeVRMSettingsRequestT,
|
||||
RpcMessage,
|
||||
SettingsRequestT,
|
||||
SettingsResponseT,
|
||||
OSCSettingsT,
|
||||
VMCOSCSettingsT,
|
||||
VRMSettingsT,
|
||||
VMCOSCSettingsRequestT,
|
||||
VMCOSCSettingsResponseT,
|
||||
VRMSettingsRequestT,
|
||||
VRMSettingsResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import { CheckBox } from '@/components/commons/Checkbox';
|
||||
@@ -23,34 +23,31 @@ import {
|
||||
} from '@/components/settings/SettingsPageLayout';
|
||||
import { error } from '@/utils/logging';
|
||||
import {
|
||||
OSCSettings,
|
||||
useOscSettingsValidator,
|
||||
OSCPortsAddress,
|
||||
useOscPortsAddressValidator,
|
||||
} from '@/hooks/osc-setting-validator';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import { boolean, object } from 'yup';
|
||||
|
||||
interface VMCSettingsForm {
|
||||
vmc: {
|
||||
oscSettings: OSCSettings;
|
||||
anchorHip: boolean;
|
||||
mirrorTracking: boolean;
|
||||
};
|
||||
enabled: boolean,
|
||||
portsAddress: OSCPortsAddress,
|
||||
anchorHip: boolean;
|
||||
mirrorTracking: boolean;
|
||||
}
|
||||
|
||||
const defaultValues = {
|
||||
vmc: {
|
||||
oscSettings: {
|
||||
enabled: false,
|
||||
portIn: 39540,
|
||||
portOut: 39539,
|
||||
address: '127.0.0.1',
|
||||
},
|
||||
anchorHip: true,
|
||||
mirrorTracking: true,
|
||||
const defaultVMCSettings: VMCSettingsForm = {
|
||||
enabled: false,
|
||||
portsAddress: {
|
||||
portIn: 39540,
|
||||
portOut: 39539,
|
||||
address: '127.0.0.1',
|
||||
},
|
||||
anchorHip: true,
|
||||
mirrorTracking: true,
|
||||
};
|
||||
|
||||
export function VMCFileUpload() {
|
||||
export function VRMFileUpload() {
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const { l10n } = useLocalization();
|
||||
const [modelName, setModelName] = useState<string | null>(null);
|
||||
@@ -66,22 +63,20 @@ export function VMCFileUpload() {
|
||||
const vrmJson = watch('vrmJson');
|
||||
|
||||
const updateVRMJson = async () => {
|
||||
const req = new ChangeSettingsRequestT();
|
||||
const vrm = new VRMSettingsT();
|
||||
const req = new ChangeVRMSettingsRequestT();
|
||||
if (vrmJson !== undefined) {
|
||||
if (vrmJson.length > 0) {
|
||||
const file = await parseVRMFile(vrmJson[0]);
|
||||
if (file) {
|
||||
vrm.vrmJson = file.json;
|
||||
req.vrmJson = file.json;
|
||||
setModelName(file.name);
|
||||
}
|
||||
} else {
|
||||
vrm.vrmJson = '';
|
||||
req.vrmJson = '';
|
||||
setModelName(null);
|
||||
}
|
||||
}
|
||||
req.vrm = vrm;
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, req);
|
||||
sendRPCPacket(RpcMessage.ChangeVRMSettingsRequest, req);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -89,11 +84,12 @@ export function VMCFileUpload() {
|
||||
}, [vrmJson]);
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
|
||||
sendRPCPacket(RpcMessage.VMCOSCSettingsRequest, new VMCOSCSettingsRequestT());
|
||||
sendRPCPacket(RpcMessage.VRMSettingsRequest, new VRMSettingsRequestT());
|
||||
}, []);
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
const vrmJson = settings.vrm?.vrmJson?.toString();
|
||||
useRPCPacket(RpcMessage.VRMSettingsResponse, (settings: VRMSettingsResponseT) => {
|
||||
const vrmJson = settings.vrmJson?.toString();
|
||||
if (vrmJson) {
|
||||
let data: any;
|
||||
try {
|
||||
@@ -114,7 +110,7 @@ export function VMCFileUpload() {
|
||||
}}
|
||||
value="help"
|
||||
importedFileName={
|
||||
// if modelname is an empty string, it's an untitled model
|
||||
// if modelName is an empty string, it's an untitled model
|
||||
modelName === ''
|
||||
? l10n.getString('settings-osc-vmc-vrm-untitled_model')
|
||||
: modelName
|
||||
@@ -128,39 +124,33 @@ export function VMCFileUpload() {
|
||||
export function VMCSettings() {
|
||||
const { l10n } = useLocalization();
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const { oscValidator } = useOscSettingsValidator();
|
||||
const { oscValidator } = useOscPortsAddressValidator();
|
||||
|
||||
const { reset, control, watch, handleSubmit } = useForm<VMCSettingsForm>({
|
||||
defaultValues,
|
||||
defaultValues: defaultVMCSettings,
|
||||
reValidateMode: 'onChange',
|
||||
mode: 'onChange',
|
||||
resolver: yupResolver(
|
||||
object({
|
||||
vmc: object({
|
||||
oscSettings: oscValidator,
|
||||
anchorHip: boolean().required(),
|
||||
mirrorTracking: boolean().required(),
|
||||
}),
|
||||
enabled: boolean().required(),
|
||||
portsAddress: oscValidator,
|
||||
anchorHip: boolean().required(),
|
||||
mirrorTracking: boolean().required(),
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
const onSubmit = async (values: VMCSettingsForm) => {
|
||||
const settings = new ChangeSettingsRequestT();
|
||||
const req = new ChangeVMCOSCSettingsRequestT();
|
||||
|
||||
if (values.vmc) {
|
||||
const vmcOsc = new VMCOSCSettingsT();
|
||||
req.enabled = values.enabled
|
||||
req.portIn = values.portsAddress.portIn
|
||||
req.portOut = values.portsAddress.portOut
|
||||
req.address = values.portsAddress.address
|
||||
req.anchorHip = values.anchorHip;
|
||||
req.mirrorTracking = values.mirrorTracking;
|
||||
|
||||
vmcOsc.oscSettings = Object.assign(
|
||||
new OSCSettingsT(),
|
||||
values.vmc.oscSettings
|
||||
);
|
||||
vmcOsc.anchorHip = values.vmc.anchorHip;
|
||||
vmcOsc.mirrorTracking = values.vmc.mirrorTracking;
|
||||
|
||||
settings.vmcOsc = vmcOsc;
|
||||
}
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settings);
|
||||
sendRPCPacket(RpcMessage.ChangeVMCOSCSettingsRequest, req);
|
||||
};
|
||||
|
||||
useEffect(() => {
|
||||
@@ -168,27 +158,19 @@ export function VMCSettings() {
|
||||
return () => subscription.unsubscribe();
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
|
||||
}, []);
|
||||
useRPCPacket(RpcMessage.VMCOSCSettingsResponse, (settings: VMCOSCSettingsResponseT) => {
|
||||
const formData: VMCSettingsForm = defaultVMCSettings;
|
||||
if (settings) {
|
||||
formData.enabled = settings.enabled;
|
||||
if (settings.portIn)
|
||||
formData.portsAddress.portIn = settings.portIn;
|
||||
if (settings.portOut)
|
||||
formData.portsAddress.portOut = settings.portOut;
|
||||
if (settings.address)
|
||||
formData.portsAddress.address = settings.address.toString();
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
const formData: VMCSettingsForm = defaultValues;
|
||||
if (settings.vmcOsc) {
|
||||
if (settings.vmcOsc.oscSettings) {
|
||||
formData.vmc.oscSettings.enabled = settings.vmcOsc.oscSettings.enabled;
|
||||
if (settings.vmcOsc.oscSettings.portIn)
|
||||
formData.vmc.oscSettings.portIn = settings.vmcOsc.oscSettings.portIn;
|
||||
if (settings.vmcOsc.oscSettings.portOut)
|
||||
formData.vmc.oscSettings.portOut =
|
||||
settings.vmcOsc.oscSettings.portOut;
|
||||
if (settings.vmcOsc.oscSettings.address)
|
||||
formData.vmc.oscSettings.address =
|
||||
settings.vmcOsc.oscSettings.address.toString();
|
||||
}
|
||||
|
||||
formData.vmc.anchorHip = settings.vmcOsc.anchorHip;
|
||||
formData.vmc.mirrorTracking = settings.vmcOsc.mirrorTracking;
|
||||
formData.anchorHip = settings.anchorHip;
|
||||
formData.mirrorTracking = settings.mirrorTracking;
|
||||
|
||||
reset(formData);
|
||||
}
|
||||
@@ -225,7 +207,7 @@ export function VMCSettings() {
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="vmc.oscSettings.enabled"
|
||||
name="enabled"
|
||||
label={l10n.getString('settings-osc-vmc-enable-label')}
|
||||
/>
|
||||
</div>
|
||||
@@ -250,7 +232,7 @@ export function VMCSettings() {
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="vmc.oscSettings.portIn"
|
||||
name="portsAddress.portIn"
|
||||
placeholder="9002"
|
||||
label=""
|
||||
/>
|
||||
@@ -262,7 +244,7 @@ export function VMCSettings() {
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="vmc.oscSettings.portOut"
|
||||
name="portsAddress.portOut"
|
||||
placeholder="9000"
|
||||
label=""
|
||||
/>
|
||||
@@ -280,7 +262,7 @@ export function VMCSettings() {
|
||||
<Input
|
||||
type="text"
|
||||
control={control}
|
||||
name="vmc.oscSettings.address"
|
||||
name="portsAddress.address"
|
||||
placeholder={l10n.getString(
|
||||
'settings-osc-vmc-network-address-placeholder'
|
||||
)}
|
||||
@@ -296,7 +278,7 @@ export function VMCSettings() {
|
||||
</Typography>
|
||||
</div>
|
||||
<div className="grid gap-3 pb-5">
|
||||
<VMCFileUpload />
|
||||
<VRMFileUpload />
|
||||
</div>
|
||||
<Typography variant="section-title">
|
||||
{l10n.getString('settings-osc-vmc-anchor_hip')}
|
||||
@@ -311,7 +293,7 @@ export function VMCSettings() {
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="vmc.anchorHip"
|
||||
name="anchorHip"
|
||||
label={l10n.getString('settings-osc-vmc-anchor_hip-label')}
|
||||
/>
|
||||
</div>
|
||||
@@ -328,7 +310,7 @@ export function VMCSettings() {
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="vmc.mirrorTracking"
|
||||
name="mirrorTracking"
|
||||
label={l10n.getString('settings-osc-vmc-mirror_tracking-label')}
|
||||
/>
|
||||
</div>
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import { Localized, useLocalization } from '@fluent/react';
|
||||
import { yupResolver } from '@hookform/resolvers/yup';
|
||||
import classNames from 'classnames';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
import { ReactNode, useEffect, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { boolean, number, object, string } from 'yup';
|
||||
import { boolean, object } from 'yup';
|
||||
import {
|
||||
ChangeVRCOSCSettingsRequestT,
|
||||
RpcMessage,
|
||||
@@ -13,7 +13,6 @@ import {
|
||||
VRCOSCOutputState,
|
||||
VRCOSCSettingsRequestT,
|
||||
VRCOSCSettingsResponseT,
|
||||
VRCOSCSettingsT,
|
||||
VRCOSCStatusChangeResponseT,
|
||||
VRCOSCStatusRequestT,
|
||||
VRCOSCTargetSource,
|
||||
@@ -29,30 +28,23 @@ import {
|
||||
SettingsPagePaneLayout,
|
||||
} from '@/components/settings/SettingsPageLayout';
|
||||
import { useWebsocketAPI } from '@/hooks/websocket-api';
|
||||
import {OSCPortsAddress, useOscPortsAddressValidator} from "@/hooks/osc-setting-validator";
|
||||
|
||||
interface VRCOSCSettingsForm {
|
||||
vrchat: {
|
||||
enabled: boolean;
|
||||
useManualNetwork: boolean;
|
||||
manualNetwork: {
|
||||
portIn: number;
|
||||
portOut: number;
|
||||
address: string;
|
||||
};
|
||||
};
|
||||
enabled: boolean;
|
||||
useManualNetwork: boolean;
|
||||
manualNetwork: OSCPortsAddress
|
||||
}
|
||||
|
||||
const createDefaultValues = (): VRCOSCSettingsForm => ({
|
||||
vrchat: {
|
||||
enabled: false,
|
||||
useManualNetwork: false,
|
||||
manualNetwork: {
|
||||
portIn: 9001,
|
||||
portOut: 9000,
|
||||
address: '127.0.0.1',
|
||||
},
|
||||
const defaultVRCOSCSettings: VRCOSCSettingsForm = {
|
||||
enabled: false,
|
||||
useManualNetwork: false,
|
||||
manualNetwork: {
|
||||
portIn: 9001,
|
||||
portOut: 9000,
|
||||
address: '127.0.0.1',
|
||||
},
|
||||
});
|
||||
};
|
||||
|
||||
function asString(value: string | Uint8Array | null | undefined): string {
|
||||
return typeof value === 'string' ? value : '';
|
||||
@@ -126,7 +118,7 @@ function StatusRow({
|
||||
}: {
|
||||
label: string;
|
||||
badge: BadgeKind;
|
||||
children?: React.ReactNode;
|
||||
children?: ReactNode;
|
||||
}) {
|
||||
return (
|
||||
<div className="flex flex-col gap-1 py-2">
|
||||
@@ -358,52 +350,23 @@ export function VRCOSCSettings() {
|
||||
);
|
||||
const [now, setNow] = useState(() => Date.now());
|
||||
|
||||
const bannedPorts = [6969, 21110];
|
||||
const portValidator = useMemo(
|
||||
() =>
|
||||
number()
|
||||
.typeError(' ')
|
||||
.required()
|
||||
.test(
|
||||
'ports-dont-match',
|
||||
l10n.getString('settings-osc-common-network-ports_match_error-v2'),
|
||||
(_port, context) => context.parent.portIn != context.parent.portOut
|
||||
)
|
||||
.notOneOf(bannedPorts, (context) =>
|
||||
l10n.getString('settings-osc-common-network-port_banned_error', {
|
||||
port: context.originalValue,
|
||||
})
|
||||
),
|
||||
[l10n]
|
||||
);
|
||||
|
||||
const { oscValidator } = useOscPortsAddressValidator();
|
||||
const { reset, control, watch, handleSubmit, setValue } =
|
||||
useForm<VRCOSCSettingsForm>({
|
||||
defaultValues: createDefaultValues(),
|
||||
defaultValues: defaultVRCOSCSettings,
|
||||
reValidateMode: 'onChange',
|
||||
mode: 'onChange',
|
||||
resolver: yupResolver(
|
||||
object({
|
||||
vrchat: object({
|
||||
enabled: boolean().required(),
|
||||
useManualNetwork: boolean().required(),
|
||||
manualNetwork: object({
|
||||
portIn: portValidator,
|
||||
portOut: portValidator,
|
||||
address: string()
|
||||
.required(' ')
|
||||
.matches(
|
||||
/^(?!0)(?!.*\.$)((1?\d?\d|25[0-5]|2[0-4]\d)(\.|$)){4}$/i,
|
||||
{ message: ' ' }
|
||||
),
|
||||
}),
|
||||
}),
|
||||
enabled: boolean().required(),
|
||||
useManualNetwork: boolean().required(),
|
||||
manualNetwork: oscValidator,
|
||||
})
|
||||
),
|
||||
});
|
||||
|
||||
const enabled = watch('vrchat.enabled');
|
||||
const useManualNetwork = watch('vrchat.useManualNetwork');
|
||||
const enabled = watch('enabled');
|
||||
const useManualNetwork = watch('useManualNetwork');
|
||||
|
||||
useEffect(() => {
|
||||
const interval = window.setInterval(() => setNow(Date.now()), 1_000);
|
||||
@@ -412,14 +375,12 @@ export function VRCOSCSettings() {
|
||||
|
||||
const onSubmit = (values: VRCOSCSettingsForm) => {
|
||||
const req = new ChangeVRCOSCSettingsRequestT();
|
||||
const vrcOsc = new VRCOSCSettingsT();
|
||||
|
||||
vrcOsc.enabled = values.vrchat.enabled;
|
||||
vrcOsc.manualNetwork = values.vrchat.useManualNetwork
|
||||
? Object.assign(new VRCOSCNetworkSettingsT(), values.vrchat.manualNetwork)
|
||||
req.enabled = values.enabled;
|
||||
req.manualNetwork = values.useManualNetwork
|
||||
? Object.assign(new VRCOSCNetworkSettingsT(), values.manualNetwork)
|
||||
: null;
|
||||
|
||||
req.settings = vrcOsc;
|
||||
sendRPCPacket(RpcMessage.ChangeVRCOSCSettingsRequest, req);
|
||||
};
|
||||
|
||||
@@ -439,18 +400,17 @@ export function VRCOSCSettings() {
|
||||
useRPCPacket(
|
||||
RpcMessage.VRCOSCSettingsResponse,
|
||||
(response: VRCOSCSettingsResponseT) => {
|
||||
const settings = response.settings;
|
||||
const formData = createDefaultValues();
|
||||
if (settings) {
|
||||
formData.vrchat.enabled = settings.enabled;
|
||||
if (settings.manualNetwork) {
|
||||
formData.vrchat.useManualNetwork = true;
|
||||
formData.vrchat.manualNetwork.portIn = settings.manualNetwork.portIn;
|
||||
formData.vrchat.manualNetwork.portOut =
|
||||
settings.manualNetwork.portOut;
|
||||
if (settings.manualNetwork.address) {
|
||||
formData.vrchat.manualNetwork.address = asString(
|
||||
settings.manualNetwork.address
|
||||
const formData = defaultVRCOSCSettings;
|
||||
if (response) {
|
||||
formData.enabled = response.enabled;
|
||||
if (response.manualNetwork) {
|
||||
formData.useManualNetwork = true;
|
||||
formData.manualNetwork.portIn = response.manualNetwork.portIn;
|
||||
formData.manualNetwork.portOut =
|
||||
response.manualNetwork.portOut;
|
||||
if (response.manualNetwork.address) {
|
||||
formData.manualNetwork.address = asString(
|
||||
response.manualNetwork.address
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -499,7 +459,7 @@ export function VRCOSCSettings() {
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="vrchat.enabled"
|
||||
name="enabled"
|
||||
label={l10n.getString('settings-osc-vrchat-enable-label')}
|
||||
/>
|
||||
</div>
|
||||
@@ -513,15 +473,15 @@ export function VRCOSCSettings() {
|
||||
status={status}
|
||||
now={now}
|
||||
onSwitchToTarget={(target) => {
|
||||
setValue('vrchat.useManualNetwork', true, {
|
||||
setValue('useManualNetwork', true, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
setValue(
|
||||
'vrchat.manualNetwork.address',
|
||||
'manualNetwork.address',
|
||||
asString(target.address),
|
||||
{ shouldDirty: true }
|
||||
);
|
||||
setValue('vrchat.manualNetwork.portOut', target.portOut, {
|
||||
setValue('manualNetwork.portOut', target.portOut, {
|
||||
shouldDirty: true,
|
||||
});
|
||||
}}
|
||||
@@ -544,7 +504,7 @@ export function VRCOSCSettings() {
|
||||
variant="toggle"
|
||||
outlined
|
||||
control={control}
|
||||
name="vrchat.useManualNetwork"
|
||||
name="useManualNetwork"
|
||||
label={l10n.getString(
|
||||
'settings-osc-vrchat-status-network-mode-toggle'
|
||||
)}
|
||||
@@ -571,7 +531,7 @@ export function VRCOSCSettings() {
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="vrchat.manualNetwork.portIn"
|
||||
name="manualNetwork.portIn"
|
||||
placeholder="9001"
|
||||
label=""
|
||||
/>
|
||||
@@ -583,7 +543,7 @@ export function VRCOSCSettings() {
|
||||
<Input
|
||||
type="number"
|
||||
control={control}
|
||||
name="vrchat.manualNetwork.portOut"
|
||||
name="manualNetwork.portOut"
|
||||
placeholder="9000"
|
||||
label=""
|
||||
/>
|
||||
@@ -603,7 +563,7 @@ export function VRCOSCSettings() {
|
||||
<Input
|
||||
type="text"
|
||||
control={control}
|
||||
name="vrchat.manualNetwork.address"
|
||||
name="manualNetwork.address"
|
||||
placeholder={l10n.getString(
|
||||
'settings-osc-vrchat-network-address-placeholder'
|
||||
)}
|
||||
|
||||
@@ -506,8 +506,7 @@ export function TrackerSettingsPage() {
|
||||
MagnetometerStatus.NOT_SUPPORTED && (
|
||||
<MagnetometerToggleSetting
|
||||
settingType="tracker"
|
||||
trackerNum={tracker.tracker.trackerId?.trackerNum}
|
||||
deviceId={tracker.tracker.trackerId?.deviceId?.id}
|
||||
trackerId={tracker.tracker.trackerId}
|
||||
/>
|
||||
)}
|
||||
<div className="flex flex-col gap-2 w-full mt-3 sentry-mask">
|
||||
|
||||
@@ -186,8 +186,8 @@ function Row({
|
||||
const warning =
|
||||
!!highlightedTrackers?.trackers.find(
|
||||
(t) =>
|
||||
t?.deviceId?.id === tracker.trackerId?.deviceId?.id &&
|
||||
t?.trackerNum === tracker.trackerId?.trackerNum
|
||||
t?.deviceId?.id === tracker.deviceId &&
|
||||
t?.trackerNum === tracker.trackerId
|
||||
) && highlightedTrackers.step;
|
||||
|
||||
return (
|
||||
|
||||
@@ -6,17 +6,13 @@ import {
|
||||
} from '@/hooks/tracking-checklist';
|
||||
import classNames from 'classnames';
|
||||
import {
|
||||
ChangeSettingsRequestT,
|
||||
EnableSteamVRDriverRequestT,
|
||||
ResetType,
|
||||
RpcMessage,
|
||||
SettingsRequestT,
|
||||
SettingsResponseT,
|
||||
OutputTrackersSettingT,
|
||||
TrackingChecklistPublicNetworksT,
|
||||
TrackingChecklistSteamVRDisconnectedT,
|
||||
TrackingChecklistStepId,
|
||||
BodyPart,
|
||||
BodyPart, ChangeOutputTrackersSettingsRequestT, OutputTrackersSettingsResponseT, OutputTrackersSettingsRequestT,
|
||||
} from 'solarxr-protocol';
|
||||
import { ReactNode, useEffect, useMemo, useState } from 'react';
|
||||
import { CheckIcon } from '@/components/commons/icon/CheckIcon';
|
||||
@@ -177,30 +173,33 @@ function SteamVRDisconnected({
|
||||
function SteamVRHandsEnabled() {
|
||||
const { sendRPCPacket, useRPCPacket } = useWebsocketAPI();
|
||||
const [steamVrTrackers, setSteamVrTrackers] = useState<Omit<
|
||||
OutputTrackersSettingT,
|
||||
ChangeOutputTrackersSettingsRequestT,
|
||||
'pack'
|
||||
> | null>(null);
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsRequestT());
|
||||
sendRPCPacket(RpcMessage.OutputTrackersSettingsRequest, new OutputTrackersSettingsRequestT());
|
||||
}, []);
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
if (settings.outputTrackers) {
|
||||
setSteamVrTrackers(settings.outputTrackers);
|
||||
useRPCPacket(RpcMessage.OutputTrackersSettingsResponse, (settings: OutputTrackersSettingsResponseT) => {
|
||||
if (settings.trackers) {
|
||||
setSteamVrTrackers(settings);
|
||||
}
|
||||
});
|
||||
|
||||
const disableHandTrackers = () => {
|
||||
const settings = new ChangeSettingsRequestT();
|
||||
settings.outputTrackers = new OutputTrackersSettingT(
|
||||
steamVrTrackers?.automaticTrackerToggle,
|
||||
steamVrTrackers?.trackers.filter(
|
||||
(tracker) =>
|
||||
tracker != BodyPart.LEFT_HAND && tracker != BodyPart.RIGHT_HAND
|
||||
)
|
||||
);
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, settings);
|
||||
const req = new ChangeOutputTrackersSettingsRequestT();
|
||||
|
||||
const newTrackers = steamVrTrackers?.trackers.filter(tracker =>
|
||||
tracker != BodyPart.LEFT_HAND && tracker != BodyPart.RIGHT_HAND
|
||||
)
|
||||
if (newTrackers !== undefined) {
|
||||
req.trackers = newTrackers
|
||||
}
|
||||
req.automaticTrackerToggle = steamVrTrackers?.automaticTrackerToggle === true
|
||||
req.sendDerivedVelocity = steamVrTrackers?.sendDerivedVelocity === true
|
||||
|
||||
sendRPCPacket(RpcMessage.ChangeOutputTrackersSettingsRequest, req);
|
||||
};
|
||||
|
||||
return (
|
||||
@@ -294,7 +293,7 @@ const stepContentLookup: Record<
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex">
|
||||
<ResetButton type={ResetType.Full} />
|
||||
<ResetButton type={ResetType.FULL} />
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
@@ -386,7 +385,7 @@ const stepContentLookup: Record<
|
||||
/>
|
||||
</div>
|
||||
<div className="flex justify-between sm:items-center gap-1 flex-col sm:flex-row">
|
||||
<ResetButton type={ResetType.Mounting} group="default" />
|
||||
<ResetButton type={ResetType.MOUNTING} group="default" />
|
||||
{step.ignorable && (
|
||||
<Button
|
||||
id="tracking_checklist-ignore"
|
||||
@@ -423,7 +422,7 @@ const stepContentLookup: Record<
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex justify-between sm:items-center gap-1 flex-col sm:flex-row">
|
||||
<ResetButton type={ResetType.Mounting} group="feet" />
|
||||
<ResetButton type={ResetType.MOUNTING} group="feet" />
|
||||
{step.ignorable && (
|
||||
<Button
|
||||
id="tracking_checklist-ignore"
|
||||
|
||||
@@ -234,10 +234,7 @@ function IMUVisualizerCanvas({
|
||||
export function IMUVisualizerWidget({ tracker }: { tracker: TrackerDataT }) {
|
||||
const { l10n } = useLocalization();
|
||||
const [enabled, setEnabled] = useState(false);
|
||||
const isExtension = useMemo(
|
||||
() => (tracker.trackerId?.trackerNum ?? 0) > 0,
|
||||
[tracker]
|
||||
);
|
||||
const isExtension = false // TODO Do we want to display extensions?
|
||||
|
||||
useEffect(() => {
|
||||
const state = localStorage.getItem('modelPreview');
|
||||
|
||||
@@ -1,89 +0,0 @@
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { useEffect, useState } from 'react';
|
||||
import { useForm } from 'react-hook-form';
|
||||
import { KeyValuesT, MessageT, Payload, Topic } from 'solarxr-protocol';
|
||||
import {
|
||||
OVERLAY_DISPLAY_SETTINGS_TOPIC,
|
||||
PayloadData,
|
||||
usePubSub,
|
||||
} from '@/hooks/pubSub';
|
||||
import { CheckBox } from '@/components/commons/Checkbox';
|
||||
import { Typography } from '@/components/commons/Typography';
|
||||
|
||||
export function OverlayWidget() {
|
||||
const { l10n } = useLocalization();
|
||||
const { publish, subscribe, keyValues } = usePubSub();
|
||||
const [loading, setLoading] = useState(true);
|
||||
const { reset, control, handleSubmit, watch } = useForm<{
|
||||
isVisible: boolean;
|
||||
isMirrored: boolean;
|
||||
}>({
|
||||
defaultValues: {
|
||||
isVisible: false,
|
||||
isMirrored: false,
|
||||
},
|
||||
});
|
||||
|
||||
subscribe(
|
||||
OVERLAY_DISPLAY_SETTINGS_TOPIC,
|
||||
(payload: PayloadData, type: Payload) => {
|
||||
setLoading(false);
|
||||
if (type !== Payload.KeyValues) throw new Error('Invalid payload');
|
||||
const obj = keyValues(payload);
|
||||
reset({
|
||||
isMirrored: obj['is_mirrored'] === 'true',
|
||||
isVisible: obj['is_visible'] === 'true',
|
||||
});
|
||||
}
|
||||
);
|
||||
|
||||
useEffect(() => {
|
||||
const message = new MessageT();
|
||||
message.topic = OVERLAY_DISPLAY_SETTINGS_TOPIC;
|
||||
message.topicType = Topic.TopicId;
|
||||
message.payloadType = Payload.NONE;
|
||||
publish(message);
|
||||
}, []);
|
||||
|
||||
useEffect(() => {
|
||||
const subscription = watch(() => handleSubmit(onSubmit)());
|
||||
return () => subscription.unsubscribe();
|
||||
}, []);
|
||||
|
||||
const onSubmit = (val: { isVisible: boolean; isMirrored: boolean }) => {
|
||||
const message = new MessageT();
|
||||
|
||||
message.topic = OVERLAY_DISPLAY_SETTINGS_TOPIC;
|
||||
message.topicType = Topic.TopicId;
|
||||
|
||||
message.payloadType = Payload.KeyValues;
|
||||
const keyValues = new KeyValuesT();
|
||||
keyValues.keys = ['is_mirrored', 'is_visible'];
|
||||
keyValues.values = [`${val.isMirrored}`, `${val.isVisible}`];
|
||||
message.payload = keyValues;
|
||||
|
||||
publish(message);
|
||||
};
|
||||
|
||||
return !loading ? (
|
||||
<form className="bg-background-60 flex flex-col w-full rounded-md px-2">
|
||||
<div className="mt-2 px-1">
|
||||
<Typography>{l10n.getString('widget-overlay')}</Typography>
|
||||
</div>
|
||||
<CheckBox
|
||||
control={control}
|
||||
name="isVisible"
|
||||
variant="toggle"
|
||||
label={l10n.getString('widget-overlay-is_visible_label')}
|
||||
/>
|
||||
<CheckBox
|
||||
control={control}
|
||||
name="isMirrored"
|
||||
variant="toggle"
|
||||
label={l10n.getString('widget-overlay-is_mirrored_label')}
|
||||
/>
|
||||
</form>
|
||||
) : (
|
||||
<></>
|
||||
);
|
||||
}
|
||||
@@ -1,9 +1,9 @@
|
||||
import {
|
||||
SkeletonConfigResponseT,
|
||||
SkeletonBone,
|
||||
RpcMessage,
|
||||
SkeletonConfigRequestT,
|
||||
ChangeSkeletonConfigRequestT,
|
||||
ChangeSkeletonProportionsRequestT,
|
||||
SkeletonProportionsRequestT,
|
||||
SkeletonProportionsResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from './websocket-api';
|
||||
import { useEffect, useMemo, useState } from 'react';
|
||||
@@ -60,7 +60,7 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
const { useRPCPacket, sendRPCPacket } = useWebsocketAPI();
|
||||
const { setConfig } = useConfig();
|
||||
const [skeleton, setSkeleton] = useState<Omit<
|
||||
SkeletonConfigResponseT,
|
||||
SkeletonProportionsResponseT,
|
||||
'pack'
|
||||
> | null>(null);
|
||||
const bodyPartsGrouped: Label[] = useMemo(() => {
|
||||
@@ -121,12 +121,12 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
];
|
||||
}, [skeleton, type]);
|
||||
|
||||
useRPCPacket(RpcMessage.SkeletonConfigResponse, (data: SkeletonConfigResponseT) => {
|
||||
useRPCPacket(RpcMessage.SkeletonProportionsResponse, (data: SkeletonProportionsResponseT) => {
|
||||
setSkeleton(data);
|
||||
});
|
||||
|
||||
useEffect(() => {
|
||||
sendRPCPacket(RpcMessage.SkeletonConfigRequest, new SkeletonConfigRequestT());
|
||||
sendRPCPacket(RpcMessage.SkeletonProportionsRequest, new SkeletonProportionsRequestT());
|
||||
}, []);
|
||||
|
||||
return {
|
||||
@@ -144,8 +144,8 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
if (!currentValue) throw 'invalid state - the bone should exists';
|
||||
const currentRatio = currentValue.value / oldGroupTotal;
|
||||
sendRPCPacket(
|
||||
RpcMessage.ChangeSkeletonConfigRequest,
|
||||
new ChangeSkeletonConfigRequestT(part, params.newValue * currentRatio)
|
||||
RpcMessage.ChangeSkeletonProportionsRequest,
|
||||
new ChangeSkeletonProportionsRequestT(part, params.newValue * currentRatio)
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -164,8 +164,8 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
newValue = 0;
|
||||
|
||||
sendRPCPacket(
|
||||
RpcMessage.ChangeSkeletonConfigRequest,
|
||||
new ChangeSkeletonConfigRequestT(params.bone, newValue)
|
||||
RpcMessage.ChangeSkeletonProportionsRequest,
|
||||
new ChangeSkeletonProportionsRequestT(params.bone, newValue)
|
||||
);
|
||||
|
||||
// Update percent from other bones ratios so the total stays 100%
|
||||
@@ -177,8 +177,8 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
const currentValue = skeleton.skeletonParts.find(({ bone }) => bone === part);
|
||||
if (!currentValue) throw 'invalid state - the bone should exists';
|
||||
sendRPCPacket(
|
||||
RpcMessage.ChangeSkeletonConfigRequest,
|
||||
new ChangeSkeletonConfigRequestT(
|
||||
RpcMessage.ChangeSkeletonProportionsRequest,
|
||||
new ChangeSkeletonProportionsRequestT(
|
||||
part,
|
||||
currentValue.value - (diffValue / (group.length - 1)) * signDiff
|
||||
)
|
||||
@@ -188,11 +188,11 @@ export function useManualProportions({ type }: { type: 'linear' | 'ratio' }): {
|
||||
|
||||
if (params.type === 'bone') {
|
||||
sendRPCPacket(
|
||||
RpcMessage.ChangeSkeletonConfigRequest,
|
||||
new ChangeSkeletonConfigRequestT(params.bone, params.newValue)
|
||||
RpcMessage.ChangeSkeletonProportionsRequest,
|
||||
new ChangeSkeletonProportionsRequestT(params.bone, params.newValue)
|
||||
);
|
||||
}
|
||||
sendRPCPacket(RpcMessage.SkeletonConfigRequest, new SkeletonConfigRequestT());
|
||||
sendRPCPacket(RpcMessage.SkeletonProportionsRequest, new SkeletonProportionsRequestT());
|
||||
setConfig({ lastUsedProportions: 'manual' });
|
||||
Sentry.metrics.count('manual_proportions_change', 1, { attributes: params });
|
||||
},
|
||||
|
||||
@@ -11,6 +11,7 @@ import { useLocation } from 'react-router-dom';
|
||||
import { useConfig } from './config';
|
||||
import { useWebsocketAPI } from './websocket-api';
|
||||
import {
|
||||
ChangeResetsSettingsRequestT,
|
||||
ChangeSettingsRequestT,
|
||||
ModelSettingsT,
|
||||
ModelTogglesT,
|
||||
@@ -108,7 +109,6 @@ export function useProvideOnboarding() {
|
||||
const onboardingEnded = () => {
|
||||
setConfig({ doneOnboarding: true });
|
||||
if (!settings?.modelSettings || !vrcOscSettings) return;
|
||||
const req = new ChangeSettingsRequestT();
|
||||
const modelSettings = new ModelSettingsT();
|
||||
|
||||
const mocap = usage === 'mocap' || usage === 'vtubing';
|
||||
@@ -118,10 +118,9 @@ export function useProvideOnboarding() {
|
||||
modelSettings.toggles = toggles;
|
||||
req.modelSettings = modelSettings;
|
||||
|
||||
const resets = Object.assign(new ResetsSettingsT(), settings.resetsSettings);
|
||||
resets.resetHmdPitch = mocapPos === 'forehead';
|
||||
req.resetsSettings = resets;
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, req);
|
||||
const resetsReq = Object.assign(new ChangeResetsSettingsRequestT(), settings.resetsSettings); // TODO
|
||||
resetsReq.resetHmdPitch = mocapPos === 'forehead';
|
||||
sendRPCPacket(RpcMessage.ChangeResetsSettingsRequest, resetsReq);
|
||||
|
||||
const osc = Object.assign(new VRCOSCSettingsT(), vrcOscSettings);
|
||||
osc.enabled = vrcOsc ?? false;
|
||||
|
||||
@@ -1,14 +1,13 @@
|
||||
import { useLocalization } from '@fluent/react';
|
||||
import { number, object, boolean, string } from 'yup';
|
||||
|
||||
export type OSCSettings = {
|
||||
enabled: boolean;
|
||||
export type OSCPortsAddress = {
|
||||
portIn: number;
|
||||
portOut: number;
|
||||
address: string;
|
||||
};
|
||||
|
||||
export function useOscSettingsValidator() {
|
||||
export function useOscPortsAddressValidator() {
|
||||
const bannedPorts = [6969, 21110];
|
||||
const { l10n } = useLocalization();
|
||||
|
||||
@@ -27,7 +26,6 @@ export function useOscSettingsValidator() {
|
||||
);
|
||||
|
||||
const oscValidator = object({
|
||||
enabled: boolean().required(),
|
||||
portIn: portValidator,
|
||||
portOut: portValidator,
|
||||
address: string()
|
||||
|
||||
@@ -1,86 +0,0 @@
|
||||
import { useEffect, useState } from 'react';
|
||||
import {
|
||||
KeyValuesT,
|
||||
MessageT,
|
||||
PubSubUnion,
|
||||
SubscriptionRequestT,
|
||||
Topic,
|
||||
TopicHandleT,
|
||||
TopicIdT,
|
||||
TopicMappingT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from './websocket-api';
|
||||
|
||||
export type PayloadData = MessageT['payload'];
|
||||
export type PayloadType = MessageT['payloadType'];
|
||||
|
||||
export function usePubSub() {
|
||||
const { sendPubSubPacket, usePubSubPacket } = useWebsocketAPI();
|
||||
const [handleTopics, setHandleTopics] = useState<{ [key: number]: TopicIdT }>({});
|
||||
|
||||
const subscribe = (
|
||||
topicId: TopicIdT,
|
||||
callback: (data: PayloadData, type: PayloadType) => void
|
||||
): void => {
|
||||
useEffect(() => {
|
||||
const subRequest = new SubscriptionRequestT();
|
||||
subRequest.topicType = Topic.TopicId;
|
||||
subRequest.topic = topicId;
|
||||
sendPubSubPacket(PubSubUnion.SubscriptionRequest, subRequest);
|
||||
}, [sendPubSubPacket, usePubSubPacket]);
|
||||
|
||||
usePubSubPacket(PubSubUnion.Message, (message: MessageT) => {
|
||||
if (message.topicType == Topic.TopicHandle) {
|
||||
const messageHandleId = message.topic as TopicHandleT;
|
||||
if (handleTopics[messageHandleId.id]) {
|
||||
callback(message.payload, message.payloadType);
|
||||
}
|
||||
}
|
||||
if (message.topicType == Topic.TopicId) {
|
||||
const messageTopicId = message.topic as TopicIdT;
|
||||
if (
|
||||
messageTopicId.appName === topicId.appName &&
|
||||
messageTopicId.organization === topicId.organization &&
|
||||
messageTopicId.topic === topicId.topic
|
||||
) {
|
||||
callback(message.payload, message.payloadType);
|
||||
}
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
usePubSubPacket(PubSubUnion.TopicMapping, (data: TopicMappingT) => {
|
||||
setHandleTopics((handleTopics) => ({
|
||||
...handleTopics,
|
||||
...(data.handle?.id && data.id ? { [data.handle?.id]: data.id } : {}),
|
||||
}));
|
||||
});
|
||||
|
||||
const publish = (message: MessageT) => {
|
||||
sendPubSubPacket(PubSubUnion.Message, message);
|
||||
};
|
||||
|
||||
return {
|
||||
subscribe,
|
||||
publish,
|
||||
keyValues: (payload: PayloadData): Record<string, string> => {
|
||||
const keyValuesPayload = payload as KeyValuesT;
|
||||
return keyValuesPayload.keys.reduce(
|
||||
(curr, _, index) => ({
|
||||
...curr,
|
||||
[keyValuesPayload.keys[index]]: keyValuesPayload.values[index],
|
||||
}),
|
||||
{}
|
||||
);
|
||||
},
|
||||
};
|
||||
}
|
||||
|
||||
export const topic = ({ appName, organization, topic }: Omit<TopicIdT, 'pack'>) =>
|
||||
Object.assign(new TopicIdT(), { appName, organization, topic });
|
||||
|
||||
export const OVERLAY_DISPLAY_SETTINGS_TOPIC = topic({
|
||||
appName: 'overlay',
|
||||
organization: 'slimevr.dev',
|
||||
topic: 'display_settings',
|
||||
});
|
||||
@@ -1,16 +1,14 @@
|
||||
import {
|
||||
ChangeSettingsRequestT,
|
||||
ResetsSettingsT,
|
||||
ResetsSettingsResponseT,
|
||||
RpcMessage,
|
||||
SettingsResetRequestT,
|
||||
SettingsResponseT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from './websocket-api';
|
||||
import { useEffect, useState } from 'react';
|
||||
import {useWebsocketAPI} from './websocket-api';
|
||||
import {useEffect, useState} from 'react';
|
||||
|
||||
export interface ResetSettingsForm {
|
||||
resetMountingFeet: boolean;
|
||||
armsMountingResetMode: number;
|
||||
armsResetMode: number;
|
||||
yawResetSmoothTime: number;
|
||||
saveMountingReset: boolean;
|
||||
resetHmdPitch: boolean;
|
||||
@@ -18,16 +16,16 @@ export interface ResetSettingsForm {
|
||||
|
||||
export const defaultResetSettings = {
|
||||
resetMountingFeet: false,
|
||||
armsMountingResetMode: 0,
|
||||
armsResetMode: 0,
|
||||
yawResetSmoothTime: 0.0,
|
||||
saveMountingReset: false,
|
||||
resetHmdPitch: false,
|
||||
};
|
||||
|
||||
export function loadResetSettings(resetSettingsForm: ResetSettingsForm) {
|
||||
const resetsSettings = new ResetsSettingsT();
|
||||
const resetsSettings = new ResetsSettingsResponseT();
|
||||
resetsSettings.resetMountingFeet = resetSettingsForm.resetMountingFeet;
|
||||
resetsSettings.armsMountingResetMode = resetSettingsForm.armsMountingResetMode;
|
||||
resetsSettings.armsResetMode = resetSettingsForm.armsResetMode;
|
||||
resetsSettings.yawResetSmoothTime = resetSettingsForm.yawResetSmoothTime;
|
||||
resetsSettings.saveMountingReset = resetSettingsForm.saveMountingReset;
|
||||
resetsSettings.resetHmdPitch = resetSettingsForm.resetHmdPitch;
|
||||
@@ -40,19 +38,17 @@ export function useResetSettings() {
|
||||
const [settings, setSettings] = useState<ResetSettingsForm>(defaultResetSettings);
|
||||
|
||||
useEffect(() =>
|
||||
sendRPCPacket(RpcMessage.SettingsRequest, new SettingsResetRequestT())
|
||||
sendRPCPacket(RpcMessage.ResetsSettingsRequest, new SettingsResetRequestT())
|
||||
);
|
||||
|
||||
useRPCPacket(RpcMessage.SettingsResponse, (settings: SettingsResponseT) => {
|
||||
if (settings.resetsSettings) setSettings(settings.resetsSettings);
|
||||
useRPCPacket(RpcMessage.ResetsSettingsResponse, (settings: ResetsSettingsResponseT) => {
|
||||
if (settings) setSettings(settings);
|
||||
});
|
||||
|
||||
return {
|
||||
update: (resetSettingsForm: Partial<ResetSettingsForm>) => {
|
||||
const req = new ChangeSettingsRequestT();
|
||||
const res = loadResetSettings({ ...settings, ...resetSettingsForm });
|
||||
req.resetsSettings = res;
|
||||
sendRPCPacket(RpcMessage.ChangeSettingsRequest, req);
|
||||
const req = loadResetSettings({...settings, ...resetSettingsForm});
|
||||
sendRPCPacket(RpcMessage.ChangeResetsSettingsRequest, req);
|
||||
},
|
||||
};
|
||||
}
|
||||
+14
-14
@@ -18,8 +18,8 @@ export type ResetBtnStatus = 'idle' | 'counting' | 'finished';
|
||||
|
||||
export type MountingResetGroup = 'default' | 'feet' | 'fingers';
|
||||
export type UseResetOptions =
|
||||
| { type: ResetType.Full | ResetType.Yaw }
|
||||
| { type: ResetType.Mounting; group: MountingResetGroup };
|
||||
| { type: ResetType.FULL | ResetType.YAW }
|
||||
| { type: ResetType.MOUNTING; group: MountingResetGroup };
|
||||
|
||||
export const BODY_PARTS_GROUPS: Record<MountingResetGroup, BodyPart[]> = {
|
||||
default: [],
|
||||
@@ -32,7 +32,7 @@ export function useReset(
|
||||
onReseted?: () => void,
|
||||
onFailed?: () => void
|
||||
) {
|
||||
if (options.type === ResetType.Mounting && !options.group) options.group = 'default';
|
||||
if (options.type === ResetType.MOUNTING && !options.group) options.group = 'default';
|
||||
|
||||
const serverGuards = useAtomValue(serverGuardsAtom);
|
||||
const { currentLocales } = useLocaleConfig();
|
||||
@@ -49,13 +49,13 @@ export function useReset(
|
||||
req.resetType = options.type;
|
||||
req.bodyParts = parts;
|
||||
switch (options.type) {
|
||||
case ResetType.Yaw:
|
||||
case ResetType.YAW:
|
||||
req.delay = 0;
|
||||
break;
|
||||
case ResetType.Full:
|
||||
case ResetType.FULL:
|
||||
req.delay = 3;
|
||||
break;
|
||||
case ResetType.Mounting:
|
||||
case ResetType.MOUNTING:
|
||||
req.delay = 3;
|
||||
break;
|
||||
}
|
||||
@@ -64,7 +64,7 @@ export function useReset(
|
||||
Sentry.metrics.count('reset_click', 1, {
|
||||
attributes: {
|
||||
resetType: ResetType[options.type],
|
||||
group: options.type === ResetType.Mounting ? options.group : undefined,
|
||||
group: options.type === ResetType.MOUNTING ? options.group : undefined,
|
||||
},
|
||||
});
|
||||
};
|
||||
@@ -102,7 +102,7 @@ export function useReset(
|
||||
({ status, resetType, progress, duration, bodyParts }: ResetResponseT) => {
|
||||
if (
|
||||
resetType !== options.type ||
|
||||
(resetType == ResetType.Mounting &&
|
||||
(resetType == ResetType.MOUNTING &&
|
||||
JSON.stringify(parts) !== JSON.stringify(bodyParts))
|
||||
) {
|
||||
onResetCanceled();
|
||||
@@ -124,11 +124,11 @@ export function useReset(
|
||||
|
||||
const name = useMemo(() => {
|
||||
switch (options.type) {
|
||||
case ResetType.Yaw:
|
||||
case ResetType.YAW:
|
||||
return 'reset-yaw';
|
||||
case ResetType.Full:
|
||||
case ResetType.FULL:
|
||||
return 'reset-full';
|
||||
case ResetType.Mounting:
|
||||
case ResetType.MOUNTING:
|
||||
if (options.group !== 'default') return `reset-mounting-${options.group}`;
|
||||
return 'reset-mounting';
|
||||
default:
|
||||
@@ -138,7 +138,7 @@ export function useReset(
|
||||
|
||||
let disabled = status === 'counting';
|
||||
let error = null;
|
||||
if (options.type === ResetType.Mounting && options.group !== 'default') {
|
||||
if (options.type === ResetType.MOUNTING && options.group !== 'default') {
|
||||
const assignedTrackers = useAtomValue(assignedTrackersAtom);
|
||||
|
||||
if (
|
||||
@@ -151,10 +151,10 @@ export function useReset(
|
||||
disabled = true;
|
||||
error = `reset-error-no_${options.group}_tracker`;
|
||||
}
|
||||
} else if (options.type === ResetType.Mounting && !serverGuards?.canDoMounting) {
|
||||
} else if (options.type === ResetType.MOUNTING && !serverGuards?.canDoMountingReset) {
|
||||
disabled = true;
|
||||
error = 'reset-error-mounting-need_full_reset';
|
||||
} else if (options.type === ResetType.Yaw && !serverGuards?.canDoYawReset) {
|
||||
} else if (options.type === ResetType.YAW && !serverGuards?.canDoYawReset) {
|
||||
disabled = true;
|
||||
error = 'reset-error-yaw-need_full_reset';
|
||||
}
|
||||
|
||||
@@ -6,7 +6,6 @@ import {
|
||||
TrackingChecklistStepVisibility,
|
||||
IgnoreTrackingChecklistStepRequestT,
|
||||
RpcMessage,
|
||||
TrackerIdT,
|
||||
} from 'solarxr-protocol';
|
||||
import { useWebsocketAPI } from './websocket-api';
|
||||
import { createContext, useContext, useEffect, useMemo, useState } from 'react';
|
||||
@@ -47,7 +46,7 @@ export type TrackingChecklistStep = TrackingChecklistStepT & {
|
||||
};
|
||||
export type highlightedTrackers = {
|
||||
step: TrackingChecklistStep;
|
||||
trackers: Array<TrackerIdT>;
|
||||
trackers: Array<number>;
|
||||
};
|
||||
|
||||
const stepVisibility = ({ visibility, status, firstRequired }: TrackingChecklistStep) =>
|
||||
|
||||
@@ -5,8 +5,6 @@ import {
|
||||
DataFeedMessageHeaderT,
|
||||
MessageBundle,
|
||||
MessageBundleT,
|
||||
PubSubHeaderT,
|
||||
PubSubUnion,
|
||||
RpcMessage,
|
||||
RpcMessageHeaderT,
|
||||
} from 'solarxr-protocol';
|
||||
@@ -24,22 +22,17 @@ export interface WebSocketApi {
|
||||
useDataFeedPacket: <T>(type: DataFeedMessage, callback: (packet: T) => void) => void;
|
||||
sendRPCPacket: (type: RpcMessage, data: RPCPacketType) => void;
|
||||
sendDataFeedPacket: (type: DataFeedMessage, data: DataFeedPacketType) => void;
|
||||
usePubSubPacket: <T>(type: PubSubUnion, callback: (packet: T) => void) => void;
|
||||
sendPubSubPacket: (type: PubSubUnion, data: PubSubPacketType) => void;
|
||||
}
|
||||
|
||||
export const WebSocketApiContext = createContext<WebSocketApi>(undefined as never);
|
||||
|
||||
export type RPCPacketType = RpcMessageHeaderT['message'];
|
||||
export type PubSubPacketType = PubSubHeaderT['u'];
|
||||
export type DataFeedPacketType = DataFeedMessageHeaderT['message'];
|
||||
// export type OutboundPacketType = OutboundPacketT['packet'];
|
||||
|
||||
export function useProvideWebsocketApi(): WebSocketApi {
|
||||
const rpcPacketCounterRef = useRef<number>(0);
|
||||
const webSocketRef = useRef<WebSocket | null>(null);
|
||||
const rpclistenerRef = useRef<EventTarget>(new EventTarget());
|
||||
const pubsublistenerRef = useRef<EventTarget>(new EventTarget());
|
||||
const datafeedlistenerRef = useRef<EventTarget>(new EventTarget());
|
||||
const [isFirstConnection, setFirstConnection] = useState(true);
|
||||
const [timedOut, setTimedOut] = useState(false);
|
||||
@@ -91,14 +84,6 @@ export function useProvideWebsocketApi(): WebSocketApi {
|
||||
})
|
||||
);
|
||||
});
|
||||
|
||||
message.pubSubMsgs.forEach((pubSubHeader) => {
|
||||
pubsublistenerRef.current?.dispatchEvent(
|
||||
new CustomEvent(PubSubUnion[pubSubHeader.uType], {
|
||||
detail: pubSubHeader.u,
|
||||
})
|
||||
);
|
||||
});
|
||||
};
|
||||
|
||||
const sendRPCPacket = (type: RpcMessage, data: RPCPacketType): void => {
|
||||
@@ -138,22 +123,6 @@ export function useProvideWebsocketApi(): WebSocketApi {
|
||||
webSocketRef.current.send(fbb.asUint8Array());
|
||||
};
|
||||
|
||||
const sendPubSubPacket = (type: PubSubUnion, data: PubSubPacketType): void => {
|
||||
if (webSocketRef?.current?.readyState !== WebSocket.OPEN) return;
|
||||
const fbb = new Builder(1);
|
||||
|
||||
const message = new MessageBundleT();
|
||||
|
||||
const pubSubHeader = new PubSubHeaderT();
|
||||
pubSubHeader.uType = type;
|
||||
pubSubHeader.u = data;
|
||||
|
||||
message.pubSubMsgs = [pubSubHeader];
|
||||
fbb.finish(message.pack(fbb));
|
||||
|
||||
webSocketRef.current.send(fbb.asUint8Array());
|
||||
};
|
||||
|
||||
const connect = () => {
|
||||
webSocketRef.current = new WebSocket(`ws://${targetIp}:${targetPort}`);
|
||||
|
||||
@@ -222,20 +191,8 @@ export function useProvideWebsocketApi(): WebSocketApi {
|
||||
};
|
||||
}, [callback, type]);
|
||||
},
|
||||
usePubSubPacket: <T>(type: PubSubUnion, callback: (packet: T) => void) => {
|
||||
useEffect(() => {
|
||||
const onEvent = (event: CustomEventInit) => {
|
||||
callback(event.detail);
|
||||
};
|
||||
pubsublistenerRef.current.addEventListener(PubSubUnion[type], onEvent);
|
||||
return () => {
|
||||
pubsublistenerRef.current.removeEventListener(PubSubUnion[type], onEvent);
|
||||
};
|
||||
}, [callback, type]);
|
||||
},
|
||||
sendRPCPacket,
|
||||
sendDataFeedPacket,
|
||||
sendPubSubPacket,
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -23,7 +23,7 @@ const resetSounds: Record<
|
||||
mew: HTMLAudioElement | null;
|
||||
}
|
||||
> = {
|
||||
[ResetType.Full]: {
|
||||
[ResetType.FULL]: {
|
||||
initial: createAudio('/sounds/full-reset/init-full-reset-with-tail.ogg'),
|
||||
tick: [
|
||||
createAudio('/sounds/full-reset/full-click-1.ogg'),
|
||||
@@ -33,13 +33,13 @@ const resetSounds: Record<
|
||||
end: createAudio('/sounds/full-reset/end-full-reset-with-tail.ogg'),
|
||||
mew,
|
||||
},
|
||||
[ResetType.Yaw]: {
|
||||
[ResetType.YAW]: {
|
||||
initial: null,
|
||||
tick: null,
|
||||
end: createAudio('/sounds/yaw-reset/yaw-reset.ogg'),
|
||||
mew: null,
|
||||
},
|
||||
[ResetType.Mounting]: {
|
||||
[ResetType.MOUNTING]: {
|
||||
initial: createAudio('/sounds/mounting-reset/init-mounting-reset-with-tail.ogg'),
|
||||
tick: [
|
||||
createAudio('/sounds/mounting-reset/mount-click-1.ogg'),
|
||||
|
||||
@@ -99,8 +99,8 @@ export const trackerFromIdAtom = ({
|
||||
({ tracker }) =>
|
||||
trackerNum &&
|
||||
deviceId &&
|
||||
tracker?.trackerId?.trackerNum == trackerNum &&
|
||||
tracker?.trackerId?.deviceId?.id == deviceId
|
||||
tracker?.trackerId == trackerNum &&
|
||||
tracker?.deviceId == deviceId
|
||||
)
|
||||
),
|
||||
(a) => a,
|
||||
|
||||
@@ -68,7 +68,7 @@ export function getSentryOrCompute(enabled = false, uuid: string, isSteam: boole
|
||||
});
|
||||
|
||||
if (!newClient) {
|
||||
error('Couldnt initialize Sentry for error logging');
|
||||
error('Couldn\'t initialize Sentry for error logging');
|
||||
} else {
|
||||
log('Initialized the Sentry client');
|
||||
}
|
||||
@@ -77,15 +77,15 @@ export function getSentryOrCompute(enabled = false, uuid: string, isSteam: boole
|
||||
}
|
||||
|
||||
export function updateSentryContext(devices: DeviceDataT[]) {
|
||||
// We filter out the shit we dont want. We dont need rotation data or ip addresses
|
||||
// We filter out what we don't want (rotations and ip addresses).
|
||||
const trackers = (devices || []).map(({ hardwareInfo, trackers, id }) => ({
|
||||
id: id?.id,
|
||||
id: id,
|
||||
hardwareInfo: { ...hardwareInfo, ipAddress: undefined },
|
||||
trackers: trackers.map(({ info, trackerId }) => ({
|
||||
trackers: trackers.map(({ info, trackerId, deviceId }) => ({
|
||||
info,
|
||||
trackerId: {
|
||||
trackerNum: trackerId?.trackerNum,
|
||||
deviceId: trackerId?.deviceId?.id,
|
||||
trackerNum: trackerId,
|
||||
deviceId: deviceId,
|
||||
},
|
||||
})),
|
||||
}));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package dev.slimevr.config
|
||||
|
||||
import kotlinx.serialization.Serializable
|
||||
import solarxr_protocol.rpc.ArmsMountingResetMode
|
||||
import solarxr_protocol.rpc.ArmsResetMode
|
||||
|
||||
enum class MountingMethods(val id: Int) {
|
||||
MANUAL(0),
|
||||
@@ -25,7 +25,7 @@ data class ResetsConfig(
|
||||
/** Always reset mounting for feet */
|
||||
val resetMountingFeet: Boolean = false,
|
||||
/** Reset mode used for the arms */
|
||||
val armsResetMode: ArmsMountingResetMode = ArmsMountingResetMode.BACK,
|
||||
val armsResetMode: ArmsResetMode = ArmsResetMode.BACK,
|
||||
/** Yaw reset smoothing time in seconds */
|
||||
val yawResetSmoothTime: Float = 0.0f,
|
||||
/** Save automatic mounting reset calibration */
|
||||
|
||||
@@ -44,7 +44,6 @@ data class TapDetectionConfig(
|
||||
var fullResetTaps: Int = 3,
|
||||
var mountingResetTaps: Int = 3,
|
||||
var numberTrackersOverThreshold: Int = 1,
|
||||
var setupMode: Boolean = false,
|
||||
)
|
||||
|
||||
@Serializable
|
||||
|
||||
@@ -79,7 +79,7 @@ class Device(
|
||||
ping = null,
|
||||
signalStrength = null,
|
||||
status = TrackerStatus.DISCONNECTED,
|
||||
mcuType = McuType.Other,
|
||||
mcuType = McuType.UNKNOWN,
|
||||
boardType = BoardType.UNKNOWN,
|
||||
firmware = null,
|
||||
packetsReceived = 0L,
|
||||
|
||||
@@ -10,7 +10,7 @@ import dev.slimevr.util.safeLaunch
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.Job
|
||||
import kotlinx.coroutines.cancelAndJoin
|
||||
import solarxr_protocol.datatypes.DeviceIdTable
|
||||
import solarxr_protocol.rpc.FirmwareDeviceIdTable
|
||||
import solarxr_protocol.rpc.FirmwarePart
|
||||
import solarxr_protocol.rpc.FirmwareUpdateDeviceId
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStatus
|
||||
@@ -99,7 +99,7 @@ class FirmwareManager(
|
||||
runningJobs[deviceIp] = scope.safeLaunch {
|
||||
doOtaFlash(
|
||||
deviceIp = deviceIp,
|
||||
deviceId = (firmwareDeviceId as? DeviceIdTable)?.id ?: error("device id should exist"),
|
||||
deviceId = (firmwareDeviceId as? FirmwareDeviceIdTable)?.id ?: error("device id should exist"),
|
||||
part = part,
|
||||
server = server,
|
||||
onStatus = { status, progress ->
|
||||
|
||||
@@ -22,7 +22,6 @@ import kotlinx.coroutines.Dispatchers
|
||||
import kotlinx.coroutines.withContext
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlinx.io.readByteArray
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.rpc.FirmwarePart
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStatus
|
||||
import java.security.MessageDigest
|
||||
@@ -115,7 +114,7 @@ internal suspend fun uploadFirmware(
|
||||
|
||||
suspend fun doOtaFlash(
|
||||
deviceIp: String,
|
||||
deviceId: DeviceId,
|
||||
deviceId: UShort,
|
||||
part: FirmwarePart,
|
||||
server: VRServer,
|
||||
onStatus: suspend (FirmwareUpdateStatus, Int) -> Unit,
|
||||
|
||||
@@ -3,13 +3,11 @@ package dev.slimevr.firmware
|
||||
import dev.slimevr.VRServer
|
||||
import kotlinx.coroutines.ExperimentalCoroutinesApi
|
||||
import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.filter
|
||||
import kotlinx.coroutines.flow.first
|
||||
import kotlinx.coroutines.flow.flatMapLatest
|
||||
import kotlinx.coroutines.flow.flowOf
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.withTimeoutOrNull
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
|
||||
private fun isOnlineStatus(status: TrackerStatus): Boolean = when (status) {
|
||||
@@ -38,18 +36,16 @@ suspend fun waitForConnected(
|
||||
macAddress: String,
|
||||
timeoutMs: Long = 30_000,
|
||||
): Boolean? = withTimeoutOrNull(timeoutMs) {
|
||||
deviceStatusFlow(server) { _, deviceMac -> deviceMac?.uppercase() == macAddress }
|
||||
.filter(::isOnlineStatus)
|
||||
.first()
|
||||
deviceStatusFlow(server) { _, deviceMac -> deviceMac?.uppercase() == macAddress }.first(::isOnlineStatus)
|
||||
true
|
||||
}
|
||||
|
||||
suspend fun waitForReconnected(
|
||||
server: VRServer,
|
||||
deviceId: DeviceId,
|
||||
deviceId: UShort,
|
||||
timeoutMs: Long = 60_000,
|
||||
): Boolean? = withTimeoutOrNull(timeoutMs) {
|
||||
val statuses = deviceStatusFlow(server) { id, _ -> id.toUByte() == deviceId.id }
|
||||
val statuses = deviceStatusFlow(server) { id, _ -> id.toUShort() == deviceId }
|
||||
.distinctUntilChanged()
|
||||
|
||||
if (isOnlineStatus(statuses.first())) {
|
||||
|
||||
@@ -26,6 +26,7 @@ data class TrackerSnapshot(val position: Vector3, val rotation: Quaternion)
|
||||
data class HeightCalibrationState(
|
||||
val status: UserHeightCalibrationStatus,
|
||||
val currentHeight: Float,
|
||||
val canDoUserHeightCalibration: Boolean,
|
||||
)
|
||||
|
||||
sealed interface HeightCalibrationActions {
|
||||
@@ -38,6 +39,7 @@ typealias HeightCalibrationBehaviourType = Behaviour<HeightCalibrationState, Hei
|
||||
val INITIAL_HEIGHT_CALIBRATION_STATE = HeightCalibrationState(
|
||||
status = UserHeightCalibrationStatus.NONE,
|
||||
currentHeight = 0f,
|
||||
canDoUserHeightCalibration = true, // TODO make the logic in behaviour for this
|
||||
)
|
||||
|
||||
class HeightCalibrationManager(
|
||||
|
||||
@@ -175,9 +175,9 @@ private fun parseSingleHIDPacket(data: ByteArray, i: Int): HIDPacket? {
|
||||
val fwDay = fwDate and 31
|
||||
HIDDeviceInfo(
|
||||
hidId = hidId,
|
||||
imuType = ImuType.fromValue(imuId.toUShort()) ?: ImuType.Other,
|
||||
imuType = ImuType.fromValue(imuId.toUShort()) ?: ImuType.UNKNOWN,
|
||||
boardType = BoardType.fromValue(brdId.toUShort()) ?: BoardType.UNKNOWN,
|
||||
mcuType = McuType.fromValue(mcuId.toUShort()) ?: McuType.Other,
|
||||
mcuType = McuType.fromValue(mcuId.toUShort()) ?: McuType.UNKNOWN,
|
||||
firmware = "%04d-%02d-%02d %d.%d.%d".format(fwYear, fwMonth, fwDay, fwMajor, fwMinor, fwPatch),
|
||||
batteryLevel = decodeBattery(batt),
|
||||
batteryVoltage = decodeBatteryVoltage(battV),
|
||||
|
||||
@@ -17,16 +17,16 @@ class ResetsBasicBehaviour : ResetsBehaviour {
|
||||
// Clear the states of the `canDoXReset`s to false
|
||||
is ResetsActions.ClearResets -> {
|
||||
state.copy(
|
||||
canDoYawReset = if (ResetType.Yaw in action.resetType) false else state.canDoYawReset,
|
||||
canDoMountingReset = if (ResetType.Mounting in action.resetType) false else state.canDoMountingReset,
|
||||
canDoYawReset = if (ResetType.YAW in action.resetType) false else state.canDoYawReset,
|
||||
canDoMountingReset = if (ResetType.MOUNTING in action.resetType) false else state.canDoMountingReset,
|
||||
)
|
||||
}
|
||||
|
||||
// Whenever a reset is finished
|
||||
is ResetsActions.EndReset -> {
|
||||
if (action.resetType == ResetType.Full) {
|
||||
if (action.resetType == ResetType.FULL) {
|
||||
state.copy(canDoYawReset = true, canDoMountingReset = true, lastFullResetTime = System.nanoTime())
|
||||
} else if (action.resetType == ResetType.Mounting) {
|
||||
} else if (action.resetType == ResetType.MOUNTING) {
|
||||
state.copy(config = state.config.copy(lastMountingMethod = MountingMethods.AUTOMATIC))
|
||||
} else {
|
||||
state.copy()
|
||||
@@ -42,7 +42,7 @@ class ResetsMountingTimeoutBehaviour : ResetsBehaviour {
|
||||
.distinctUntilChangedBy { it.lastFullResetTime }
|
||||
.mapLatest {
|
||||
delay(MOUNTING_RESET_TIMEOUT)
|
||||
receiver.context.dispatch(ResetsActions.ClearResets(listOf(ResetType.Mounting)))
|
||||
receiver.context.dispatch(ResetsActions.ClearResets(listOf(ResetType.MOUNTING)))
|
||||
}
|
||||
.launchIn(receiver.context.scope)
|
||||
}
|
||||
|
||||
@@ -94,7 +94,7 @@ class ResetsManager(val context: ResetsContext, val server: VRServer) {
|
||||
} else {
|
||||
// Exclude feet trackers from mounting reset if resetMountingFeet = false
|
||||
allTrackers.filter {
|
||||
resetType != ResetType.Mounting ||
|
||||
resetType != ResetType.MOUNTING ||
|
||||
config.resetMountingFeet ||
|
||||
it.context.state.value.bodyPart !in setOf(BodyPart.LEFT_FOOT, BodyPart.RIGHT_FOOT)
|
||||
}
|
||||
@@ -109,9 +109,9 @@ class ResetsManager(val context: ResetsContext, val server: VRServer) {
|
||||
trackers.forEach {
|
||||
it.context.dispatch(
|
||||
when (resetType) {
|
||||
ResetType.Yaw -> TrackerActions.YawReset(referenceRotation)
|
||||
ResetType.Full -> TrackerActions.FullReset(referenceRotation)
|
||||
ResetType.Mounting -> TrackerActions.MountingReset(referenceRotation)
|
||||
ResetType.YAW -> TrackerActions.YawReset(referenceRotation)
|
||||
ResetType.FULL -> TrackerActions.FullReset(referenceRotation)
|
||||
ResetType.MOUNTING -> TrackerActions.MountingReset(referenceRotation)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
@@ -3,6 +3,7 @@ package dev.slimevr.solarxr
|
||||
import dev.slimevr.AppLogger
|
||||
import dev.slimevr.VRServer
|
||||
import dev.slimevr.device.DeviceState
|
||||
import dev.slimevr.heightcalibration.HeightCalibrationManager
|
||||
import dev.slimevr.resets.ResetsManager
|
||||
import dev.slimevr.skeleton.BoneState
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
@@ -18,14 +19,12 @@ import solarxr_protocol.data_feed.PollDataFeed
|
||||
import solarxr_protocol.data_feed.StartDataFeed
|
||||
import solarxr_protocol.data_feed.device_data.DeviceData
|
||||
import solarxr_protocol.data_feed.server.ServerGuards
|
||||
import solarxr_protocol.data_feed.tracker.TrackerData
|
||||
import solarxr_protocol.data_feed.tracker.TrackerDataMask
|
||||
import solarxr_protocol.data_feed.tracker.TrackerInfo
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.data_feed.tracker_data.TrackerData
|
||||
import solarxr_protocol.data_feed.tracker_data.TrackerDataMask
|
||||
import solarxr_protocol.data_feed.tracker_data.TrackerInfo
|
||||
import solarxr_protocol.datatypes.Ipv4Address
|
||||
import solarxr_protocol.datatypes.MagnetometerStatus
|
||||
import solarxr_protocol.datatypes.Temperature
|
||||
import solarxr_protocol.datatypes.TrackerId
|
||||
import solarxr_protocol.datatypes.hardware_info.HardwareInfo
|
||||
import solarxr_protocol.datatypes.hardware_info.HardwareStatus
|
||||
import solarxr_protocol.datatypes.math.Quat
|
||||
@@ -40,11 +39,9 @@ private fun ipv4AddressFromString(address: String): UInt {
|
||||
}
|
||||
}
|
||||
|
||||
private fun createTracker(device: DeviceState, tracker: TrackerState, trackerMask: TrackerDataMask, datafeedConfig: DataFeedConfig): TrackerData = TrackerData(
|
||||
trackerId = TrackerId(
|
||||
trackerNum = tracker.id.toUByte(),
|
||||
deviceId = DeviceId(device.id.toUByte()),
|
||||
),
|
||||
private fun createTracker(device: DeviceState, tracker: TrackerState, trackerMask: TrackerDataMask): TrackerData = TrackerData(
|
||||
deviceId = device.id.toUShort(),
|
||||
trackerId = tracker.id.toUShort(),
|
||||
status = if (trackerMask.status == true) tracker.status else null,
|
||||
rotation = if (trackerMask.rotation == true) tracker.rawRotation.let { Quat(it.x, it.y, it.z, it.w) } else null,
|
||||
position = if (trackerMask.position == true && tracker.position != null) tracker.position.let { Vec3f(it.x, it.y, it.z) } else null,
|
||||
@@ -78,7 +75,7 @@ private fun createDevice(
|
||||
val trackerMask = datafeedConfig.dataMask?.trackerData
|
||||
|
||||
return DeviceData(
|
||||
id = DeviceId(device.id.toUByte()),
|
||||
id = device.id.toUShort(),
|
||||
hardwareStatus = HardwareStatus(
|
||||
batteryVoltage = device.batteryVoltage,
|
||||
batteryPctEstimate = device.batteryLevel?.let { (it * 100).toUInt().toUByte() },
|
||||
@@ -100,7 +97,7 @@ private fun createDevice(
|
||||
),
|
||||
trackers = if (trackerMask != null) {
|
||||
trackers.filter { it.deviceId == device.id }
|
||||
.map { tracker -> createTracker(device, tracker, trackerMask, datafeedConfig) }
|
||||
.map { tracker -> createTracker(device, tracker, trackerMask) }
|
||||
} else {
|
||||
null
|
||||
},
|
||||
@@ -114,12 +111,13 @@ private fun createBone(bone: BoneState): solarxr_protocol.data_feed.Bone = solar
|
||||
headPositionG = bone.headPosition.let { Vec3f(it.x, it.y, it.z) },
|
||||
)
|
||||
|
||||
private fun createServerGuards(resetsManager: ResetsManager): ServerGuards {
|
||||
private fun createServerGuards(resetsManager: ResetsManager, heightCalibrationManager: HeightCalibrationManager): ServerGuards {
|
||||
val resetsState = resetsManager.context.state.value
|
||||
val heightCalibrationState = heightCalibrationManager.context.state.value
|
||||
return ServerGuards(
|
||||
candomounting = resetsState.canDoMountingReset,
|
||||
candoyawreset = resetsState.canDoYawReset,
|
||||
// candouserheightcalibration = true, TODO
|
||||
canDoMountingReset = resetsState.canDoMountingReset,
|
||||
canDoYawReset = resetsState.canDoYawReset,
|
||||
canDoUserHeightCalibration = heightCalibrationState.canDoUserHeightCalibration,
|
||||
)
|
||||
}
|
||||
|
||||
@@ -128,6 +126,7 @@ fun createDatafeedFrame(
|
||||
datafeedConfig: DataFeedConfig,
|
||||
skeleton: Skeleton,
|
||||
resetsManager: ResetsManager,
|
||||
heightCalibrationManager: HeightCalibrationManager,
|
||||
index: Int = 0,
|
||||
): DataFeedMessageHeader {
|
||||
val serverState = server.context.state.value
|
||||
@@ -140,7 +139,7 @@ fun createDatafeedFrame(
|
||||
null
|
||||
}
|
||||
val serverGuards = if (datafeedConfig.serverGuardsMask == true) {
|
||||
createServerGuards(resetsManager)
|
||||
createServerGuards(resetsManager, heightCalibrationManager)
|
||||
} else {
|
||||
null
|
||||
}
|
||||
@@ -161,16 +160,23 @@ class DataFeedInitBehaviour(val server: VRServer, val skeleton: Skeleton) : Sola
|
||||
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.dataFeedDispatcher.on<StartDataFeed> { event ->
|
||||
val datafeeds = event.dataFeeds ?: return@on
|
||||
val dataFeeds = event.dataFeeds ?: return@on
|
||||
|
||||
receiver.datafeedTimers.forEach { it.cancelAndJoin() }
|
||||
|
||||
val timers = datafeeds.mapIndexed { index, config ->
|
||||
val timers = dataFeeds.mapIndexed { index, config ->
|
||||
receiver.context.scope.safeLaunch {
|
||||
val minTime = config.minimumTimeSinceLast.toLong()
|
||||
while (isActive) {
|
||||
try {
|
||||
receiver.sendDataFeed(createDatafeedFrame(server = server, datafeedConfig = config, skeleton = skeleton, resetsManager = receiver.appContext.resetsManager, index = index))
|
||||
receiver.sendDataFeed(createDatafeedFrame(
|
||||
server = server,
|
||||
datafeedConfig = config,
|
||||
skeleton = skeleton,
|
||||
resetsManager = receiver.appContext.resetsManager,
|
||||
heightCalibrationManager = receiver.appContext.heightCalibrationManager,
|
||||
index = index
|
||||
))
|
||||
} catch (e: Exception) {
|
||||
AppLogger.solarxr.error(e, "Error sending data feed")
|
||||
}
|
||||
@@ -180,12 +186,18 @@ class DataFeedInitBehaviour(val server: VRServer, val skeleton: Skeleton) : Sola
|
||||
}
|
||||
|
||||
receiver.datafeedTimers = timers
|
||||
receiver.context.dispatch(SolarXRBridgeActions.SetConfig(datafeeds))
|
||||
receiver.context.dispatch(SolarXRBridgeActions.SetConfig(dataFeeds))
|
||||
}
|
||||
|
||||
receiver.dataFeedDispatcher.on<PollDataFeed> { event ->
|
||||
val config = event.config ?: return@on
|
||||
receiver.sendDataFeed(createDatafeedFrame(server = server, datafeedConfig = config, skeleton = skeleton, resetsManager = receiver.appContext.resetsManager))
|
||||
receiver.sendDataFeed(createDatafeedFrame(
|
||||
server = server,
|
||||
datafeedConfig = config,
|
||||
skeleton = skeleton,
|
||||
resetsManager = receiver.appContext.resetsManager,
|
||||
heightCalibrationManager = receiver.appContext.heightCalibrationManager
|
||||
))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,7 @@ import kotlinx.coroutines.flow.distinctUntilChanged
|
||||
import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.DeviceIdTable
|
||||
import solarxr_protocol.rpc.FirmwareDeviceIdTable
|
||||
import solarxr_protocol.rpc.FirmwareUpdateRequest
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStatusResponse
|
||||
import solarxr_protocol.rpc.FirmwareUpdateStopQueuesRequest
|
||||
@@ -47,7 +47,7 @@ class FirmwareBehaviour(private val server: VRServer, private val firmwareManage
|
||||
firmwareManager.flash(
|
||||
portLocation,
|
||||
parts,
|
||||
method.needmanualreboot == true,
|
||||
method.needManualReboot == true,
|
||||
method.ssid,
|
||||
method.password,
|
||||
server,
|
||||
@@ -57,9 +57,9 @@ class FirmwareBehaviour(private val server: VRServer, private val firmwareManage
|
||||
is OTAFirmwareUpdate -> {
|
||||
val deviceId = method.deviceId ?: return@on
|
||||
val part = method.firmwarePart ?: return@on
|
||||
val device = server.getDevice(deviceId.id.toInt()) ?: return@on
|
||||
val device = server.getDevice(deviceId.toInt()) ?: return@on
|
||||
val deviceIp = device.context.state.value.address
|
||||
firmwareManager.otaFlash(deviceIp, DeviceIdTable(id = deviceId), part, server)
|
||||
firmwareManager.otaFlash(deviceIp, FirmwareDeviceIdTable(id = deviceId), part, server)
|
||||
}
|
||||
|
||||
else -> return@on
|
||||
|
||||
@@ -24,7 +24,7 @@ class HeightCalibrationBehaviour(
|
||||
receiver.sendRpc(
|
||||
UserHeightRecordingStatusResponse(
|
||||
status = state.status,
|
||||
hmdheight = state.currentHeight,
|
||||
hmdHeight = state.currentHeight,
|
||||
),
|
||||
)
|
||||
}.launchIn(receiver.context.scope)
|
||||
|
||||
@@ -7,7 +7,7 @@ class InstalledInfoBehaviour : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<InstalledInfoRequest> {
|
||||
val udevRulesInstalled = receiver.appContext.featureFlags.udevRulesInstalled ?: return@on
|
||||
receiver.sendRpc(InstalledInfoResponse(isudevinstalled = udevRulesInstalled))
|
||||
receiver.sendRpc(InstalledInfoResponse(isUdevInstalled = udevRulesInstalled))
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -20,7 +20,7 @@ class MagBehaviour(
|
||||
) : SolarXRBridgeBehaviour {
|
||||
private fun setUDPTrackerMag(trackerId: Int, deviceId: Int, enable: Boolean): Boolean {
|
||||
val connection = appContext.udpServer.findConnectionForDevice(deviceId) ?: return false
|
||||
val sensorId = connection.context.state.value.trackerIds.find { it.id == trackerId }?.trackerNum ?: return false
|
||||
val sensorId = connection.context.state.value.trackerIds.find { it.trackerId == trackerId }?.sensorId ?: return false
|
||||
connection.context.dispatch(
|
||||
UDPConnectionActions.SetSensorConfig(
|
||||
sensorId = sensorId,
|
||||
@@ -50,8 +50,7 @@ class MagBehaviour(
|
||||
return@on
|
||||
}
|
||||
|
||||
val trackerNum = trackerId.trackerNum ?: return@on
|
||||
val tracker = appContext.server.getTracker(trackerNum.toInt()) ?: return@on
|
||||
val tracker = appContext.server.getTracker(trackerId.toInt()) ?: return@on
|
||||
val trackerState = tracker.context.state.value
|
||||
if (trackerState.magStatus == MagnetometerStatus.NOT_SUPPORTED) return@on
|
||||
|
||||
@@ -93,8 +92,7 @@ class MagBehaviour(
|
||||
return@on
|
||||
}
|
||||
|
||||
val trackerNum = trackerId.trackerNum ?: return@on
|
||||
val trackerState = appContext.server.getTracker(trackerNum.toInt())?.context?.state?.value ?: return@on
|
||||
val trackerState = appContext.server.getTracker(trackerId.toInt())?.context?.state?.value ?: return@on
|
||||
receiver.sendRpc(
|
||||
MagToggleResponse(
|
||||
trackerId = trackerId,
|
||||
|
||||
@@ -72,11 +72,10 @@ class SolarXRBridge(
|
||||
appContext.vrcConfigManager?.let { vrc ->
|
||||
add(VrcBehaviour(vrc, appContext.server, userHeight = { appContext.skeleton.context.state.value.userHeight }))
|
||||
}
|
||||
add(ResetsBehaviour(appContext.config.settings))
|
||||
add(ResetsBehaviour(appContext.resetsManager))
|
||||
add(TapDetectionBehaviour(appContext.config.settings))
|
||||
add(VrcOscBehaviour(appContext.vrcOscManager))
|
||||
add(VmcBehaviour(appContext.vmcManager))
|
||||
add(SettingsBehaviour(appContext.config.settings, appContext.vmcManager))
|
||||
add(HeightCalibrationBehaviour(appContext.heightCalibrationManager))
|
||||
add(ProvisioningBehaviour(appContext.server, appContext.provisioningManager))
|
||||
add(SkeletonBehaviour(appContext.config.userConfig, appContext.skeleton))
|
||||
|
||||
@@ -1,38 +1,37 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.config.ResetsConfig
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.config.SettingsActions
|
||||
import dev.slimevr.config.TapDetectionConfig
|
||||
import solarxr_protocol.rpc.ChangeSettingsRequest
|
||||
import solarxr_protocol.rpc.ResetsSettings
|
||||
import solarxr_protocol.rpc.TapDetectionSettings
|
||||
import dev.slimevr.resets.ResetsActions
|
||||
import dev.slimevr.resets.ResetsManager
|
||||
import solarxr_protocol.rpc.ChangeResetsSettingsRequest
|
||||
import solarxr_protocol.rpc.ResetsSettingsRequest
|
||||
import solarxr_protocol.rpc.ResetsSettingsResponse
|
||||
|
||||
class ResetsBehaviour(
|
||||
private val settings: Settings,
|
||||
private val resetsManager: ResetsManager,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ChangeSettingsRequest> { req ->
|
||||
val resetsSettings = req.resetsSettings ?: return@on
|
||||
receiver.rpcDispatcher.on<ResetsSettingsRequest> {
|
||||
receiver.sendRpc(buildResetsSettings(resetsManager.context.state.value.config))
|
||||
}
|
||||
|
||||
val oldConfig = settings.context.state.value.data.resetsConfig
|
||||
val newConfig = oldConfig.copy(
|
||||
resetMountingFeet = resetsSettings.resetMountingFeet == true,
|
||||
armsResetMode = resetsSettings.armsMountingResetMode ?: oldConfig.armsResetMode,
|
||||
yawResetSmoothTime = resetsSettings.yawResetSmoothTime ?: oldConfig.yawResetSmoothTime,
|
||||
saveMountingReset = resetsSettings.saveMountingReset == true,
|
||||
resetHmdPitch = resetsSettings.resetHmdPitch == true,
|
||||
)
|
||||
|
||||
settings.context.dispatch(SettingsActions.Update { copy(resetsConfig = newConfig) })
|
||||
val oldConfig = resetsManager.context.state.value.config
|
||||
receiver.rpcDispatcher.on<ChangeResetsSettingsRequest> { req ->
|
||||
resetsManager.context.dispatch(ResetsActions.UpdateConfig(ResetsConfig(
|
||||
resetMountingFeet = req.resetMountingFeet == true,
|
||||
armsResetMode = req.armsResetMode ?: oldConfig.armsResetMode,
|
||||
yawResetSmoothTime = req.yawResetSmoothTime ?: oldConfig.yawResetSmoothTime,
|
||||
saveMountingReset = req.saveMountingReset == true,
|
||||
resetHmdPitch = req.resetHmdPitch == true,
|
||||
)))
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildResetsSettings(config: ResetsConfig): ResetsSettings = ResetsSettings(
|
||||
resetMountingFeet = config.resetMountingFeet,
|
||||
armsMountingResetMode = config.armsResetMode,
|
||||
yawResetSmoothTime = config.yawResetSmoothTime,
|
||||
saveMountingReset = config.saveMountingReset,
|
||||
resetHmdPitch = config.resetHmdPitch,
|
||||
)
|
||||
private fun buildResetsSettings(config: ResetsConfig): ResetsSettingsResponse = ResetsSettingsResponse(
|
||||
resetMountingFeet = config.resetMountingFeet,
|
||||
armsResetMode = config.armsResetMode,
|
||||
yawResetSmoothTime = config.yawResetSmoothTime,
|
||||
saveMountingReset = config.saveMountingReset,
|
||||
resetHmdPitch = config.resetHmdPitch,
|
||||
)
|
||||
}
|
||||
@@ -13,7 +13,7 @@ class SessionCalibrationBehaviour(
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ResetRequest> { req ->
|
||||
resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.Yaw, req.delay ?: 0f, req.bodyParts)
|
||||
resetsManager.scheduleReset("SolarXRBridge", req.resetType ?: ResetType.YAW, req.delay ?: 0f, req.bodyParts)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,29 +0,0 @@
|
||||
package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.vmc.VMCManager
|
||||
import solarxr_protocol.rpc.SettingsRequest
|
||||
import solarxr_protocol.rpc.SettingsResponse
|
||||
|
||||
// Central handler for SettingsRequest. Aggregates per-feature settings into one SettingsResponse
|
||||
// so the GUI receives a single response. Each feature builder lives next to its behaviour
|
||||
// (e.g. buildVmcOscSettings in vmc.kt).
|
||||
// TODO: Would be nice to split settings based on their solarxr behaviour.
|
||||
// TODO: Almost all build functions could be their own request. making it easier to work with
|
||||
class SettingsBehaviour(
|
||||
private val settings: Settings,
|
||||
private val vmcManager: VMCManager,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<SettingsRequest> {
|
||||
receiver.sendRpc(
|
||||
SettingsResponse(
|
||||
resetsSettings = buildResetsSettings(settings.context.state.value.data.resetsConfig),
|
||||
tapDetectionSettings = buildTapDetectionSettings(settings.context.state.value.data.tapDetectionConfig),
|
||||
vmcOsc = buildVmcOscSettings(vmcManager.context.state.value.config),
|
||||
vrm = buildVrmSettings(vmcManager.context.state.value.config),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -2,19 +2,18 @@ package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.config.UserConfig
|
||||
import dev.slimevr.config.UserConfigActions
|
||||
import dev.slimevr.skeleton.SKELETON_BONE_TO_BODY_PARTS
|
||||
import dev.slimevr.skeleton.Skeleton
|
||||
import dev.slimevr.skeleton.computeAllDefaultProportionsByBone
|
||||
import dev.slimevr.skeleton.computeDefaultProportionsByBone
|
||||
import dev.slimevr.skeleton.configToBoneValues
|
||||
import dev.slimevr.skeleton.height
|
||||
import dev.slimevr.skeleton.toBoneValues
|
||||
import solarxr_protocol.rpc.ChangeSettingsRequest
|
||||
import solarxr_protocol.rpc.ChangeSkeletonConfigRequest
|
||||
import solarxr_protocol.rpc.SkeletonConfigRequest
|
||||
import solarxr_protocol.rpc.SkeletonConfigResponse
|
||||
import solarxr_protocol.rpc.ChangeSkeletonProportionsRequest
|
||||
import solarxr_protocol.rpc.ChangeSkeletonSettingsRequest
|
||||
import solarxr_protocol.rpc.SkeletonPart
|
||||
import solarxr_protocol.rpc.SkeletonResetAllRequest
|
||||
import solarxr_protocol.rpc.SkeletonProportionsRequest
|
||||
import solarxr_protocol.rpc.SkeletonProportionsResetAllRequest
|
||||
import solarxr_protocol.rpc.SkeletonProportionsResponse
|
||||
|
||||
private const val MIN_HEIGHT = 1.0f
|
||||
|
||||
@@ -23,7 +22,7 @@ class SkeletonBehaviour(
|
||||
private val skeleton: Skeleton,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
|
||||
private fun buildConfigResponse(): SkeletonConfigResponse {
|
||||
private fun buildConfigResponse(): SkeletonProportionsResponse {
|
||||
val proportions = userConfig.context.state.value.data.proportions
|
||||
val bones = skeleton.context.state.value.rawBones
|
||||
val skeletonParts = bones.mapValues { it.value.offset }.toBoneValues().map { (offset, bone) -> SkeletonPart(offset, bone) }
|
||||
@@ -33,16 +32,16 @@ class SkeletonBehaviour(
|
||||
} else {
|
||||
skeleton.context.state.value.userHeight
|
||||
}
|
||||
return SkeletonConfigResponse(skeletonParts = skeletonParts, userHeight = userHeight)
|
||||
return SkeletonProportionsResponse(skeletonParts = skeletonParts, userHeight = userHeight)
|
||||
}
|
||||
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<SkeletonConfigRequest> {
|
||||
receiver.rpcDispatcher.on<SkeletonProportionsRequest> {
|
||||
receiver.sendRpc(buildConfigResponse())
|
||||
}
|
||||
|
||||
receiver.rpcDispatcher.on<ChangeSettingsRequest> { req ->
|
||||
req.modelSettings?.skeletonHeight?.let { skeletonHeight ->
|
||||
receiver.rpcDispatcher.on<ChangeSkeletonSettingsRequest> { req ->
|
||||
req.skeletonHeight?.let { skeletonHeight ->
|
||||
val hmdHeight = skeletonHeight.hmdHeight ?: return@let
|
||||
val floorHeight = skeletonHeight.floorHeight ?: 0f
|
||||
val height = hmdHeight - floorHeight
|
||||
@@ -56,7 +55,7 @@ class SkeletonBehaviour(
|
||||
}
|
||||
}
|
||||
|
||||
receiver.rpcDispatcher.on<SkeletonResetAllRequest> {
|
||||
receiver.rpcDispatcher.on<SkeletonProportionsResetAllRequest> {
|
||||
val height = userConfig.context.state.value.data.userHeight
|
||||
if (height >= MIN_HEIGHT) {
|
||||
val defaults = computeAllDefaultProportionsByBone(height)
|
||||
@@ -65,7 +64,7 @@ class SkeletonBehaviour(
|
||||
receiver.sendRpc(buildConfigResponse())
|
||||
}
|
||||
|
||||
receiver.rpcDispatcher.on<ChangeSkeletonConfigRequest> { req ->
|
||||
receiver.rpcDispatcher.on< ChangeSkeletonProportionsRequest> { req ->
|
||||
val bone = req.bone ?: return@on
|
||||
val value = req.value ?: return@on
|
||||
|
||||
|
||||
@@ -3,51 +3,57 @@ package dev.slimevr.solarxr
|
||||
import dev.slimevr.config.Settings
|
||||
import dev.slimevr.config.SettingsActions
|
||||
import dev.slimevr.config.TapDetectionConfig
|
||||
import solarxr_protocol.rpc.ChangeSettingsRequest
|
||||
import solarxr_protocol.rpc.TapDetectionSettings
|
||||
import solarxr_protocol.rpc.ChangeTapDetectionSettingsRequest
|
||||
import solarxr_protocol.rpc.TapDetectionSettingsRequest
|
||||
import solarxr_protocol.rpc.TapDetectionSettingsResponse
|
||||
import solarxr_protocol.rpc.TapDetectionSetupModeRequest
|
||||
import solarxr_protocol.rpc.VMCOSCSettingsRequest
|
||||
|
||||
class TapDetectionBehaviour(
|
||||
private val settings: Settings,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ChangeSettingsRequest> { req ->
|
||||
val tapDetectionSettings = req.tapDetectionSettings ?: return@on
|
||||
receiver.rpcDispatcher.on<TapDetectionSettingsRequest> {
|
||||
receiver.sendRpc(buildTapDetectionSettings(settings.context.state.value.data.tapDetectionConfig))
|
||||
}
|
||||
|
||||
val oldConfig = settings.context.state.value.data.tapDetectionConfig
|
||||
val newConfig = oldConfig.copy(
|
||||
yawResetDelay = tapDetectionSettings.yawResetDelay ?: oldConfig.yawResetDelay,
|
||||
fullResetDelay = tapDetectionSettings.fullResetDelay ?: oldConfig.fullResetDelay,
|
||||
mountingResetDelay = tapDetectionSettings.mountingResetDelay ?: oldConfig.mountingResetDelay,
|
||||
yawResetEnabled = tapDetectionSettings.yawResetEnabled == true,
|
||||
fullResetEnabled = tapDetectionSettings.fullResetEnabled == true,
|
||||
mountingResetEnabled = tapDetectionSettings.mountingResetEnabled == true,
|
||||
yawResetTaps = tapDetectionSettings.yawResetTaps?.toInt() ?: oldConfig.yawResetTaps,
|
||||
fullResetTaps = tapDetectionSettings.fullResetTaps?.toInt() ?: oldConfig.fullResetTaps,
|
||||
mountingResetTaps = tapDetectionSettings.mountingResetTaps?.toInt() ?: oldConfig.mountingResetTaps,
|
||||
yawResetBodyPart = tapDetectionSettings.yawResetTracker ?: oldConfig.yawResetBodyPart,
|
||||
fullResetBodyPart = tapDetectionSettings.fullResetTracker ?: oldConfig.fullResetBodyPart,
|
||||
mountingResetBodyPart = tapDetectionSettings.mountingResetTracker ?: oldConfig.mountingResetBodyPart,
|
||||
numberTrackersOverThreshold = tapDetectionSettings.numberTrackersOverThreshold?.toInt() ?: oldConfig.numberTrackersOverThreshold,
|
||||
setupMode = tapDetectionSettings.setupMode == true,
|
||||
)
|
||||
receiver.rpcDispatcher.on<TapDetectionSetupModeRequest> { req ->
|
||||
println(req.setupMode) // TODO
|
||||
}
|
||||
|
||||
settings.context.dispatch(SettingsActions.Update { copy(tapDetectionConfig = newConfig) })
|
||||
val oldConfig = settings.context.state.value.data.tapDetectionConfig
|
||||
receiver.rpcDispatcher.on<ChangeTapDetectionSettingsRequest> { req ->
|
||||
settings.context.dispatch(SettingsActions.Update { copy(tapDetectionConfig = TapDetectionConfig(
|
||||
yawResetDelay = req.yawResetDelay ?: oldConfig.yawResetDelay,
|
||||
fullResetDelay = req.fullResetDelay ?: oldConfig.fullResetDelay,
|
||||
mountingResetDelay = req.mountingResetDelay ?: oldConfig.mountingResetDelay,
|
||||
yawResetEnabled = req.yawResetEnabled == true,
|
||||
fullResetEnabled = req.fullResetEnabled == true,
|
||||
mountingResetEnabled = req.mountingResetEnabled == true,
|
||||
yawResetTaps = req.yawResetTaps?.toInt() ?: oldConfig.yawResetTaps,
|
||||
fullResetTaps = req.fullResetTaps?.toInt() ?: oldConfig.fullResetTaps,
|
||||
mountingResetTaps = req.mountingResetTaps?.toInt() ?: oldConfig.mountingResetTaps,
|
||||
yawResetBodyPart = req.yawResetTracker ?: oldConfig.yawResetBodyPart,
|
||||
fullResetBodyPart = req.fullResetTracker ?: oldConfig.fullResetBodyPart,
|
||||
mountingResetBodyPart = req.mountingResetTracker ?: oldConfig.mountingResetBodyPart,
|
||||
numberTrackersOverThreshold = req.numberTrackersOverThreshold?.toInt() ?: oldConfig.numberTrackersOverThreshold,
|
||||
))})
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildTapDetectionSettings(config: TapDetectionConfig): TapDetectionSettings = TapDetectionSettings(
|
||||
yawResetDelay = config.yawResetDelay,
|
||||
fullResetDelay = config.fullResetDelay,
|
||||
mountingResetDelay = config.mountingResetDelay,
|
||||
yawResetEnabled = config.yawResetEnabled,
|
||||
fullResetEnabled = config.fullResetEnabled,
|
||||
mountingResetEnabled = config.mountingResetEnabled,
|
||||
yawResetTaps = config.yawResetTaps.toUByte(),
|
||||
fullResetTaps = config.fullResetTaps.toUByte(),
|
||||
mountingResetTaps = config.mountingResetTaps.toUByte(),
|
||||
yawResetTracker = config.yawResetBodyPart,
|
||||
fullResetTracker = config.fullResetBodyPart,
|
||||
mountingResetTracker = config.mountingResetBodyPart,
|
||||
numberTrackersOverThreshold = config.numberTrackersOverThreshold.toUByte(),
|
||||
)
|
||||
private fun buildTapDetectionSettings(config: TapDetectionConfig): TapDetectionSettingsResponse = TapDetectionSettingsResponse(
|
||||
yawResetDelay = config.yawResetDelay,
|
||||
fullResetDelay = config.fullResetDelay,
|
||||
mountingResetDelay = config.mountingResetDelay,
|
||||
yawResetEnabled = config.yawResetEnabled,
|
||||
fullResetEnabled = config.fullResetEnabled,
|
||||
mountingResetEnabled = config.mountingResetEnabled,
|
||||
yawResetTaps = config.yawResetTaps.toUByte(),
|
||||
fullResetTaps = config.fullResetTaps.toUByte(),
|
||||
mountingResetTaps = config.mountingResetTaps.toUByte(),
|
||||
yawResetTracker = config.yawResetBodyPart,
|
||||
fullResetTracker = config.fullResetBodyPart,
|
||||
mountingResetTracker = config.mountingResetBodyPart,
|
||||
numberTrackersOverThreshold = config.numberTrackersOverThreshold.toUByte(),
|
||||
)
|
||||
}
|
||||
@@ -11,8 +11,8 @@ class AssignTrackerBehaviour(
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<AssignTrackerRequest> { req ->
|
||||
val trackerNum = req.trackerId?.trackerNum ?: return@on
|
||||
val tracker = server.getTracker(trackerNum.toInt())
|
||||
val id = req.trackerId ?: return@on
|
||||
val tracker = server.getTracker(id.toInt())
|
||||
?: return@on
|
||||
|
||||
val bodyPart = req.bodyPosition?.takeIf { it != BodyPart.NONE }
|
||||
|
||||
@@ -3,48 +3,41 @@ package dev.slimevr.solarxr
|
||||
import dev.slimevr.config.VMCConfig
|
||||
import dev.slimevr.vmc.VMCActions
|
||||
import dev.slimevr.vmc.VMCManager
|
||||
import solarxr_protocol.rpc.ChangeSettingsRequest
|
||||
import solarxr_protocol.rpc.OSCSettings
|
||||
import solarxr_protocol.rpc.VMCOSCSettings
|
||||
import solarxr_protocol.rpc.VRMSettings
|
||||
import solarxr_protocol.rpc.ChangeVMCOSCSettingsRequest
|
||||
import solarxr_protocol.rpc.VMCOSCSettingsRequest
|
||||
import solarxr_protocol.rpc.VMCOSCSettingsResponse
|
||||
|
||||
class VmcBehaviour(
|
||||
private val vmcManager: VMCManager,
|
||||
) : SolarXRBridgeBehaviour {
|
||||
override fun observe(receiver: SolarXRBridge) {
|
||||
receiver.rpcDispatcher.on<ChangeSettingsRequest> { req ->
|
||||
val vmc = req.vmcOsc ?: return@on
|
||||
val osc = vmc.oscSettings ?: return@on
|
||||
val portIn = osc.portIn?.toInt() ?: return@on
|
||||
val portOut = osc.portOut?.toInt() ?: return@on
|
||||
receiver.rpcDispatcher.on<VMCOSCSettingsRequest> {
|
||||
receiver.sendRpc(buildVmcOscSettings(vmcManager.context.state.value.config))
|
||||
}
|
||||
|
||||
val oldConfig = vmcManager.context.state.value.config
|
||||
receiver.rpcDispatcher.on<ChangeVMCOSCSettingsRequest> { req ->
|
||||
vmcManager.context.dispatch(
|
||||
VMCActions.UpdateConfig(
|
||||
VMCConfig(
|
||||
enabled = osc.enabled == true,
|
||||
portIn = portIn,
|
||||
portOut = portOut,
|
||||
address = osc.address.orEmpty(),
|
||||
mirrorTracking = vmc.mirrorTracking == true,
|
||||
anchorAtHips = vmc.anchorHip == true,
|
||||
vrmJson = req.vrm?.vrmJson?.ifEmpty { null },
|
||||
enabled = req.enabled == true,
|
||||
portIn = req.portIn?.toInt() ?: oldConfig.portIn,
|
||||
portOut = req.portOut?.toInt() ?: oldConfig.portOut,
|
||||
address = req.address ?: oldConfig.address,
|
||||
mirrorTracking = req.mirrorTracking == true,
|
||||
anchorAtHips = req.anchorHip == true,
|
||||
),
|
||||
),
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun buildVmcOscSettings(config: VMCConfig): VMCOSCSettings = VMCOSCSettings(
|
||||
oscSettings = OSCSettings(
|
||||
private fun buildVmcOscSettings(config: VMCConfig): VMCOSCSettingsResponse = VMCOSCSettingsResponse(
|
||||
enabled = config.enabled,
|
||||
portIn = config.portIn.toUShort(),
|
||||
portOut = config.portOut.toUShort(),
|
||||
address = config.address,
|
||||
),
|
||||
anchorHip = config.anchorAtHips,
|
||||
mirrorTracking = config.mirrorTracking,
|
||||
)
|
||||
|
||||
fun buildVrmSettings(config: VMCConfig): VRMSettings = VRMSettings(
|
||||
vrmJson = config.vrmJson,
|
||||
)
|
||||
anchorHip = config.anchorAtHips,
|
||||
mirrorTracking = config.mirrorTracking,
|
||||
)
|
||||
}
|
||||
@@ -2,7 +2,6 @@ package dev.slimevr.solarxr
|
||||
|
||||
import dev.slimevr.config.VRCOSCConfig
|
||||
import dev.slimevr.config.VRCOSCManualNetworkConfig
|
||||
import dev.slimevr.config.VRCOSCTrackers
|
||||
import dev.slimevr.vrcosc.VRCOSCActions
|
||||
import dev.slimevr.vrcosc.VRCOSCManager
|
||||
import dev.slimevr.vrcosc.VRCOSCStatus
|
||||
@@ -14,7 +13,6 @@ import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.flow.sample
|
||||
import solarxr_protocol.rpc.ChangeVRCOSCSettingsRequest
|
||||
import solarxr_protocol.rpc.VRCOSCNetworkSettings
|
||||
import solarxr_protocol.rpc.VRCOSCSettings
|
||||
import solarxr_protocol.rpc.VRCOSCSettingsRequest
|
||||
import solarxr_protocol.rpc.VRCOSCSettingsResponse
|
||||
import solarxr_protocol.rpc.VRCOSCStatusChangeResponse
|
||||
@@ -40,7 +38,7 @@ internal class VrcOscBehaviour(
|
||||
.launchIn(receiver.context.scope)
|
||||
|
||||
receiver.rpcDispatcher.on<VRCOSCSettingsRequest> {
|
||||
receiver.sendRpc(VRCOSCSettingsResponse(settings = buildVrcOscSettings(vrcOscManager.context.state.value.config)))
|
||||
receiver.sendRpc(buildVrcOscSettings(vrcOscManager.context.state.value.config))
|
||||
}
|
||||
|
||||
receiver.rpcDispatcher.on<VRCOSCStatusRequest> {
|
||||
@@ -49,12 +47,11 @@ internal class VrcOscBehaviour(
|
||||
}
|
||||
|
||||
receiver.rpcDispatcher.on<ChangeVRCOSCSettingsRequest> { req ->
|
||||
val vrcOsc = req.settings ?: return@on
|
||||
vrcOscManager.context.dispatch(
|
||||
VRCOSCActions.UpdateConfig(
|
||||
VRCOSCConfig(
|
||||
enabled = vrcOsc.enabled == true,
|
||||
manualNetwork = vrcOsc.manualNetwork?.takeIf { it.portIn !== null && it.portOut !== null && it.address !== null }?.let { network ->
|
||||
enabled = req.enabled == true,
|
||||
manualNetwork = req.manualNetwork?.takeIf { it.portIn !== null && it.portOut !== null && it.address !== null }?.let { network ->
|
||||
VRCOSCManualNetworkConfig(
|
||||
portIn = network.portIn?.toInt() ?: error("portIn should be set"),
|
||||
portOut = network.portOut?.toInt() ?: error("portOut should be set"),
|
||||
@@ -66,35 +63,35 @@ internal class VrcOscBehaviour(
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
private fun buildStatusResponse(status: VRCOSCStatus, enabled: Boolean) = VRCOSCStatusChangeResponse(
|
||||
enabled = enabled,
|
||||
inputState = status.inputState,
|
||||
inputPort = status.inputPort?.toUShort(),
|
||||
inputError = status.inputError,
|
||||
lastReceivedInputMillis = status.lastReceivedInputMillis?.toULong(),
|
||||
outputState = status.outputState,
|
||||
outputError = status.outputError,
|
||||
targetAddress = status.targetAddress,
|
||||
targetPort = status.targetPort?.toUShort(),
|
||||
targetSource = status.targetSource,
|
||||
lastFrameSentMillis = status.lastFrameSentMillis?.toULong(),
|
||||
oscqueryState = status.oscQueryState,
|
||||
oscqueryAdvertisedPort = status.oscQueryAdvertisedPort?.toUShort(),
|
||||
oscqueryError = status.oscQueryError,
|
||||
discoveredTargets = status.discoveredTargets.map { target ->
|
||||
RpcVRCOSCDiscoveredTarget(name = target.name, address = target.address, portOut = target.portOut.toUShort())
|
||||
},
|
||||
)
|
||||
|
||||
private fun buildVrcOscSettings(config: VRCOSCConfig): VRCOSCSettingsResponse = VRCOSCSettingsResponse(
|
||||
enabled = config.enabled,
|
||||
manualNetwork = config.manualNetwork?.let { manual ->
|
||||
VRCOSCNetworkSettings(
|
||||
portIn = manual.portIn.toUShort(),
|
||||
portOut = manual.portOut.toUShort(),
|
||||
address = manual.address,
|
||||
)
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
internal fun buildStatusResponse(status: VRCOSCStatus, enabled: Boolean) = VRCOSCStatusChangeResponse(
|
||||
enabled = enabled,
|
||||
inputState = status.inputState,
|
||||
inputPort = status.inputPort?.toUShort(),
|
||||
inputError = status.inputError,
|
||||
lastReceivedInputMillis = status.lastReceivedInputMillis?.toULong(),
|
||||
outputState = status.outputState,
|
||||
outputError = status.outputError,
|
||||
targetAddress = status.targetAddress,
|
||||
targetPort = status.targetPort?.toUShort(),
|
||||
targetSource = status.targetSource,
|
||||
lastFrameSentMillis = status.lastFrameSentMillis?.toULong(),
|
||||
oscqueryState = status.oscQueryState,
|
||||
oscqueryAdvertisedPort = status.oscQueryAdvertisedPort?.toUShort(),
|
||||
oscqueryError = status.oscQueryError,
|
||||
discoveredTargets = status.discoveredTargets.map { target ->
|
||||
RpcVRCOSCDiscoveredTarget(name = target.name, address = target.address, portOut = target.portOut.toUShort())
|
||||
},
|
||||
)
|
||||
|
||||
internal fun buildVrcOscSettings(config: VRCOSCConfig): VRCOSCSettings = VRCOSCSettings(
|
||||
enabled = config.enabled,
|
||||
manualNetwork = config.manualNetwork?.let { manual ->
|
||||
VRCOSCNetworkSettings(
|
||||
portIn = manual.portIn.toUShort(),
|
||||
portOut = manual.portOut.toUShort(),
|
||||
address = manual.address,
|
||||
)
|
||||
},
|
||||
)
|
||||
@@ -17,8 +17,6 @@ import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import kotlinx.coroutines.isActive
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.datatypes.TrackerId
|
||||
import solarxr_protocol.rpc.ResetType
|
||||
import solarxr_protocol.rpc.TapDetectionSetupNotification
|
||||
import kotlin.concurrent.atomics.AtomicInt
|
||||
@@ -87,7 +85,8 @@ class TrackerTapDetectionBehaviour : TrackerBehaviour {
|
||||
resetTapDetection()
|
||||
|
||||
// If setupMode is true, double tap to assign
|
||||
if (tapDetectionConfig.setupMode) {
|
||||
// TODO setupMode
|
||||
if (false) {
|
||||
setupModeAssign = true
|
||||
resetType = null
|
||||
tapsNeeded = 2
|
||||
@@ -111,19 +110,19 @@ class TrackerTapDetectionBehaviour : TrackerBehaviour {
|
||||
|
||||
// BodyParts above could be null
|
||||
yawResetBodyPart if tapDetectionConfig.yawResetEnabled -> {
|
||||
resetType = ResetType.Yaw
|
||||
resetType = ResetType.YAW
|
||||
tapsNeeded = tapDetectionConfig.yawResetTaps
|
||||
actionDelay = tapDetectionConfig.yawResetDelay
|
||||
}
|
||||
|
||||
fullResetBodyPart if tapDetectionConfig.fullResetEnabled -> {
|
||||
resetType = ResetType.Full
|
||||
resetType = ResetType.FULL
|
||||
tapsNeeded = tapDetectionConfig.fullResetTaps
|
||||
actionDelay = tapDetectionConfig.fullResetDelay
|
||||
}
|
||||
|
||||
mountingResetBodyPart if tapDetectionConfig.mountingResetEnabled -> {
|
||||
resetType = ResetType.Mounting
|
||||
resetType = ResetType.MOUNTING
|
||||
tapsNeeded = tapDetectionConfig.mountingResetTaps
|
||||
actionDelay = tapDetectionConfig.mountingResetDelay
|
||||
}
|
||||
@@ -178,9 +177,7 @@ class TrackerTapDetectionBehaviour : TrackerBehaviour {
|
||||
// If it's in setup mode, tap to assign
|
||||
if (setupModeAssign) {
|
||||
receiver.appContext.server.sendSolarxrRpc(
|
||||
TapDetectionSetupNotification(
|
||||
TrackerId(DeviceId(currentTracker.deviceId.toUByte()), currentTracker.id.toUByte()),
|
||||
),
|
||||
TapDetectionSetupNotification(currentTracker.id.toUShort()),
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -14,10 +14,10 @@ import solarxr_protocol.datatypes.MagnetometerStatus
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.datatypes.hardware_info.ImuType
|
||||
|
||||
data class TrackerIdNum(val id: Int, val trackerNum: Int)
|
||||
data class TrackerSensorIds(val trackerId: Int, val sensorId: Int)
|
||||
|
||||
data class TrackerState(
|
||||
val id: Int, // trackerNum
|
||||
val id: Int,
|
||||
val name: String,
|
||||
val hardwareId: String,
|
||||
val sensorType: ImuType?,
|
||||
|
||||
@@ -23,8 +23,6 @@ import kotlinx.coroutines.flow.launchIn
|
||||
import kotlinx.coroutines.flow.map
|
||||
import kotlinx.coroutines.flow.onEach
|
||||
import solarxr_protocol.datatypes.BodyPart
|
||||
import solarxr_protocol.datatypes.DeviceId
|
||||
import solarxr_protocol.datatypes.TrackerId
|
||||
import solarxr_protocol.datatypes.TrackerStatus
|
||||
import solarxr_protocol.rpc.TrackingChecklistNeedCalibration
|
||||
import solarxr_protocol.rpc.TrackingChecklistPublicNetworks
|
||||
@@ -50,8 +48,6 @@ private fun trackerStatesFlow(server: VRServer): Flow<List<TrackerState>> = allC
|
||||
|
||||
private fun deviceStatesFlow(server: VRServer): Flow<List<DeviceState>> = allContextStates(server, { state -> state.devices.values }) { device -> device.context.state }
|
||||
|
||||
private fun trackerIdOf(tracker: TrackerState): TrackerId = TrackerId(trackerNum = tracker.id.toUByte(), deviceId = DeviceId(tracker.deviceId.toUByte()))
|
||||
|
||||
class SteamVRCheckBehaviour(private val server: VRServer) : TrackingChecklistBehaviourType {
|
||||
override fun observe(receiver: TrackingChecklist) {
|
||||
server.context.state
|
||||
@@ -82,7 +78,7 @@ class HMDCheckBehaviour(private val server: VRServer) : TrackingChecklistBehavio
|
||||
ignorable = true,
|
||||
extraData = if (!isAssigned) {
|
||||
TrackingChecklistUnassignedHMD(
|
||||
trackerId = hmdTracker?.let { tracker -> trackerIdOf(tracker) },
|
||||
trackerId = hmdTracker?.id?.toUShort(),
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -111,7 +107,7 @@ class TrackerRestCheckBehaviour(private val server: VRServer) : TrackingChecklis
|
||||
enabled = trackers.isNotEmpty(),
|
||||
extraData = if (!uncalibratedTrackers.isEmpty()) {
|
||||
TrackingChecklistNeedCalibration(
|
||||
trackersId = uncalibratedTrackers.map { tracker -> trackerIdOf(tracker) },
|
||||
trackersId = uncalibratedTrackers.map { tracker -> tracker.id.toUShort() },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
@@ -138,7 +134,7 @@ class TrackerErrorCheckBehaviour(private val server: VRServer) : TrackingCheckli
|
||||
enabled = trackers.isNotEmpty(),
|
||||
extraData = if (errorTrackers.isNotEmpty()) {
|
||||
TrackingChecklistTrackerError(
|
||||
trackersId = errorTrackers.map { tracker -> trackerIdOf(tracker) },
|
||||
trackersId = errorTrackers.map { tracker -> tracker.id.toUShort() },
|
||||
)
|
||||
} else {
|
||||
null
|
||||
|
||||
@@ -8,7 +8,7 @@ import dev.slimevr.device.DeviceActions
|
||||
import dev.slimevr.device.DeviceOrigin
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerActions
|
||||
import dev.slimevr.tracker.TrackerIdNum
|
||||
import dev.slimevr.tracker.TrackerSensorIds
|
||||
import dev.slimevr.util.safeLaunch
|
||||
import io.github.axisangles.ktmath.Quaternion
|
||||
import kotlinx.coroutines.Job
|
||||
@@ -225,7 +225,7 @@ class TimeoutBehaviour : UDPConnectionBehaviour {
|
||||
receiver.getDevice()?.context?.dispatch(
|
||||
DeviceActions.Update { copy(status = TrackerStatus.TIMED_OUT) },
|
||||
)
|
||||
state.trackerIds.mapNotNull { receiver.appContext.server.getTracker(it.id) }.forEach { tracker ->
|
||||
state.trackerIds.mapNotNull { receiver.appContext.server.getTracker(it.trackerId) }.forEach { tracker ->
|
||||
tracker.context.dispatch(TrackerActions.SetStatus(TrackerStatus.TIMED_OUT))
|
||||
}
|
||||
} else {
|
||||
@@ -251,7 +251,7 @@ class DisconnectBehaviour : UDPConnectionBehaviour {
|
||||
receiver.getDevice()?.context?.dispatch(
|
||||
DeviceActions.Update { copy(status = TrackerStatus.DISCONNECTED) },
|
||||
)
|
||||
currentState.trackerIds.mapNotNull { receiver.appContext.server.getTracker(it.id) }.forEach { tracker ->
|
||||
currentState.trackerIds.mapNotNull { receiver.appContext.server.getTracker(it.trackerId) }.forEach { tracker ->
|
||||
tracker.context.dispatch(TrackerActions.SetStatus(TrackerStatus.DISCONNECTED))
|
||||
}
|
||||
}
|
||||
@@ -303,7 +303,7 @@ class SensorInfoBehaviour : UDPConnectionBehaviour {
|
||||
if (existingTracker != null) {
|
||||
receiver.context.dispatch(
|
||||
UDPConnectionActions.AssignTracker(
|
||||
trackerId = TrackerIdNum(id = existingTracker.context.state.value.id, trackerNum = event.data.sensorId),
|
||||
trackerId = TrackerSensorIds(trackerId = existingTracker.context.state.value.id, sensorId = event.data.sensorId),
|
||||
),
|
||||
)
|
||||
return existingTracker to false
|
||||
@@ -321,7 +321,7 @@ class SensorInfoBehaviour : UDPConnectionBehaviour {
|
||||
)
|
||||
receiver.appContext.server.context.dispatch(VRServerActions.NewTracker(trackerId = trackerId, context = newTracker))
|
||||
receiver.context.dispatch(
|
||||
UDPConnectionActions.AssignTracker(trackerId = TrackerIdNum(id = trackerId, trackerNum = event.data.sensorId)),
|
||||
UDPConnectionActions.AssignTracker(trackerId = TrackerSensorIds(trackerId = trackerId, sensorId = event.data.sensorId)),
|
||||
)
|
||||
return newTracker to true
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import dev.slimevr.context.Behaviour
|
||||
import dev.slimevr.context.Context
|
||||
import dev.slimevr.device.Device
|
||||
import dev.slimevr.tracker.Tracker
|
||||
import dev.slimevr.tracker.TrackerIdNum
|
||||
import dev.slimevr.tracker.TrackerSensorIds
|
||||
import dev.slimevr.util.safeLaunch
|
||||
import io.ktor.network.sockets.BoundDatagramSocket
|
||||
import io.ktor.network.sockets.Datagram
|
||||
@@ -14,7 +14,6 @@ import io.ktor.network.sockets.InetSocketAddress
|
||||
import kotlinx.coroutines.CoroutineScope
|
||||
import kotlinx.coroutines.channels.Channel
|
||||
import kotlinx.io.Buffer
|
||||
import kotlinx.io.readByteArray
|
||||
import solarxr_protocol.datatypes.MagnetometerStatus
|
||||
|
||||
data class LastPing(
|
||||
@@ -36,7 +35,7 @@ data class UDPConnectionState(
|
||||
val lastPing: LastPing,
|
||||
val didHandshake: Boolean,
|
||||
val deviceId: Int?,
|
||||
val trackerIds: List<TrackerIdNum>,
|
||||
val trackerIds: List<TrackerSensorIds>,
|
||||
val features: FirmwareFeatures?,
|
||||
val sensorConfigFlags: Map<Int, SensorConfigFlags>,
|
||||
)
|
||||
@@ -45,7 +44,7 @@ sealed interface UDPConnectionActions {
|
||||
data class StartPing(val startTime: Long, val pingId: Int) : UDPConnectionActions
|
||||
data class Handshake(val deviceId: Int) : UDPConnectionActions
|
||||
data class LastPacket(val packetNum: Long? = null, val time: Long) : UDPConnectionActions
|
||||
data class AssignTracker(val trackerId: TrackerIdNum) : UDPConnectionActions
|
||||
data class AssignTracker(val trackerId: TrackerSensorIds) : UDPConnectionActions
|
||||
data class FirmwareFeatures(val features: dev.slimevr.udp.FirmwareFeatures) : UDPConnectionActions
|
||||
data class SetSensorConfig(val sensorId: Int, val flags: SensorConfigFlags) : UDPConnectionActions
|
||||
data object TimedOut : UDPConnectionActions
|
||||
@@ -79,8 +78,8 @@ class UDPConnection(
|
||||
}
|
||||
|
||||
fun getTracker(id: Int): Tracker? {
|
||||
val trackerId = context.state.value.trackerIds.find { it.trackerNum == id }
|
||||
return if (trackerId != null) appContext.server.getTracker(trackerId.id) else null
|
||||
val trackerId = context.state.value.trackerIds.find { it.sensorId == id }
|
||||
return if (trackerId != null) appContext.server.getTracker(trackerId.trackerId) else null
|
||||
}
|
||||
|
||||
companion object {
|
||||
|
||||
@@ -151,7 +151,7 @@ data object Heartbeat : UDPPacket
|
||||
data class Handshake(
|
||||
val boardType: BoardType = BoardType.UNKNOWN,
|
||||
val imuType: Int = 0,
|
||||
val mcuType: McuType = McuType.Other,
|
||||
val mcuType: McuType = McuType.UNKNOWN,
|
||||
val protocolVersion: Int = 0,
|
||||
val firmware: String? = null,
|
||||
val macString: String? = null,
|
||||
@@ -166,7 +166,7 @@ data class Handshake(
|
||||
if (remaining == 0L) return Handshake()
|
||||
val b = if (remaining >= 4) BoardType.fromValue(readInt().toUShort()) ?: BoardType.UNKNOWN else BoardType.UNKNOWN
|
||||
val i = if (remaining >= 4) readInt() else 0
|
||||
val m = if (remaining >= 4) McuType.fromValue(readInt().toUShort()) ?: McuType.Other else McuType.Other
|
||||
val m = if (remaining >= 4) McuType.fromValue(readInt().toUShort()) ?: McuType.UNKNOWN else McuType.UNKNOWN
|
||||
if (remaining >= 12) {
|
||||
readInt()
|
||||
readInt()
|
||||
@@ -296,7 +296,7 @@ data class ErrorPacket(override val sensorId: Int = 0, val errorNumber: Int = 0)
|
||||
data class SensorInfo(
|
||||
override val sensorId: Int = 0,
|
||||
val status: TrackerStatus = TrackerStatus.DISCONNECTED,
|
||||
val imuType: ImuType = ImuType.Other,
|
||||
val imuType: ImuType = ImuType.UNKNOWN,
|
||||
val sensorConfig: SensorConfig? = null,
|
||||
val hasCompletedRestCalibration: Boolean? = null,
|
||||
val trackerPosition: Int? = null,
|
||||
@@ -337,7 +337,7 @@ data class SensorInfo(
|
||||
fun read(src: Source) = with(src) {
|
||||
val id = readU8()
|
||||
val stat = statusFromUDP(readUByte())
|
||||
val imu = if (remaining > 0) ImuType.fromValue(readUByte().toUShort()) ?: ImuType.Other else ImuType.Other
|
||||
val imu = if (remaining > 0) ImuType.fromValue(readUByte().toUShort()) ?: ImuType.UNKNOWN else ImuType.UNKNOWN
|
||||
val conf = if (remaining >= 2) SensorConfig.fromUDP(readShort().toUShort()) else null
|
||||
val calib = if (remaining > 0) readU8() != 0 else null
|
||||
val pos = if (remaining > 0) readU8() else null
|
||||
|
||||
@@ -42,6 +42,10 @@ class VRServer(
|
||||
fun nextHandle() = handleCounter.incrementAndFetch()
|
||||
fun getTracker(id: Int) = context.state.value.trackers[id]
|
||||
fun getDevice(id: Int) = context.state.value.devices[id]
|
||||
fun getDeviceFromTrackerId(id: Int): Device? {
|
||||
val deviceId = getTracker(id)?.context?.state?.value?.deviceId ?: return null
|
||||
return getDevice(deviceId)
|
||||
}
|
||||
|
||||
suspend fun sendSolarxrRpc(message: RpcMessage) = context.state.value.solarxr.values.forEach { it.sendRpc(message) }
|
||||
|
||||
|
||||
+1
-1
Submodule solarxr-protocol updated: b8160c4760...17da40a966.
Reference in new issue
Block a user