Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 16 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 "../../../helpers/useRebootCallback"

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,15 @@ const ArmTakeoffLandAction = () => {
>
Land
</Button>

{/** Reboot Button */}
<Button
onClick={rebootCallback}
color={tailwindColors.red[600]}
className="grow"
>
Reboot FC
</Button>
</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")
})
3 changes: 3 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 "../../helpers/useRebootCallback"

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,7 @@ export function Commands() {
AddCommand("open_settings", () => {
open()
})
AddCommand("reboot_autopilot", rebootCallback)

// Register hotkeys
useHotkeys([
Expand Down
22 changes: 22 additions & 0 deletions gcs/src/helpers/useRebootCallback.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import { useCallback } from "react"
import { useDispatch } from "react-redux"

import {
emitRebootAutopilot,
setAutoPilotRebootModalOpen,
resetParamState,
} from "../redux/slices/paramsSlice.js"

/**
* Hook that returns a callback to reboot the autopilot.
* Initiates autopilot reboot, displays status modal, and resets params.
* @returns Callback to reboot autopilot
*/
export function useRebootCallback() {
const dispatch = useDispatch()
return useCallback(() => {
dispatch(emitRebootAutopilot())
dispatch(setAutoPilotRebootModalOpen(true))
dispatch(resetParamState())
Comment thread
Turnlings marked this conversation as resolved.
}, [dispatch])
}
12 changes: 2 additions & 10 deletions gcs/src/params.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -22,9 +22,9 @@ const tailwindColors = resolveConfig(tailwindConfig).theme.colors
// 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"
import { useRebootCallback } from "./helpers/useRebootCallback.js"

// Redux
import { useDispatch, useSelector } from "react-redux"
Expand All @@ -34,7 +34,6 @@ import { showErrorNotification } from "./helpers/notification.js"
import { selectConnectedToDrone } from "./redux/slices/droneConnectionSlice.js"
import {
emitExportParamsToFile,
emitRebootAutopilot,
emitRefreshParams,
emitSetMultipleParams,
resetParamState,
Expand All @@ -46,7 +45,6 @@ import {
selectParamSearchValue,
selectShowModifiedParams,
selectShownParams,
setAutoPilotRebootModalOpen,
setFetchingVars,
setHasFetchedOnce,
setLoadedFileName,
Expand All @@ -70,6 +68,7 @@ function cleanFloat(value, decimals = 5) {
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 +124,6 @@ export default function Params() {
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 +201,6 @@ export default function Params() {

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

{connected ? (
Expand Down
Loading