From cbd7d02ad8f7791043ffe4a6f06a36b641743740 Mon Sep 17 00:00:00 2001 From: Jakob Gegeniger Date: Wed, 9 Sep 2026 22:42:06 +0200 Subject: [PATCH] new features: Mute, and different sounds --- makefile | 2 + src/router/index.ts | 6 + src/services/mqtt.ts | 72 ++++++++--- src/views/Home.vue | 50 +++++++- src/views/Maintenance.vue | 165 ++++++++++++++++++++---- src/views/Setup.vue | 259 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 506 insertions(+), 48 deletions(-) create mode 100644 makefile create mode 100644 src/views/Setup.vue diff --git a/makefile b/makefile new file mode 100644 index 0000000..83193c1 --- /dev/null +++ b/makefile @@ -0,0 +1,2 @@ +serve: + npm run dev \ No newline at end of file diff --git a/src/router/index.ts b/src/router/index.ts index e326a85..0f97b47 100644 --- a/src/router/index.ts +++ b/src/router/index.ts @@ -1,6 +1,7 @@ import { createRouter, createWebHistory } from 'vue-router' import Home from '../views/Home.vue' import Maintenance from '../views/Maintenance.vue' +import Setup from '../views/Setup.vue' import Players from '../views/Players.vue' import Start from '../views/Start.vue' import Text from '../views/Text.vue' @@ -28,6 +29,11 @@ const routes: any[] = [ name: 'TextDirect', component: Text }, + { + path: '/setup', + name: 'Setup', + component: Setup + }, { path: '/maintenance', name: 'Maintenance', diff --git a/src/services/mqtt.ts b/src/services/mqtt.ts index 302c96e..cd52ad5 100644 --- a/src/services/mqtt.ts +++ b/src/services/mqtt.ts @@ -30,11 +30,11 @@ export function getMqttClient(): any { export function publishStartHit(): void { const tempClient = getClient() - const mqttTopic = mqttTopicRoot + 'run' + const mqttTopic = mqttTopicRoot + 'set' tempClient.on('connect', () => { tempClient.publish(mqttTopic, mqttMessage, { qos: 1 }, () => { - + }) }) @@ -71,28 +71,28 @@ export function subscribeToIntTopic(callback: (response: IntTopicResponse) => vo } interface IntTopicResponse { - version: string mode: number sE: boolean sS: boolean sP: boolean lE: boolean + snd: boolean + vol: number + delay: number } export function parseIntMessage(message: string): IntTopicResponse { const result: IntTopicResponse = { - version: '', mode: 0, sE: false, // EndPoint sS: false, // StartPoint sP: false, // PullSensor - lE: false // LatchEnable + lE: false, // LatchEnable + snd: false, // LatchEnable + vol: 0, // Volumen + delay: 0, // Delay } - const versionMatch = message.match(/T([\d.]+)/) - if (versionMatch) { - result.version = versionMatch[1] - } const modeMatch = message.match(/Mode=(\d+)/) if (modeMatch) { result.mode = parseInt(modeMatch[1], 10) @@ -113,19 +113,33 @@ export function parseIntMessage(message: string): IntTopicResponse { if (lEMatch) { result.lE = lEMatch[1] === 'true' } + const soundMute = message.match(/snd:(true|false)/) + if (soundMute) { + result.snd = soundMute[1] === 'true' + } + const volMatch = message.match(/v:(\d+)/) + if (volMatch) { + result.vol = Number(volMatch[1]) + } + const delayMatch = message.match(/pD:(\d+)/) + if (delayMatch) { + result.delay = Number(delayMatch[1]) + } return result } export function enterMaintananceMode( - callback: (sE: number, sS: number, sP: number, lE: number) => void) + statCallback: (snd:number, sE: number, sS: number, sP: number, lE: number, vol: number, delay: number) => void, + verCallback: (ver: string) => void) : mqtt.MqttClient { const client = getClient() - const mqttTopic = mqttTopicRoot + 'stat' + const statMqttTopic = mqttTopicRoot + 'stat' + const verMqttTopic = mqttTopicRoot + 'ver' client.on('connect', () => { - publicMaintananceCmd(client, "SetMaintanance") - client.subscribe(mqttTopic, { qos: 1 }, (error) => { + publishCmd(client, "SetMaintanance") + client.subscribe(statMqttTopic, { qos: 1 }, (error) => { if (error) { console.error('MQTT subscribe failed:', error) } @@ -137,14 +151,22 @@ export function enterMaintananceMode( }) client.on('message', (topic: string, message: Buffer) => { - if (topic === mqttTopic) { + console.log(`MQTT: Got ${topic}: ${message}`) + if (topic === statMqttTopic) { const messageStr = message.toString() - const status = parseIntMessage(message.toString()) + const status = parseIntMessage(messageStr) + const snd = status.snd ? 1 : 0 const sE = status.sE ? 1 : 0 const sS = status.sS ? 1 : 0 const sP = status.sP ? 1 : 0 const lE = status.lE ? 1 : 0 - callback(sE, sS, sP, lE) + const vol = status.vol + const delay = status.delay + statCallback(snd, sE, sS, sP, lE, vol, delay) + } + if (topic === verMqttTopic) { + const messageStr = message.toString() + verCallback(messageStr) } }) @@ -152,7 +174,7 @@ export function enterMaintananceMode( } export function exitMaintananceMode(client: mqtt.MqttClient): void { - publicMaintananceCmd(client, "Exit") + publishCmd(client, "Exit") const mqttTopic = mqttTopicRoot + 'stat' client.unsubscribe(mqttTopic, (error) => { if (error) { @@ -162,10 +184,20 @@ export function exitMaintananceMode(client: mqtt.MqttClient): void { client.end() } -export function publicMaintananceCmd(client: mqtt.MqttClient, message : string): void { - const mqttTopic = mqttTopicRoot + 'run' +export function publishCmd(client: mqtt.MqttClient, message: string): void { + const mqttTopic = mqttTopicRoot + 'cfg' console.log(`MQTT: Publish ${mqttTopic}: ${message}`) - client.publish(mqttTopic, message, { qos: 1 }, (error) => { + client.publish(mqttTopic, message, { qos: 2 }, (error) => { + if (error) { + console.error('MQTT publish failed:', error) + } + }) +} + +export function publishQueryVersionCmd(client: mqtt.MqttClient) { + const mqttTopic = mqttTopicRoot + 'ver' + console.log(`MQTT: Publish ${mqttTopic}`) + client.publish(mqttTopic, "", { qos: 1 }, (error) => { if (error) { console.error('MQTT publish failed:', error) } diff --git a/src/views/Home.vue b/src/views/Home.vue index 9a6126d..5cefe56 100644 --- a/src/views/Home.vue +++ b/src/views/Home.vue @@ -7,19 +7,34 @@

Version

-

1.0.0

+

0.8.0

Service Hotline

-

+1 800-123-4567

+

+49 176 64036128

- + + @@ -27,3 +42,28 @@ + + + diff --git a/src/views/Maintenance.vue b/src/views/Maintenance.vue index 9578905..7fd8580 100644 --- a/src/views/Maintenance.vue +++ b/src/views/Maintenance.vue @@ -4,16 +4,17 @@

Sword Status

+

Inputs

-
- EndSens: - {{ endSensStatus }} -
StartSens: {{ startSensStatus }}
+
+ EndSens: + {{ endSensStatus }} +
PullSens: {{ pullSensStatus }} @@ -29,14 +30,61 @@
+
+
+ +

Sound

+
+
+ Sound Active: + {{ soundStatus }} +
+
+
+
+ + +
+
+ +

Sounds

+
+
-

Status

+

Setup

+
+
+
+
+ Volume + {{ volume }} +
+ +
+
+
+ Promo Delay + {{ promoDelay }} +
+ +
+
+
+

Info

+
+
+ Version: + {{ version }} +
+

Game Views

@@ -55,61 +103,97 @@ + +