Skip to content

Commit b6724bd

Browse files
authored
Add reboot autopilot to dashboard actions and spotlight (#854)
* Spotlight working on params page * useRebootCallback hook * Add reboot to dashboard actions * Hoist the reboot modal * lint and copilot * use const for reboot callback * Extract useRebootCallback into helper * linting * copilot * Copilot recommended formatting
1 parent 3e33929 commit b6724bd

6 files changed

Lines changed: 48 additions & 10 deletions

File tree

gcs/src/components/dashboard/tabsSectionTabs/actionTabsSection.jsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,11 @@ import { useEffect, useMemo, useState } from "react"
1010
import { Button, NumberInput, Popover, Select, Tabs } from "@mantine/core"
1111
import { useLocalStorage } from "@mantine/hooks"
1212

13+
// Styling imports
14+
import resolveConfig from "tailwindcss/resolveConfig"
15+
import tailwindConfig from "../../../../tailwind.config"
16+
const tailwindColors = resolveConfig(tailwindConfig).theme.colors
17+
1318
// Mavlink
1419
import { getFlightModeMap } from "../../../helpers/mavlinkConstants"
1520

@@ -27,6 +32,7 @@ import {
2732
} from "../../../redux/slices/droneInfoSlice"
2833

2934
import { NoConnectionMsg } from "../tabsSection"
35+
import { useRebootCallback } from "../../../helpers/useRebootCallback"
3036

3137
export default function ActionTabsSection({
3238
connected,
@@ -113,6 +119,7 @@ const ArmTakeoffLandAction = () => {
113119
defaultValue: 10,
114120
})
115121
const isArmed = useSelector(selectArmed)
122+
const rebootCallback = useRebootCallback()
116123

117124
function armDisarm(arm, force = false) {
118125
// TODO: Add force arm ability
@@ -165,6 +172,15 @@ const ArmTakeoffLandAction = () => {
165172
>
166173
Land
167174
</Button>
175+
176+
{/** Reboot Button */}
177+
<Button
178+
onClick={rebootCallback}
179+
color={tailwindColors.red[600]}
180+
className="grow"
181+
>
182+
Reboot FC
183+
</Button>
168184
</div>
169185
</>
170186
)

gcs/src/components/mainContent.jsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import { Route, Routes } from "react-router-dom"
88
import SettingsModal from "./settingsModal"
99
import { Commands } from "./spotlight/commandHandler"
1010
import Toolbar from "./toolbar/toolbar"
11+
import AutopilotRebootModal from "./params/autopilotRebootModal.jsx"
1112

1213
// Wrappers
1314
import { SettingsProvider } from "../helpers/settingsProvider"
@@ -59,6 +60,7 @@ export default function AppContent() {
5960
<Route path="/fla" element={<FLA />} />
6061
</Routes>
6162
<Commands />
63+
<AutopilotRebootModal />
6264
</ErrorBoundary>
6365
</SingleRunWrapper>
6466
</SettingsProvider>

gcs/src/components/spotlight/actions.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -135,3 +135,6 @@ AddSpotlightAction(
135135
RunCommand("new_preflight_checklist")
136136
},
137137
)
138+
AddSpotlightAction("reboot_autopilot", "Reboot Autopilot", "command", () => {
139+
RunCommand("reboot_autopilot")
140+
})

gcs/src/components/spotlight/commandHandler.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,14 @@ import { useHotkeys } from "@mantine/hooks"
88
import { useEffect, useState } from "react"
99
import { useNavigate } from "react-router"
1010
import { useSettings } from "../../helpers/settings"
11+
import { useRebootCallback } from "../../helpers/useRebootCallback"
1112

1213
let commands = []
1314

1415
export function Commands() {
1516
let navigate = useNavigate()
1617
const [isMac, setIsMac] = useState(false)
18+
const rebootCallback = useRebootCallback()
1719

1820
useEffect(() => {
1921
window.ipcRenderer.invoke("app:is-mac").then((result) => {
@@ -49,6 +51,7 @@ export function Commands() {
4951
AddCommand("open_settings", () => {
5052
open()
5153
})
54+
AddCommand("reboot_autopilot", rebootCallback)
5255

5356
// Register hotkeys
5457
useHotkeys([
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
import { useCallback } from "react"
2+
import { useDispatch } from "react-redux"
3+
4+
import {
5+
emitRebootAutopilot,
6+
setAutoPilotRebootModalOpen,
7+
resetParamState,
8+
} from "../redux/slices/paramsSlice.js"
9+
10+
/**
11+
* Hook that returns a callback to reboot the autopilot.
12+
* Initiates autopilot reboot, displays status modal, and resets params.
13+
* @returns Callback to reboot autopilot
14+
*/
15+
export function useRebootCallback() {
16+
const dispatch = useDispatch()
17+
return useCallback(() => {
18+
dispatch(emitRebootAutopilot())
19+
dispatch(setAutoPilotRebootModalOpen(true))
20+
dispatch(resetParamState())
21+
}, [dispatch])
22+
}

gcs/src/params.jsx

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,9 @@ const tailwindColors = resolveConfig(tailwindConfig).theme.colors
2222
// Custom components, helpers, and data
2323
import Layout from "./components/layout.jsx"
2424
import NoDroneConnected from "./components/noDroneConnected.jsx"
25-
import AutopilotRebootModal from "./components/params/autopilotRebootModal.jsx"
2625
import ParamsToolbar from "./components/params/paramsToolbar.jsx"
2726
import { Row } from "./components/params/row.jsx"
27+
import { useRebootCallback } from "./helpers/useRebootCallback.js"
2828

2929
// Redux
3030
import { useDispatch, useSelector } from "react-redux"
@@ -36,7 +36,6 @@ import { showErrorNotification } from "./helpers/notification.js"
3636
import { selectConnectedToDrone } from "./redux/slices/droneConnectionSlice.js"
3737
import {
3838
emitExportParamsToFile,
39-
emitRebootAutopilot,
4039
emitRefreshParams,
4140
emitSetMultipleParams,
4241
resetParamState,
@@ -48,7 +47,6 @@ import {
4847
selectParamSearchValue,
4948
selectShowModifiedParams,
5049
selectShownParams,
51-
setAutoPilotRebootModalOpen,
5250
setFetchingVars,
5351
setHasFetchedOnce,
5452
setLoadedFileName,
@@ -72,6 +70,7 @@ function cleanFloat(value, decimals = 5) {
7270
export default function Params() {
7371
const dispatch = useDispatch()
7472
const connected = useSelector(selectConnectedToDrone)
73+
const rebootCallback = useRebootCallback()
7574

7675
// Parameter states
7776
const hasFetchedOnce = useSelector(selectHasFetchedOnce)
@@ -127,12 +126,6 @@ export default function Params() {
127126
dispatch(setFetchingVars(true))
128127
}
129128

130-
function rebootCallback() {
131-
dispatch(emitRebootAutopilot())
132-
dispatch(setAutoPilotRebootModalOpen(true))
133-
dispatch(resetParamState())
134-
}
135-
136129
async function saveParamsToFile() {
137130
const options = {
138131
title: "Save parameters to a file",
@@ -210,7 +203,6 @@ export default function Params() {
210203

211204
return (
212205
<Layout currentPage="params">
213-
<AutopilotRebootModal />
214206
<LoadParamsFileModal />
215207
<ParamsWriteModal />
216208
<ParamsFailedToWriteModal />

0 commit comments

Comments
 (0)