Skip to content
Merged
18 changes: 18 additions & 0 deletions gcs/src/components/dashboard/tabsSectionTabs/actionTabsSection.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ import { useEffect, useMemo, useState } from "react"
import { Button, NumberInput, Popover, Select, Tabs } from "@mantine/core"
import { useLocalStorage } from "@mantine/hooks"

// Styling imports
import resolveConfig from "tailwindcss/resolveConfig"
import tailwindConfig from "../../../../tailwind.config"
const tailwindColors = resolveConfig(tailwindConfig).theme.colors
Comment thread
Turnlings marked this conversation as resolved.

// Mavlink
import { getFlightModeMap } from "../../../helpers/mavlinkConstants"

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

import { NoConnectionMsg } from "../tabsSection"
import { useRebootCallback } from "../../../params"

export default function ActionTabsSection({
connected,
Expand Down Expand Up @@ -113,6 +119,7 @@ const ArmTakeoffLandAction = () => {
defaultValue: 10,
})
const isArmed = useSelector(selectArmed)
const rebootCallback = useRebootCallback()

function armDisarm(arm, force = false) {
// TODO: Add force arm ability
Expand Down Expand Up @@ -165,6 +172,17 @@ const ArmTakeoffLandAction = () => {
>
Land
</Button>

{/** Reboot Button */}
<Button
onClick={() => {
rebootCallback()
}}
Comment thread
Turnlings marked this conversation as resolved.
Outdated
color={tailwindColors.red[600]}
className="grow"
>
Reboot FC
</Button>
Comment thread
Turnlings marked this conversation as resolved.
</div>
</>
)
Expand Down
2 changes: 2 additions & 0 deletions gcs/src/components/mainContent.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import { Route, Routes } from "react-router-dom"
import SettingsModal from "./settingsModal"
import { Commands } from "./spotlight/commandHandler"
import Toolbar from "./toolbar/toolbar"
import AutopilotRebootModal from "./params/autopilotRebootModal.jsx"

// Wrappers
import { SettingsProvider } from "../helpers/settingsProvider"
Expand Down Expand Up @@ -59,6 +60,7 @@ export default function AppContent() {
<Route path="/fla" element={<FLA />} />
</Routes>
<Commands />
<AutopilotRebootModal />
</ErrorBoundary>
</SingleRunWrapper>
</SettingsProvider>
Expand Down
3 changes: 3 additions & 0 deletions gcs/src/components/spotlight/actions.js
Original file line number Diff line number Diff line change
Expand Up @@ -135,3 +135,6 @@ AddSpotlightAction(
RunCommand("new_preflight_checklist")
},
)
AddSpotlightAction("reboot_autopilot", "Reboot Autopilot", "command", () => {
RunCommand("reboot_autopilot")
})
5 changes: 5 additions & 0 deletions gcs/src/components/spotlight/commandHandler.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import { useHotkeys } from "@mantine/hooks"
import { useEffect, useState } from "react"
import { useNavigate } from "react-router"
import { useSettings } from "../../helpers/settings"
import { useRebootCallback } from "../../params"

let commands = []

export function Commands() {
let navigate = useNavigate()
const [isMac, setIsMac] = useState(false)
const rebootCallback = useRebootCallback()

useEffect(() => {
window.ipcRenderer.invoke("app:is-mac").then((result) => {
Expand Down Expand Up @@ -49,6 +51,9 @@ export function Commands() {
AddCommand("open_settings", () => {
open()
})
AddCommand("reboot_autopilot", () => {
rebootCallback()
})

// Register hotkeys
useHotkeys([
Expand Down
18 changes: 10 additions & 8 deletions gcs/src/params.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,6 @@
// Custom components, helpers, and data
import Layout from "./components/layout.jsx"
import NoDroneConnected from "./components/noDroneConnected.jsx"
import AutopilotRebootModal from "./components/params/autopilotRebootModal.jsx"
import ParamsToolbar from "./components/params/paramsToolbar.jsx"
import { Row } from "./components/params/row.jsx"

Expand Down Expand Up @@ -67,9 +66,19 @@
return value
}

Comment thread
Turnlings marked this conversation as resolved.
export function useRebootCallback() {

Check warning on line 69 in gcs/src/params.jsx

View workflow job for this annotation

GitHub Actions / Run linters

Fast refresh only works when a file only exports components. Use a new file to share constants or functions between components
const dispatch = useDispatch()
return () => {
dispatch(emitRebootAutopilot())
dispatch(setAutoPilotRebootModalOpen(true))
dispatch(resetParamState())
}
}
Comment thread
Turnlings marked this conversation as resolved.
Outdated

export default function Params() {
const dispatch = useDispatch()
const connected = useSelector(selectConnectedToDrone)
const rebootCallback = useRebootCallback()

// Parameter states
const hasFetchedOnce = useSelector(selectHasFetchedOnce)
Expand Down Expand Up @@ -125,12 +134,6 @@
dispatch(setFetchingVars(true))
}

function rebootCallback() {
dispatch(emitRebootAutopilot())
dispatch(setAutoPilotRebootModalOpen(true))
dispatch(resetParamState())
}

async function saveParamsToFile() {
const options = {
title: "Save parameters to a file",
Expand Down Expand Up @@ -208,7 +211,6 @@

return (
<Layout currentPage="params">
<AutopilotRebootModal />
<LoadParamsFileModal />

{connected ? (
Expand Down
Loading