Skip to content

Commit

Permalink
feat: ⚗️ send keyboard steps relative to received datum
Browse files Browse the repository at this point in the history
  • Loading branch information
JamesNZL committed Oct 15, 2024
1 parent 41946a5 commit d89c013
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 3 deletions.
46 changes: 44 additions & 2 deletions client/src/app/place/PlaceOverlay.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,7 @@ export function PlaceOverlay({ socketUrl, overlaySize, circleSize, hideOverlay =
* Shift+Direction will cause the gantry to step a fixed distance in the specified direction
*/

const previousOffset = targetOffset ?? { x:0.5, y:0.5 }
const previousOffset = targetOffset ?? currentMachineState?.gantryPosition ?? { x: 0.5, y: 0.5 }

if (event.shiftKey) {

Expand Down Expand Up @@ -395,7 +395,49 @@ export function PlaceOverlay({ socketUrl, overlaySize, circleSize, hideOverlay =
return
}

if (!targetPositionOffsets?.length) return
if (!targetPositionOffsets?.length) {
const unclampedOffset = { ...previousOffset }
switch (event.code) {
case 'KeyR':
case 'KeyS':
case 'ArrowDown':
case 'KeyJ':
unclampedOffset.y = previousOffset.y + 0.0002
break
case 'KeyW':
case 'ArrowUp':
case 'KeyK':
unclampedOffset.y = previousOffset.y - 0.0002
break
case 'KeyA':
case 'ArrowLeft':
case 'KeyH':
unclampedOffset.x = previousOffset.x - 0.0002
break
case 'KeyD':
case 'ArrowRight':
case 'KeyL':
unclampedOffset.x = previousOffset.x + 0.0002
break
default:
return
}

const clampedOffset = {
x: Math.max(0, Math.min(1, unclampedOffset.x)),
y: Math.max(0, Math.min(1, unclampedOffset.y)),
}

if ((clampedOffset.x === 0.5) && (clampedOffset.y === 0.5)) {
console.log('Setting null')
setTargetOffset(null)
}
else {
setTargetOffset(clampedOffset)
socket.sendTargetDeltas(webSocket, clampedOffset)
}
return
}

const getFlatMapper = (searchAngleDegrees: number, searchArcDegrees: number) => (targetPosition: Position) => {
const targetDeltas = {
Expand Down
7 changes: 6 additions & 1 deletion client/src/lib/socket.ts
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,12 @@ export async function processMessage(data: unknown): Promise<Action> {
actionType: 'UPDATE_STATE',
messageType: decodedMessage.tag,
rawPayload,
payload: decodedMessage.machineState,
payload: {
gantryPosition: denormalisePosition(decodedMessage.machineState.gantryPosition),
isHeadDown: decodedMessage.machineState.isHeadDown,
isVacuumEngaged: decodedMessage.machineState.isVacuumEngaged,
isComponentPicked: decodedMessage.machineState.isComponentPicked,
},
silent: true,
}

Expand Down

1 comment on commit d89c013

@github-actions
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Deploy preview for p4p-83-interface ready!

✅ Preview
https://p4p-83-interface-ixzix1im4-jamesnzls-projects.vercel.app

Built with commit d89c013.
This pull request is being automatically deployed with vercel-action

Please sign in to comment.