-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
ping-viewer-next-frontend: Add Ping360 widget
- Loading branch information
1 parent
8094ff2
commit 0e2ffc3
Showing
7 changed files
with
511 additions
and
393 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
80 changes: 80 additions & 0 deletions
80
ping-viewer-next-frontend/src/components/widgets/Ping360.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
<template> | ||
<div class="w-full h-full"> | ||
<div class="relative w-full pb-[100%]"> | ||
<div class="absolute inset-0"> | ||
<template v-if="useMask"> | ||
<SonarDisplayWrapper | ||
:angle="currentMeasurement?.angle ?? 0" | ||
:lineColor="lineColor" | ||
:lineWidth="lineWidth" | ||
:maxDistance="maxDistance" | ||
:numMarkers="numMarkers" | ||
:showRadiusLines="showRadiusLines" | ||
:showMarkers="showMarkers" | ||
:radiusLineColor="radiusLineColor" | ||
:markerColor="markerColor" | ||
:radiusLineWidth="radiusLineWidth" | ||
> | ||
<Sonar360 | ||
:measurement="currentMeasurement" | ||
:numLines="400" | ||
:lineLength="1200" | ||
/> | ||
</SonarDisplayWrapper> | ||
</template> | ||
<template v-else> | ||
<Sonar360 | ||
:measurement="currentMeasurement" | ||
:numLines="400" | ||
:lineLength="1200" | ||
/> | ||
</template> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
<script setup lang="ts"> | ||
import { ref, watch } from 'vue'; | ||
import SonarDisplayWrapper from './sonar360/Sonar360Mask.vue'; | ||
import Sonar360 from './sonar360/Sonar360Shader.vue'; | ||
interface SonarMeasurement { | ||
angle: number; | ||
data: Uint8Array; | ||
} | ||
const props = withDefaults(defineProps<{ | ||
measurement: SonarMeasurement | null; | ||
useMask?: boolean; | ||
lineColor?: string; | ||
lineWidth?: number; | ||
maxDistance?: number; | ||
numMarkers?: number; | ||
showRadiusLines?: boolean; | ||
showMarkers?: boolean; | ||
radiusLineColor?: string; | ||
markerColor?: string; | ||
radiusLineWidth?: number; | ||
}>(), { | ||
measurement: null, | ||
useMask: true, | ||
lineColor: 'red', | ||
lineWidth: 0.5, | ||
maxDistance: 300, | ||
numMarkers: 5, | ||
showRadiusLines: true, | ||
showMarkers: true, | ||
radiusLineColor: 'rgba(255,255,255,0.3)', | ||
markerColor: 'white', | ||
radiusLineWidth: 0.5 | ||
}); | ||
const currentMeasurement = ref<SonarMeasurement | null>(null); | ||
watch(() => props.measurement, (newMeasurement) => { | ||
if (newMeasurement) { | ||
currentMeasurement.value = newMeasurement; | ||
} | ||
}); | ||
</script> |
93 changes: 93 additions & 0 deletions
93
ping-viewer-next-frontend/src/components/widgets/Ping360Loader.vue
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,93 @@ | ||
<template> | ||
<div class="flex bg-gray-100 p-6"> | ||
<div class="max-w-4xl mx-auto bg-white shadow-lg rounded-lg overflow-hidden"> | ||
<div class="bg-gray-800 text-white py-4 px-6"> | ||
<h1 class="text-2xl font-bold">Ping Viewer Next - Sonar Display</h1> | ||
</div> | ||
|
||
<div class="p-6"> | ||
<h2 class="text-xl font-semibold mb-4">WebSocket Connection</h2> | ||
|
||
<div class="flex items-center mb-6"> | ||
<input v-model="websocketUrl" placeholder="Enter WebSocket URL" | ||
class="text-black flex-grow mr-2 p-2 border border-gray-300 rounded" /> | ||
<button @click="toggleConnection" | ||
class="bg-blue-500 hover:bg-blue-600 text-white font-bold py-2 px-4 rounded"> | ||
{{ isConnected ? 'Disconnect' : 'Connect' }} | ||
</button> | ||
</div> | ||
|
||
<h2 class="text-xl font-semibold mb-4">Sonar Display</h2> | ||
|
||
<div class="p-4 rounded"> | ||
<Ping360 | ||
:measurement="currentMeasurement" | ||
:maxDistance="300" | ||
:showMarkers="true" | ||
/> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
</template> | ||
|
||
<script setup lang="ts"> | ||
import { ref } from 'vue'; | ||
import Ping360 from "./Ping360.vue"; | ||
interface SonarMeasurement { | ||
angle: number; | ||
data: Uint8Array; | ||
} | ||
const websocketUrl = ref('ws://raulsyellowsubmarine2.duckdns.org:9997/ws?device_number=00000000-0000-0000-6113-f5df77d4fbd6'); | ||
const socket = ref<WebSocket | null>(null); | ||
const isConnected = ref(false); | ||
const currentMeasurement = ref<SonarMeasurement | null>(null); | ||
const toggleConnection = () => { | ||
if (isConnected.value) { | ||
disconnectWebSocket(); | ||
} else { | ||
connectWebSocket(); | ||
} | ||
}; | ||
const connectWebSocket = () => { | ||
if (socket.value) { | ||
socket.value.close(); | ||
} | ||
socket.value = new WebSocket(websocketUrl.value); | ||
socket.value.addEventListener('open', () => { | ||
console.log('WebSocket connected.'); | ||
isConnected.value = true; | ||
}); | ||
socket.value.addEventListener('close', () => { | ||
console.log('WebSocket closed.'); | ||
isConnected.value = false; | ||
}); | ||
socket.value.addEventListener('error', (error) => { | ||
console.error('WebSocket error:', error); | ||
isConnected.value = false; | ||
}); | ||
socket.value.addEventListener('message', (event) => { | ||
const message = JSON.parse(event.data); | ||
const deviceData = message.DeviceMessage.PingMessage.Ping360.DeviceData; | ||
currentMeasurement.value = { | ||
angle: deviceData.angle, | ||
data: new Uint8Array(deviceData.data) | ||
}; | ||
}); | ||
}; | ||
const disconnectWebSocket = () => { | ||
if (socket.value) { | ||
socket.value.close(); | ||
} | ||
}; | ||
</script> |
File renamed without changes.
Oops, something went wrong.