@@ -11,7 +11,8 @@ import { ResizableBox } from "react-resizable"
1111import { v4 as uuidv4 } from "uuid"
1212
1313// Custom component and helpers
14- import { Button , Divider , FileButton , Tabs } from "@mantine/core"
14+ import { Button , Divider , FileButton , Tabs , Tooltip } from "@mantine/core"
15+ import { IconInfoCircle } from "@tabler/icons-react"
1516import Layout from "./components/layout"
1617import MissionItemsTable from "./components/missions/missionItemsTable"
1718import MissionsMapSection from "./components/missions/missionsMap"
@@ -403,6 +404,53 @@ export default function Missions() {
403404 }
404405 }
405406
407+ function updateMissionHomePosition ( lat , lon ) {
408+ const newHomePosition = {
409+ lat : Number . isInteger ( lat ) ? lat : coordToInt ( lat ) ,
410+ lon : Number . isInteger ( lon ) ? lon : coordToInt ( lon ) ,
411+ alt : 0.1 ,
412+ }
413+ setHomePosition ( newHomePosition )
414+
415+ // Also update the first waypoint if it is a home position waypoint
416+ if ( missionItems . length > 0 && isGlobalFrameHomeCommand ( missionItems [ 0 ] ) ) {
417+ // Check if the first item is a home position command
418+ const updatedMissionItems = [ ...missionItems ]
419+ updatedMissionItems [ 0 ] = {
420+ ...updatedMissionItems [ 0 ] ,
421+ x : newHomePosition . lat ,
422+ y : newHomePosition . lon ,
423+ }
424+ setMissionItems ( updatedMissionItems )
425+ } else {
426+ // If the first item is not a home position command, add a new home position item
427+ const newHomeMissionItem = {
428+ id : uuidv4 ( ) ,
429+ seq : 0 ,
430+ x : newHomePosition . lat ,
431+ y : newHomePosition . lon ,
432+ z : 0.1 ,
433+ frame : parseInt (
434+ Object . keys ( MAV_FRAME_LIST ) . find (
435+ ( key ) => MAV_FRAME_LIST [ key ] === "MAV_FRAME_GLOBAL" ,
436+ ) ,
437+ ) ,
438+ command : 16 , // MAV_CMD_NAV_WAYPOINT
439+ param1 : 0 ,
440+ param2 : 0 ,
441+ param3 : 0 ,
442+ param4 : 0 ,
443+ current : 0 ,
444+ autocontinue : 1 ,
445+ target_component : targetInfo . target_component ,
446+ target_system : targetInfo . target_system ,
447+ mission_type : 0 ,
448+ mavpackettype : "MISSION_ITEM_INT" ,
449+ }
450+ setMissionItems ( ( prevItems ) => [ newHomeMissionItem , ...prevItems ] )
451+ }
452+ }
453+
406454 return (
407455 < Layout currentPage = "missions" >
408456 { /* Banner to let people know that things are still under development */ }
@@ -472,7 +520,17 @@ export default function Missions() {
472520 < Divider className = "my-1" />
473521
474522 < div className = "flex flex-col gap-2" >
475- < p className = "font-bold" > Home location</ p >
523+ < p className = "font-bold" >
524+ Home location{ " " }
525+ < span >
526+ < Tooltip
527+ className = "inline"
528+ label = "The home location is written to a mission save file."
529+ >
530+ < IconInfoCircle size = { 20 } />
531+ </ Tooltip >
532+ </ span >
533+ </ p >
476534 < p >
477535 Lat:{ " " }
478536 { intToCoord ( homePosition ?. lat ) . toFixed (
@@ -509,6 +567,7 @@ export default function Missions() {
509567 markerDragEndCallback = { updateMissionItem }
510568 rallyDragEndCallback = { updateRallyItem }
511569 addNewMissionItem = { addNewMissionItem }
570+ updateMissionHomePosition = { updateMissionHomePosition }
512571 mapId = "missions"
513572 />
514573 </ div >
0 commit comments