diff --git a/src/actions/hub.ts b/src/actions/hub.ts index 816b2b36..75429215 100644 --- a/src/actions/hub.ts +++ b/src/actions/hub.ts @@ -78,6 +78,13 @@ export function downloadAndRun(data: ArrayBuffer): HubThunkAction { }; } +// SPACE, SPACE, SPACE, SPACE +const startReplCommand = new Uint8Array([0x20, 0x20, 0x20, 0x20]); + +export function startRepl(): HubThunkAction { + return write(startReplCommand); +} + // CTRL+C, CTRL+C, CTRL+D const stopCommand = new Uint8Array([0x03, 0x03, 0x04]); diff --git a/src/components/ReplButton.tsx b/src/components/ReplButton.tsx new file mode 100644 index 00000000..35dbdbfe --- /dev/null +++ b/src/components/ReplButton.tsx @@ -0,0 +1,39 @@ +import { connect } from 'react-redux'; +import { ThunkDispatch } from 'redux-thunk'; +import { AnyAction } from 'redux'; +import { RootState } from '../reducers'; +import { HubRuntimeState } from '../reducers/hub'; +import { startRepl } from '../actions/hub'; +import ActionButton, { ActionButtonProps } from './ActionButton'; + +type Dispatch = ThunkDispatch<{}, {}, AnyAction>; + +type StateProps = Pick; +type DispatchProps = Pick; +type OwnProps = Pick; + +const mapStateToProps = (state: RootState): StateProps => ({ + enabled: + state.hub.runtime === HubRuntimeState.Idle || + state.hub.runtime === HubRuntimeState.Error, +}); + +const mapDispatchToProps = (dispatch: Dispatch): DispatchProps => ({ + onAction: (): void => { + dispatch(startRepl()); + }, +}); + +const mergeProps = ( + stateProps: StateProps, + dispatchProps: DispatchProps, + ownProps: OwnProps, +): ActionButtonProps => ({ + tooltip: 'Start REPL in terminal', + icon: 'repl.svg', + ...ownProps, + ...stateProps, + ...dispatchProps, +}); + +export default connect(mapStateToProps, mapDispatchToProps, mergeProps)(ActionButton); diff --git a/src/components/Toolbar.tsx b/src/components/Toolbar.tsx index e3f2a3ac..53f7b60c 100644 --- a/src/components/Toolbar.tsx +++ b/src/components/Toolbar.tsx @@ -8,6 +8,7 @@ import ActionButton from './ActionButton'; import BluetoothButton from './BluetoothButton'; import RunButton from './RunButton'; import StopButton from './StopButton'; +import ReplButton from './ReplButton'; interface ToolbarState { bleState: BLEConnectionState; @@ -39,12 +40,7 @@ class Toolbar extends React.Component<{}, ToolbarState> { - +