Skip to content

Commit

Permalink
show current direction on manual mounting (#1108)
Browse files Browse the repository at this point in the history
Co-authored-by: Uriel <[email protected]>
  • Loading branch information
ZycaR and ImUrX authored Aug 13, 2024
1 parent b06f038 commit 60f8db7
Showing 1 changed file with 27 additions and 2 deletions.
29 changes: 27 additions & 2 deletions gui/src/components/onboarding/pages/mounting/ManualMounting.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,14 @@
import { useMemo, useState } from 'react';
import { useCallback, useMemo, useState } from 'react';
import { AssignTrackerRequestT, BodyPart, RpcMessage } from 'solarxr-protocol';
import { FlatDeviceTracker } from '@/hooks/app';
import { useOnboarding } from '@/hooks/onboarding';
import { useTrackers } from '@/hooks/tracker';
import { useWebsocketAPI } from '@/hooks/websocket-api';
import { MountingOrientationDegreesToQuatT } from '@/maths/quaternion';
import {
MountingOrientationDegreesToQuatT,
QuaternionFromQuatT,
similarQuaternions,
} from '@/maths/quaternion';
import { Button } from '@/components/commons/Button';
import { TipBox } from '@/components/commons/TipBox';
import { Typography } from '@/components/commons/Typography';
Expand Down Expand Up @@ -62,10 +66,31 @@ export function ManualMountingPage() {
setSelectRole(BodyPart.NONE);
};

const getCurrRotation = useCallback(
(role: BodyPart) => {
if (role === BodyPart.NONE) return undefined;

const trackers = trackerPartGrouped[role] || [];
const [mountingOrientation, ...orientation] = trackers
.map((td) => td.tracker.info?.mountingOrientation)
.filter((orientation) => !!orientation)
.map((orientation) => QuaternionFromQuatT(orientation));

const identicalOrientations =
mountingOrientation !== undefined &&
orientation.every((quat) =>
similarQuaternions(quat, mountingOrientation)
);
return identicalOrientations ? mountingOrientation : undefined;
},
[trackerPartGrouped]
);

return (
<>
<MountingSelectionMenu
bodyPart={selectedRole}
currRotation={getCurrRotation(selectedRole)}
isOpen={selectedRole !== BodyPart.NONE}
onClose={() => setSelectRole(BodyPart.NONE)}
onDirectionSelected={onDirectionSelected}
Expand Down

0 comments on commit 60f8db7

Please sign in to comment.