Skip to content

Commit

Permalink
cam_static is static_cam, pylint fixes, polishing
Browse files Browse the repository at this point in the history
  • Loading branch information
TojikCZ committed Oct 10, 2023
1 parent 948662c commit 6d7d30a
Show file tree
Hide file tree
Showing 67 changed files with 82 additions and 33 deletions.
2 changes: 1 addition & 1 deletion MANIFEST.in
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ include requirements-pi.txt
graft prusa/link/data
graft prusa/link/templates
graft prusa/link/static
graft prusa/link/cam_static
graft prusa/link/static_cam
graft image_builder
global-exclude *~
global-exclude *.swp
Expand Down
6 changes: 4 additions & 2 deletions prusa/link/printer_adapter/prusa_cam.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
"""Implements the PrusaLink class"""
# pylint: disable=duplicate-code

import logging
from threading import Event
from threading import enumerate as enumerate_threads
Expand All @@ -13,7 +15,7 @@
from ..cameras.v4l2_driver import V4L2Driver
from ..conditions import HW, use_connect_errors
from ..config import Config, Settings
from ..sdk_augmentation.printer import MyPrinter
from ..sdk_augmentation.printer import CameraOnly
from ..service_discovery import ServiceDiscovery
from .command_queue import CommandQueue
from .model import Model
Expand Down Expand Up @@ -46,7 +48,7 @@ def __init__(self, cfg: Config, settings: Settings) -> None:
# These start by themselves
self.service_discovery = ServiceDiscovery(self.cfg.http.port)

self.printer = MyPrinter()
self.printer = CameraOnly()

drivers: List[Type[CameraDriver]] = [V4L2Driver]
if PiCameraDriver.supported:
Expand Down
60 changes: 46 additions & 14 deletions prusa/link/sdk_augmentation/printer.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
"""Contains implementation of the augmented Printer class from the SDK"""
from logging import getLogger
from pathlib import Path
from threading import Event
from time import sleep
from typing import Any, Dict

Expand All @@ -25,8 +26,10 @@
log = getLogger("connect-printer")


class CameraPrinter(SDKPrinter):
"""An SDK Printer class, but only for cameras. Weird if you ask me"""
class Base(SDKPrinter):
"""An SDK Printer class, but only the base that sends snapshots to connect
This is further forked to a fully fledged Printer, or just a camera
triggering class"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down Expand Up @@ -59,13 +62,53 @@ def wait_stopped(self):
"""
self.snapshot_thread.join()

def connection_from_settings(self, settings):
"""Loads connection details from the Settings class."""
self.api_key = settings.service_local.api_key
server = SDKPrinter.connect_url(settings.service_connect.hostname,
settings.service_connect.tls,
settings.service_connect.port)
token = settings.service_connect.token

self.set_connection(server, token)
use_connect_errors(settings.use_connect())

def snapshot_loop(self):
"""Gives snapshot loop a consistent name with the rest of the app"""
prctl_name()
self.camera_controller.snapshot_loop()


class MyPrinter(CameraPrinter, metaclass=MCSingleton):
class CameraOnly(Base):
"""An SDK Printer class but only for cameras, will probably need renaming
"""

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._quit_evt = Event()
self.trigger_thread = Thread(target=self.trigger_loop, daemon=True)

def start(self):
"""Start SDK related threads.
"""
super().start()
self.trigger_thread.start()

def trigger_loop(self):
"""Gives trigger loop a consistent name with the rest of the app"""
while not self._quit_evt.is_set():
self.camera_controller.tick()
self._quit_evt.wait(0.2)

def wait_stopped(self):
"""Waits for the SDK threads to join
Waits for the additional trigger thread
"""
super().wait_stopped()
self.trigger_thread.join()


class MyPrinter(Base, metaclass=MCSingleton):
"""
Overrides some methods of the SDK Printer to provide better support for
PrusaLink
Expand Down Expand Up @@ -106,17 +149,6 @@ def get_info(self) -> Dict[str, Any]:
info["prusalink"] = __version__
return info

def connection_from_settings(self, settings):
"""Loads connection details from the Settings class."""
self.api_key = settings.service_local.api_key
server = SDKPrinter.connect_url(settings.service_connect.hostname,
settings.service_connect.tls,
settings.service_connect.port)
token = settings.service_connect.token

self.set_connection(server, token)
use_connect_errors(settings.use_connect())

def get_file_info(self, caller: Command) -> Dict[str, Any]:
"""Return file info for a given file
sometimes only when it exists"""
Expand Down
2 changes: 1 addition & 1 deletion prusa/link/static/index.html

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions prusa/link/static/main.38331aecb9f4fc5529ae.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions prusa/link/static/main.fefa0d0f82f3a5f05365.js

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
File renamed without changes
File renamed without changes
File renamed without changes
File renamed without changes

Large diffs are not rendered by default.

File renamed without changes.
File renamed without changes.
1 change: 1 addition & 0 deletions prusa/link/static_cam/main.6bb81a887945baa7f7fb.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions prusa/link/static_cam/main.cfdc12238939a0bebde7.js

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions prusa/link/web/camera_wizard.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""This module houses a modified wizard path for camera only PrusaLink"""
# pylint: disable=duplicate-code

from functools import wraps

Expand Down
2 changes: 1 addition & 1 deletion prusa/link/web/lib/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

CAMERA_STATIC_DIR = abspath(
os.environ.get('PRUSA_LINK_STATIC', join(str(files('prusa.link')),
'cam_static')))
'static_cam')))


class LinkWebApp(Application):
Expand Down
32 changes: 21 additions & 11 deletions prusa/link/web/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,17 +132,21 @@ def api_info(req):
printer = app.daemon.prusa_link.printer

info = {
'name': printer_settings.name,
'location': printer_settings.location,
'farm_mode': printer_settings.farm_mode,
"network_error_chime": printer_settings.network_error_chime,
'nozzle_diameter': printer.nozzle_diameter,
'min_extrusion_temp': LimitsMK3S.min_temp_nozzle_e,
'serial': printer.sn,
'hostname': service_connect.hostname,
'port': service_connect.port,
}

if not app.daemon.is_camera:
info.update({
'name': printer_settings.name,
'location': printer_settings.location,
'farm_mode': printer_settings.farm_mode,
"network_error_chime": printer_settings.network_error_chime,
'nozzle_diameter': printer.nozzle_diameter,
'min_extrusion_temp': LimitsMK3S.min_temp_nozzle_e,
'serial': printer.sn,
})

return JSONResponse(**info)


Expand All @@ -154,10 +158,7 @@ def api_status(req):
# pylint: disable=too-many-locals
status = {}
camera_configurator = app.daemon.prusa_link.camera_configurator

# --- Camera ---
status["camera"] = {"id": camera_configurator.order[0]} \
if camera_configurator.order else None
camera_controller = camera_configurator.camera_controller

if not app.daemon.is_camera:
job = app.daemon.prusa_link.model.job
Expand Down Expand Up @@ -233,6 +234,15 @@ def api_status(req):
}
status["transfer"] = status_transfer

# --- Camera ---
status["camera"] = {"id": camera_configurator.order[0]} \
if camera_configurator.order else None

status.setdefault("printer", {}).update({
"cameras": len(list(camera_controller.cameras_in_order)),
"state": State.IDLE.value,
})

return JSONResponse(**filter_null(status))


Expand Down
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class BuildStatic(Command):
), (
'target-cam-dir=',
'c',
"target cam build directory (default: './prusa/link/cam_static')",
"target cam build directory (default: './prusa/link/static_cam')",
), (
'use-prusalator=',
'p',
Expand All @@ -89,7 +89,7 @@ def finalize_options(self):
self.target_dir = os.path.join(cwd, 'prusa', 'link', 'static')
if self.target_cam_dir is None:
self.target_cam_dir = os.path.join(
cwd, 'prusa', 'link', 'cam_static')
cwd, 'prusa', 'link', 'static_cam')
if self.use_prusalator is not None:
self.use_prusalator = (self.use_prusalator.lower()
in ['true', '1', 'yes'])
Expand Down

0 comments on commit 6d7d30a

Please sign in to comment.