Skip to content

Commit

Permalink
Allow to pause/resume auto macro
Browse files Browse the repository at this point in the history
  • Loading branch information
albireox committed Jan 12, 2023
1 parent 3188cd7 commit 326e9d6
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 7 deletions.
6 changes: 5 additions & 1 deletion src/renderer/HAL/Auto.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
* @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause)
*/

import { Paper, Stack, TextField, Typography } from '@mui/material';
import { Collapse, Paper, Stack, TextField, Typography } from '@mui/material';
import React from 'react';
import IOSSwitch from 'renderer/Components/IOSwitch';
import { useKeywordContext } from 'renderer/hooks';
import PauseResumeButton from './Components/PauseResumeButton';
import useIsMacroRunning from './useIsMacroRunning';

function parseStageStatus(stageData: string[]) {
Expand Down Expand Up @@ -132,6 +133,9 @@ export default function AutoMode() {
'& .MuiInputBase-root': { marginTop: 1 },
}}
/>
<Collapse orientation='horizontal' in={isRunning}>
<PauseResumeButton macro='auto' />
</Collapse>
<IOSSwitch
checked={isRunning}
onChange={handleSwitch}
Expand Down
50 changes: 50 additions & 0 deletions src/renderer/HAL/Components/PauseResumeButton.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*
* @Author: José Sánchez-Gallego (gallegoj@uw.edu)
* @Date: 2023-01-12
* @Filename: PauseResumeButton.tsx
* @License: BSD 3-clause (http://www.opensource.org/licenses/BSD-3-Clause)
*/

import PauseIcon from '@mui/icons-material/Pause';
import PlayArrowIcon from '@mui/icons-material/PlayArrow';
import { IconButton, Tooltip } from '@mui/material';
import React from 'react';
import { useKeywordContext } from 'renderer/hooks';

interface PauseResumeButtonProps {
macro: string;
}

export default function PauseResumeButton(props: PauseResumeButtonProps) {
const { macro } = props;

const keywords = useKeywordContext();
const { 'hal.expose_is_paused': isPausedKw } = keywords;

const [isPaused, setIsPaused] = React.useState(false);

React.useEffect(() => {
setIsPaused(isPausedKw?.values[0] ?? false);
}, [isPausedKw]);

const handleClick = React.useCallback(() => {
if (isPaused) {
window.electron.tron.send(`hal ${macro} --resume`);
} else {
window.electron.tron.send(`hal ${macro} --pause`);
}
}, [macro, isPaused]);

return (
<Tooltip title={isPaused ? 'Resume macro' : 'Pause macro'}>
<IconButton
onClick={handleClick}
disableFocusRipple
disableTouchRipple
disableRipple
>
{isPaused ? <PlayArrowIcon /> : <PauseIcon />}
</IconButton>
</Tooltip>
);
}
22 changes: 16 additions & 6 deletions src/renderer/HAL/Expose.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import SendIcon from '@mui/icons-material/Send';
import {
Box,
Checkbox,
Collapse,
Divider,
FormControlLabel,
Grid,
Expand All @@ -29,6 +30,7 @@ import { ExposureTimeInput } from './Components/ExposureTimeInput';
import MacroPaper from './Components/MacroPaper';
import { MacroStageSelect } from './Components/MacroStageSelect';
import MacroStepper from './Components/MacroStepper';
import PauseResumeButton from './Components/PauseResumeButton';
import macros from './macros.json';
import useIsMacroRunning from './useIsMacroRunning';

Expand All @@ -48,6 +50,8 @@ function LinearProgressWithLabel(props: LinearProgressWithLabelProps) {

React.useEffect(() => {
let interval: NodeJS.Timer | undefined;
const { etr: propsETR } = props;
if (propsETR) setEtrDisplay(propsETR);
if (running) {
interval = setInterval(
() => setEtrDisplay((etrD) => (etrD - 1 <= 0 ? 0 : etrD - 1)),
Expand All @@ -56,7 +60,7 @@ function LinearProgressWithLabel(props: LinearProgressWithLabelProps) {
}

return () => clearInterval(interval);
}, [running]);
}, [running, props]);

React.useEffect(() => {
setEtrDisplay(!etr || etr <= 0 ? 0 : etr);
Expand Down Expand Up @@ -97,7 +101,7 @@ function LinearProgressWithLabel(props: LinearProgressWithLabelProps) {
export default function Expose() {
const macroName = 'expose';

const isLarge = useMediaQuery('(min-width: 630px)');
const isLarge = useMediaQuery('(min-width: 680px)');

const [apogeeReads, setApogeeReads] = React.useState<string>(
macros.expose.defaults.apogee_reads.toString()
Expand Down Expand Up @@ -131,6 +135,9 @@ export default function Expose() {
const { stages: stagesKw } = halKeywords;
const { running_macros: runningMacrosKw } = halKeywords;

const { 'hal.expose_is_paused': pausedKw } = halKeywords;
const isPaused = pausedKw?.values[0] ?? false;

const getCommandString = React.useCallback(
(modify = false) => {
const commandString: string[] = ['hal expose'];
Expand Down Expand Up @@ -262,7 +269,7 @@ export default function Expose() {

setBossProgress(
<LinearProgressWithLabel
running={bossCurrent > 0 && isRunning}
running={bossCurrent > 0 && isRunning && !isPaused}
total={bossTotal}
etr={bossEtr}
header='BOSS'
Expand All @@ -274,7 +281,7 @@ export default function Expose() {
}

setBossProgress(<span />);
}, [actorStages, bossStateKw, isRunning]);
}, [actorStages, bossStateKw, isRunning, isPaused]);

React.useEffect(() => {
// Create and update the APOGEE progress bar.
Expand All @@ -290,7 +297,7 @@ export default function Expose() {

setApogeeProgress(
<LinearProgressWithLabel
running={apogeeCurrent > 0 && isRunning}
running={apogeeCurrent > 0 && isRunning && !isPaused}
total={apogeeTotal}
etr={apogeeEtr}
header='APOGEE'
Expand All @@ -303,7 +310,7 @@ export default function Expose() {
}

setApogeeProgress(<span />);
}, [actorStages, apogeeStateKw, isRunning]);
}, [actorStages, apogeeStateKw, isRunning, isPaused]);

return (
<MacroPaper>
Expand Down Expand Up @@ -399,6 +406,9 @@ export default function Expose() {
/>
</Stack>
<Box flexGrow={1} />
<Collapse orientation='horizontal' in={isRunning}>
<PauseResumeButton macro='expose' />
</Collapse>
<CommandWrapper
commandString={getCommandString()}
abortCommand='hal expose --stop'
Expand Down
1 change: 1 addition & 0 deletions src/renderer/HAL/HAL.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ export default function HAL() {
'hal.available_scripts',
'hal.exposure_state_apogee',
'hal.exposure_state_boss',
'hal.expose_is_paused',
'hal.auto_mode_message',
'jaeger.configuration_loaded',
'jaeger.design_preloaded',
Expand Down

0 comments on commit 326e9d6

Please sign in to comment.