Skip to content

Commit

Permalink
Add drift compensation warning (#1160)
Browse files Browse the repository at this point in the history
  • Loading branch information
JovannMC authored Oct 8, 2024
1 parent 1dae302 commit ed34001
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
9 changes: 9 additions & 0 deletions gui/public/i18n/en/translation.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -321,7 +321,16 @@ settings-general-tracker_mechanics-drift_compensation = Drift compensation
settings-general-tracker_mechanics-drift_compensation-description =
Compensates IMU yaw drift by applying an inverse rotation.
Change amount of compensation and up to how many resets are taken into account.
This should only be used if you need to reset very often!
settings-general-tracker_mechanics-drift_compensation-enabled-label = Drift compensation
settings-general-tracker_mechanics-drift_compensation_warning =
<b>Warning:</b> Only use drift compensation if you need to reset
very often (every ~5-10 minutes).
Some IMUs prone to frequent resets include:
Joy-Cons, owoTrack, and MPUs (without recent firmware).
settings-general-tracker_mechanics-drift_compensation_warning-cancel = Cancel
settings-general-tracker_mechanics-drift_compensation_warning-done = I understand
settings-general-tracker_mechanics-drift_compensation-amount-label = Compensation amount
settings-general-tracker_mechanics-drift_compensation-max_resets-label = Use up to x last resets
settings-general-tracker_mechanics-save_mounting_reset = Save automatic mounting reset calibration
Expand Down
72 changes: 72 additions & 0 deletions gui/src/components/settings/DriftCompensationModal.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { Button } from '@/components/commons/Button';
import { WarningBox } from '@/components/commons/TipBox';
import { Localized, useLocalization } from '@fluent/react';
import { BaseModal } from '@/components/commons/BaseModal';
import ReactModal from 'react-modal';

export function DriftCompensationModal({
isOpen = true,
onClose,
accept,
...props
}: {
/**
* Is the parent/sibling component opened?
*/
isOpen: boolean;
/**
* Function to trigger when the warning hasn't been accepted
*/
onClose: () => void;
/**
* Function when you press `I understand`
*/
accept: () => void;
} & ReactModal.Props) {
const { l10n } = useLocalization();

return (
<BaseModal
isOpen={isOpen}
shouldCloseOnOverlayClick
onRequestClose={onClose}
className={props.className}
overlayClassName={props.overlayClassName}
>
<div className="flex w-full h-full flex-col ">
<div className="flex flex-col flex-grow items-center gap-3">
<Localized
id="settings-general-tracker_mechanics-drift_compensation_warning"
elems={{ b: <b></b> }}
>
<WarningBox>
<b>Warning:</b> Drift compensation should only be used if you find
you need to reset very often (~5-10 minutes).
<br />
Some IMUs prone to frequent resets include: Joy-Cons, owoTrack,
and MPUs (without recent firmware).
</WarningBox>
</Localized>

<div className="flex flex-row gap-3 pt-5 place-content-center">
<Button variant="primary" onClick={onClose}>
{l10n.getString(
'settings-general-tracker_mechanics-drift_compensation_warning-cancel'
)}
</Button>
<Button
variant="tertiary"
onClick={() => {
accept();
}}
>
{l10n.getString(
'settings-general-tracker_mechanics-drift_compensation_warning-done'
)}
</Button>
</div>
</div>
</div>
</BaseModal>
);
}
20 changes: 20 additions & 0 deletions gui/src/components/settings/pages/GeneralSettings.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ import {
SettingsPagePaneLayout,
} from '@/components/settings/SettingsPageLayout';
import { HandsWarningModal } from '@/components/settings/HandsWarningModal';
import { DriftCompensationModal } from '@/components/settings/DriftCompensationModal';

interface SettingsForm {
trackers: {
Expand Down Expand Up @@ -435,6 +436,8 @@ export function GeneralSettings() {
// }
// }, [state]);

const [showDriftCompWarning, setShowDriftCompWarning] = useState(false);

return (
<SettingsPageLayout>
<HandsWarningModal
Expand Down Expand Up @@ -697,7 +700,24 @@ export function GeneralSettings() {
label={l10n.getString(
'settings-general-tracker_mechanics-drift_compensation-enabled-label'
)}
onClick={() => {
if (getValues('driftCompensation.enabled')) {
return;
}

setShowDriftCompWarning(true);
}}
/>
<DriftCompensationModal
accept={() => {
setShowDriftCompWarning(false);
}}
onClose={() => {
setShowDriftCompWarning(false);
setValue('driftCompensation.enabled', false);
}}
isOpen={showDriftCompWarning}
></DriftCompensationModal>
<div className="flex gap-5 pt-5 md:flex-row flex-col">
<NumberSelector
control={control}
Expand Down

0 comments on commit ed34001

Please sign in to comment.