Skip to content

Commit 60f8db7

Browse files
ZycaRImUrX
andauthored
show current direction on manual mounting (#1108)
Co-authored-by: Uriel <imurx@proton.me>
1 parent b06f038 commit 60f8db7

File tree

1 file changed

+27
-2
lines changed

1 file changed

+27
-2
lines changed

gui/src/components/onboarding/pages/mounting/ManualMounting.tsx

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,14 @@
1-
import { useMemo, useState } from 'react';
1+
import { useCallback, useMemo, useState } from 'react';
22
import { AssignTrackerRequestT, BodyPart, RpcMessage } from 'solarxr-protocol';
33
import { FlatDeviceTracker } from '@/hooks/app';
44
import { useOnboarding } from '@/hooks/onboarding';
55
import { useTrackers } from '@/hooks/tracker';
66
import { useWebsocketAPI } from '@/hooks/websocket-api';
7-
import { MountingOrientationDegreesToQuatT } from '@/maths/quaternion';
7+
import {
8+
MountingOrientationDegreesToQuatT,
9+
QuaternionFromQuatT,
10+
similarQuaternions,
11+
} from '@/maths/quaternion';
812
import { Button } from '@/components/commons/Button';
913
import { TipBox } from '@/components/commons/TipBox';
1014
import { Typography } from '@/components/commons/Typography';
@@ -62,10 +66,31 @@ export function ManualMountingPage() {
6266
setSelectRole(BodyPart.NONE);
6367
};
6468

69+
const getCurrRotation = useCallback(
70+
(role: BodyPart) => {
71+
if (role === BodyPart.NONE) return undefined;
72+
73+
const trackers = trackerPartGrouped[role] || [];
74+
const [mountingOrientation, ...orientation] = trackers
75+
.map((td) => td.tracker.info?.mountingOrientation)
76+
.filter((orientation) => !!orientation)
77+
.map((orientation) => QuaternionFromQuatT(orientation));
78+
79+
const identicalOrientations =
80+
mountingOrientation !== undefined &&
81+
orientation.every((quat) =>
82+
similarQuaternions(quat, mountingOrientation)
83+
);
84+
return identicalOrientations ? mountingOrientation : undefined;
85+
},
86+
[trackerPartGrouped]
87+
);
88+
6589
return (
6690
<>
6791
<MountingSelectionMenu
6892
bodyPart={selectedRole}
93+
currRotation={getCurrRotation(selectedRole)}
6994
isOpen={selectedRole !== BodyPart.NONE}
7095
onClose={() => setSelectRole(BodyPart.NONE)}
7196
onDirectionSelected={onDirectionSelected}

0 commit comments

Comments
 (0)