diff --git a/app/admin_panel/js/behaviour_tree.js b/app/admin_panel/js/behaviour_tree.js index bd2a4faf..7abd9f05 100644 --- a/app/admin_panel/js/behaviour_tree.js +++ b/app/admin_panel/js/behaviour_tree.js @@ -10,10 +10,16 @@ function startBehaviourTree(_event, _args) { websocket_server.startBehaviourTree(); } +function stopBehaviourTree(_event, _args) { + websocket_server.stopBehaviourTree() +} + ipcMain.handle('sendBehaviourTree', sendBehaviourTree); ipcMain.handle('startBehaviourTree', startBehaviourTree); +ipcMain.handle('stopBehaviourTree', stopBehaviourTree); module.exports = { sendBehaviourTree: sendBehaviourTree, startBehaviourTree: startBehaviourTree, + stopBehaviourTree: stopBehaviourTree, } \ No newline at end of file diff --git a/app/admin_panel/js/main.js b/app/admin_panel/js/main.js index 75a229b5..e5e5a7fe 100644 --- a/app/admin_panel/js/main.js +++ b/app/admin_panel/js/main.js @@ -80,7 +80,7 @@ const { websocket_server } = require('./websocket'); const { closeWebSocketServer } = require('./websocket_events'); const { selectRaspberryPi, unselectRaspberryPi, getRaspberryPiList, getSelectedRaspberryPi } = require('./raspberry_pi'); const { getLocalIPList } = require('./device'); -const { sendBehaviourTree, startBehaviourTree } = require('./behaviour_tree'); +const { sendBehaviourTree, startBehaviourTree, stopBehaviourTree } = require('./behaviour_tree'); function onClose() { closeWebSocketServer(); diff --git a/app/admin_panel/js/preload.js b/app/admin_panel/js/preload.js index 847807ed..7cc1e4be 100644 --- a/app/admin_panel/js/preload.js +++ b/app/admin_panel/js/preload.js @@ -21,6 +21,7 @@ const WINDOW_API = { sendBehaviourTree: (/** @type {any} */ args) => ipcRenderer.invoke("sendBehaviourTree", args), startBehaviourTree: () => ipcRenderer.invoke("startBehaviourTree"), + stopBehaviourTree: () => ipcRenderer.invoke("stopBehaviourTree"), } contextBridge.exposeInMainWorld("api", WINDOW_API) \ No newline at end of file diff --git a/app/admin_panel/js/websocket.js b/app/admin_panel/js/websocket.js index 85461736..3ee55406 100644 --- a/app/admin_panel/js/websocket.js +++ b/app/admin_panel/js/websocket.js @@ -185,6 +185,20 @@ class WebSocketServer { action: 'start', })); } + + stopBehaviourTree() { + if (this._wss === undefined) { + return; + } + if (this._selected_raspberry_pi === undefined) { + return; + } + this._selected_raspberry_pi.ws.send(JSON.stringify({ + type: 'command', + command: 'behaviour_tree', + action: 'stop', + })); + } } module.exports = { websocket_server: new WebSocketServer() }; \ No newline at end of file diff --git a/app/admin_panel/src/lib/CodeBox.svelte b/app/admin_panel/src/lib/CodeBox.svelte index 98ec07f7..c6f48a08 100644 --- a/app/admin_panel/src/lib/CodeBox.svelte +++ b/app/admin_panel/src/lib/CodeBox.svelte @@ -23,7 +23,7 @@ let start_behaviour_tree_text = "Start Behaviour Tree"; /** @type {string} */ - let start_behaviour_tree_color = "#89AAFF" + let start_behaviour_tree_color = "#89AAFF"; /** @type {boolean} */ let start_behaviour_tree_debounce = false; @@ -34,7 +34,9 @@ } send_behaviour_tree_debounce = true; try { - await api.sendBehaviourTree({ data: xmlFormat.minify($behaviour_tree_xml_code) }); + await api.sendBehaviourTree({ + data: xmlFormat.minify($behaviour_tree_xml_code), + }); send_behaviour_tree_text = "Sent Behaviour Tree!"; send_behaviour_tree_color = "#3457AA"; } catch (error) { @@ -67,10 +69,14 @@ start_behaviour_tree_debounce = false; }, 1000); } + + async function stopBehaviourTree() { + await api.stopBehaviourTree(); + }