Compare commits
10 Commits
Author | SHA1 | Date | |
---|---|---|---|
![]() |
c8b27813ae | ||
![]() |
802f1c71db | ||
![]() |
0a35ac49b9 | ||
![]() |
ce3de4c1e3 | ||
![]() |
1c7a8de4e1 | ||
![]() |
a5303ff232 | ||
![]() |
2bb3102828 | ||
![]() |
a06912de69 | ||
![]() |
5b6b56eb86 | ||
![]() |
a059d282ed |
@@ -11,7 +11,7 @@ export default defineConfig((/* ctx */) => {
|
|||||||
// app boot file (/src/boot)
|
// app boot file (/src/boot)
|
||||||
// --> boot files are part of "main.js"
|
// --> boot files are part of "main.js"
|
||||||
// https://v2.quasar.dev/quasar-cli-vite/boot-files
|
// https://v2.quasar.dev/quasar-cli-vite/boot-files
|
||||||
boot: [],
|
boot: ['websocket'],
|
||||||
|
|
||||||
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#css
|
// https://v2.quasar.dev/quasar-cli-vite/quasar-config-file#css
|
||||||
css: ['app.scss'],
|
css: ['app.scss'],
|
||||||
|
25
src/boot/websocket.ts
Normal file
25
src/boot/websocket.ts
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
import { boot } from 'quasar/wrappers';
|
||||||
|
import type { QVueGlobals } from 'quasar';
|
||||||
|
import { initWebSocket } from 'src/services/websocket';
|
||||||
|
|
||||||
|
export default boot(({ app }) => {
|
||||||
|
const $q = app.config.globalProperties.$q as QVueGlobals;
|
||||||
|
const host = window.location.hostname; // gets current domain or IP
|
||||||
|
const port = 8100; // your WebSocket port
|
||||||
|
|
||||||
|
const randomId = Math.floor(Math.random() * 10001); // random number from 0 to 10000
|
||||||
|
const ws = initWebSocket(`ws://${host}:${port}/ws?id=q${randomId}`, $q);
|
||||||
|
|
||||||
|
app.config.globalProperties.$socket = ws;
|
||||||
|
ws.connect();
|
||||||
|
});
|
||||||
|
|
||||||
|
declare module '@vue/runtime-core' {
|
||||||
|
interface ComponentCustomProperties {
|
||||||
|
$socket: {
|
||||||
|
connect: () => void;
|
||||||
|
close: () => void;
|
||||||
|
socket: WebSocket | null;
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
@@ -7,10 +7,11 @@
|
|||||||
dense
|
dense
|
||||||
:nodes="dbmData"
|
:nodes="dbmData"
|
||||||
node-key="key"
|
node-key="key"
|
||||||
:default-expand-all="true"
|
:default-expand-all="false"
|
||||||
|
v-model:expanded="expanded"
|
||||||
>
|
>
|
||||||
<template v-slot:[`default-header`]="props">
|
<template v-slot:[`default-header`]="props">
|
||||||
<div class="row items-center text-blue">
|
<div class="row items-center text-blue" @click="ClickNode(props.node)">
|
||||||
<div
|
<div
|
||||||
class="row items-center text-blue"
|
class="row items-center text-blue"
|
||||||
@contextmenu.prevent="openContextMenu($event, props.node)"
|
@contextmenu.prevent="openContextMenu($event, props.node)"
|
||||||
@@ -25,12 +26,12 @@
|
|||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
<q-popup-edit
|
<q-popup-edit
|
||||||
v-if="props.node.value !== undefined"
|
v-if="props.node.value !== undefined && props.node.value !== ''"
|
||||||
v-model="props.node.value"
|
v-model="props.node.value"
|
||||||
class="q-ml-xl bg-grey text-white"
|
class="q-ml-xl bg-grey text-white"
|
||||||
@save="onValueEdit(props.node)"
|
@save="(val) => onValueEdit(val, props.node)"
|
||||||
>
|
>
|
||||||
<template v-if="props.node.value !== undefined" v-slot="scope">
|
<template v-slot="scope">
|
||||||
<q-input
|
<q-input
|
||||||
dark
|
dark
|
||||||
color="white"
|
color="white"
|
||||||
@@ -56,32 +57,34 @@
|
|||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { onMounted } from 'vue';
|
import { onMounted, ref } from 'vue';
|
||||||
import { useWebSocket } from 'src/composables/useWebSocket';
|
|
||||||
import type { TreeNode } from 'src/composables/dbmTree';
|
import type { TreeNode } from 'src/composables/dbmTree';
|
||||||
import { subs, dbmData, buildTree } from 'src/composables/dbmTree';
|
import {
|
||||||
|
dbmData,
|
||||||
|
buildTree,
|
||||||
|
// addChildrentoTree,
|
||||||
|
getSubscriptionsByUuid,
|
||||||
|
addChildrentoTree,
|
||||||
|
removeSubtreeByParentKey,
|
||||||
|
} from 'src/composables/dbmTree';
|
||||||
import { openContextMenu } from 'src/composables/useContextMenu';
|
import { openContextMenu } from 'src/composables/useContextMenu';
|
||||||
import SubMenu from 'src/components/SubMenu.vue';
|
import SubMenu from 'src/components/SubMenu.vue';
|
||||||
import { QCard } from 'quasar';
|
import { QCard } from 'quasar';
|
||||||
|
import { send } from 'src/services/websocket';
|
||||||
const { connect, send } = useWebSocket('ws://127.0.0.1:8100/ws?id=quasar');
|
import { onBeforeRouteLeave } from 'vue-router';
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
connect();
|
|
||||||
send({
|
send({
|
||||||
subscribe: [
|
subscribe: [
|
||||||
{
|
{
|
||||||
path: '.*',
|
path: '.*',
|
||||||
depth: 2,
|
depth: 1,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response?.subscribe) {
|
if (response?.subscribe) {
|
||||||
subs.value = response.subscribe;
|
dbmData.value = buildTree(response.subscribe ?? []);
|
||||||
dbmData.value = buildTree(subs.value);
|
|
||||||
} else {
|
|
||||||
console.log('Response from server:', response);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
@@ -89,40 +92,106 @@ onMounted(() => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// function updateValue(uuid: string, newValue: string) {
|
onBeforeRouteLeave((to, from, next) => {
|
||||||
// const target = subs.value.find((s) => s.uuid === uuid);
|
|
||||||
// if (target) {
|
|
||||||
// target.value = newValue;
|
|
||||||
// treeData.value = buildTree(subs.value);
|
|
||||||
// }
|
|
||||||
// }
|
|
||||||
|
|
||||||
function onValueEdit(node: TreeNode) {
|
|
||||||
console.log(88, node.value);
|
|
||||||
|
|
||||||
const sub = subs.value.find((s) => s.path === node.key);
|
|
||||||
if (sub) {
|
|
||||||
sub.value = node.value;
|
|
||||||
send({
|
send({
|
||||||
set: [
|
unsubscribe: [
|
||||||
{
|
{
|
||||||
path: sub.path ?? '',
|
path: '.*',
|
||||||
value: Number(node.value),
|
depth: 0,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
if (response?.subscribe) {
|
if (response?.subscribe) {
|
||||||
subs.value = response.subscribe;
|
dbmData.value = buildTree(response.subscribe ?? []);
|
||||||
dbmData.value = buildTree(subs.value);
|
|
||||||
} else {
|
|
||||||
console.log('Response from server:', response);
|
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('Error fetching data:', err);
|
console.error('Error fetching data:', err);
|
||||||
});
|
});
|
||||||
// Optionally: push to server or log
|
next();
|
||||||
|
});
|
||||||
|
|
||||||
|
const expanded = ref<string[]>([]);
|
||||||
|
|
||||||
|
function ClickNode(node: TreeNode) {
|
||||||
|
if (node.key === 'DBM') return;
|
||||||
|
|
||||||
|
const nodeKey = node.key as string;
|
||||||
|
|
||||||
|
const isExpanded = expanded.value.includes(nodeKey);
|
||||||
|
|
||||||
|
if (isExpanded) {
|
||||||
|
// Collapse the parent node and its children
|
||||||
|
//expanded.value = expanded.value.filter((k) => k !== nodeKey && !k.startsWith(nodeKey));
|
||||||
|
|
||||||
|
// 2. Send unsubscribe request
|
||||||
|
send({
|
||||||
|
unsubscribe: [
|
||||||
|
{
|
||||||
|
uuid: nodeKey,
|
||||||
|
path: '.*',
|
||||||
|
depth: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response?.unsubscribe) {
|
||||||
|
removeSubtreeByParentKey(nodeKey);
|
||||||
|
}
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
expanded.value = expanded.value.filter((k) => k !== nodeKey && !k.startsWith(nodeKey));
|
||||||
|
});
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Error during unsubscribe:', err);
|
||||||
|
});
|
||||||
|
|
||||||
|
// 3. Do not continue further — important!
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 4. If not expanded, send subscribe and expand
|
||||||
|
send({
|
||||||
|
subscribe: [
|
||||||
|
{
|
||||||
|
uuid: nodeKey,
|
||||||
|
path: '.*',
|
||||||
|
depth: 1,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response?.subscribe) {
|
||||||
|
addChildrentoTree(response.subscribe);
|
||||||
|
|
||||||
|
// Delay to ensure reactive updates apply cleanly
|
||||||
|
requestAnimationFrame(() => {
|
||||||
|
if (!expanded.value.includes(nodeKey)) {
|
||||||
|
expanded.value.push(nodeKey);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Error during subscribe:', err);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function onValueEdit(newValue: undefined, node: TreeNode) {
|
||||||
|
console.log(node.value, node.value === undefined);
|
||||||
|
const sub = getSubscriptionsByUuid(node.key);
|
||||||
|
if (sub) {
|
||||||
|
send({
|
||||||
|
set: [
|
||||||
|
{
|
||||||
|
path: sub.path ?? '',
|
||||||
|
value: newValue,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
}).catch((err) => {
|
||||||
|
console.error('Error fetching data:', err);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
</script>
|
||||||
|
@@ -95,17 +95,22 @@
|
|||||||
color="purple"
|
color="purple"
|
||||||
style="opacity: 0.8"
|
style="opacity: 0.8"
|
||||||
/>
|
/>
|
||||||
|
<div class="colums q-ma-xl">
|
||||||
|
<q-btn color="secondary" @click="settings = !settings" icon="settings">Settings</q-btn>
|
||||||
|
<SettingDialog :settings-dialog="settings"></SettingDialog>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { watch, onMounted, reactive } from 'vue';
|
import { watch, reactive, ref } from 'vue';
|
||||||
import { useWebSocket } from 'src/composables/useWebSocket';
|
|
||||||
import type { Light } from 'src/models/Light';
|
import type { Light } from 'src/models/Light';
|
||||||
|
import { send } from 'src/services/websocket';
|
||||||
|
import SettingDialog from 'src/components/SettingDomeLight.vue';
|
||||||
|
|
||||||
const { connect, send } = useWebSocket('ws://127.0.0.1:8100/ws?id=quasar');
|
const settings = ref(false);
|
||||||
|
|
||||||
const light = reactive<Light>({
|
const light = reactive<Light>({
|
||||||
State: false,
|
State: false,
|
||||||
@@ -118,10 +123,6 @@ const light = reactive<Light>({
|
|||||||
Purple: 0,
|
Purple: 0,
|
||||||
});
|
});
|
||||||
|
|
||||||
onMounted(() => {
|
|
||||||
connect();
|
|
||||||
});
|
|
||||||
|
|
||||||
watch(light, (newVal: Light) => {
|
watch(light, (newVal: Light) => {
|
||||||
send({
|
send({
|
||||||
set: [
|
set: [
|
133
src/components/DragPad.vue
Normal file
133
src/components/DragPad.vue
Normal file
@@ -0,0 +1,133 @@
|
|||||||
|
<template>
|
||||||
|
<div class="row q-ma-xs">
|
||||||
|
<q-item-label class="text-bold">Tilt</q-item-label>
|
||||||
|
<q-slider
|
||||||
|
class="q-mr-sm"
|
||||||
|
vertical
|
||||||
|
:reverse="!props.reverseTilt"
|
||||||
|
v-model="tilt"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
label
|
||||||
|
color="black"
|
||||||
|
style="opacity: 1"
|
||||||
|
/>
|
||||||
|
<div class="column items-center q-ml-sm">
|
||||||
|
<div
|
||||||
|
class="bg-grey-3"
|
||||||
|
style="
|
||||||
|
width: 200px;
|
||||||
|
height: 200px;
|
||||||
|
position: relative;
|
||||||
|
border: 1px solid #ccc;
|
||||||
|
border-radius: 8px;
|
||||||
|
touch-action: none;
|
||||||
|
"
|
||||||
|
@mousedown="startDrag"
|
||||||
|
@touchstart="startTouch"
|
||||||
|
@touchend="stopTouch"
|
||||||
|
ref="pad"
|
||||||
|
>
|
||||||
|
<div class="marker" :style="markerStyle" :class="{ crosshair: dragging }"></div>
|
||||||
|
</div>
|
||||||
|
<q-item-label class="text-bold">Pan</q-item-label>
|
||||||
|
<q-slider
|
||||||
|
:reverse="props.reversePan"
|
||||||
|
class="q-ml-sm"
|
||||||
|
v-model="pan"
|
||||||
|
:min="0"
|
||||||
|
:max="100"
|
||||||
|
:step="1"
|
||||||
|
label
|
||||||
|
color="black"
|
||||||
|
style="opacity: 1"
|
||||||
|
/>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script lang="ts" setup>
|
||||||
|
import { ref, computed } from 'vue';
|
||||||
|
|
||||||
|
const pad = ref<HTMLElement | null>(null);
|
||||||
|
const dragging = ref(false);
|
||||||
|
|
||||||
|
const pan = defineModel<number>('pan', { default: 0 });
|
||||||
|
const tilt = defineModel<number>('tilt', { default: 0 });
|
||||||
|
const props = defineProps<{
|
||||||
|
reversePan: boolean;
|
||||||
|
reverseTilt: boolean;
|
||||||
|
}>();
|
||||||
|
|
||||||
|
const markerStyle = computed(() => ({
|
||||||
|
position: 'absolute' as const,
|
||||||
|
top: `${2 * (props.reverseTilt ? tilt.value : 100 - tilt.value)}px`,
|
||||||
|
left: `${2 * (props.reversePan ? 100 - pan.value : pan.value)}px`,
|
||||||
|
width: '12px',
|
||||||
|
height: '12px',
|
||||||
|
borderRadius: '50%',
|
||||||
|
background: 'red',
|
||||||
|
border: '2px solid white',
|
||||||
|
cursor: 'pointer',
|
||||||
|
transform: 'translate(-50%, -50%)',
|
||||||
|
}));
|
||||||
|
|
||||||
|
function startDrag(e: MouseEvent) {
|
||||||
|
dragging.value = true;
|
||||||
|
updatePosition(e);
|
||||||
|
window.addEventListener('mousemove', onDrag);
|
||||||
|
window.addEventListener('mouseup', stopDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopDrag() {
|
||||||
|
dragging.value = false;
|
||||||
|
window.removeEventListener('mousemove', onDrag);
|
||||||
|
window.removeEventListener('mouseup', stopDrag);
|
||||||
|
}
|
||||||
|
|
||||||
|
function startTouch(e: TouchEvent) {
|
||||||
|
e.preventDefault(); // ✅ block scroll
|
||||||
|
const touch = e.touches[0];
|
||||||
|
if (!touch) return;
|
||||||
|
dragging.value = true;
|
||||||
|
updatePosition(touch);
|
||||||
|
window.addEventListener('touchmove', onTouch, { passive: false });
|
||||||
|
window.addEventListener('touchend', stopTouch);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onTouch(e: TouchEvent) {
|
||||||
|
e.preventDefault(); // ✅ block scroll
|
||||||
|
if (!dragging.value) return;
|
||||||
|
const touch = e.touches[0];
|
||||||
|
if (!touch) return;
|
||||||
|
updatePosition(touch);
|
||||||
|
}
|
||||||
|
|
||||||
|
function onDrag(e: MouseEvent) {
|
||||||
|
e.preventDefault(); // optional, for extra safety
|
||||||
|
if (!dragging.value) return;
|
||||||
|
updatePosition(e);
|
||||||
|
}
|
||||||
|
|
||||||
|
function stopTouch() {
|
||||||
|
dragging.value = false;
|
||||||
|
window.removeEventListener('touchmove', onTouch);
|
||||||
|
window.removeEventListener('touchend', stopTouch);
|
||||||
|
}
|
||||||
|
|
||||||
|
function updatePosition(e: MouseEvent | Touch) {
|
||||||
|
if (!pad.value) return;
|
||||||
|
|
||||||
|
const rect = pad.value.getBoundingClientRect();
|
||||||
|
const newX = Math.min(Math.max(0, e.clientX - rect.left), rect.width);
|
||||||
|
const newY = Math.min(Math.max(0, e.clientY - rect.top), rect.height);
|
||||||
|
|
||||||
|
pan.value = props.reversePan
|
||||||
|
? Math.round((1 - newX / rect.width) * 100)
|
||||||
|
: Math.round((newX / rect.width) * 100);
|
||||||
|
tilt.value = props.reverseTilt
|
||||||
|
? Math.round((newY / rect.height) * 100)
|
||||||
|
: Math.round(100 - (newY / rect.height) * 100);
|
||||||
|
}
|
||||||
|
</script>
|
@@ -10,11 +10,11 @@ select
|
|||||||
<div class="q-pa-md">
|
<div class="q-pa-md">
|
||||||
<q-card>
|
<q-card>
|
||||||
<q-card-section class="q-mt-md q-mr-sm row items-start">
|
<q-card-section class="q-mt-md q-mr-sm row items-start">
|
||||||
<div class="column justify-center q-mr-lg" style="height: 200px">
|
<div class="column justify-center q-ma-lg" style="height: 200px">
|
||||||
<q-btn
|
<q-btn
|
||||||
@click="light.State = !light.State"
|
@click="changeState"
|
||||||
round
|
round
|
||||||
:color="light.State ? 'yellow' : 'blue'"
|
:color="brightness > 0 ? 'yellow' : 'blue'"
|
||||||
icon="lightbulb"
|
icon="lightbulb"
|
||||||
style="position: relative"
|
style="position: relative"
|
||||||
/>
|
/>
|
||||||
@@ -22,10 +22,10 @@ select
|
|||||||
<q-item-label class="text-bold">Dimmer</q-item-label>
|
<q-item-label class="text-bold">Dimmer</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
label
|
label
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.Brightness"
|
v-model="brightness"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -34,10 +34,10 @@ select
|
|||||||
/>
|
/>
|
||||||
<q-item-label class="text-bold">Red</q-item-label>
|
<q-item-label class="text-bold">Red</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.Red"
|
v-model="red"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -47,10 +47,10 @@ select
|
|||||||
/>
|
/>
|
||||||
<q-item-label class="text-bold">Green</q-item-label>
|
<q-item-label class="text-bold">Green</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.Green"
|
v-model="green"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -60,10 +60,10 @@ select
|
|||||||
/>
|
/>
|
||||||
<q-item-label class="text-bold">Blue</q-item-label>
|
<q-item-label class="text-bold">Blue</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.Blue"
|
v-model="blue"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -71,12 +71,12 @@ select
|
|||||||
color="blue"
|
color="blue"
|
||||||
style="opacity: 0.8"
|
style="opacity: 0.8"
|
||||||
/>
|
/>
|
||||||
<q-item-label class="text-bold">White</q-item-label>
|
<q-item-label class="text-bold items-center">White</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.White"
|
v-model="white"
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -86,23 +86,10 @@ select
|
|||||||
/>
|
/>
|
||||||
<q-item-label class="text-bold">Zoom</q-item-label>
|
<q-item-label class="text-bold">Zoom</q-item-label>
|
||||||
<q-slider
|
<q-slider
|
||||||
class="q-mr-lg"
|
class="q-ma-lg"
|
||||||
vertical
|
vertical
|
||||||
reverse
|
reverse
|
||||||
v-model="light.Zoom"
|
v-model="zoom"
|
||||||
:min="0"
|
|
||||||
:max="100"
|
|
||||||
:step="1"
|
|
||||||
label
|
|
||||||
color="black"
|
|
||||||
style="opacity: 1"
|
|
||||||
/>
|
|
||||||
<q-item-label class="text-bold">Tilt</q-item-label>
|
|
||||||
<q-slider
|
|
||||||
class="q-mr-sm"
|
|
||||||
vertical
|
|
||||||
reverse
|
|
||||||
v-model="light.Tilt"
|
|
||||||
:min="0"
|
:min="0"
|
||||||
:max="100"
|
:max="100"
|
||||||
:step="1"
|
:step="1"
|
||||||
@@ -111,205 +98,144 @@ select
|
|||||||
style="opacity: 1"
|
style="opacity: 1"
|
||||||
/>
|
/>
|
||||||
<div class="column items-center q-ml-sm">
|
<div class="column items-center q-ml-sm">
|
||||||
<div
|
<DragPad
|
||||||
class="bg-grey-3"
|
v-model:pan="pan"
|
||||||
style="
|
v-model:reverse-pan="reversePan"
|
||||||
width: 200px;
|
v-model:tilt="tilt"
|
||||||
height: 200px;
|
v-model:reverse-tilt="reverseTilt"
|
||||||
position: relative;
|
|
||||||
border: 1px solid #ccc;
|
|
||||||
border-radius: 8px;
|
|
||||||
"
|
|
||||||
@mousedown="startDrag"
|
|
||||||
@mousemove="onDrag"
|
|
||||||
@mouseup="stopDrag"
|
|
||||||
@mouseleave="stopDrag"
|
|
||||||
@touchstart="startTouch"
|
|
||||||
@touchmove="onTouch"
|
|
||||||
@touchend="stopDrag"
|
|
||||||
ref="pad"
|
|
||||||
>
|
|
||||||
<div class="marker" :style="markerStyle" :class="{ crosshair: dragging }"></div>
|
|
||||||
</div>
|
|
||||||
<q-item-label class="text-bold">Pan</q-item-label>
|
|
||||||
<q-slider
|
|
||||||
class="q-ml-sm"
|
|
||||||
v-model="light.Pan"
|
|
||||||
:min="0"
|
|
||||||
:max="100"
|
|
||||||
:step="1"
|
|
||||||
label
|
|
||||||
color="black"
|
|
||||||
style="opacity: 1"
|
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="colums q-ma-xl">
|
||||||
|
<q-btn color="secondary" @click="settings = !settings" icon="settings">Settings</q-btn>
|
||||||
|
<SettingDialog
|
||||||
|
:settings-dialog="settings"
|
||||||
|
v-model:reverse-pan="reversePan"
|
||||||
|
v-model:reverse-tilt="reverseTilt"
|
||||||
|
></SettingDialog>
|
||||||
|
</div>
|
||||||
</q-card-section>
|
</q-card-section>
|
||||||
</q-card>
|
</q-card>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { ref, watch, onMounted, reactive, computed } from 'vue';
|
import { computed, onMounted, onUnmounted, ref } from 'vue';
|
||||||
import { useWebSocket } from 'src/composables/useWebSocket';
|
import { send } from 'src/services/websocket';
|
||||||
import type { MovingHead } from 'src/models/MovingHead';
|
import { LocalStorage } from 'quasar';
|
||||||
|
import { getSubscriptionsByPath, buildTree, dbmData } from 'src/composables/dbmTree';
|
||||||
|
import DragPad from './DragPad.vue';
|
||||||
|
import SettingDialog from './SettingMovingHead.vue';
|
||||||
|
|
||||||
const { connect, send } = useWebSocket('ws://127.0.0.1:8100/ws?id=quasar');
|
const red = updateValue('MovingHead:Red', true);
|
||||||
const pad = ref<HTMLElement | null>(null);
|
const green = updateValue('MovingHead:Green', true);
|
||||||
const dragging = ref(false);
|
const blue = updateValue('MovingHead:Blue', true);
|
||||||
|
const white = updateValue('MovingHead:White', true);
|
||||||
const light = reactive<MovingHead>({
|
const brightness = updateBrightnessValue('MovingHead:Brightness');
|
||||||
State: false,
|
const pan = updateValue('MovingHead:Pan', true);
|
||||||
Brightness: 0,
|
const tilt = updateValue('MovingHead:Tilt', true);
|
||||||
Red: 0,
|
const zoom = updateValue('MovingHead:Zoom');
|
||||||
Green: 0,
|
const state = updateValue('MovingHead:State');
|
||||||
Blue: 0,
|
const settings = ref(false);
|
||||||
White: 0,
|
const reversePan = ref(false);
|
||||||
Zoom: 0,
|
const reverseTilt = ref(false);
|
||||||
Pan: 50,
|
|
||||||
Tilt: 50,
|
|
||||||
});
|
|
||||||
|
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
connect();
|
reversePan.value = LocalStorage.getItem('reversePan') ?? false;
|
||||||
});
|
reverseTilt.value = LocalStorage.getItem('reverseTilt') ?? false;
|
||||||
|
|
||||||
const markerStyle = computed(() => ({
|
|
||||||
position: 'absolute' as const,
|
|
||||||
top: `${2 * (100 - light.Tilt)}px`,
|
|
||||||
left: `${2 * light.Pan}px`,
|
|
||||||
width: '12px',
|
|
||||||
height: '12px',
|
|
||||||
borderRadius: '50%',
|
|
||||||
background: 'red',
|
|
||||||
border: '2px solid white',
|
|
||||||
cursor: 'pointer',
|
|
||||||
transform: 'translate(-50%, -50%)',
|
|
||||||
}));
|
|
||||||
|
|
||||||
function startDrag(e: MouseEvent) {
|
|
||||||
dragging.value = true;
|
|
||||||
updatePosition(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onDrag(e: MouseEvent) {
|
|
||||||
if (!dragging.value) return;
|
|
||||||
updatePosition(e);
|
|
||||||
}
|
|
||||||
|
|
||||||
function stopDrag() {
|
|
||||||
dragging.value = false;
|
|
||||||
}
|
|
||||||
|
|
||||||
function startTouch(e: TouchEvent) {
|
|
||||||
const touch = e.touches[0];
|
|
||||||
if (!touch) return;
|
|
||||||
dragging.value = true;
|
|
||||||
updatePosition(touch);
|
|
||||||
}
|
|
||||||
|
|
||||||
function onTouch(e: TouchEvent) {
|
|
||||||
if (!dragging.value) return;
|
|
||||||
const touch = e.touches[0];
|
|
||||||
if (!touch) return;
|
|
||||||
updatePosition(touch);
|
|
||||||
}
|
|
||||||
|
|
||||||
function updatePosition(e: MouseEvent | Touch) {
|
|
||||||
if (!pad.value) return;
|
|
||||||
const rect = pad.value.getBoundingClientRect();
|
|
||||||
const newX = Math.min(Math.max(0, e.clientX - rect.left), rect.width);
|
|
||||||
const newY = Math.min(Math.max(0, e.clientY - rect.top), rect.height);
|
|
||||||
|
|
||||||
light.Pan = Math.round((newX / rect.width) * 100);
|
|
||||||
light.Tilt = Math.round(100 - (newY / rect.height) * 100);
|
|
||||||
console.log(light.Pan, light.Tilt);
|
|
||||||
}
|
|
||||||
|
|
||||||
watch(light, (newVal: MovingHead) => {
|
|
||||||
send({
|
send({
|
||||||
set: [
|
subscribe: [
|
||||||
{
|
{
|
||||||
// Red
|
path: 'MovingHead:.*',
|
||||||
path: 'MovingHead:001:Red',
|
depth: 0,
|
||||||
value: Math.round((255 / 100) * newVal.Red * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
//Red fine
|
|
||||||
path: 'MovingHead:001:RedFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Red * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Green
|
|
||||||
path: 'MovingHead:001:Green',
|
|
||||||
value: Math.round((255 / 100) * newVal.Green * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Green fine
|
|
||||||
path: 'MovingHead:001:GreenFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Green * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Blue
|
|
||||||
path: 'MovingHead:001:Blue',
|
|
||||||
value: Math.round((255 / 100) * newVal.Blue * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Blue fine
|
|
||||||
path: 'MovingHead:001:BlueFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Blue * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// White
|
|
||||||
path: 'MovingHead:001:White',
|
|
||||||
value: Math.round((255 / 100) * newVal.White * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// White fine
|
|
||||||
path: 'MovingHead:001:WhiteFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.White * newVal.Brightness * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Dimmer
|
|
||||||
path: 'MovingHead:001:Dimmer',
|
|
||||||
value: Math.round((255 / 100) * newVal.Brightness * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Dimmer fine
|
|
||||||
path: 'MovingHead:001:DimmerFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Brightness * Number(newVal.State)),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Zoom
|
|
||||||
path: 'MovingHead:001:Zoom',
|
|
||||||
value: Math.round((255 / 100) * newVal.Zoom),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Pan
|
|
||||||
path: 'MovingHead:001:Pan',
|
|
||||||
value: Math.round((255 / 100) * newVal.Pan),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Pan fine
|
|
||||||
path: 'MovingHead:001:PanFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Pan),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Tilt
|
|
||||||
path: 'MovingHead:001:Tilt',
|
|
||||||
value: Math.round((255 / 100) * newVal.Tilt),
|
|
||||||
},
|
|
||||||
{
|
|
||||||
// Tilt fine
|
|
||||||
path: 'MovingHead:001:TiltFine',
|
|
||||||
value: Math.round((255 / 100) * newVal.Tilt),
|
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
})
|
})
|
||||||
.then((response) => {
|
.then((response) => {
|
||||||
|
if (response?.subscribe) {
|
||||||
|
dbmData.value = buildTree(response.subscribe ?? []);
|
||||||
|
} else {
|
||||||
console.log('Response from server:', response);
|
console.log('Response from server:', response);
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch((err) => {
|
.catch((err) => {
|
||||||
console.error('Error fetching data:', err);
|
console.error('Error fetching data:', err);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
onUnmounted(() => {
|
||||||
|
send({
|
||||||
|
unsubscribe: [
|
||||||
|
{
|
||||||
|
path: 'MovingHead:.*',
|
||||||
|
depth: 0,
|
||||||
|
},
|
||||||
|
],
|
||||||
|
})
|
||||||
|
.then((response) => {
|
||||||
|
if (response?.subscribe) {
|
||||||
|
dbmData.value = buildTree(response.subscribe ?? []);
|
||||||
|
} else {
|
||||||
|
console.log('Response from server:', response);
|
||||||
|
}
|
||||||
|
})
|
||||||
|
.catch((err) => {
|
||||||
|
console.error('Error fetching data:', err);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
function changeState() {
|
||||||
|
if (brightness.value === 0) {
|
||||||
|
if (state.value === 0) {
|
||||||
|
brightness.value = 100;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
brightness.value = state.value;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
state.value = brightness.value;
|
||||||
|
brightness.value = 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateValue(path: string, isDouble = false) {
|
||||||
|
return computed({
|
||||||
|
get() {
|
||||||
|
const sub = getSubscriptionsByPath(path);
|
||||||
|
const value = sub ? Number(sub.value ?? 0) : 0;
|
||||||
|
return isDouble ? Math.round((100 / 255) * value) : Math.round((100 / 255) * value);
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
const baseValue = Math.round((255 / 100) * val);
|
||||||
|
const setPaths = [{ path, value: baseValue }];
|
||||||
|
|
||||||
|
if (isDouble) {
|
||||||
|
setPaths.push({ path: `${path}Fine`, value: baseValue });
|
||||||
|
}
|
||||||
|
|
||||||
|
send({
|
||||||
|
set: setPaths,
|
||||||
|
}).catch((err) => console.error(`Failed to update ${path.split(':')[1]}:`, err));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function updateBrightnessValue(path: string) {
|
||||||
|
return computed({
|
||||||
|
get() {
|
||||||
|
const sub = getSubscriptionsByPath(path);
|
||||||
|
const value = sub ? Number(sub.value ?? 0) : 0;
|
||||||
|
return Math.round((100 / 255) * value);
|
||||||
|
},
|
||||||
|
set(val) {
|
||||||
|
const baseValue = Math.round((255 / 100) * val);
|
||||||
|
const setPaths = [{ path, value: baseValue }];
|
||||||
|
setPaths.push({ path: `${path}Fine`, value: baseValue });
|
||||||
|
setPaths.push({ path: `MovingHead:Strobe`, value: 255 });
|
||||||
|
|
||||||
|
send({
|
||||||
|
set: setPaths,
|
||||||
|
}).catch((err) => console.error(`Failed to update ${path.split(':')[1]}:`, err));
|
||||||
|
},
|
||||||
|
});
|
||||||
|
}
|
||||||
</script>
|
</script>
|
||||||
|
27
src/components/SettingDomeLight.vue
Normal file
27
src/components/SettingDomeLight.vue
Normal file
@@ -0,0 +1,27 @@
|
|||||||
|
<template>
|
||||||
|
<q-dialog v-model="settingsDialog">
|
||||||
|
<q-card style="min-width: 300px">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Settings</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-section>
|
||||||
|
<q-btn>Normal</q-btn>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section> </q-card-section>
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn flat label="Cancel" v-close-popup />
|
||||||
|
<q-btn flat label="Save" @click="saveSettings" />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
const settingsDialog = defineModel<boolean>('settingsDialog', { default: false, required: true });
|
||||||
|
|
||||||
|
function saveSettings() {
|
||||||
|
// Save logic here
|
||||||
|
settingsDialog.value = false;
|
||||||
|
}
|
||||||
|
</script>
|
50
src/components/SettingMovingHead.vue
Normal file
50
src/components/SettingMovingHead.vue
Normal file
@@ -0,0 +1,50 @@
|
|||||||
|
<template>
|
||||||
|
<q-dialog v-model="settingsDialog">
|
||||||
|
<q-card style="min-width: 300px">
|
||||||
|
<q-card-section>
|
||||||
|
<div class="text-h6">Settings</div>
|
||||||
|
</q-card-section>
|
||||||
|
|
||||||
|
<q-card-section>
|
||||||
|
<q-btn
|
||||||
|
:icon="!reverseTilt ? 'swap_vert' : undefined"
|
||||||
|
:icon-right="reverseTilt ? 'swap_vert' : undefined"
|
||||||
|
@click="reverseTilt = !reverseTilt"
|
||||||
|
>{{ reverseTilt ? 'Reversed Tilt' : 'Normal Tilt' }}</q-btn
|
||||||
|
>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section>
|
||||||
|
<q-btn
|
||||||
|
:icon="!reversePan ? 'swap_vert' : undefined"
|
||||||
|
:icon-right="reversePan ? 'swap_vert' : undefined"
|
||||||
|
@click="reversePan = !reversePan"
|
||||||
|
>{{ reversePan ? 'Reversed Pan' : 'Normal Pan' }}</q-btn
|
||||||
|
>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-section>
|
||||||
|
<q-input type="number" label="Start Address" v-model:model-value="startAddress"></q-input>
|
||||||
|
</q-card-section>
|
||||||
|
<q-card-actions align="right">
|
||||||
|
<q-btn flat label="Cancel" v-close-popup />
|
||||||
|
<q-btn flat label="Save" @click="saveSettings" />
|
||||||
|
</q-card-actions>
|
||||||
|
</q-card>
|
||||||
|
</q-dialog>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { LocalStorage } from 'quasar';
|
||||||
|
const settingsDialog = defineModel<boolean>('settingsDialog', { default: false, required: true });
|
||||||
|
const reversePan = defineModel<boolean>('reversePan', { default: false, required: true });
|
||||||
|
const reverseTilt = defineModel<boolean>('reverseTilt', { default: false, required: true });
|
||||||
|
const startAddress = defineModel<number>('startAddress', { default: 0 });
|
||||||
|
|
||||||
|
function saveSettings() {
|
||||||
|
LocalStorage.set('reversePan', reversePan.value);
|
||||||
|
LocalStorage.set('reverseTilt', reverseTilt.value);
|
||||||
|
|
||||||
|
console.log(88, startAddress.value);
|
||||||
|
|
||||||
|
settingsDialog.value = false;
|
||||||
|
}
|
||||||
|
</script>
|
@@ -13,11 +13,11 @@
|
|||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import { contextMenu } from 'src/composables/useContextMenu';
|
import { contextMenu } from 'src/composables/useContextMenu';
|
||||||
import { useWebSocket } from 'src/composables/useWebSocket';
|
import { send } from 'src/services/websocket';
|
||||||
const { send } = useWebSocket('ws://127.0.0.1:8100/ws?id=quasar');
|
|
||||||
|
|
||||||
function handleAction(action: string) {
|
function handleAction(action: string) {
|
||||||
console.log(`Action '${action}' on node:`, contextMenu.value.node);
|
console.log(`Action '${action}' on node:`, contextMenu.value.node);
|
||||||
|
|
||||||
// Add your actual logic here
|
// Add your actual logic here
|
||||||
switch (action) {
|
switch (action) {
|
||||||
case 'Add':
|
case 'Add':
|
||||||
|
@@ -1,14 +1,14 @@
|
|||||||
import type { Subs } from 'src/models/Subscribe';
|
import type { Subs } from 'src/models/Subscribe';
|
||||||
import { ref } from 'vue';
|
import { ref, nextTick } from 'vue';
|
||||||
|
|
||||||
export const dbmData = ref<TreeNode[]>(buildTree([]));
|
const Subscriptions = ref<Subs>([]);
|
||||||
|
|
||||||
export const subs = ref<Subs>([]);
|
export const dbmData = ref<TreeNode[]>([]);
|
||||||
|
|
||||||
export interface TreeNode {
|
export interface TreeNode {
|
||||||
path: string;
|
path: string | undefined;
|
||||||
key?: string; // optional: useful for QTree's node-key
|
key?: string; // optional: useful for QTree's node-key
|
||||||
value?: string | undefined;
|
value?: string | number | boolean | undefined;
|
||||||
children?: TreeNode[];
|
children?: TreeNode[];
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -23,6 +23,8 @@ export function buildTree(subs: Subs): TreeNode[] {
|
|||||||
|
|
||||||
const root: TreeMap = {};
|
const root: TreeMap = {};
|
||||||
|
|
||||||
|
Subscriptions.value = subs;
|
||||||
|
|
||||||
for (const item of subs) {
|
for (const item of subs) {
|
||||||
const pathParts = item.path?.split(':') ?? [];
|
const pathParts = item.path?.split(':') ?? [];
|
||||||
let current = root;
|
let current = root;
|
||||||
@@ -63,3 +65,46 @@ export function buildTree(subs: Subs): TreeNode[] {
|
|||||||
},
|
},
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
export function getTreeElementByPath(path: string) {
|
||||||
|
return dbmData.value.find((s) => s.path === path);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSubscriptionsByUuid(uid: string | undefined) {
|
||||||
|
return Subscriptions.value.find((s) => s.uuid === uid);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function addChildrentoTree(subs: Subs) {
|
||||||
|
Subscriptions.value.push(...subs);
|
||||||
|
void nextTick(() => {
|
||||||
|
dbmData.value = buildTree(Subscriptions.value);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
export function removeSubtreeByParentKey(parentKey: string) {
|
||||||
|
// Find the parent node using its uuid
|
||||||
|
const parent = Subscriptions.value.find((s) => s.uuid === parentKey);
|
||||||
|
if (!parent || !parent.path) return;
|
||||||
|
|
||||||
|
const parentPath = parent.path;
|
||||||
|
|
||||||
|
// Now filter out the children, but NOT the parent itself
|
||||||
|
Subscriptions.value = Subscriptions.value.filter((s) => {
|
||||||
|
// Keep the parent itself (don't remove it)
|
||||||
|
if (s.uuid === parentKey) return true;
|
||||||
|
|
||||||
|
// Remove any child whose path starts with parentPath + '/' (descendants)
|
||||||
|
return !s.path?.startsWith(parentPath + ':');
|
||||||
|
});
|
||||||
|
|
||||||
|
// Rebuild the tree after removing children, but keeping the parent
|
||||||
|
dbmData.value = buildTree(Subscriptions.value);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getSubscriptionsByPath(path: string) {
|
||||||
|
return Subscriptions.value.find((s) => s.path === path);
|
||||||
|
}
|
||||||
|
|
||||||
|
export function getAllSubscriptions() {
|
||||||
|
return Subscriptions.value;
|
||||||
|
}
|
||||||
|
@@ -7,5 +7,6 @@ export type Response = {
|
|||||||
get?: Gets;
|
get?: Gets;
|
||||||
set?: Sets;
|
set?: Sets;
|
||||||
subscribe?: Subs;
|
subscribe?: Subs;
|
||||||
|
unsubscribe?: Subs;
|
||||||
publish?: Pubs;
|
publish?: Pubs;
|
||||||
};
|
};
|
||||||
|
@@ -1,6 +1,6 @@
|
|||||||
type Set = {
|
export type Set = {
|
||||||
path: string;
|
path: string;
|
||||||
value: number | undefined;
|
value: number | boolean | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Sets = Set[];
|
export type Sets = Set[];
|
||||||
|
@@ -1,8 +1,8 @@
|
|||||||
export type Subscribe = {
|
export type Subscribe = {
|
||||||
uuid?: string;
|
uuid?: string | undefined;
|
||||||
path?: string;
|
path?: string | undefined;
|
||||||
depth?: number;
|
depth?: number;
|
||||||
value?: string | undefined;
|
value?: string | number | boolean | undefined;
|
||||||
};
|
};
|
||||||
|
|
||||||
export type Subs = Subscribe[];
|
export type Subs = Subscribe[];
|
||||||
|
@@ -1,5 +1,4 @@
|
|||||||
<template>
|
<template>
|
||||||
<h1>Test Page</h1>
|
|
||||||
<DBMTree></DBMTree>
|
<DBMTree></DBMTree>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
|
@@ -1,11 +1,23 @@
|
|||||||
<template>
|
<template>
|
||||||
<q-page>
|
<q-page>
|
||||||
<light-component />
|
<q-tabs v-model="tab">
|
||||||
<moving-head></moving-head>
|
<q-tab name="movingHead" label="Moving Head" />
|
||||||
|
<q-tab name="dome" label="Dome" />
|
||||||
|
</q-tabs>
|
||||||
|
<q-tab-panels v-model="tab" animated class="text-white">
|
||||||
|
<q-tab-panel name="movingHead">
|
||||||
|
<moving-head />
|
||||||
|
</q-tab-panel>
|
||||||
|
<q-tab-panel name="dome">
|
||||||
|
<Dome />
|
||||||
|
</q-tab-panel>
|
||||||
|
</q-tab-panels>
|
||||||
</q-page>
|
</q-page>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import LightComponent from 'src/components/LightComponent.vue';
|
|
||||||
import MovingHead from 'src/components/MovingHead.vue';
|
import MovingHead from 'src/components/MovingHead.vue';
|
||||||
|
import Dome from 'src/components/DomeLight.vue';
|
||||||
|
import { ref } from 'vue';
|
||||||
|
const tab = ref('movingHead');
|
||||||
</script>
|
</script>
|
||||||
|
@@ -1,18 +1,22 @@
|
|||||||
import type { Response } from 'src/models/Response';
|
import type { Response } from 'src/models/Response';
|
||||||
import type { Publish } from 'src/models/Publish';
|
import type { Publish } from 'src/models/Publish';
|
||||||
import type { Request } from 'src/models/Request';
|
import type { Request } from 'src/models/Request';
|
||||||
import { subs, buildTree, dbmData } from 'src/composables/dbmTree';
|
import type { QVueGlobals } from 'quasar';
|
||||||
import { onBeforeUnmount, ref } from 'vue';
|
import {
|
||||||
import { useQuasar } from 'quasar';
|
getAllSubscriptions,
|
||||||
|
getSubscriptionsByPath,
|
||||||
|
buildTree,
|
||||||
|
dbmData,
|
||||||
|
} from 'src/composables/dbmTree';
|
||||||
|
import { ref, reactive } from 'vue';
|
||||||
|
|
||||||
const pendingResponses = new Map<string, (data: Response | undefined) => void>();
|
const pendingResponses = new Map<string, (data: Response | undefined) => void>();
|
||||||
|
export const lastKnownValues = reactive(new Map<string, string>());
|
||||||
|
|
||||||
let socket: WebSocket | null = null;
|
export let socket: WebSocket | null = null;
|
||||||
const isConnected = ref(false);
|
const isConnected = ref(false);
|
||||||
|
|
||||||
export function useWebSocket(url: string) {
|
export function initWebSocket(url: string, $q?: QVueGlobals) {
|
||||||
const $q = useQuasar();
|
|
||||||
|
|
||||||
const connect = () => {
|
const connect = () => {
|
||||||
socket = new WebSocket(url);
|
socket = new WebSocket(url);
|
||||||
|
|
||||||
@@ -22,22 +26,24 @@ export function useWebSocket(url: string) {
|
|||||||
};
|
};
|
||||||
socket.onclose = () => {
|
socket.onclose = () => {
|
||||||
isConnected.value = false;
|
isConnected.value = false;
|
||||||
$q.notify({
|
console.log('WebSocket disconnected');
|
||||||
|
$q?.notify({
|
||||||
message: 'WebSocket disconnected',
|
message: 'WebSocket disconnected',
|
||||||
color: 'orange',
|
color: 'orange',
|
||||||
position: 'bottom-right',
|
position: 'bottom-right',
|
||||||
icon: 'warning',
|
icon: 'warning',
|
||||||
timeout: 5000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
socket.onerror = (err) => {
|
socket.onerror = (err) => {
|
||||||
|
console.log(`WebSocket error: ${err.type}`);
|
||||||
isConnected.value = false;
|
isConnected.value = false;
|
||||||
$q.notify({
|
$q?.notify({
|
||||||
message: `WebSocket error: ${err.type}`,
|
message: `WebSocket error: ${err.type}`,
|
||||||
color: 'red',
|
color: 'red',
|
||||||
position: 'bottom-right',
|
position: 'bottom-right',
|
||||||
icon: 'error',
|
icon: 'error',
|
||||||
timeout: 5000,
|
timeout: 10000,
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
socket.onmessage = (event) => {
|
socket.onmessage = (event) => {
|
||||||
@@ -47,16 +53,38 @@ export function useWebSocket(url: string) {
|
|||||||
if (id && pendingResponses.has(id)) {
|
if (id && pendingResponses.has(id)) {
|
||||||
pendingResponses.get(id)?.(message); // resolve the promise
|
pendingResponses.get(id)?.(message); // resolve the promise
|
||||||
pendingResponses.delete(id);
|
pendingResponses.delete(id);
|
||||||
} else if (message.publish) {
|
return;
|
||||||
message.publish.forEach((pub: Publish) => {
|
}
|
||||||
const target = subs.value.find((s) => s.path === pub.path);
|
|
||||||
if (target) {
|
if (message.publish) {
|
||||||
target.value = pub.value ?? '';
|
let changed = false;
|
||||||
dbmData.value = buildTree(subs.value);
|
|
||||||
|
(message.publish as Publish[]).forEach((pub) => {
|
||||||
|
const path = pub.path;
|
||||||
|
const value = pub.value ?? '';
|
||||||
|
|
||||||
|
if (path === undefined) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const oldValue = lastKnownValues.get(path);
|
||||||
|
if (oldValue !== value) {
|
||||||
|
lastKnownValues.set(path, value); // this is now reactive
|
||||||
|
|
||||||
|
const existing = getSubscriptionsByPath(path);
|
||||||
|
if (existing) {
|
||||||
|
existing.value = value;
|
||||||
|
} else {
|
||||||
|
getAllSubscriptions().push({ path, value, uuid: pub.uuid });
|
||||||
|
}
|
||||||
|
|
||||||
|
changed = true;
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
} else {
|
|
||||||
console.warn('Unmatched message:', message);
|
if (changed) {
|
||||||
|
dbmData.value = buildTree(getAllSubscriptions()); // rebuild reactive tree
|
||||||
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
};
|
};
|
||||||
@@ -67,13 +95,8 @@ export function useWebSocket(url: string) {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
onBeforeUnmount(() => {
|
|
||||||
close();
|
|
||||||
});
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
connect,
|
connect,
|
||||||
send,
|
|
||||||
close,
|
close,
|
||||||
socket,
|
socket,
|
||||||
};
|
};
|
||||||
@@ -102,13 +125,12 @@ function waitForSocketConnection(): Promise<void> {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
function send(data: Request): Promise<Response | undefined> {
|
export function send(data: Request): Promise<Response | undefined> {
|
||||||
const id = generateId();
|
const id = generateId();
|
||||||
const payload = { ...data, id };
|
const payload = { ...data, id };
|
||||||
|
|
||||||
return new Promise((resolve) => {
|
return new Promise((resolve) => {
|
||||||
pendingResponses.set(id, resolve);
|
pendingResponses.set(id, resolve);
|
||||||
|
|
||||||
waitForSocketConnection()
|
waitForSocketConnection()
|
||||||
.then(() => {
|
.then(() => {
|
||||||
socket?.send(JSON.stringify(payload));
|
socket?.send(JSON.stringify(payload));
|
||||||
@@ -122,5 +144,5 @@ function send(data: Request): Promise<Response | undefined> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
function generateId(): string {
|
function generateId(): string {
|
||||||
return Math.random().toString(36).substr(2, 9); // simple unique ID
|
return Math.random().toString(36).substring(2, 9); // simple unique ID
|
||||||
}
|
}
|
Reference in New Issue
Block a user