working camera movement

This commit is contained in:
marcinator_2 committed 2026-10-16 01:38:10 +02:00
1 parent fce8f62534
commit 11e0875a20
21 files changed
+2117 -334

No files matched your search

+25 -7
View File
@@ -19,6 +19,7 @@ from .follow import FollowService
PAGE = (Path(__file__).parent / "index.html").read_text(encoding="utf-8")
CAMERA_PAGE = (Path(__file__).parent / "camera.html").read_text(encoding="utf-8")
PROFILE_CLEANUP_INTERVAL_SECONDS = 3600
LOGGER = logging.getLogger(__name__)
@@ -101,10 +102,15 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
response.headers["Referrer-Policy"] = "no-referrer"
return response
@app.get("/grab", response_class=HTMLResponse)
@app.get("/", response_class=HTMLResponse)
async def index():
return PAGE
@app.get("/kamera", response_class=HTMLResponse)
async def camera_page():
return CAMERA_PAGE
@app.get("/api/status")
async def status():
return {"controller": controller.status(), "camera": camera.status(),
@@ -120,7 +126,7 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
@app.post("/api/detection/config", dependencies=[Depends(require_ui)])
async def configure_detection(payload: dict):
if follow.active and payload.get("enabled"):
if follow.driver is not None and payload.get("enabled"):
raise HTTPException(status_code=409, detail="Zuerst Kameranachführung stoppen")
try:
return detection.configure(payload)
@@ -131,7 +137,7 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
@app.get("/api/follow")
async def follow_status():
return follow.status()
return {**follow.status(), "camera": camera.status()}
@app.post("/api/follow/{action}", dependencies=[Depends(require_ui)])
async def follow_action(action: str, payload: dict):
@@ -144,17 +150,18 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
if action == "select":
return follow.select(payload.get("token"), payload.get("x"), payload.get("y"))
if action == "start":
if detection.get_config()["enabled"]:
raise ValueError("Zuerst automatische Auslösung ausschalten und speichern")
if type(payload.get("hardware", False)) is not bool:
raise ValueError("Ungültige Servofreigabe")
controller.stop()
if payload.get("hardware", False) and detection.get_config()["enabled"]:
raise HTTPException(status_code=409, detail="Für echte Kamerabewegung zuerst auf der Grab-Seite die automatische Auslösung ausschalten und speichern")
session = follow.begin(payload.get("hardware", False),
payload.get("acknowledged") is True,
payload.get("operation", "follow"))
return {"session": session}
if action == "jog":
return follow.jog(payload.get("session"), payload.get("direction"), payload.get("sequence"))
if action == "center":
return follow.center(payload.get("session"), payload.get("sequence"))
if action == "remember":
return follow.remember(payload.get("session"), payload.get("direction"))
if action == "heartbeat":
@@ -261,6 +268,17 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
) from exc
return {"accepted": accepted, "reason": reason, "controller": controller.status()}
@app.post("/api/grave/stop", dependencies=[Depends(require_ui)])
async def grave_stop():
controller.stop()
return controller.status()
@app.post("/api/grave/reset", dependencies=[Depends(require_ui)])
async def grave_reset():
controller.reset()
detection.reset()
return controller.status()
@app.post("/api/stop", dependencies=[Depends(require_ui)])
async def stop():
follow.halt()
@@ -297,7 +315,7 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
if camera.error:
return
if frame is None or number == last_number:
await asyncio.sleep(0.1)
await asyncio.sleep(0.02)
continue
last_number = number
yield (
@@ -305,7 +323,7 @@ def create_app(demo: bool = False, state_dir: Path | None = None) -> FastAPI:
+ str(len(frame)).encode("ascii")
+ b"\r\n\r\n" + frame + b"\r\n"
)
await asyncio.sleep(0.1)
await asyncio.sleep(0.02)
return StreamingResponse(
frames(), media_type="multipart/x-mixed-replace; boundary=frame"