From 7beaff208e7b56d7232253ce1f6ce6bcbd6805ab Mon Sep 17 00:00:00 2001 From: Victoria Lee Date: Wed, 23 Oct 2024 21:21:13 -0700 Subject: [PATCH] Test with staff bot and bugfix --- src/main/MainApp.ts | 14 ++++++------- src/main/network/PacketStream.ts | 2 +- src/main/network/RuntimeComms.ts | 6 +++--- src/renderer/App.tsx | 34 +++++++++++++++++--------------- src/renderer/Editor.tsx | 8 +++++--- 5 files changed, 34 insertions(+), 30 deletions(-) diff --git a/src/main/MainApp.ts b/src/main/MainApp.ts index f3fa907..401987c 100644 --- a/src/main/MainApp.ts +++ b/src/main/MainApp.ts @@ -39,10 +39,6 @@ const CODE_FILE_FILTERS: FileFilter[] = [ * Relative path to persistent configuration file. */ const CONFIG_RELPATH = 'dawn-config.json'; -/** - * Path on robot to upload student code to. - */ -const REMOTE_CODE_PATH = '/home/pi/runtime/executor/studentcode.py'; /** * Port to use when connecting to robot with SSH. */ @@ -50,11 +46,15 @@ const ROBOT_SSH_PORT = 22; /** * Username to log in as when connecting to robot with SSH. */ -const ROBOT_SSH_USER = 'pi'; +const ROBOT_SSH_USER = 'ubuntu'; /** * Password to log in with when connecting to robot with SSH. */ -const ROBOT_SSH_PASS = 'raspberry'; +const ROBOT_SSH_PASS = 'potato'; +/** + * Path on robot to upload student code to. + */ +const REMOTE_CODE_PATH = `/home/${ROBOT_SSH_USER}/runtime/executor/studentcode.py`; /** * Adds a listener for the main-quit IPC event fired by the renderer. @@ -393,7 +393,7 @@ export default class MainApp implements MenuHandler, RuntimeCommsListener { } /** - * Tries to load code from a file into the editor. Fails is the user does not choose a path. + * Tries to load code from a file into the editor. Fails if the user does not choose a path. */ #openCodeFile() { const success = this.#showCodePathDialog('load'); diff --git a/src/main/network/PacketStream.ts b/src/main/network/PacketStream.ts index 29c3653..d8e8429 100644 --- a/src/main/network/PacketStream.ts +++ b/src/main/network/PacketStream.ts @@ -62,7 +62,7 @@ export default class PacketStream extends Transform { while (this.#tryReadPacket(shouldConcatHeader)) { shouldConcatHeader = false; } - callback(null, chunk); + callback(); } /** diff --git a/src/main/network/RuntimeComms.ts b/src/main/network/RuntimeComms.ts index a8519d9..571dda2 100644 --- a/src/main/network/RuntimeComms.ts +++ b/src/main/network/RuntimeComms.ts @@ -322,9 +322,9 @@ export default class RuntimeComms { const { type, data } = packet; switch (type) { case MsgType.LOG: - // this.#commsListener.onReceiveRobotLogs( - // protos.Text.decode(data).payload, - // ); + this.#commsListener.onReceiveRobotLogs( + protos.Text.decode(data).payload, + ); break; case MsgType.TIME_STAMPS: this.#commsListener.onReceiveLatency( diff --git a/src/renderer/App.tsx b/src/renderer/App.tsx index 95f3e7f..58f57e8 100644 --- a/src/renderer/App.tsx +++ b/src/renderer/App.tsx @@ -8,7 +8,7 @@ import { useLayoutEffect, } from 'react'; import Topbar from './Topbar'; -import Editor, { EditorContentStatus } from './Editor'; +import Editor, { EditorContentStatus, KeyboardControlsStatus } from './Editor'; import DeviceInfo from './DeviceInfo'; import AppConsole from './AppConsole'; import type AppConsoleMessage from '../common/AppConsoleMessage'; // No crypto package on the renderer @@ -73,8 +73,8 @@ export default function App() { // Whether a new message has been added to the AppConsole since it has been closed (if it is // closed) const [consoleIsAlerted, setConsoleIsAlerted] = useState(false); - // Whether keyboard controls are enabled - const [keyboardControlsEnabled, setKeyboardControlsEnabled] = useState(false); + // Whether keyboard controls are enabled. + const [keyboardControlsEnabled, setKeyboardControlsEnabled] = useState('on' as KeyboardControlsStatus); // Whether the robot is running student code const [robotRunning, setRobotRunning] = useState(false); // Most recent window.innerWidth/Height needed to clamp editor and col size @@ -268,7 +268,7 @@ export default function App() { // Possible bug requires testing: gamepad indices are not preserved after filtering // Filter removes disconnected and 'ghost'/duplicate gamepads (can be distinguished by // different mapping) - const gamepadInputs = navigator + const inputs = navigator .getGamepads() .filter((gp): gp is Gamepad => gp !== null && gp.mapping === 'standard') .map((gp) => { @@ -285,17 +285,19 @@ export default function App() { source: RobotInputSource.GAMEPAD, }); }); - const keyboardInput = new RobotInput({ - connected: keyboardControlsEnabled, - axes: [], - buttons: keyboardControlsEnabled ? Number(keyboardBitmap) : 0, - 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, - ]); + if (keyboardControlsEnabled != 'off') { + // Possible bug requires testing: is Runtime ok with mixed input sources in same packet? + inputs.push(new RobotInput({ + connected: keyboardControlsEnabled == 'on', + axes: [], + buttons: keyboardControlsEnabled ? Number(keyboardBitmap) : 0, + source: RobotInputSource.KEYBOARD, + })); + if (keyboardControlsEnabled == 'offEdge') { + setKeyboardControlsEnabled('off'); + } + } + window.electron.ipcRenderer.sendMessage('main-robot-input', inputs); }, GAMEPAD_UPDATE_PERIOD_MS); return () => { clearInterval(gamepadUpdateInterval); @@ -441,7 +443,7 @@ export default function App() { setConsoleIsAlerted(false); }} onToggleKeyboardControls={() => { - setKeyboardControlsEnabled((v) => !v); + setKeyboardControlsEnabled((v) => v == 'on' ? 'offEdge' : 'on'); }} /> void; @@ -133,7 +135,7 @@ export default function Editor({ return (
@@ -270,7 +272,7 @@ export default function Editor({ mode="python" onChange={onChange} value={content} - readOnly={keyboardControlsEnabled} + readOnly={keyboardControlsEnabled == 'on'} />