Skip to content

Commit

Permalink
feat: send ebb device info to client
Browse files Browse the repository at this point in the history
  • Loading branch information
nornagon committed Mar 10, 2019
1 parent 4065d4f commit 0e9cd16
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
2 changes: 2 additions & 0 deletions src/server.ts
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ export function startServer(port: number, device: string | null = null) {
}
});

ws.send(JSON.stringify({c: "dev", p: {path: ebb.port.path}}));

ws.on("close", () => {
clients = clients.filter((w) => w !== ws);
});
Expand Down
17 changes: 16 additions & 1 deletion src/ui.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ const planOptionsEqual = (a: PlanOptions, b: PlanOptions): boolean => {
const initialState = {
connected: true,

deviceInfo: null as DeviceInfo | null,

// UI state
planOptions: {
penUpHeight: 50,
Expand Down Expand Up @@ -105,6 +107,8 @@ function reducer(state: State, action: any): State {
switch (action.type) {
case 'SET_PLAN_OPTION':
return {...state, planOptions: {...state.planOptions, ...action.value}}
case 'SET_DEVICE_INFO':
return {...state, deviceInfo: action.value}
case 'SET_PATHS':
const {paths, layers, selectedLayers} = action
return {...state, plan: (null as Plan | null), paths, layers, planOptions: {...state.planOptions, selectedLayers}}
Expand All @@ -120,10 +124,15 @@ function reducer(state: State, action: any): State {
}
}

type DeviceInfo = {
path: string;
}

class Driver {
onprogress: (motionIdx: number) => void | null;
oncancelled: () => void | null;
onfinished: () => void | null;
ondevinfo: (devInfo: DeviceInfo) => void | null;
onconnectionchange: (connected: boolean) => void | null;

private socket: WebSocket;
Expand Down Expand Up @@ -156,6 +165,9 @@ class Driver {
case 'finished': {
if (this.onfinished != null) this.onfinished()
}; break;
case 'dev': {
if (this.ondevinfo != null) this.ondevinfo(msg.p)
}
default: {
console.log('Unknown message from server:', msg)
}; break;
Expand Down Expand Up @@ -637,6 +649,9 @@ function Root({driver}: {driver: Driver}) {
driver.onconnectionchange = (connected: boolean) => {
dispatch({type: 'SET_CONNECTED', connected})
}
driver.ondevinfo = (devInfo: DeviceInfo) => {
dispatch({type: 'SET_DEVICE_INFO', value: devInfo})
}
const ondrop = (e: DragEvent) => {
e.preventDefault()
const item = e.dataTransfer.items[0]
Expand Down Expand Up @@ -676,7 +691,7 @@ function Root({driver}: {driver: Driver}) {
return <DispatchContext.Provider value={dispatch}>
<div className={`root ${state.connected ? "connected" : "disconnected"}`}>
<div className="control-panel">
<div className={`saxi-title red`}>
<div className={`saxi-title red`} title={state.deviceInfo ? state.deviceInfo.path : null}>
<span className="red reg">s</span><span className="teal">axi</span>
</div>
{!state.connected ? <div className="info-disconnected">disconnected</div> : null}
Expand Down

0 comments on commit 0e9cd16

Please sign in to comment.