Skip to content

Commit

Permalink
Send inputs from main process to Runtime
Browse files Browse the repository at this point in the history
  • Loading branch information
Hal-9k1 committed Oct 18, 2024
1 parent 74128b1 commit b536c45
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 17 deletions.
9 changes: 2 additions & 7 deletions src/main/MainApp.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Check failure on line 212 in src/main/MainApp.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Replace `'main-update-robot-mode',·this.#runtimeComms.sendRunMode.bind(this.#runtimeComms)` with `⏎······'main-update-robot-mode',⏎······this.#runtimeComms.sendRunMode.bind(this.#runtimeComms),⏎····`
addRendererListener('main-robot-input', this.#runtimeComms.sendInputs.bind(this.#runtimeComms));

Check failure on line 213 in src/main/MainApp.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Replace `'main-robot-input',·this.#runtimeComms.sendInputs.bind(this.#runtimeComms)` with `⏎······'main-robot-input',⏎······this.#runtimeComms.sendInputs.bind(this.#runtimeComms),⏎····`

try {
this.#config = coerceToConfig(
Expand Down
15 changes: 5 additions & 10 deletions src/main/network/RuntimeComms.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 }));
}
}

Expand Down Expand Up @@ -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 : [
Expand All @@ -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(

Check failure on line 224 in src/main/network/RuntimeComms.ts

View workflow job for this annotation

GitHub Actions / test (ubuntu-latest)

Replace `⏎········this.#createPacket(MsgType.INPUTS,·{·inputs·}),⏎······` with `this.#createPacket(MsgType.INPUTS,·{·inputs·})`
this.#createPacket(MsgType.INPUTS, {
inputs: inputs.length
? inputs
: [protos.Input.create({ connected: false, source })],
}),
this.#createPacket(MsgType.INPUTS, { inputs }),
);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/renderer/App.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit b536c45

Please sign in to comment.