import { useState } from 'react'; import { DSP408 } from '../../../../types'; import { Channel, InputSource, InputType, DiscreteFrequency } from '../../types'; import { SidebarId } from '../../constants'; import Button from '../../../../components/Button/Button'; import Card from '../../../../components/Card/Card'; import ChoiceSelect from '../../../../components/ChoiceSelect/ChoiceSelect'; import LinkChannelsModal from './LinkChannelsModal'; import CopyChannelModal from './CopyChannelModal'; import './MiscellaneousSection.css'; import { EyeIcon, EyeOffIcon } from '../../../../assets/icons/EyesIcons'; const INPUT_TYPES: readonly InputType[] = Object.values(InputType); const DISCRETE_FREQUENCIES: readonly DiscreteFrequency[] = Object.values(DiscreteFrequency); function MiscellaneousPanel({ dsp, factoryReset, copyChannel, setInputSource, linkChannels, lockDevice, setActiveSidebar, }: { dsp: DSP408; factoryReset: (force: boolean) => Promise; copyChannel: (channel1: Channel, channel2: Channel) => Promise; setInputSource: (inputSource: InputSource) => Promise; linkChannels: (source: Channel, destinations: Channel[]) => Promise; lockDevice: (password: string) => Promise; setActiveSidebar: (id: SidebarId) => void; }) { const [isFactoryResetting, setIsFactoryResetting] = useState(false); const [isResetConfirmOpen, setIsResetConfirmOpen] = useState(false); const [isLinkModalOpen, setIsLinkModalOpen] = useState(false); const [isCopyModalOpen, setIsCopyModalOpen] = useState(false); const [inputSource, setInputSourceState] = useState({ type: InputType.Analog, frequency: DiscreteFrequency.F20, }); const [password, setPassword] = useState(''); const [isPasswordVisible, setIsPasswordVisible] = useState(false); const handleInputTypeChange = async (type: InputType) => { const nextSource: InputSource = { type, frequency: type === InputType.SineWave ? inputSource.frequency : DiscreteFrequency.F20, }; setInputSourceState(nextSource); await setInputSource(nextSource); }; const handleFrequencyChange = async (frequency: DiscreteFrequency) => { const nextSource: InputSource = { ...inputSource, frequency, }; setInputSourceState(nextSource); await setInputSource(nextSource); }; const handleFactoryReset = () => { setIsResetConfirmOpen(true); }; const confirmFactoryReset = async () => { setIsResetConfirmOpen(false); setIsFactoryResetting(true); try { await factoryReset(true); } finally { setIsFactoryResetting(false); } }; const handleLock = async () => { if (!password) { return; } const success = await lockDevice(password); if (success) { setPassword(''); setActiveSidebar('overview'); } }; return (
{/* Input Source */}

Input Source

Select the signal source used by the DSP.

id="misc-input-type" value={inputSource.type} options={INPUT_TYPES} onChange={handleInputTypeChange} style={{ color: 'var(--font-primary)' }} />
{inputSource.type === InputType.SineWave && (
id="misc-frequency" value={inputSource.frequency} options={DISCRETE_FREQUENCIES} formatLabel={(frequency) => { if (frequency === DiscreteFrequency.F31_5) { return '31.5 Hz'; } return `${frequency.slice(1)} Hz`; }} onChange={handleFrequencyChange} style={{ color: 'var(--font-primary)' }} />
)}
{/* Channel Tools */}

Channel Tools

Copy settings between channels or link multiple channels.

{/* Security */}

Device Security

Lock access to the DSP.

{ const value = e.target.value; if (/^[\x20-\x7E]*$/.test(value)) { setPassword(value); } }} />
{/* Factory Reset */}

Factory Reset

Restore the DSP to its factory configuration. This cannot be undone.

{isLinkModalOpen && ( setIsLinkModalOpen(false)} linkChannels={linkChannels} /> )} {isCopyModalOpen && ( setIsCopyModalOpen(false)} copyChannel={copyChannel} /> )} {isResetConfirmOpen && (
setIsResetConfirmOpen(false)}>
e.stopPropagation()}>

Factory Reset DSP?

This will restore the DSP to its factory configuration. This action cannot be undone.

)}
); } export default MiscellaneousPanel;