added main panel controls that react accordingly to status, TODO: cleanup, add status to lift script

This commit is contained in:
0xEmm 2024-12-11 21:13:26 +01:00
parent 936efa730d
commit 34e8fc9388
9 changed files with 245 additions and 41 deletions

View file

@ -70,9 +70,9 @@ async def barco_telnet_query_status(writer, select: str):
for val in cmdMap.values():
print(f"Querying Barco {select} with: [{val}?]")
writer.write(f"[{val}?]" + '\r\n') # TODO test if funny CRLF necessary (it probably gets ignored)
await asyncio.sleep(1) # sleep between writes necessary, otherwise it gets confused.
await asyncio.sleep(0.2) # sleep between writes necessary, otherwise it gets confused.
# simultaneous commands from control could break this? TODO fix later
await asyncio.sleep(10) # TODO find appropriate period
await asyncio.sleep(30) # TODO find appropriate period
# async def shell(reader, writer):
@ -85,10 +85,10 @@ async def barco_telnet_query_status(writer, select: str):
async def main():
#conf = toml.load('config.toml')
mainBarcoIP = conf[gethostname()]['projektor_glavni']
sideBarcoIP = conf[gethostname()]['projektor_stranski']
mainReader, mainWriter = await telnetlib3.open_connection(mainBarcoIP, 3023)
sideReader, sideWriter = await telnetlib3.open_connection(sideBarcoIP, 3023)
# mainBarcoIP = conf[gethostname()]['projektor_glavni']
# sideBarcoIP = conf[gethostname()]['projektor_stranski']
mainReader, mainWriter = await telnetlib3.open_connection('localhost', 3023)
sideReader, sideWriter = await telnetlib3.open_connection('localhost', 3024)
async with aiomqtt.Client('localhost', 1883) as client:
task_status_query_main = asyncio.create_task(barco_telnet_query_status(mainWriter, 'glavni'))
task_status_reader_main = asyncio.create_task(barco_telnet_read_status(client, mainReader, 'glavni'))
@ -103,13 +103,13 @@ async def main():
### fuj to, ne tk delat
if __name__ == '__main__':
# if __name__ == '__main__':
loop = asyncio.get_event_loop()
coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell)
coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell)
# coro = telnetlib3.open_connection('localhost', 1234, shell=shell)
reader, writer = loop.run_until_complete(coro)
loop.run_until_complete(writer.protocol.waiter_closed)
# loop = asyncio.get_event_loop()
# coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell)
# coro = telnetlib3.open_connection(mainBarcoIP, 3023, shell=shell)
# # coro = telnetlib3.open_connection('localhost', 1234, shell=shell)
# reader, writer = loop.run_until_complete(coro)
# loop.run_until_complete(writer.protocol.waiter_closed)
asyncio.run(main())

View file

@ -1,3 +1,3 @@
VITE_MQTT_HOST=p01malina.local
VITE_MQTT_HOST=localhost #p01malina.local
VITE_MQTT_PORT=8080
VITE_MQTT_SSL=false

View file

@ -1,7 +1,7 @@
<script setup lang="ts">
import { ref, onMounted } from 'vue'
import MainPage from './components/pages/MainPage.vue';
import ProjManualPage from './components/pages/ProjManualPage.vue';
import VideoPage from './components/pages/VideoPage.vue';
import VerticalTabs from './components/tabs/VerticalTabs.vue';
import Tab from './components/tabs/Tab.vue';
import LightingPage from './components/pages/LightingPage.vue';
@ -9,39 +9,68 @@ import ServisPage from './components/pages/ServisPage.vue';
let urlParams = new URLSearchParams(window.location.search);
const currentRoom = ref(urlParams.get('room') || 'p01')
const currentRoom = ref(urlParams.get('room') || 'none') // if no param specified
// should also check if valid room parameter ampak se ne mudi
// TODO does this make sense al se naj naprej defaulta kr na p01?
const pageNum = ref(0) // TODO spremen na 0
const pageNum = ref(0)
const srvcUnlocked = ref(false)
const showPinPopup = ref(false)
function openPinDiag() {
}
function closePinDiag() {
}
function unlockServicePage() {
showPinPopup.value = true
while (true) {
if ('' == '') {
srvcUnlocked.value = true
closePinDiag()
break
}
}
}
function lockServicePage() {
srvcUnlocked.value = false
}
</script>
<template>
<div id="wrapper">
<div v-if="currentRoom == 'none'">
<h1>Incorrect or missing room parameter!</h1>
</div>
<div v-else id="wrapper">
<header class="sidebar">
<img class="logo" src="https://fri.uni-lj.si/sites/all/themes/fri_theme/images/fri_logo.png" />
<h1>{{ currentRoom.toUpperCase() }}</h1>
<VerticalTabs id="nav">
<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">Lučke</Tab>
<Tab @click="pageNum=4" :selected="pageNum==4">Servis</Tab>
<Tab @click="pageNum=0; lockServicePage()" :selected="pageNum==0">Priprava</Tab>
<Tab @click="pageNum=1; lockServicePage()" :selected="pageNum==1">Video</Tab>
<Tab @click="pageNum=2; lockServicePage()" :selected="pageNum==2">Audio</Tab>
<Tab @click="pageNum=3; lockServicePage()" :selected="pageNum==3">Lučke</Tab>
<Tab @click="pageNum=4; unlockServicePage()" :selected="pageNum==4">Servis</Tab>
</VerticalTabs>
<small>turbo odličen super mega kontrol panel</small>
<large style="display: flex;">turbo odličen super mega kontrol panel</large>
</header>
<main>
<MainPage v-if="pageNum == 0" />
<ProjManualPage v-else-if="pageNum == 1" :room="currentRoom" />
<MainPage v-if="pageNum == 0" :room="currentRoom" />
<VideoPage v-else-if="pageNum == 1" :room="currentRoom" />
<LightingPage v-else-if="pageNum == 3" :room="currentRoom" />
<ServisPage v-else-if="pageNum == 4" :room="currentRoom" />
<ServisPage v-else-if="pageNum == 4 && srvcUnlocked" :room="currentRoom" />
</main>
</div>
</template>

View file

@ -0,0 +1,139 @@
<script setup lang="ts">
//import HelloWorld from './components/HelloWorld.vue'
//import TheWelcome from './components/TheWelcome.vue'
import { ref, onMounted, reactive, watch } from 'vue'
import { $mqtt } from 'vue-paho-mqtt'
const props = defineProps({
room: String,
position: String,
})
const topicstrs = [ //TODO everything else
props.room + '/projectors/' + props.position + '/status/power',
props.room + '/projectors/' + props.position + '/platno/status',
props.room + '/projectors/' + props.position + '/lift/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)
let typ: string = ''
if (topic.includes('power')) {
typ = topic.split('/')[4]
} else if (topic.includes('platno')) {
typ = topic.split('/')[3]
} else if (topic.includes('lift')) {
typ = topic.split('/')[3]
} else { return }
handleIncStatus(typ, msg)
}
function handleIncStatus(typ: string, msg: string) {
console.log('handling status')
//console.log(projStatus)
if (typ == 'power') { roomStatus.proj_power = msg == '1' }
else if (typ == 'platno') { roomStatus.platno_state = msg }
else if (typ == 'lift') { roomStatus.lift_state = msg }
}
onMounted(() => {
// console.log('test')
//$mqtt.publish('peepee', 'poopoo', 'Qr') // dela
})
function sleep(ms: number) {
return new Promise(resolve => {
setTimeout(resolve, ms)
})
}
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')
}
async function setLecture(pos?: String) {
if (!pos) { return }
let topicPref = props.room + "/projektorji/" + props.position + "/"
let command = '0'
if (roomState.value == 0) {
command = '1'
} else if (roomState.value == 1) {
command = '0'
} else { return }
publishMQTTMsg((topicPref + 'set/power'), command)
publishMQTTMsg((topicPref + 'platno/goto'), command == '1' ? 'DOWN' : 'UP')
publishMQTTMsg((topicPref + 'lift/move/' + (command == '1' ? 'down' : 'up') ), command)
await sleep(500)
publishMQTTMsg((topicPref + 'platno/goto'), 'STOP')
publishMQTTMsg((topicPref + 'lift/move/' + (command == '1' ? 'down' : 'up') ), '0')
}
//TODO organize better, binds, etc.
const roomStatus = reactive({
proj_power: false,
lift_state: 'UNKNOWN',
platno_state: 'UNKNOWN',
})
const roomState = ref(0)
// OFF -> 0; ON -> 1; IN BETWEEN -> 2
watch (roomStatus, (_oldState, _newState) => {
let allOn = _newState.proj_power && _newState.platno_state == 'DOWN' && _newState.lift_state == 'DOWN'
let allOff = !_newState.proj_power && _newState.platno_state == 'UP' && _newState.lift_state == 'UP'
if (allOn) {
roomState.value = 1
} else if (allOff) {
roomState.value = 0
} else {
roomState.value = 2
}
})
</script>
<template>
<div>
<!-- TODO lepš -->
<div>
<h3 v-if="roomState == 1">AKTIVNO</h3>
<h3 v-else-if="roomState == 0">V PRIPRAVLJENOSTI</h3>
<h3 v-else-if="roomState == 2">POČAKAJTE</h3>
<h3 v-else="roomState == 1">NAPAKA</h3>
<button style="" @click="setLecture(props.position)" :disabled="roomState == 2">
{{ roomState == 1 ? 'UGASNI' : (roomState == 0 ? 'PRIŽGI' : '...') }}
</button>
</div>
<h6>Projektor status: {{ roomStatus.proj_power ? "ON" : "OFF" }}</h6>
<h6>Platno pozicija: {{ roomStatus.platno_state }}</h6>
<h6>Dvigalo pozicija: {{ roomStatus.lift_state }}</h6>
</div>
</template>
<style scoped>
.disabled {
opacity: .8;
pointer-events: none;
}
button {
padding: 1rem;
width: 100%;
}
</style>

View file

@ -8,7 +8,8 @@ import UpIcon from './icons/UpIcon.vue';
const props = defineProps({
room: String,
position: String
position: String,
ctrlType: [String, null]
})
const topicstrs = [ //TODO everything else
@ -95,16 +96,16 @@ const platnoStatus = ref(platnoState.UNKNOWN)
@click="publishMQTTMsg(publishPrefix + 'goto', 'UP')"><UpIcon/></button>
<button
@click="publishMQTTMsg(publishPrefix + 'goto', 'DOWN')"><DownIcon/></button>
<div>
<div v-if="props.ctrlType == 'service'">
<h5>Manual control</h5>
<button
@mousedown="publishMQTTMsg(publishPrefix + 'move', 'UP')"
@mouseup="publishMQTTMsg(publishPrefix + 'move', 'STOP')" >
Move up</button>
<UpIcon /></button>
<button
@mousedown="publishMQTTMsg(publishPrefix + 'move', 'DOWN')"
@mouseup="publishMQTTMsg(publishPrefix + 'move', 'STOP')" >
Move down</button>
<DownIcon /></button>
</div>
<!-- </form> -->

View file

@ -6,7 +6,8 @@ import { $mqtt } from 'vue-paho-mqtt'
const props = defineProps({
room: String,
position: String
position: String,
ctrlType: [String, null]
})
const topicstrs = [ //TODO everything else

View file

@ -1,3 +1,35 @@
<script setup lang="ts"></script>
<script setup lang="ts">
import {ref, onMounted, reactive } from 'vue'
import { $mqtt } from 'vue-paho-mqtt'
import Projektor from '../Projektor.vue';
import Platno from '../Platno.vue';
import Lift from '../Lift.vue';
import LectureModule from '../LectureModule.vue';
<template>tukaj pride hecn gumbek za vse prižgat</template>
const props = defineProps({
room: String
})
const _glavni_position = ref('glavni')
const _stranski_position = ref('stranski')
let disableControl = false
let _glavni = ref('glavni')
let _stranski = ref('stranski')
</script>
<template>
<div style="display:flex; gap: 1rem">
<div style="width: 50%;">
<h4>Glavni:</h4>
<LectureModule :room="props.room" :position="_glavni" />
</div>
<div style="width: 50%;">
<h4>Stranski:</h4>
<LectureModule :room="props.room" :position="_stranski" />
</div>
</div>
</template>

View file

@ -6,27 +6,28 @@ import { $mqtt } from 'vue-paho-mqtt'
// import Projektor from '../Projektor.vue'
// import Platno from '../Platno.vue'
import Lift from '../Lift.vue';
import Projektor from '../Projektor.vue';
const props = defineProps({
room: String,
})
const _glavni_position = ref('glavni')
const _stranski_position = ref('stranski')
const _ctrl_type = ref('service')
</script>
<template>
<div style="display: flex; gap: 1rem">
<div>
<Projektor :room="props.room" :position="_glavni_position" :ctrlType="_ctrl_type" />
<Lift :room="props.room" :position="_glavni_position" />
<!-- <Projektor :room="props.room" :position="_glavni_position" /> -->
<!-- <Platno :room="props.room" :position="_glavni_position" /> -->
<Platno :room="props.room" :position="_glavni_position" :ctrlType="_ctrl_type"/>
</div>
<div>
<Projektor :room="props.room" :position="_stranski_position" :ctrlType="_ctrl_type"/>
<Lift :room="props.room" :position="_stranski_position" />
<!-- <Projektor :room="props.room" :position="_stranski_position" /> -->
<!-- <Platno :room="props.room" :position="_stranski_position" /> -->
<Platno :room="props.room" :position="_stranski_position" :ctrlType="_ctrl_type" />
</div>
</div>
</template>

View file

@ -11,6 +11,7 @@ const props = defineProps({
})
const _glavni_position = ref('glavni')
const _stranski_position = ref('stranski')
const _test = ref('test')
</script>
@ -18,7 +19,7 @@ const _stranski_position = ref('stranski')
<div style="display: flex; gap: 1rem">
<div>
<h4>Glavni</h4>
<Projektor :room="props.room" :position="_glavni_position" />
<Projektor :room="props.room" :position="_glavni_position" :ctrl-type="_test" />
<Platno :room="props.room" :position="_glavni_position" />
</div>
<div>