reworked relay controls with i2c relay boards, added lift controls to service panel on frontend
This commit is contained in:
parent
ec9c2e818d
commit
936efa730d
12 changed files with 458 additions and 77 deletions
|
@ -5,7 +5,7 @@ import telnetlib3
|
|||
import toml
|
||||
from socket import gethostname
|
||||
|
||||
mainBarcoIP = 'localhost' #'192.168.192.12'
|
||||
mainBarcoIP = '192.168.192.12'
|
||||
sideBarcoIP = '192.168.192.13'
|
||||
|
||||
# TODO all the checks and stuff
|
||||
|
@ -85,30 +85,31 @@ 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']
|
||||
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)
|
||||
sideReader, sideWriter = await telnetlib3.open_connection(sideBarcoIP, 3023)
|
||||
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'))
|
||||
task_control_main = asyncio.create_task(barco_telnet_command(client, mainWriter, 'glavni'))
|
||||
#task_status_query_side = asyncio.create_task(barco_telnet_query_status(sideWriter, 'stranski'))
|
||||
#task_status_reader_side = asyncio.create_task(barco_telnet_read_status(client, sideReader, 'stranski'))
|
||||
#task_control_side = asyncio.create_task(barco_telnet_command(client, sideWriter, 'stranski'))
|
||||
task_status_query_side = asyncio.create_task(barco_telnet_query_status(sideWriter, 'stranski'))
|
||||
task_status_reader_side = asyncio.create_task(barco_telnet_read_status(client, sideReader, 'stranski'))
|
||||
task_control_side = asyncio.create_task(barco_telnet_command(client, sideWriter, 'stranski'))
|
||||
|
||||
await asyncio.gather(task_status_query_main, task_status_reader_main, task_control_main)#,
|
||||
#task_status_query_side, task_status_reader_side, task_control_side)
|
||||
await asyncio.gather(task_status_query_main, task_status_reader_main, task_control_main,
|
||||
task_status_query_side, task_status_reader_side, task_control_side)
|
||||
|
||||
|
||||
### fuj to, ne tk delat
|
||||
|
||||
# if __name__ == '__main__':
|
||||
if __name__ == '__main__':
|
||||
|
||||
# loop = asyncio.get_event_loop()
|
||||
# #coro = telnetlib3.open_connection('192.168.192.12', 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())
|
|
@ -17,10 +17,12 @@
|
|||
- `/move` - `UP`, `DOWN` or `STOP`
|
||||
- `/goto` - `UP` or `DOWN`
|
||||
- `/lift/`
|
||||
- `up` - 0/1
|
||||
- `down` - 0/1
|
||||
- `service_up` - 0/1
|
||||
- `service_down` - 0/1
|
||||
- `status/` blablbabla
|
||||
- `move/`
|
||||
- `up` - 0/1
|
||||
- `down` - 0/1
|
||||
- `service_up` - 0/1
|
||||
- `service_down` - 0/1
|
||||
|
||||
- `/power/` - Controls power for different parts of the installation
|
||||
- `/master/` - Master power for most hardware in the rack
|
||||
|
@ -35,4 +37,4 @@
|
|||
|
||||
- `/firanki/`
|
||||
- `status` - `STOPPED`, `MOVING_UP`, `MOVING_DOWN`
|
||||
- `move` - `STOP`, `MOVE_UP`, `MOVE_DOWN`
|
||||
- `move` - `STOP`, `MOVE_UP`, `MOVE_DOWN`
|
||||
|
|
BIN
frontend/.DS_Store
vendored
Normal file
BIN
frontend/.DS_Store
vendored
Normal file
Binary file not shown.
|
@ -1,3 +1,3 @@
|
|||
VITE_MQTT_HOST=localhost
|
||||
VITE_MQTT_HOST=p01malina.local
|
||||
VITE_MQTT_PORT=8080
|
||||
VITE_MQTT_SSL=false
|
|
@ -5,6 +5,7 @@ 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';
|
||||
import ServisPage from './components/pages/ServisPage.vue';
|
||||
|
||||
let urlParams = new URLSearchParams(window.location.search);
|
||||
|
||||
|
@ -38,7 +39,9 @@ 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"/>
|
||||
<LightingPage v-else-if="pageNum == 3" :room="currentRoom" />
|
||||
|
||||
<ServisPage v-else-if="pageNum == 4" :room="currentRoom" />
|
||||
</main>
|
||||
</div>
|
||||
</template>
|
||||
|
|
125
frontend/vju_display/src/components/Lift.vue
Normal file
125
frontend/vju_display/src/components/Lift.vue
Normal file
|
@ -0,0 +1,125 @@
|
|||
<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 + 'lift/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)
|
||||
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 + '/projectors/' + props.position + '/lift/')
|
||||
|
||||
|
||||
</script>
|
||||
|
||||
<!--
|
||||
TODO: NE HARDCODANO
|
||||
-->
|
||||
|
||||
<template>
|
||||
<div style="display:flex; gap: 1rem">
|
||||
<div>
|
||||
<h4>Lifti {{ props.position }}</h4>
|
||||
|
||||
<button
|
||||
@mousedown="publishMQTTMsg(publishPrefix + 'move/up', '1')"
|
||||
@mouseup="publishMQTTMsg(publishPrefix + 'move/up', '0')" >
|
||||
<UpIcon /></button>
|
||||
<button
|
||||
@mousedown="publishMQTTMsg(publishPrefix + 'move/down', '1')"
|
||||
@mouseup="publishMQTTMsg(publishPrefix + 'move/down', '0')" >
|
||||
<DownIcon /></button>
|
||||
</div><div>
|
||||
<h4>Servis lifti {{ props.position }}</h4>
|
||||
|
||||
<button
|
||||
@mousedown="publishMQTTMsg(publishPrefix + 'move/service_up', '1')"
|
||||
@mouseup="publishMQTTMsg(publishPrefix + 'move/service_up', '0')" >
|
||||
<UpIcon /></button>
|
||||
<button
|
||||
@mousedown="publishMQTTMsg(publishPrefix + 'move/service_down', '1')"
|
||||
@mouseup="publishMQTTMsg(publishPrefix + 'move/service_down', '0')" >
|
||||
<DownIcon /></button>
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
.disabled {
|
||||
opacity: .8;
|
||||
pointer-events: none;
|
||||
}
|
||||
button {
|
||||
padding: 1rem;
|
||||
margin: 0.1rem;
|
||||
width: 45%;
|
||||
}
|
||||
</style>
|
|
@ -107,6 +107,7 @@ const publishPrefix = ref(props.room + '/firanki/')
|
|||
}
|
||||
button {
|
||||
padding: 1rem;
|
||||
width: 50%;
|
||||
margin: 0.1rem;
|
||||
width: 45%;
|
||||
}
|
||||
</style>
|
||||
|
|
36
frontend/vju_display/src/components/pages/ServisPage.vue
Normal file
36
frontend/vju_display/src/components/pages/ServisPage.vue
Normal file
|
@ -0,0 +1,36 @@
|
|||
<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 Projektor from '../Projektor.vue'
|
||||
// import Platno from '../Platno.vue'
|
||||
import Lift from '../Lift.vue';
|
||||
|
||||
const props = defineProps({
|
||||
room: String,
|
||||
})
|
||||
const _glavni_position = ref('glavni')
|
||||
const _stranski_position = ref('stranski')
|
||||
|
||||
</script>
|
||||
|
||||
<template>
|
||||
<div style="display: flex; gap: 1rem">
|
||||
<div>
|
||||
<Lift :room="props.room" :position="_glavni_position" />
|
||||
<!-- <Projektor :room="props.room" :position="_glavni_position" /> -->
|
||||
<!-- <Platno :room="props.room" :position="_glavni_position" /> -->
|
||||
|
||||
</div>
|
||||
<div>
|
||||
<Lift :room="props.room" :position="_stranski_position" />
|
||||
<!-- <Projektor :room="props.room" :position="_stranski_position" /> -->
|
||||
<!-- <Platno :room="props.room" :position="_stranski_position" /> -->
|
||||
</div>
|
||||
</div>
|
||||
</template>
|
||||
|
||||
<style scoped>
|
||||
|
||||
</style>
|
154
poetry.lock
generated
Normal file
154
poetry.lock
generated
Normal file
|
@ -0,0 +1,154 @@
|
|||
# This file is automatically @generated by Poetry 1.8.5 and should not be changed by hand.
|
||||
|
||||
[[package]]
|
||||
name = "aiomqtt"
|
||||
version = "2.3.0"
|
||||
description = "The idiomatic asyncio MQTT client, wrapped around paho-mqtt"
|
||||
optional = false
|
||||
python-versions = "<4.0,>=3.8"
|
||||
files = [
|
||||
{file = "aiomqtt-2.3.0-py3-none-any.whl", hash = "sha256:127926717bd6b012d1630f9087f24552eb9c4af58205bc2964f09d6e304f7e63"},
|
||||
{file = "aiomqtt-2.3.0.tar.gz", hash = "sha256:312feebe20bc76dc7c20916663011f3bd37aa6f42f9f687a19a1c58308d80d47"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
paho-mqtt = ">=2.1.0,<3.0.0"
|
||||
|
||||
[[package]]
|
||||
name = "aioserial"
|
||||
version = "1.3.1"
|
||||
description = "An asynchronous serial port library of Python"
|
||||
optional = false
|
||||
python-versions = ">=3.6,<4.0"
|
||||
files = [
|
||||
{file = "aioserial-1.3.1.tar.gz", hash = "sha256:702bf03b0eb84b8ef2d8dac5cb925e1e685dce98f77b125569bc6fd2b3b58228"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
pyserial = "*"
|
||||
|
||||
[[package]]
|
||||
name = "colorzero"
|
||||
version = "2.0"
|
||||
description = "Yet another Python color library"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "colorzero-2.0-py2.py3-none-any.whl", hash = "sha256:0e60d743a6b8071498a56465f7719c96a5e92928f858bab1be2a0d606c9aa0f8"},
|
||||
{file = "colorzero-2.0.tar.gz", hash = "sha256:e7d5a5c26cd0dc37b164ebefc609f388de24f8593b659191e12d85f8f9d5eb58"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
setuptools = "*"
|
||||
|
||||
[package.extras]
|
||||
doc = ["pkginfo", "sphinx", "sphinx-rtd-theme"]
|
||||
test = ["pytest", "pytest-cov"]
|
||||
|
||||
[[package]]
|
||||
name = "gpiozero"
|
||||
version = "2.0.1"
|
||||
description = "A simple interface to GPIO devices with Raspberry Pi"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "gpiozero-2.0.1-py3-none-any.whl", hash = "sha256:8f621de357171d574c0b7ea0e358cb66e560818a47b0eeedf41ce1cdbd20c70b"},
|
||||
{file = "gpiozero-2.0.1.tar.gz", hash = "sha256:d4ea1952689ec7e331f9d4ebc9adb15f1d01c2c9dcfabb72e752c9869ab7e97e"},
|
||||
]
|
||||
|
||||
[package.dependencies]
|
||||
colorzero = "*"
|
||||
|
||||
[package.extras]
|
||||
doc = ["sphinx (>=4.0)", "sphinx-rtd-theme (>=1.0)"]
|
||||
test = ["pytest", "pytest-cov"]
|
||||
|
||||
[[package]]
|
||||
name = "paho-mqtt"
|
||||
version = "2.1.0"
|
||||
description = "MQTT version 5.0/3.1.1 client class"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "paho_mqtt-2.1.0-py3-none-any.whl", hash = "sha256:6db9ba9b34ed5bc6b6e3812718c7e06e2fd7444540df2455d2c51bd58808feee"},
|
||||
{file = "paho_mqtt-2.1.0.tar.gz", hash = "sha256:12d6e7511d4137555a3f6ea167ae846af2c7357b10bc6fa4f7c3968fc1723834"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
proxy = ["pysocks"]
|
||||
|
||||
[[package]]
|
||||
name = "pyserial"
|
||||
version = "3.5"
|
||||
description = "Python Serial Port Extension"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "pyserial-3.5-py2.py3-none-any.whl", hash = "sha256:c4451db6ba391ca6ca299fb3ec7bae67a5c55dde170964c7a14ceefec02f2cf0"},
|
||||
{file = "pyserial-3.5.tar.gz", hash = "sha256:3c77e014170dfffbd816e6ffc205e9842efb10be9f58ec16d3e8675b4925cddb"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
cp2110 = ["hidapi"]
|
||||
|
||||
[[package]]
|
||||
name = "setuptools"
|
||||
version = "75.6.0"
|
||||
description = "Easily download, build, install, upgrade, and uninstall Python packages"
|
||||
optional = false
|
||||
python-versions = ">=3.9"
|
||||
files = [
|
||||
{file = "setuptools-75.6.0-py3-none-any.whl", hash = "sha256:ce74b49e8f7110f9bf04883b730f4765b774ef3ef28f722cce7c273d253aaf7d"},
|
||||
{file = "setuptools-75.6.0.tar.gz", hash = "sha256:8199222558df7c86216af4f84c30e9b34a61d8ba19366cc914424cdbd28252f6"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
check = ["pytest-checkdocs (>=2.4)", "pytest-ruff (>=0.2.1)", "ruff (>=0.7.0)"]
|
||||
core = ["importlib_metadata (>=6)", "jaraco.collections", "jaraco.functools (>=4)", "jaraco.text (>=3.7)", "more_itertools", "more_itertools (>=8.8)", "packaging", "packaging (>=24.2)", "platformdirs (>=4.2.2)", "tomli (>=2.0.1)", "wheel (>=0.43.0)"]
|
||||
cover = ["pytest-cov"]
|
||||
doc = ["furo", "jaraco.packaging (>=9.3)", "jaraco.tidelift (>=1.4)", "pygments-github-lexers (==0.0.5)", "pyproject-hooks (!=1.1)", "rst.linker (>=1.9)", "sphinx (>=3.5)", "sphinx-favicon", "sphinx-inline-tabs", "sphinx-lint", "sphinx-notfound-page (>=1,<2)", "sphinx-reredirects", "sphinxcontrib-towncrier", "towncrier (<24.7)"]
|
||||
enabler = ["pytest-enabler (>=2.2)"]
|
||||
test = ["build[virtualenv] (>=1.0.3)", "filelock (>=3.4.0)", "ini2toml[lite] (>=0.14)", "jaraco.develop (>=7.21)", "jaraco.envs (>=2.2)", "jaraco.path (>=3.2.0)", "jaraco.test (>=5.5)", "packaging (>=24.2)", "pip (>=19.1)", "pyproject-hooks (!=1.1)", "pytest (>=6,!=8.1.*)", "pytest-home (>=0.5)", "pytest-perf", "pytest-subprocess", "pytest-timeout", "pytest-xdist (>=3)", "tomli-w (>=1.0.0)", "virtualenv (>=13.0.0)", "wheel (>=0.44.0)"]
|
||||
type = ["importlib_metadata (>=7.0.2)", "jaraco.develop (>=7.21)", "mypy (>=1.12,<1.14)", "pytest-mypy"]
|
||||
|
||||
[[package]]
|
||||
name = "smbus2"
|
||||
version = "0.5.0"
|
||||
description = "smbus2 is a drop-in replacement for smbus-cffi/smbus-python in pure Python"
|
||||
optional = false
|
||||
python-versions = "*"
|
||||
files = [
|
||||
{file = "smbus2-0.5.0-py2.py3-none-any.whl", hash = "sha256:1a15c3b9fa69357beb038cc0b5d37939702f8bfde1ddc89ca9f17d8461dbe949"},
|
||||
{file = "smbus2-0.5.0.tar.gz", hash = "sha256:4a5946fd82277870c2878befdb1a29bb28d15cda14ea4d8d2d54cf3d4bdcb035"},
|
||||
]
|
||||
|
||||
[package.extras]
|
||||
docs = ["sphinx (>=1.5.3)"]
|
||||
qa = ["flake8"]
|
||||
|
||||
[[package]]
|
||||
name = "telnetlib3"
|
||||
version = "2.0.4"
|
||||
description = "Python 3 asyncio Telnet server and client Protocol library"
|
||||
optional = false
|
||||
python-versions = ">=3.7"
|
||||
files = [
|
||||
{file = "telnetlib3-2.0.4-py2.py3-none-any.whl", hash = "sha256:b3c0f984a7fb1b6ee16e6fdaa410c56389b0dc492174a99c6661b1ba4c9d457d"},
|
||||
{file = "telnetlib3-2.0.4.tar.gz", hash = "sha256:dbcbc16456a0e03a62431be7cfefff00515ab2f4ce2afbaf0d3a0e51a98c948d"},
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "toml"
|
||||
version = "0.10.2"
|
||||
description = "Python Library for Tom's Obvious, Minimal Language"
|
||||
optional = false
|
||||
python-versions = ">=2.6, !=3.0.*, !=3.1.*, !=3.2.*"
|
||||
files = [
|
||||
{file = "toml-0.10.2-py2.py3-none-any.whl", hash = "sha256:806143ae5bfb6a3c6e736a764057db0e6a0e05e338b5630894a5f779cabb4f9b"},
|
||||
{file = "toml-0.10.2.tar.gz", hash = "sha256:b3bda1d108d5dd99f4a20d24d9c348e91c4db7ab1b749200bded2f839ccbe68f"},
|
||||
]
|
||||
|
||||
[metadata]
|
||||
lock-version = "2.0"
|
||||
python-versions = "^3.10"
|
||||
content-hash = "5e30fcfae3a69f8475da0f4ba655b5194a80b2a2185c652cbce2c72fa83aa752"
|
|
@ -1,62 +1,98 @@
|
|||
import gpiozero.pins.mock
|
||||
from gpiozero import *
|
||||
#import gpiozero.pins.mock
|
||||
#from gpiozero import *
|
||||
#from grove.factory import Factory
|
||||
#from grove.grove_relay import GroveRelay
|
||||
import aiomqtt
|
||||
import asyncio
|
||||
#from i2cpy import I2C
|
||||
from smbus2 import SMBus
|
||||
#import i2cpy
|
||||
#i2cset -y 1 0x11 0x11 0x42
|
||||
#set i2c address from 0x11 to 0x42
|
||||
|
||||
# ONLY FOR TESTING ON NON RPI
|
||||
Device.pin_factory = gpiozero.pins.mock.MockFactory()
|
||||
#Device.pin_factory = gpiozero.pins.mock.MockFactory()
|
||||
|
||||
relays = [LED(17), LED(27), LED(22), LED(23), LED(5), LED(6), LED(24), LED(25)]
|
||||
#relays = [LED(17), LED(27), LED(22), LED(23), LED(5), LED(6), LED(24), LED(25)]
|
||||
relayBoardMain = 0x42
|
||||
relayBoardSide = 0x43
|
||||
""" 0 1 2 3 """
|
||||
relayMasks = [0b0001, 0b0010, 0b0100, 0b1000] #probably ne rabim
|
||||
|
||||
bus = SMBus(1)
|
||||
|
||||
relMapping = {
|
||||
'service_down': 0,
|
||||
'service_up': 1,
|
||||
'down': 2,
|
||||
'up': 3
|
||||
}
|
||||
|
||||
currentState = {
|
||||
'glavni': 0b0000,
|
||||
'stranski': 0b0000
|
||||
}
|
||||
|
||||
async def msgRelayBoard(projSelect, command, state: bool):
|
||||
#i2cAddr = relayBoardMain if projSelect == 'glavni' else relayBoardSide
|
||||
#TODO this is not optimal, check for more crap
|
||||
|
||||
# register 0x10 za releje
|
||||
|
||||
I2CAddr = 0x42 #glavni
|
||||
if projSelect == 'stranski':
|
||||
I2CAddr += 0x1
|
||||
|
||||
maskShift = relMapping[command]
|
||||
mask = (1 << maskShift)
|
||||
if state:
|
||||
currentState[projSelect] = currentState[projSelect] | mask
|
||||
else:
|
||||
currentState[projSelect] = currentState[projSelect] & ~mask
|
||||
|
||||
bus.write_byte_data(I2CAddr, 0x10, currentState[projSelect])
|
||||
|
||||
print('testirovano jako')
|
||||
|
||||
|
||||
"""
|
||||
SrvDwn SrvUp OpDwn OpUp
|
||||
MAIN: 0x42 0001 0010 0100 1000
|
||||
SIDE: 0x43 0001 0010 0100 1000
|
||||
"""
|
||||
|
||||
|
||||
#old board
|
||||
"""
|
||||
MAIN: SrvDwn SrvUp OpDwn OpUp
|
||||
0 1 2 3
|
||||
SIDE: 4 5 6 7
|
||||
"""
|
||||
#dej like bolš to podukumentiraj or smth
|
||||
|
||||
async def task_command2relays(controlClient: aiomqtt.Client):
|
||||
|
||||
#relayCtrl = lambda cmd, relay: relays[relay].on() if cmd == 1 else relays[relay].off()
|
||||
relayCtrl = lambda cmd, relay: [relays[r].on() if cmd == 1 and r == relay else relays[r].off for r in range(len(relays))]
|
||||
await controlClient.subscribe("p1/projektorji/+/dvigala/#")
|
||||
async with controlClient.messages() as msgs:
|
||||
async for mesg in msgs:
|
||||
mesg: aiomqtt.Message
|
||||
if mesg.topic.matches('p1/projektorji/+/dvigala/#'):
|
||||
msgTopicArr = mesg.topic.value.split('/')
|
||||
cmnd = mesg.payload.decode()
|
||||
print("Received: [" + str(msgTopicArr) + "] payload: [" + cmnd + "]")
|
||||
testCase = (msgTopicArr[2], msgTopicArr[4])
|
||||
match testCase:
|
||||
case ('glavni', 'servis_dol'):
|
||||
relayCtrl(cmnd, 0)
|
||||
print('GLAVNI: SERVIS_DOL: ' + cmnd)
|
||||
case ('glavni', 'servis_gor'):
|
||||
relayCtrl(cmnd, 1)
|
||||
print('GLAVNI: SERVIS_GOR: ' + cmnd)
|
||||
case ('glavni', 'delovni_dol'):
|
||||
relayCtrl(cmnd, 2)
|
||||
print('GLAVNI: DELOVNI_DOL: ' + cmnd)
|
||||
case ('glavni', 'delovni_gor'):
|
||||
relayCtrl(cmnd, 3)
|
||||
print('GLAVNI: DELOVNI_GOR: ' + cmnd)
|
||||
case ('stranski', 'servis_dol'):
|
||||
relayCtrl(cmnd, 4)
|
||||
print('GLAVNI: SERVIS_DOL: ' + cmnd)
|
||||
case ('stranski', 'servis_gor'):
|
||||
relayCtrl(cmnd, 5)
|
||||
print('GLAVNI: SERVIS_GOR: ' + cmnd)
|
||||
case ('stranski', 'delovni_dol'):
|
||||
relayCtrl(cmnd, 6)
|
||||
print('GLAVNI: DELOVNI_DOL: ' + cmnd)
|
||||
case ('stranski', 'delovni_gor'):
|
||||
relayCtrl(cmnd, 7)
|
||||
print('GLAVNI: DELOVNI_GOR: ' + cmnd)
|
||||
case _:
|
||||
print("Unrecognized command.")
|
||||
continue
|
||||
print("Pushing \'off\' to other relays to prevent conflicts")
|
||||
await asyncio.sleep(0.01)
|
||||
#relayCtrl = lambda cmd, relay: [relays[r].on() if cmd == 1 and r == relay else relays[r].off for r in range(len(relays))]
|
||||
|
||||
relayCtrl = lambda x, y: print(x, y)
|
||||
await controlClient.subscribe("p01/projectors/+/lift/#")
|
||||
msgs = controlClient.messages
|
||||
async for mesg in msgs:
|
||||
mesg: aiomqtt.Message
|
||||
if mesg.topic.matches('p01/projectors/+/lift/move/#'):
|
||||
msgTopicArr = mesg.topic.value.split('/')
|
||||
state = mesg.payload.decode()
|
||||
print("Received: " + str(msgTopicArr) + " payload: [" + state + "]")
|
||||
#testCase = (msgTopicArr[2], msgTopicArr[4])
|
||||
projSel = msgTopicArr[2]
|
||||
if projSel != 'glavni' and projSel != 'stranski':
|
||||
continue
|
||||
command = msgTopicArr[5]
|
||||
await msgRelayBoard(projSel, command, state == '1')
|
||||
|
||||
#print("Pushing \'off\' to other relays to prevent conflicts")
|
||||
await asyncio.sleep(0.01)
|
||||
|
||||
|
||||
|
||||
|
|
21
pyproject.toml
Normal file
21
pyproject.toml
Normal file
|
@ -0,0 +1,21 @@
|
|||
[tool.poetry]
|
||||
name = "fri-mm-maline"
|
||||
version = "0.1.0"
|
||||
description = ""
|
||||
authors = ["Your Name <you@example.com>"]
|
||||
license = "GPLv3"
|
||||
readme = "README.md"
|
||||
|
||||
[tool.poetry.dependencies]
|
||||
python = "^3.10"
|
||||
aiomqtt = "^2.3.0"
|
||||
aioserial = "^1.3.1"
|
||||
gpiozero = "^2.0.1"
|
||||
telnetlib3 = "^2.0.4"
|
||||
toml = "^0.10.2"
|
||||
smbus2 = "^0.5.0"
|
||||
|
||||
|
||||
[build-system]
|
||||
requires = ["poetry-core"]
|
||||
build-backend = "poetry.core.masonry.api"
|
|
@ -7,14 +7,14 @@ from dataclasses import dataclass
|
|||
|
||||
room = 'p01' #TODO make be do get fronm file of configuration
|
||||
|
||||
# aser: aioserial.AioSerial = aioserial.AioSerial(
|
||||
# port='/dev/cu.usbserial-14240', #TODO not hardcode it
|
||||
# baudrate=1200,
|
||||
# parity=serial.PARITY_NONE,
|
||||
# bytesize=serial.EIGHTBITS,
|
||||
# stopbits=serial.STOPBITS_ONE
|
||||
# )
|
||||
# TODO adjust serial on actual TSE interface
|
||||
aser: aioserial.AioSerial = aioserial.AioSerial(
|
||||
port='/dev/serial/by-id/usb-Prolific_Technology_Inc._USB-Serial_Controller_D-if00-port0',
|
||||
#id say not hardcode it ampak kinda nimamo izbire
|
||||
baudrate=1200,
|
||||
parity=serial.PARITY_NONE,
|
||||
bytesize=serial.EIGHTBITS,
|
||||
stopbits=serial.STOPBITS_ONE
|
||||
)
|
||||
|
||||
#TODO get this from file da ni hardcoded
|
||||
|
||||
|
@ -41,9 +41,11 @@ shades_mapping = {
|
|||
}
|
||||
|
||||
#reverse_lookup = {v: k for k, v in mapping.items()} #fujto
|
||||
# TODO simple reverse lookup za ko kripa pove kaj
|
||||
|
||||
|
||||
# TODO simple reverse lookup za ko kripa pove kaj
|
||||
# in vse tole
|
||||
|
||||
async def task_status2mqtt(statusClient: aiomqtt.Client):
|
||||
while True:
|
||||
#data = await aser.read_until_async()
|
||||
|
@ -71,7 +73,7 @@ async def executeAndPublish(mqttClient, pubTopic, pubPayload, relStat):
|
|||
print("Sending to TSE box: " + setRelayCmd)
|
||||
print(f"Also publishing topic [{pubTopic}] with status [{pubPayload}]")
|
||||
print()
|
||||
#await aser.write_async(bytes(setRelayCmd + '\r\n', "ascii"))
|
||||
await aser.write_async(bytes(setRelayCmd + '\r\n', "ascii"))
|
||||
await mqttClient.publish(pubTopic, payload=pubPayload)
|
||||
|
||||
|
||||
|
|
Loading…
Reference in a new issue