From b536c456cec557152c90a3c236fb6b1e73106457 Mon Sep 17 00:00:00 2001 From: Eddy Meals Date: Fri, 18 Oct 2024 00:20:59 -0700 Subject: [PATCH] Send inputs from main process to Runtime --- src/main/MainApp.ts | 9 ++------- src/main/network/RuntimeComms.ts | 15 +++++---------- src/renderer/App.tsx | 1 + 3 files changed, 8 insertions(+), 17 deletions(-) diff --git a/src/main/MainApp.ts b/src/main/MainApp.ts index 98c2bed..1ae9b93 100644 --- a/src/main/MainApp.ts +++ b/src/main/MainApp.ts @@ -209,13 +209,8 @@ export default class MainApp implements MenuHandler, RuntimeCommsListener { this.#preventQuit = false; this.#mainWindow.close(); }); - addRendererListener('main-update-robot-mode', (mode) => { - this.#runtimeComms.sendRunMode({ mode }); - }); - // eslint-disable-next-line no-unused - addRendererListener('main-robot-input', (inputs) => { - // TODO: send inputs to robot - }); + addRendererListener('main-update-robot-mode', this.#runtimeComms.sendRunMode.bind(this.#runtimeComms)); + addRendererListener('main-robot-input', this.#runtimeComms.sendInputs.bind(this.#runtimeComms)); try { this.#config = coerceToConfig( diff --git a/src/main/network/RuntimeComms.ts b/src/main/network/RuntimeComms.ts index 48ec7e2..63d5af8 100644 --- a/src/main/network/RuntimeComms.ts +++ b/src/main/network/RuntimeComms.ts @@ -167,11 +167,11 @@ export default class RuntimeComms { /** * Sends a new run mode. - * @param runMode - the new run mode. + * @param mode - the new run mode. */ - sendRunMode(runMode: protos.IRunMode) { + sendRunMode(mode: protos.Mode) { if (this.#tcpSock) { - this.#tcpSock.write(this.#createPacket(MsgType.RUN_MODE, runMode)); + this.#tcpSock.write(this.#createPacket(MsgType.RUN_MODE, { mode })); } } @@ -210,9 +210,8 @@ export default class RuntimeComms { /** * Sends control inputs to the robot. * @param inputs - the inputs to send. - * @param source - the device that is the source of the inputs. */ - sendInputs(inputs: protos.Input[], source: protos.Source) { + sendInputs(inputs: protos.Input[]) { // if (this.#udpSock) { // this.udpSock.send(protos.UserInputs.encode({ // inputs: inputs.length ? inputs : [ @@ -223,11 +222,7 @@ export default class RuntimeComms { // Old Dawn sends inputs through TCP, though comments say this is just for 2021? if (this.#tcpSock) { this.#tcpSock.write( - this.#createPacket(MsgType.INPUTS, { - inputs: inputs.length - ? inputs - : [protos.Input.create({ connected: false, source })], - }), + this.#createPacket(MsgType.INPUTS, { inputs }), ); } } diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 67adbc5..9ee5290 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -298,6 +298,7 @@ export default function App() { source: RobotInputSource.KEYBOARD, }), }; + // Possible bug requires testing: is Runtime ok with mixed input sources in same packet? window.electron.ipcRenderer.sendMessage('main-robot-input', [ ...gamepadInputs, keyboardInput,