new features: Mute, and different sounds
This commit is contained in:
1 parent
81ddf048ca
commit
cbd7d02ad8
6 files changed
+506
-48
No files matched your search
@@ -0,0 +1,259 @@
|
||||
<template>
|
||||
<main class="app">
|
||||
<h1>Setup View</h1>
|
||||
|
||||
<h2>Setup</h2>
|
||||
<div class="status-container">
|
||||
<div class="status-frame setup-frame">
|
||||
<div class="slider-item">
|
||||
<div class="slider-header">
|
||||
<span class="slider-label">Volume</span>
|
||||
<span class="slider-value">{{ volume }}</span>
|
||||
</div>
|
||||
<input class="slider-input" type="range" min="0" max="100" step="1" v-model.number="volume"
|
||||
@input="handleVolume" />
|
||||
</div>
|
||||
<div class="slider-item">
|
||||
<div class="slider-header">
|
||||
<span class="slider-label">Promo Delay</span>
|
||||
<span class="slider-value">{{ promoDelay }}</span>
|
||||
</div>
|
||||
<input class="slider-input" type="range" min="30" max="300" step="1" v-model.number="promoDelay"
|
||||
@input="handlePromoDelay" />
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Sound</h2>
|
||||
<div class="status-frame">
|
||||
<div class="status-item" :class="{ active: soundStatus === 1 }">
|
||||
<span class="status-label">Sound Active:</span>
|
||||
<span class="status-value">{{ soundStatus }}</span>
|
||||
</div>
|
||||
</div>
|
||||
<div class="status-frame">
|
||||
<div class="control-buttons">
|
||||
<button @click="handleMute" class="btn-lock">Mute</button>
|
||||
<button @click="handleUnMute" class="btn-unlock">Un-Mute</button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<h2>Sword Status</h2>
|
||||
<div class="status-container">
|
||||
<div class="status-frame">
|
||||
<div class="status-item" :class="{ active: endSensStatus === 1 }">
|
||||
<span class="status-label">Sword Present:</span>
|
||||
<span class="status-value">{{ endSensStatus }}</span>
|
||||
</div>
|
||||
<div class="status-item" :class="{ active: lockStatus === 1 }">
|
||||
<span class="status-label">Lock Active:</span>
|
||||
<span class="status-value">{{ lockStatus }}</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</main>
|
||||
</template>
|
||||
|
||||
<script setup lang="ts">
|
||||
import { enterMaintananceMode, exitMaintananceMode, publishCmd } from '../services/mqtt'
|
||||
import { useRoute } from 'vue-router'
|
||||
import { ref, onMounted, onUnmounted } from 'vue'
|
||||
import type mqtt from 'mqtt'
|
||||
|
||||
const route = useRoute()
|
||||
|
||||
const version = ref<string>()
|
||||
const endSensStatus = ref<number>(0)
|
||||
const startSensStatus = ref<number>(0)
|
||||
const pullSensStatus = ref<number>(0)
|
||||
const lockStatus = ref<number>(0)
|
||||
const soundStatus = ref<number>(0)
|
||||
const volume = ref<number>(50)
|
||||
const promoDelay = ref<number>(180)
|
||||
|
||||
let mqttClient: mqtt.MqttClient | null = null
|
||||
|
||||
function cleanup(): void {
|
||||
if (mqttClient) {
|
||||
exitMaintananceMode(mqttClient)
|
||||
}
|
||||
}
|
||||
|
||||
function handleMute(): void {
|
||||
if (mqttClient) {
|
||||
publishCmd(mqttClient, "mute")
|
||||
}
|
||||
}
|
||||
|
||||
function handleUnMute(): void {
|
||||
if (mqttClient) {
|
||||
publishCmd(mqttClient, "unmute")
|
||||
}
|
||||
}
|
||||
|
||||
function handleVolume(): void {
|
||||
if (mqttClient) {
|
||||
publishCmd(mqttClient, `volume:${volume.value}`)
|
||||
}
|
||||
}
|
||||
|
||||
function handlePromoDelay(): void {
|
||||
if (mqttClient) {
|
||||
publishCmd(mqttClient, `promoDelay:${promoDelay.value}`)
|
||||
}
|
||||
}
|
||||
|
||||
function handlePlayX(sound: number): void {
|
||||
if (mqttClient) {
|
||||
if (sound === 1) {
|
||||
publishCmd(mqttClient, "playSound:Promo")
|
||||
} else if (sound === 2) {
|
||||
publishCmd(mqttClient, "playSound:Deny")
|
||||
} else if (sound === 3) {
|
||||
publishCmd(mqttClient, "playSound:Chosen")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
onMounted(() => {
|
||||
mqttClient = enterMaintananceMode(
|
||||
(sound, endSens, startSens, pullSens, lock, vol, delay) => {
|
||||
endSensStatus.value = endSens
|
||||
startSensStatus.value = startSens
|
||||
pullSensStatus.value = pullSens
|
||||
lockStatus.value = lock
|
||||
soundStatus.value = sound
|
||||
volume.value = vol
|
||||
promoDelay.value = delay
|
||||
},
|
||||
(ver) => {})
|
||||
window.addEventListener('beforeunload', cleanup)
|
||||
if (mqttClient) {
|
||||
publishCmd(mqttClient, `promoDelay:${promoDelay.value}`)
|
||||
}
|
||||
|
||||
})
|
||||
|
||||
onUnmounted(() => {
|
||||
window.removeEventListener('beforeunload', cleanup)
|
||||
cleanup()
|
||||
})
|
||||
</script>
|
||||
|
||||
<style scoped>
|
||||
.status-container {
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.status-frame {
|
||||
border: 2px solid #d1d5db;
|
||||
border-radius: 8px;
|
||||
padding: 16px;
|
||||
background: #f9fafb;
|
||||
margin-bottom: 16px;
|
||||
display: grid;
|
||||
grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
|
||||
gap: 12px;
|
||||
}
|
||||
|
||||
.setup-frame {
|
||||
grid-template-columns: 1fr;
|
||||
gap: 20px;
|
||||
}
|
||||
|
||||
.slider-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
gap: 8px;
|
||||
}
|
||||
|
||||
.slider-header {
|
||||
display: flex;
|
||||
justify-content: space-between;
|
||||
align-items: baseline;
|
||||
}
|
||||
|
||||
.slider-label {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
color: #6b7280;
|
||||
}
|
||||
|
||||
.slider-value {
|
||||
font-size: 18px;
|
||||
font-weight: 600;
|
||||
color: #111827;
|
||||
}
|
||||
|
||||
.slider-input {
|
||||
width: 100%;
|
||||
cursor: pointer;
|
||||
}
|
||||
|
||||
.status-item {
|
||||
display: flex;
|
||||
flex-direction: column;
|
||||
align-items: center;
|
||||
justify-content: center;
|
||||
padding: 12px;
|
||||
border-radius: 6px;
|
||||
background: #e5e7eb;
|
||||
color: #6b7280;
|
||||
transition: background 0.3s, color 0.3s;
|
||||
font-weight: 500;
|
||||
}
|
||||
|
||||
.status-item.active {
|
||||
background: #10b981;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.status-label {
|
||||
font-size: 12px;
|
||||
text-transform: uppercase;
|
||||
letter-spacing: 0.05em;
|
||||
opacity: 0.8;
|
||||
}
|
||||
|
||||
.status-value {
|
||||
font-size: 20px;
|
||||
font-weight: 600;
|
||||
margin-top: 4px;
|
||||
}
|
||||
|
||||
.control-buttons {
|
||||
display: flex;
|
||||
gap: 12px;
|
||||
margin-bottom: 20px;
|
||||
}
|
||||
|
||||
.btn-lock,
|
||||
.btn-unlock {
|
||||
padding: 10px 20px;
|
||||
border: none;
|
||||
border-radius: 6px;
|
||||
font-weight: 500;
|
||||
cursor: pointer;
|
||||
transition: background 0.2s, color 0.2s;
|
||||
}
|
||||
|
||||
.btn-lock {
|
||||
background: #111827;
|
||||
color: #ffffff;
|
||||
}
|
||||
|
||||
.btn-lock:hover {
|
||||
background: #1f2937;
|
||||
}
|
||||
|
||||
.btn-unlock {
|
||||
background: #e5e7eb;
|
||||
color: #111827;
|
||||
border: 1px solid #d1d5db;
|
||||
}
|
||||
|
||||
.btn-unlock:hover {
|
||||
background: #d1d5db;
|
||||
}
|
||||
</style>
|
||||
Reference in new issue
Block a user