added panel for lighting - added and tested functionality for shading control

This commit is contained in:
0xEmm 2024-12-09 21:23:43 +01:00
parent d42b296bae
commit ec9c2e818d
4 changed files with 122 additions and 7 deletions

View file

@ -34,5 +34,5 @@
- `set` - set the power status (`0` or `1`)
- `/firanki/`
- `status` - `STATIONARY`, `MOVING_UP`, `MOVING_DOWN`
- `command` - `NONE`, `MOVE_UP`, `MOVE_DOWN`
- `status` - `STOPPED`, `MOVING_UP`, `MOVING_DOWN`
- `move` - `STOP`, `MOVE_UP`, `MOVE_DOWN`

View file

@ -4,6 +4,7 @@ import MainPage from './components/pages/MainPage.vue';
import ProjManualPage from './components/pages/ProjManualPage.vue';
import VerticalTabs from './components/tabs/VerticalTabs.vue';
import Tab from './components/tabs/Tab.vue';
import LightingPage from './components/pages/LightingPage.vue';
let urlParams = new URLSearchParams(window.location.search);
@ -27,7 +28,8 @@ const pageNum = ref(0) // TODO spremen na 0
<Tab @click="pageNum=0" :selected="pageNum==0">Priprava</Tab>
<Tab @click="pageNum=1" :selected="pageNum==1">Video</Tab>
<Tab @click="pageNum=2" :selected="pageNum==2">Zvok</Tab>
<Tab @click="pageNum=3" :selected="pageNum==3">Servis</Tab>
<Tab @click="pageNum=3" :selected="pageNum==3">Lučke</Tab>
<Tab @click="pageNum=4" :selected="pageNum==4">Servis</Tab>
</VerticalTabs>
<small>turbo odličen super mega kontrol panel</small>
</header>
@ -36,6 +38,7 @@ const pageNum = ref(0) // TODO spremen na 0
<MainPage v-if="pageNum == 0" />
<ProjManualPage v-else-if="pageNum == 1" :room="currentRoom" />
<LightingPage v-else-if="pageNum == 3" :room="currentRoom"/>
</main>
</div>
</template>

View file

@ -0,0 +1,112 @@
<script setup lang="ts">
//import HelloWorld from './components/HelloWorld.vue'
//import TheWelcome from './components/TheWelcome.vue'
import {ref, onMounted, reactive } from 'vue'
import { $mqtt } from 'vue-paho-mqtt'
import DownIcon from '../icons/DownIcon.vue';
import UpIcon from '../icons/UpIcon.vue';
const props = defineProps({
room: String,
position: String
})
const topicstrs = [ //TODO everything else
props.room + '/projectors/' + props.position + 'platno/status',
props.room + '/projectors/' + props.position + 'platno/status',
]
const subscriptions =
topicstrs.map(topic => {
// console.log('subbing to', topic)
$mqtt.subscribe(topic, (msg) => {
// console.log('received:', topic, msg)
handleIncomingMQTT(topic, msg)
})
})
function handleIncomingMQTT(topic: string, msg: string) {
console.log('Received on', topic, 'with message', msg)
if (topic.includes('status')) {
//console.log(topic.split('/'))
let typ = topic.split('/')[4]
handlePlatnoStatus(msg)
}
}
enum firankState {
UP,
DOWN,
MOVING,
STOPPED
}
const firankStatus = ref(firankState.STOPPED)
function handlePlatnoStatus(msg: string) {
console.log('handling status')
//console.log(projStatus)
let newState: firankState
switch (msg) {
case "UP":
newState = firankState.UP
break
case "DOWN":
newState = firankState.DOWN
break
case "MOVING":
newState = firankState.MOVING
break
default:
newState = firankState.STOPPED
break
}
firankStatus.value = newState
}
onMounted(() => {
// console.log('test')
//$mqtt.publish('peepee', 'poopoo', 'Qr') // dela
})
function publishMQTTMsg(topic: string, msg: string) {
//msg = msg.toString()
console.log('Sending to [', topic, '] with message [', msg, ']')
$mqtt.publish(topic, msg, 'Qr') //todo refactor to 1 or 0 maybe
console.log('sent')
}
const publishPrefix = ref(props.room + '/firanki/')
</script>
<template>
<div style="display: flex; gap: 1rem">
</div>
<div style="display:flex; gap: 1rem">
<div>
<h4>Firanki</h4>
<button
@mousedown="publishMQTTMsg(publishPrefix + 'move', 'MOVE_UP')"
@mouseup="publishMQTTMsg(publishPrefix + 'move', 'STOP')" >
<UpIcon /></button>
<button
@mousedown="publishMQTTMsg(publishPrefix + 'move', 'MOVE_DOWN')"
@mouseup="publishMQTTMsg(publishPrefix + 'move', 'STOP')" >
<DownIcon /></button>
</div>
</div>
</template>
<style scoped>
.disabled {
opacity: .8;
pointer-events: none;
}
button {
padding: 1rem;
width: 50%;
}
</style>

View file

@ -89,8 +89,8 @@ async def handleTseSencilo(client, cmd):
rel = RelayState(shades_mapping['dol'], True)
await executeAndPublish(client, topicPub, "MOVING_DOWN", rel)
else:
await executeAndPublish(client, topicPub, "STATIONARY", RelayState(shades_mapping['gor'], False))
await executeAndPublish(client, topicPub, "STATIONARY", RelayState(shades_mapping['dol'], False))
await executeAndPublish(client, topicPub, "STOPPED", RelayState(shades_mapping['gor'], False))
await executeAndPublish(client, topicPub, "STOPPED", RelayState(shades_mapping['dol'], False))
platnoBckgdMoving = False # mucho importante variable prav zares dedoles
@ -176,8 +176,8 @@ async def task_command2serial(controlClient: aiomqtt.Client):
systype = msgTopic[2]
await handleTsePower(controlClient, systype, cmnd)
elif mesg.topic.matches(f'{room}/firanki/command/#'):
await handleTseSencilo(topicVal, controlClient, cmnd)
elif mesg.topic.matches(f'{room}/firanki/move/#'):
await handleTseSencilo(controlClient, cmnd)
else:
continue