diff --git a/Dockerfile b/Dockerfile index db2b3a2..c73e397 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,27 +1,25 @@ -FROM python:3.11-alpine AS base +FROM python:3.11-alpine +COPY --from=ghcr.io/astral-sh/uv:latest /uv /uvx /bin/ +RUN apk add --no-cache --virtual .build-deps musl-dev gcc openldap-dev libffi-dev + ENV PYTHONUNBUFFERED=1 \ PYTHONDONTWRITEBYTECODE=1 \ PIP_NO_CACHE_DIR=off \ PIP_DISABLE_PIP_VERSION_CHECK=on \ - PIP_DEFAULT_TIMEOUT=100 \ - POETRY_HOME="/opt/poetry" \ - POETRY_VIRTUALENVS_IN_PROJECT=true \ - POETRY_NO_INTERACTION=1 \ - PYSETUP_PATH="/opt/pysetup" \ - VENV_PATH="/opt/pysetup/.venv" -ENV PATH="$POETRY_HOME/bin:$VENV_PATH/bin:$PATH" + PIP_DEFAULT_TIMEOUT=100 -FROM base AS builder -RUN apk add --no-cache --virtual .build-deps musl-dev gcc openldap-dev libffi-dev -RUN pip install poetry -WORKDIR $PYSETUP_PATH -COPY ./poetry.lock ./pyproject.toml ./ -RUN poetry install +# Change the working directory to the `app` directory +WORKDIR /app + +# Install dependencies +RUN --mount=type=cache,target=/root/.cache/uv \ + --mount=type=bind,source=uv.lock,target=uv.lock \ + --mount=type=bind,source=pyproject.toml,target=pyproject.toml \ + uv sync --locked --no-install-project -FROM base AS production -RUN apk add --no-cache --virtual .build-deps musl-dev gcc openldap-dev libffi-dev -COPY --from=builder $VENV_PATH $VENV_PATH COPY . /app -WORKDIR /app +RUN --mount=type=cache,target=/root/.cache/uv \ + uv sync --locked + ENTRYPOINT ["/app/contrib/entrypoint.sh"] diff --git a/contrib/entrypoint.sh b/contrib/entrypoint.sh index 58fec56..040b9b3 100755 --- a/contrib/entrypoint.sh +++ b/contrib/entrypoint.sh @@ -1,6 +1,6 @@ #!/bin/sh cd /app export PYTHONUNBUFFERED=1 -. /opt/pysetup/.venv/bin/activate +. ./.venv/bin/activate python ./manage.py migrate exec python ./manage.py runserver --noreload 0.0.0.0:8000 diff --git a/hackmap/urls.py b/hackmap/urls.py index 12bf95f..6cfc154 100644 --- a/hackmap/urls.py +++ b/hackmap/urls.py @@ -25,6 +25,8 @@ path("map", labmap.views.map), path("lights", labmap.views.lights), path("printers", labprinter.views.Printers.as_view()), + path("printers/lights/on", labprinter.views.lights_on), + path("printers/lights/off", labprinter.views.lights_off), re_path(r"lights/(?P[0-9,]+)/(?P[0-9.]+)", labmap.views.set_lights), re_path(r"lights/preset/(?P[A-z]+)", labmap.views.set_light_preset), path("", include("labdash.urls")), diff --git a/labdash/migrations/0016_buttongroup_screen.py b/labdash/migrations/0016_buttongroup_screen.py new file mode 100644 index 0000000..8c3a579 --- /dev/null +++ b/labdash/migrations/0016_buttongroup_screen.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1 on 2025-11-14 18:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('labdash', '0015_add_buttongroup_hide'), + ] + + operations = [ + migrations.AddField( + model_name='buttongroup', + name='screen', + field=models.CharField(blank=True, default='main', max_length=50), + ), + ] diff --git a/labdash/models.py b/labdash/models.py index ccbab68..261138d 100644 --- a/labdash/models.py +++ b/labdash/models.py @@ -3,6 +3,7 @@ class ButtonGroup(models.Model): name = models.CharField(max_length=200) + screen = models.CharField(max_length=50, default="main", blank=True) color = models.CharField(max_length=200) priority = models.IntegerField(default=50) tile_width = models.IntegerField(default=1) diff --git a/labdash/urls.py b/labdash/urls.py index e076766..07cf8ae 100644 --- a/labdash/urls.py +++ b/labdash/urls.py @@ -1,9 +1,10 @@ from django.urls import re_path from django.conf.urls.static import static from django.conf import settings -from labdash.views import Dashboard, trigger_button +from labdash.views import Dashboard, custom_screen, trigger_button urlpatterns = [ re_path(r"^$", Dashboard.as_view()), + re_path(r"^screen/(?P[A-z]+)", custom_screen), re_path(r"^trigger/(?P[0-9]+)", trigger_button), ] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/labdash/views.py b/labdash/views.py index 1be2bf3..8ed290a 100644 --- a/labdash/views.py +++ b/labdash/views.py @@ -1,5 +1,5 @@ from django.http import JsonResponse -from django.shortcuts import get_object_or_404 +from django.shortcuts import get_object_or_404, render from django.views.generic.list import ListView from labdash.models import ButtonGroup, Button import labdash.mqtt @@ -8,7 +8,23 @@ class Dashboard(ListView): model = ButtonGroup context_object_name = "groups" - queryset = ButtonGroup.objects.filter(hide=False).order_by("priority") + queryset = ButtonGroup.objects.filter(screen="main", hide=False).order_by( + "priority" + ) + + +def custom_screen(req, name): + groups = ( + ButtonGroup.objects.filter(screen=name, hide=False).order_by("priority").all() + ) + return render( + req, + "labdash/buttongroup_list.html", + context={ + "groups": groups, + "do_home_timeout": req.GET.get("kiosk", False) != False, + }, + ) def trigger_button(request, pk): diff --git a/labmap/views.py b/labmap/views.py index 41a1257..d871eaa 100644 --- a/labmap/views.py +++ b/labmap/views.py @@ -24,15 +24,12 @@ def lights(req: HttpRequest) -> HttpResponse: @csrf_exempt def set_lights(req: HttpRequest, ids: str, val: int) -> JsonResponse: mqtt = labmap.mqtt.client() - lights = ids.split(",") - for light in lights: - try: - light_id = int(light) - assert light_id < 18 - mqtt.publish(f"dali/g1/set/{light_id}", payload=val) - except Exception as e: - print(e) - continue + try: + lights = ",".join([str(int(light)) for light in ids.split(",")]) + mqtt.publish(f"dali/g1/set/{lights}", payload=val) + except Exception as e: + print(e) + return JsonResponse({"msg": "invalid light ids"}) return JsonResponse({}) diff --git a/labprinter/migrations/0003_printer_camera_url.py b/labprinter/migrations/0003_printer_camera_url.py new file mode 100644 index 0000000..b5386c4 --- /dev/null +++ b/labprinter/migrations/0003_printer_camera_url.py @@ -0,0 +1,17 @@ +# Generated by Django 5.1 on 2026-08-01 19:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("labprinter", "0002_printer_color"), + ] + + operations = [ + migrations.AddField( + model_name="printer", + name="camera_url", + field=models.CharField(blank=True, default="", max_length=300), + ), + ] diff --git a/labprinter/migrations/0004_printer_led_topic.py b/labprinter/migrations/0004_printer_led_topic.py new file mode 100644 index 0000000..630d28e --- /dev/null +++ b/labprinter/migrations/0004_printer_led_topic.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1 on 2026-08-01 20:02 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('labprinter', '0003_printer_camera_url'), + ] + + operations = [ + migrations.AddField( + model_name='printer', + name='led_topic', + field=models.CharField(blank=True, default='', max_length=300), + ), + ] diff --git a/labprinter/migrations/0005_printer_priority.py b/labprinter/migrations/0005_printer_priority.py new file mode 100644 index 0000000..c70d570 --- /dev/null +++ b/labprinter/migrations/0005_printer_priority.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1 on 2026-08-01 20:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('labprinter', '0004_printer_led_topic'), + ] + + operations = [ + migrations.AddField( + model_name='printer', + name='priority', + field=models.IntegerField(default=50), + ), + ] diff --git a/labprinter/models.py b/labprinter/models.py index 185487d..3a7c326 100644 --- a/labprinter/models.py +++ b/labprinter/models.py @@ -6,6 +6,9 @@ class Printer(models.Model): shortname = models.CharField(max_length=200) description = models.CharField(max_length=200) color = models.CharField(max_length=20, default="black") + camera_url = models.CharField(max_length=300, blank=True, default="") + led_topic = models.CharField(max_length=300, blank=True, default="") + priority = models.IntegerField(default=50) def __str__(self): return self.name diff --git a/labprinter/views.py b/labprinter/views.py index a96df6e..883fa2c 100644 --- a/labprinter/views.py +++ b/labprinter/views.py @@ -1,9 +1,27 @@ from django.shortcuts import render from labprinter.models import Printer from django.views.generic.list import ListView +import labdash.mqtt +from django.http import JsonResponse class Printers(ListView): model = Printer context_object_name = "printers" - queryset = Printer.objects.all().order_by("shortname") + queryset = Printer.objects.all().order_by("priority") + + +def lights_on(request): + mqtt = labdash.mqtt.client() + for printer in Printer.objects.all().exclude(led_topic__exact=""): + mqtt.publish(printer.led_topic, payload="1") + + return JsonResponse({"status": "ok"}) + + +def lights_off(request): + mqtt = labdash.mqtt.client() + for printer in Printer.objects.all().exclude(led_topic__exact=""): + mqtt.publish(printer.led_topic, payload="0") + + return JsonResponse({"status": "ok"}) diff --git a/poetry.lock b/poetry.lock deleted file mode 100644 index 5fdd065..0000000 --- a/poetry.lock +++ /dev/null @@ -1,319 +0,0 @@ -# This file is automatically @generated by Poetry 1.8.4 and should not be changed by hand. - -[[package]] -name = "asgiref" -version = "3.8.1" -description = "ASGI specs, helper code, and adapters" -optional = false -python-versions = ">=3.8" -files = [ - {file = "asgiref-3.8.1-py3-none-any.whl", hash = "sha256:3e1e3ecc849832fe52ccf2cb6686b7a55f82bb1d6aee72a58826471390335e47"}, - {file = "asgiref-3.8.1.tar.gz", hash = "sha256:c343bd80a0bec947a9860adb4c432ffa7db769836c64238fc34bdc3fec84d590"}, -] - -[package.extras] -tests = ["mypy (>=0.800)", "pytest", "pytest-asyncio"] - -[[package]] -name = "asyncio-paho" -version = "0.6.0" -description = "A Paho MQTT client supporting asyncio loop without additional setup." -optional = false -python-versions = ">=3.8" -files = [ - {file = "asyncio_paho-0.6.0-py3-none-any.whl", hash = "sha256:7239dc5ec17afef1c1ea162e6c32c477c6cc728ce64740ca433b984bded122e7"}, - {file = "asyncio_paho-0.6.0.tar.gz", hash = "sha256:19fffd4758bfcf704393acf8b540d06a9def27270b2cf55826f956660a8f1496"}, -] - -[package.dependencies] -paho-mqtt = ">=1.6,<2.0" - -[[package]] -name = "django" -version = "5.1" -description = "A high-level Python web framework that encourages rapid development and clean, pragmatic design." -optional = false -python-versions = ">=3.10" -files = [ - {file = "Django-5.1-py3-none-any.whl", hash = "sha256:d3b811bf5371a26def053d7ee42a9df1267ef7622323fe70a601936725aa4557"}, - {file = "Django-5.1.tar.gz", hash = "sha256:848a5980e8efb76eea70872fb0e4bc5e371619c70fffbe48e3e1b50b2c09455d"}, -] - -[package.dependencies] -asgiref = ">=3.8.1,<4" -sqlparse = ">=0.3.1" -tzdata = {version = "*", markers = "sys_platform == \"win32\""} - -[package.extras] -argon2 = ["argon2-cffi (>=19.1.0)"] -bcrypt = ["bcrypt"] - -[[package]] -name = "django-auth-ldap" -version = "5.1.0" -description = "Django LDAP authentication backend" -optional = false -python-versions = ">=3.9" -files = [ - {file = "django_auth_ldap-5.1.0-py3-none-any.whl", hash = "sha256:a5f7bdb54b2ab80e4e9eb080cd3e06e89e4c9d2d534ddb39b66cd970dd6d3536"}, - {file = "django_auth_ldap-5.1.0.tar.gz", hash = "sha256:9c607e8d9c53cf2a0ccafbe0acfc33eb1d1fd474c46ec52d30aee0dca1da9668"}, -] - -[package.dependencies] -Django = ">=4.2" -python-ldap = ">=3.1" - -[[package]] -name = "django-stubs" -version = "5.1.1" -description = "Mypy stubs for Django" -optional = false -python-versions = ">=3.8" -files = [ - {file = "django_stubs-5.1.1-py3-none-any.whl", hash = "sha256:c4dc64260bd72e6d32b9e536e8dd0d9247922f0271f82d1d5132a18f24b388ac"}, - {file = "django_stubs-5.1.1.tar.gz", hash = "sha256:126d354bbdff4906c4e93e6361197f6fbfb6231c3df6def85a291dae6f9f577b"}, -] - -[package.dependencies] -asgiref = "*" -django = "*" -django-stubs-ext = ">=5.1.1" -types-PyYAML = "*" -typing-extensions = ">=4.11.0" - -[package.extras] -compatible-mypy = ["mypy (>=1.12,<1.14)"] -oracle = ["oracledb"] -redis = ["redis"] - -[[package]] -name = "django-stubs-ext" -version = "5.1.1" -description = "Monkey-patching and extensions for django-stubs" -optional = false -python-versions = ">=3.8" -files = [ - {file = "django_stubs_ext-5.1.1-py3-none-any.whl", hash = "sha256:3907f99e178c93323e2ce908aef8352adb8c047605161f8d9e5e7b4efb5a6a9c"}, - {file = "django_stubs_ext-5.1.1.tar.gz", hash = "sha256:db7364e4f50ae7e5360993dbd58a3a57ea4b2e7e5bab0fbd525ccdb3e7975d1c"}, -] - -[package.dependencies] -django = "*" -typing-extensions = "*" - -[[package]] -name = "django-vite" -version = "3.0.4" -description = "Integration of Vite in a Django project." -optional = false -python-versions = "*" -files = [ - {file = "django-vite-3.0.4.tar.gz", hash = "sha256:043ab5068b4c66eb33cb26c5215a6dfe275d3c4de15d59b0b7b97b4567912fb0"}, - {file = "django_vite-3.0.4-py3-none-any.whl", hash = "sha256:e4088e0c79b7c9cf013ebb2ae0117a8fa57646337a40e90209ba916d65f359d3"}, -] - -[package.dependencies] -Django = ">=3.2" - -[package.extras] -dev = ["black"] - -[[package]] -name = "paho-mqtt" -version = "1.6.1" -description = "MQTT version 5.0/3.1.1 client class" -optional = false -python-versions = "*" -files = [ - {file = "paho-mqtt-1.6.1.tar.gz", hash = "sha256:2a8291c81623aec00372b5a85558a372c747cbca8e9934dfe218638b8eefc26f"}, -] - -[package.extras] -proxy = ["PySocks"] - -[[package]] -name = "pyasn1" -version = "0.6.1" -description = "Pure-Python implementation of ASN.1 types and DER/BER/CER codecs (X.208)" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pyasn1-0.6.1-py3-none-any.whl", hash = "sha256:0d632f46f2ba09143da3a8afe9e33fb6f92fa2320ab7e886e2d0f7672af84629"}, - {file = "pyasn1-0.6.1.tar.gz", hash = "sha256:6f580d2bdd84365380830acf45550f2511469f673cb4a5ae3857a3170128b034"}, -] - -[[package]] -name = "pyasn1-modules" -version = "0.4.1" -description = "A collection of ASN.1-based protocols modules" -optional = false -python-versions = ">=3.8" -files = [ - {file = "pyasn1_modules-0.4.1-py3-none-any.whl", hash = "sha256:49bfa96b45a292b711e986f222502c1c9a5e1f4e568fc30e2574a6c7d07838fd"}, - {file = "pyasn1_modules-0.4.1.tar.gz", hash = "sha256:c28e2dbf9c06ad61c71a075c7e0f9fd0f1b0bb2d2ad4377f240d33ac2ab60a7c"}, -] - -[package.dependencies] -pyasn1 = ">=0.4.6,<0.7.0" - -[[package]] -name = "python-ldap" -version = "3.4.4" -description = "Python modules for implementing LDAP clients" -optional = false -python-versions = ">=3.6" -files = [ - {file = "python-ldap-3.4.4.tar.gz", hash = "sha256:7edb0accec4e037797705f3a05cbf36a9fde50d08c8f67f2aef99a2628fab828"}, -] - -[package.dependencies] -pyasn1 = ">=0.3.7" -pyasn1_modules = ">=0.1.5" - -[[package]] -name = "sqlparse" -version = "0.5.1" -description = "A non-validating SQL parser." -optional = false -python-versions = ">=3.8" -files = [ - {file = "sqlparse-0.5.1-py3-none-any.whl", hash = "sha256:773dcbf9a5ab44a090f3441e2180efe2560220203dc2f8c0b0fa141e18b505e4"}, - {file = "sqlparse-0.5.1.tar.gz", hash = "sha256:bb6b4df465655ef332548e24f08e205afc81b9ab86cb1c45657a7ff173a3a00e"}, -] - -[package.extras] -dev = ["build", "hatch"] -doc = ["sphinx"] - -[[package]] -name = "types-pyyaml" -version = "6.0.12.20240917" -description = "Typing stubs for PyYAML" -optional = false -python-versions = ">=3.8" -files = [ - {file = "types-PyYAML-6.0.12.20240917.tar.gz", hash = "sha256:d1405a86f9576682234ef83bcb4e6fff7c9305c8b1fbad5e0bcd4f7dbdc9c587"}, - {file = "types_PyYAML-6.0.12.20240917-py3-none-any.whl", hash = "sha256:392b267f1c0fe6022952462bf5d6523f31e37f6cea49b14cee7ad634b6301570"}, -] - -[[package]] -name = "typing-extensions" -version = "4.12.2" -description = "Backported and Experimental Type Hints for Python 3.8+" -optional = false -python-versions = ">=3.8" -files = [ - {file = "typing_extensions-4.12.2-py3-none-any.whl", hash = "sha256:04e5ca0351e0f3f85c6853954072df659d0d13fac324d0072316b67d7794700d"}, - {file = "typing_extensions-4.12.2.tar.gz", hash = "sha256:1a7ead55c7e559dd4dee8856e3a88b41225abfe1ce8df57b7c13915fe121ffb8"}, -] - -[[package]] -name = "tzdata" -version = "2024.1" -description = "Provider of IANA time zone data" -optional = false -python-versions = ">=2" -files = [ - {file = "tzdata-2024.1-py2.py3-none-any.whl", hash = "sha256:9068bc196136463f5245e51efda838afa15aaeca9903f49050dfa2679db4d252"}, - {file = "tzdata-2024.1.tar.gz", hash = "sha256:2674120f8d891909751c38abcdfd386ac0a5a1127954fbc332af6b5ceae07efd"}, -] - -[[package]] -name = "websockets" -version = "13.0" -description = "An implementation of the WebSocket Protocol (RFC 6455 & 7692)" -optional = false -python-versions = ">=3.8" -files = [ - {file = "websockets-13.0-cp310-cp310-macosx_10_9_universal2.whl", hash = "sha256:ad4fa707ff9e2ffee019e946257b5300a45137a58f41fbd9a4db8e684ab61528"}, - {file = "websockets-13.0-cp310-cp310-macosx_10_9_x86_64.whl", hash = "sha256:6fd757f313c13c34dae9f126d3ba4cf97175859c719e57c6a614b781c86b617e"}, - {file = "websockets-13.0-cp310-cp310-macosx_11_0_arm64.whl", hash = "sha256:cbac2eb7ce0fac755fb983c9247c4a60c4019bcde4c0e4d167aeb17520cc7ef1"}, - {file = "websockets-13.0-cp310-cp310-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d4b83cf7354cbbc058e97b3e545dceb75b8d9cf17fd5a19db419c319ddbaaf7a"}, - {file = "websockets-13.0-cp310-cp310-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:9202c0010c78fad1041e1c5285232b6508d3633f92825687549540a70e9e5901"}, - {file = "websockets-13.0-cp310-cp310-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:3e6566e79c8c7cbea75ec450f6e1828945fc5c9a4769ceb1c7b6e22470539712"}, - {file = "websockets-13.0-cp310-cp310-musllinux_1_2_aarch64.whl", hash = "sha256:e7fcad070dcd9ad37a09d89a4cbc2a5e3e45080b88977c0da87b3090f9f55ead"}, - {file = "websockets-13.0-cp310-cp310-musllinux_1_2_i686.whl", hash = "sha256:0a8f7d65358a25172db00c69bcc7df834155ee24229f560d035758fd6613111a"}, - {file = "websockets-13.0-cp310-cp310-musllinux_1_2_x86_64.whl", hash = "sha256:63b702fb31e3f058f946ccdfa551f4d57a06f7729c369e8815eb18643099db37"}, - {file = "websockets-13.0-cp310-cp310-win32.whl", hash = "sha256:3a20cf14ba7b482c4a1924b5e061729afb89c890ca9ed44ac4127c6c5986e424"}, - {file = "websockets-13.0-cp310-cp310-win_amd64.whl", hash = "sha256:587245f0704d0bb675f919898d7473e8827a6d578e5a122a21756ca44b811ec8"}, - {file = "websockets-13.0-cp311-cp311-macosx_10_9_universal2.whl", hash = "sha256:06df8306c241c235075d2ae77367038e701e53bc8c1bb4f6644f4f53aa6dedd0"}, - {file = "websockets-13.0-cp311-cp311-macosx_10_9_x86_64.whl", hash = "sha256:85a1f92a02f0b8c1bf02699731a70a8a74402bb3f82bee36e7768b19a8ed9709"}, - {file = "websockets-13.0-cp311-cp311-macosx_11_0_arm64.whl", hash = "sha256:9ed02c604349068d46d87ef4c2012c112c791f2bec08671903a6bb2bd9c06784"}, - {file = "websockets-13.0-cp311-cp311-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:b89849171b590107f6724a7b0790736daead40926ddf47eadf998b4ff51d6414"}, - {file = "websockets-13.0-cp311-cp311-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:939a16849d71203628157a5e4a495da63967c744e1e32018e9b9e2689aca64d4"}, - {file = "websockets-13.0-cp311-cp311-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ad818cdac37c0ad4c58e51cb4964eae4f18b43c4a83cb37170b0d90c31bd80cf"}, - {file = "websockets-13.0-cp311-cp311-musllinux_1_2_aarch64.whl", hash = "sha256:cbfe82a07596a044de78bb7a62519e71690c5812c26c5f1d4b877e64e4f46309"}, - {file = "websockets-13.0-cp311-cp311-musllinux_1_2_i686.whl", hash = "sha256:e07e76c49f39c5b45cbd7362b94f001ae209a3ea4905ae9a09cfd53b3c76373d"}, - {file = "websockets-13.0-cp311-cp311-musllinux_1_2_x86_64.whl", hash = "sha256:372f46a0096cfda23c88f7e42349a33f8375e10912f712e6b496d3a9a557290f"}, - {file = "websockets-13.0-cp311-cp311-win32.whl", hash = "sha256:376a43a4fd96725f13450d3d2e98f4f36c3525c562ab53d9a98dd2950dca9a8a"}, - {file = "websockets-13.0-cp311-cp311-win_amd64.whl", hash = "sha256:2be1382a4daa61e2f3e2be3b3c86932a8db9d1f85297feb6e9df22f391f94452"}, - {file = "websockets-13.0-cp312-cp312-macosx_10_9_universal2.whl", hash = "sha256:b5407c34776b9b77bd89a5f95eb0a34aaf91889e3f911c63f13035220eb50107"}, - {file = "websockets-13.0-cp312-cp312-macosx_10_9_x86_64.whl", hash = "sha256:4782ec789f059f888c1e8fdf94383d0e64b531cffebbf26dd55afd53ab487ca4"}, - {file = "websockets-13.0-cp312-cp312-macosx_11_0_arm64.whl", hash = "sha256:c8feb8e19ef65c9994e652c5b0324abd657bedd0abeb946fb4f5163012c1e730"}, - {file = "websockets-13.0-cp312-cp312-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:d3f3d2e20c442b58dbac593cb1e02bc02d149a86056cc4126d977ad902472e3b"}, - {file = "websockets-13.0-cp312-cp312-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:e39d393e0ab5b8bd01717cc26f2922026050188947ff54fe6a49dc489f7750b7"}, - {file = "websockets-13.0-cp312-cp312-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:1f661a4205741bdc88ac9c2b2ec003c72cee97e4acd156eb733662ff004ba429"}, - {file = "websockets-13.0-cp312-cp312-musllinux_1_2_aarch64.whl", hash = "sha256:384129ad0490e06bab2b98c1da9b488acb35bb11e2464c728376c6f55f0d45f3"}, - {file = "websockets-13.0-cp312-cp312-musllinux_1_2_i686.whl", hash = "sha256:df5c0eff91f61b8205a6c9f7b255ff390cdb77b61c7b41f79ca10afcbb22b6cb"}, - {file = "websockets-13.0-cp312-cp312-musllinux_1_2_x86_64.whl", hash = "sha256:02cc9bb1a887dac0e08bf657c5d00aa3fac0d03215d35a599130c2034ae6663a"}, - {file = "websockets-13.0-cp312-cp312-win32.whl", hash = "sha256:d9726d2c9bd6aed8cb994d89b3910ca0079406edce3670886ec828a73e7bdd53"}, - {file = "websockets-13.0-cp312-cp312-win_amd64.whl", hash = "sha256:fa0839f35322f7b038d8adcf679e2698c3a483688cc92e3bd15ee4fb06669e9a"}, - {file = "websockets-13.0-cp313-cp313-macosx_10_13_universal2.whl", hash = "sha256:da7e501e59857e8e3e9d10586139dc196b80445a591451ca9998aafba1af5278"}, - {file = "websockets-13.0-cp313-cp313-macosx_10_13_x86_64.whl", hash = "sha256:a00e1e587c655749afb5b135d8d3edcfe84ec6db864201e40a882e64168610b3"}, - {file = "websockets-13.0-cp313-cp313-macosx_11_0_arm64.whl", hash = "sha256:a7fbf2a8fe7556a8f4e68cb3e736884af7bf93653e79f6219f17ebb75e97d8f0"}, - {file = "websockets-13.0-cp313-cp313-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:7ea9c9c7443a97ea4d84d3e4d42d0e8c4235834edae652993abcd2aff94affd7"}, - {file = "websockets-13.0-cp313-cp313-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:35c2221b539b360203f3f9ad168e527bf16d903e385068ae842c186efb13d0ea"}, - {file = "websockets-13.0-cp313-cp313-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:358d37c5c431dd050ffb06b4b075505aae3f4f795d7fff9794e5ed96ce99b998"}, - {file = "websockets-13.0-cp313-cp313-musllinux_1_2_aarch64.whl", hash = "sha256:038e7a0f1bfafc7bf52915ab3506b7a03d1e06381e9f60440c856e8918138151"}, - {file = "websockets-13.0-cp313-cp313-musllinux_1_2_i686.whl", hash = "sha256:fd038bc9e2c134847f1e0ce3191797fad110756e690c2fdd9702ed34e7a43abb"}, - {file = "websockets-13.0-cp313-cp313-musllinux_1_2_x86_64.whl", hash = "sha256:93b8c2008f372379fb6e5d2b3f7c9ec32f7b80316543fd3a5ace6610c5cde1b0"}, - {file = "websockets-13.0-cp313-cp313-win32.whl", hash = "sha256:851fd0afb3bc0b73f7c5b5858975d42769a5fdde5314f4ef2c106aec63100687"}, - {file = "websockets-13.0-cp313-cp313-win_amd64.whl", hash = "sha256:7d14901fdcf212804970c30ab9ee8f3f0212e620c7ea93079d6534863444fb4e"}, - {file = "websockets-13.0-cp38-cp38-macosx_10_9_universal2.whl", hash = "sha256:ae7a519a56a714f64c3445cabde9fc2fc927e7eae44f413eae187cddd9e54178"}, - {file = "websockets-13.0-cp38-cp38-macosx_10_9_x86_64.whl", hash = "sha256:5575031472ca87302aeb2ce2c2349f4c6ea978c86a9d1289bc5d16058ad4c10a"}, - {file = "websockets-13.0-cp38-cp38-macosx_11_0_arm64.whl", hash = "sha256:9895df6cd0bfe79d09bcd1dbdc03862846f26fbd93797153de954306620c1d00"}, - {file = "websockets-13.0-cp38-cp38-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:a4de299c947a54fca9ce1c5fd4a08eb92ffce91961becb13bd9195f7c6e71b47"}, - {file = "websockets-13.0-cp38-cp38-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:05c25f7b849702950b6fd0e233989bb73a0d2bc83faa3b7233313ca395205f6d"}, - {file = "websockets-13.0-cp38-cp38-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:ede95125a30602b1691a4b1da88946bf27dae283cf30f22cd2cb8ca4b2e0d119"}, - {file = "websockets-13.0-cp38-cp38-musllinux_1_2_aarch64.whl", hash = "sha256:addf0a16e4983280efed272d8cb3b2e05f0051755372461e7d966b80a6554e16"}, - {file = "websockets-13.0-cp38-cp38-musllinux_1_2_i686.whl", hash = "sha256:06b3186e97bf9a33921fa60734d5ed90f2a9b407cce8d23c7333a0984049ef61"}, - {file = "websockets-13.0-cp38-cp38-musllinux_1_2_x86_64.whl", hash = "sha256:eae368cac85adc4c7dc3b0d5f84ffcca609d658db6447387300478e44db70796"}, - {file = "websockets-13.0-cp38-cp38-win32.whl", hash = "sha256:337837ac788d955728b1ab01876d72b73da59819a3388e1c5e8e05c3999f1afa"}, - {file = "websockets-13.0-cp38-cp38-win_amd64.whl", hash = "sha256:f66e00e42f25ca7e91076366303e11c82572ca87cc5aae51e6e9c094f315ab41"}, - {file = "websockets-13.0-cp39-cp39-macosx_10_9_universal2.whl", hash = "sha256:94c1c02721139fe9940b38d28fb15b4b782981d800d5f40f9966264fbf23dcc8"}, - {file = "websockets-13.0-cp39-cp39-macosx_10_9_x86_64.whl", hash = "sha256:bd4ba86513430513e2aa25a441bb538f6f83734dc368a2c5d18afdd39097aa33"}, - {file = "websockets-13.0-cp39-cp39-macosx_11_0_arm64.whl", hash = "sha256:a1ab8f0e0cadc5be5f3f9fa11a663957fecbf483d434762c8dfb8aa44948944a"}, - {file = "websockets-13.0-cp39-cp39-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:3670def5d3dfd5af6f6e2b3b243ea8f1f72d8da1ef927322f0703f85c90d9603"}, - {file = "websockets-13.0-cp39-cp39-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6058b6be92743358885ad6dcdecb378fde4a4c74d4dd16a089d07580c75a0e80"}, - {file = "websockets-13.0-cp39-cp39-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:516062a0a8ef5ecbfa4acbaec14b199fc070577834f9fe3d40800a99f92523ca"}, - {file = "websockets-13.0-cp39-cp39-musllinux_1_2_aarch64.whl", hash = "sha256:da7e918d82e7bdfc6f66d31febe1b2e28a1ca3387315f918de26f5e367f61572"}, - {file = "websockets-13.0-cp39-cp39-musllinux_1_2_i686.whl", hash = "sha256:9cc7f35dcb49a4e32db82a849fcc0714c4d4acc9d2273aded2d61f87d7f660b7"}, - {file = "websockets-13.0-cp39-cp39-musllinux_1_2_x86_64.whl", hash = "sha256:f5737c53eb2c8ed8f64b50d3dafd3c1dae739f78aa495a288421ac1b3de82717"}, - {file = "websockets-13.0-cp39-cp39-win32.whl", hash = "sha256:265e1f0d3f788ce8ef99dca591a1aec5263b26083ca0934467ad9a1d1181067c"}, - {file = "websockets-13.0-cp39-cp39-win_amd64.whl", hash = "sha256:4d70c89e3d3b347a7c4d3c33f8d323f0584c9ceb69b82c2ef8a174ca84ea3d4a"}, - {file = "websockets-13.0-pp310-pypy310_pp73-macosx_10_15_x86_64.whl", hash = "sha256:602cbd010d8c21c8475f1798b705bb18567eb189c533ab5ef568bc3033fdf417"}, - {file = "websockets-13.0-pp310-pypy310_pp73-macosx_11_0_arm64.whl", hash = "sha256:bf8eb5dca4f484a60f5327b044e842e0d7f7cdbf02ea6dc4a4f811259f1f1f0b"}, - {file = "websockets-13.0-pp310-pypy310_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:89d795c1802d99a643bf689b277e8604c14b5af1bc0a31dade2cd7a678087212"}, - {file = "websockets-13.0-pp310-pypy310_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:788bc841d250beccff67a20a5a53a15657a60111ef9c0c0a97fbdd614fae0fe2"}, - {file = "websockets-13.0-pp310-pypy310_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:7334752052532c156d28b8eaf3558137e115c7871ea82adff69b6d94a7bee273"}, - {file = "websockets-13.0-pp310-pypy310_pp73-win_amd64.whl", hash = "sha256:e7a1963302947332c3039e3f66209ec73b1626f8a0191649e0713c391e9f5b0d"}, - {file = "websockets-13.0-pp38-pypy38_pp73-macosx_10_9_x86_64.whl", hash = "sha256:2e1cf4e1eb84b4fd74a47688e8b0940c89a04ad9f6937afa43d468e71128cd68"}, - {file = "websockets-13.0-pp38-pypy38_pp73-macosx_11_0_arm64.whl", hash = "sha256:c026ee729c4ce55708a14b839ba35086dfae265fc12813b62d34ce33f4980c1c"}, - {file = "websockets-13.0-pp38-pypy38_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:f5f9d23fbbf96eefde836d9692670bfc89e2d159f456d499c5efcf6a6281c1af"}, - {file = "websockets-13.0-pp38-pypy38_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:6ad684cb7efce227d756bae3e8484f2e56aa128398753b54245efdfbd1108f2c"}, - {file = "websockets-13.0-pp38-pypy38_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:e1e10b3fbed7be4a59831d3a939900e50fcd34d93716e433d4193a4d0d1d335d"}, - {file = "websockets-13.0-pp38-pypy38_pp73-win_amd64.whl", hash = "sha256:d42a818e634f789350cd8fb413a3f5eec1cf0400a53d02062534c41519f5125c"}, - {file = "websockets-13.0-pp39-pypy39_pp73-macosx_10_15_x86_64.whl", hash = "sha256:e5ba5e9b332267d0f2c33ede390061850f1ac3ee6cd1bdcf4c5ea33ead971966"}, - {file = "websockets-13.0-pp39-pypy39_pp73-macosx_11_0_arm64.whl", hash = "sha256:f9af457ed593e35f467140d8b61d425495b127744a9d65d45a366f8678449a23"}, - {file = "websockets-13.0-pp39-pypy39_pp73-manylinux_2_17_aarch64.manylinux2014_aarch64.whl", hash = "sha256:bcea3eb58c09c3a31cc83b45c06d5907f02ddaf10920aaa6443975310f699b95"}, - {file = "websockets-13.0-pp39-pypy39_pp73-manylinux_2_5_i686.manylinux1_i686.manylinux_2_17_i686.manylinux2014_i686.whl", hash = "sha256:c210d1460dc8d326ffdef9703c2f83269b7539a1690ad11ae04162bc1878d33d"}, - {file = "websockets-13.0-pp39-pypy39_pp73-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_17_x86_64.manylinux2014_x86_64.whl", hash = "sha256:b32f38bc81170fd56d0482d505b556e52bf9078b36819a8ba52624bd6667e39e"}, - {file = "websockets-13.0-pp39-pypy39_pp73-win_amd64.whl", hash = "sha256:81a11a1ddd5320429db47c04d35119c3e674d215173d87aaeb06ae80f6e9031f"}, - {file = "websockets-13.0-py3-none-any.whl", hash = "sha256:dbbac01e80aee253d44c4f098ab3cc17c822518519e869b284cfbb8cd16cc9de"}, - {file = "websockets-13.0.tar.gz", hash = "sha256:b7bf950234a482b7461afdb2ec99eee3548ec4d53f418c7990bb79c620476602"}, -] - -[metadata] -lock-version = "2.0" -python-versions = "^3.11" -content-hash = "c402be98f3a91a1cf82217fef7134d45ffca74e909efe3bd50f3ef0fb3accc0c" diff --git a/pyproject.toml b/pyproject.toml index 92b9109..c710ffb 100644 --- a/pyproject.toml +++ b/pyproject.toml @@ -1,24 +1,36 @@ -[tool.poetry] +[project] name = "hackmap" version = "0.1.0" description = "Map for edinburgh hacklab" -authors = ["Aria Shrimpton "] -license = "AGPL" +authors = [{ name = "Aria Shrimpton", email = "me@aria.rip" }] +requires-python = ">=3.11,<4" readme = "README.md" -package-mode = false +license = "AGPL" +classifiers = [ + "Programming Language :: Python :: 3", + "Programming Language :: Python :: 3.11", + "Programming Language :: Python :: 3.12", + "Programming Language :: Python :: 3.13", + "Programming Language :: Python :: 3.14", +] +dependencies = [ + "django>=5.1,<6", + "django-vite>=3.0.4,<4", + "websockets>=13.0,<14", + "asyncio-paho>=0.6.0,<0.7", + "django-auth-ldap>=5.1.0,<6", +] -[tool.poetry.dependencies] -python = "^3.11" -django = "^5.1" -django-vite = "^3.0.4" -websockets = "^13.0" -asyncio-paho = "^0.6.0" -django-auth-ldap = "^5.1.0" +[dependency-groups] +dev = ["django-stubs>=5.1.1,<6"] +[tool.uv] +package = false +default-groups = "all" -[tool.poetry.group.dev.dependencies] -django-stubs = "^5.1.1" +[tool.uv.build-backend] +module-root = "" [build-system] -requires = ["poetry-core"] -build-backend = "poetry.core.masonry.api" +requires = ["uv_build>=0.11.32,<0.12.0"] +build-backend = "uv_build" diff --git a/shell.nix b/shell.nix index 13a1c9e..a2d72b0 100644 --- a/shell.nix +++ b/shell.nix @@ -3,7 +3,6 @@ }: pkgs.mkShell { buildInputs = [ - pkgs.poetry pkgs.ruff pkgs.pyright pkgs.sqlite diff --git a/static/css/printers.css b/static/css/printers.css index 906dd56..4da48d5 100644 --- a/static/css/printers.css +++ b/static/css/printers.css @@ -5,7 +5,7 @@ --progress-outline: var(--color-foreground); --progress-bg: var(--color-background); --progress-fg: var(--color-bright-yellow); - --animation-length: 0.3s; + --animation-length: 0.2s; } main { @@ -13,6 +13,11 @@ main { margin: 0 auto; } +main > h1 { + text-align: center; + font-size: 3rem; +} + main section { box-sizing: border-box; margin-bottom: 2rem; @@ -23,6 +28,7 @@ main section { display: grid; opacity: 0.5; + transition: opacity var(--animation-length) linear; grid-template-columns: 100%; /* TODO: camera styling */ } @@ -34,6 +40,15 @@ main section .description { main section .info { padding: 0.8rem; } +main section .camera { + max-width: 100%; +} +main section .camera img { + display: block; + width: 80%; + aspect-ratio: 1.7777; + margin: 1rem auto; +} main section progress { width: 100%; background: var(--progress-bg); @@ -43,14 +58,37 @@ main section progress { } } +main section .status, +main section progress { + transition: height var(--animation-length) linear, + margin var(--animation-length) linear, + opacity var(--animation-length) linear, + box-shadow var(--animation-length) linear; + margin: 0; +} + main section:not(.active) .status, main section:not(.active) progress { - display: none; + height: 0; + opacity: 0; } + main section.active { box-shadow: 0px 0px 2px 3px var(--active-outline-color); opacity: 1; } main section.active progress { border: 1px solid var(--progress-outline); + height: 1lh; +} +main section.active .status { + height: 1lh; + margin: 0.75lh 0; +} + +main section .camera { + width: 50%; + margin: 0 auto; + transition: width var(--animation-length) ease-in; } +main section.active .camera { width: 100%; } diff --git a/static/js/control.js b/static/js/control.js index ad26316..2f09f68 100644 --- a/static/js/control.js +++ b/static/js/control.js @@ -1,5 +1,9 @@ // regular old buttons +var lastInteraction = new Date(); +const KIOSK_INTERACT_TIMEOUT = 60 * 1000; + $('.ajax').click(function(e) { + lastInteraction = new Date(); $.ajax({ url: '/trigger/' + $(this).data('id') }); @@ -97,3 +101,14 @@ client.on("reconnect", () => { console.log("mqtt reconnecting..."); }); + +// timeout to go back home when not on main page +var doHomeTimeout = JSON.parse(document.getElementById('doHomeTimeout').textContent); +if (doHomeTimeout) { + console.log("in kiosk mode"); + setInterval(function() { + if (new Date() - lastInteraction >= KIOSK_INTERACT_TIMEOUT) { + document.location = "/"; + } + }, KIOSK_INTERACT_TIMEOUT); +} diff --git a/static/js/map.js b/static/js/map.js index 9034e6f..5c6dc88 100644 --- a/static/js/map.js +++ b/static/js/map.js @@ -6,7 +6,8 @@ const client = mqtt.connect(wsURL, { protocolVersion: 4, clean: true, reconnectPeriod: 5000, - connectTimeout: 30 * 1000, + connectTimeout: 15 * 1000, + reconnectOnConnackError: true, }); const mapElement = document.querySelector('#map'); @@ -33,7 +34,7 @@ function updateElementState(msg) { if (msg.type === "heating") { el.innerHTML = msg.state !== "off" ? msg.state + "°" : ""; } else if (msg.type == "temperature") { - el.innerHTML = msg.state + "°"; + el.innerHTML = parseFloat(msg.state).toFixed(1) + "°"; } else { el.className.baseVal = [msg.target, msg.type, msg.state].join(' '); } @@ -49,8 +50,11 @@ client.on("connect", () => { "tool/+/user", "tool/+/status", // for when tool controllers are powered down "environment/+/heating", - "environment/+/elsys/temperature", - "sensor/g1/temperature" + "environment/g1/elsys/temperature", + "sensor/g11/temperature/28c893a704000068", + "sensor/g2/temperature/28c9b9a70400001a", + "sensor/g8/temperature/282c7da7040000e5", + "sensor/g14/temperature/28ff1097c4170523", ].forEach(key => { console.log(`mqtt subscribe: ${key}`); client.subscribe(key); @@ -117,10 +121,8 @@ client.on("message", (topic, message, packet) => { target: room, state: value, }; - } else if (topic.endsWith("/temperature")) { + } else if (topic.includes("temperature")) { var room = topic.split("/")[1]; - if (room === "g1" && topic.includes("elsys")) - return; msg = { display: "", diff --git a/static/js/printers.js b/static/js/printers.js index 0db70d1..a77ed04 100644 --- a/static/js/printers.js +++ b/static/js/printers.js @@ -9,6 +9,7 @@ const client = mqtt.connect(wsURL, { reconnectPeriod: 5000, connectTimeout: 30 * 1000, }); + client.on("connect", () => { console.log("mqtt connected"); @@ -17,6 +18,7 @@ client.on("connect", () => { $(`[data-printer]`).each(function() { var printer = $(this).data("printer"); topics.add(`printers/${printer}/state`); + topics.add(`printers/${printer}/file`); topics.add(`printers/${printer}/percent_done`); topics.add(`printers/${printer}/time_remaining_mins`); }); @@ -31,24 +33,30 @@ client.on("message", (topic, message, packet) => { var value = message.toString(); let printer = topic.split("/")[1]; let typ = topic.split("/")[2]; + let printerSection = $(`section[data-printer=${printer}]`); if (typ === "state" && value === "Printing") { - $(`section[data-printer=${printer}]`).addClass(`active`); + printerSection.addClass(`active`); + printerSection.removeClass(`preparing`); } else if (typ === "state" && value == "Preprint") { - $(`section[data-printer=${printer}]`).addClass(`active`); - $(`[data-printer=${printer}] .percent`).text(`Preparing to print...`); + printerSection.addClass(`active`); + printerSection.addClass(`preparing`); + $(`[data-printer=${printer}] .percent`).text(`Preparing...`); $(`[data-printer=${printer}] .time`).text(``); + $(`[data-printer=${printer}] .file`).text(``); $(`[data-printer=${printer}] progress`).val(0); } else if (typ === "state") { - $(`section[data-printer=${printer}]`).removeClass(`active`); + printerSection.removeClass(`active`); + printerSection.removeClass(`preparing`); $(`[data-printer=${printer}] .percent`).text(``); $(`[data-printer=${printer}] .time`).text(``); $(`[data-printer=${printer}] progress`).val(0); + return; } - if (typ === "percent_done") { + if (typ === "percent_done" && !printerSection.hasClass('preparing')) { $(`[data-printer=${printer}] .percent`).text(`${value}% complete -`); $(`[data-printer=${printer}] progress`).val(value); - } else if (typ === "time_remaining_mins" && value != "0") { + } else if (typ === "time_remaining_mins" && !printerSection.hasClass('preparing')) { $(`[data-printer=${printer}] .time`).text(`${value} minutes remaining`); } else if (typ === "file") { $(`[data-printer=${printer}] .file`).text(`Printing ${value} - `); @@ -63,3 +71,61 @@ client.on("error", (err) => { client.on("reconnect", () => { console.log("mqtt reconnecting..."); }); + + +let lightsOffTask = undefined; +function lights_on() { + $.ajax({ + url: '/printers/lights/on' + }); + + // Turn off after 20 seconds + if (lightsOffTask) + clearTimeout(lightsOffTask) + lightsOffTask = setTimeout(lights_off, 20 * 1000); +} + +function lights_off() { + $.ajax({ + url: '/printers/lights/off' + }); +} + +function update_cameras() { + $('.camera img').each(function() { + if (!this.src) + return; + + var url = URL.parse(this.src); + let params = url.searchParams; + params.set('cacheBusting', Date.now()); + url.search = params.toString(); + + this.src = url.toString(); + }); +} + +let fps = 5; +setInterval(update_cameras, 1000 / fps); + +document.onkeydown = function (e) { + if (e.key == "a") { + lights_on() + } +}; + +document.onblur = function (e) { + var targetElements = document.querySelectorAll('.camera img'); + for (var el of targetElements) { + el.dataset['src'] = el.src; + el.src = ''; + } +}; + +document.onfocus = function (e) { + var targetElements = document.querySelectorAll('.camera img'); + for (var el of targetElements) { + if (el.dataset['src']) + el.src = el.dataset['src']; + } +}; diff --git a/templates/labdash/buttongroup_list.html b/templates/labdash/buttongroup_list.html index df275bb..df95fb0 100644 --- a/templates/labdash/buttongroup_list.html +++ b/templates/labdash/buttongroup_list.html @@ -47,6 +47,7 @@

diff --git a/templates/labprinter/printer_list.html b/templates/labprinter/printer_list.html index 4b81e6c..427e48e 100644 --- a/templates/labprinter/printer_list.html +++ b/templates/labprinter/printer_list.html @@ -9,9 +9,10 @@ {% block body %}
+

3D Printers

{% for printer in printers %}
-
+

{{ printer.name }}

{{ printer.description }}

@@ -22,6 +23,11 @@

{{ printer.name }}

+ {% if printer.camera_url %} +
+ Webcam Unavailable +
+ {% endif %}
{% endfor %}
diff --git a/templates/map.html b/templates/map.html index 2a491cb..48cff1f 100644 --- a/templates/map.html +++ b/templates/map.html @@ -19,25 +19,25 @@ + transform="translate(268.39243,123.95924)"> lasercutter + x="-267.40039" + y="199.73814">lasercutter1