fixxed imports, added state.py

This commit is contained in:
oberon 2026-02-16 14:49:18 +01:00
parent 6265683cce
commit f3679cbd29
6 changed files with 26 additions and 3 deletions

View File

@ -6,6 +6,7 @@ from .routes.main import main_bp
from .routes.admin import admin_bp from .routes.admin import admin_bp
from .routes.api import api_bp from .routes.api import api_bp
import threading import threading
import pygame
def create_app(): def create_app():
@ -32,6 +33,11 @@ def create_app():
from .bluetooth.manager import init_bluetooth from .bluetooth.manager import init_bluetooth
init_bluetooth() init_bluetooth()
# pygame initialisieren (einmalig)
pygame.mixer.init(frequency=44100, size=-16, channels=2, buffer=512)
pygame.mixer.music.set_volume(0.8) # Standard-Lautstärke
app.logger.info("pygame initialisiert")
# Blueprints registrieren # Blueprints registrieren
from .routes.main import main_bp from .routes.main import main_bp
from .routes.admin import admin_bp from .routes.admin import admin_bp

View File

@ -30,6 +30,8 @@ def init_bluetooth():
logger.info("Bluetooth-Komponenten initialisiert (Advertiser + Tracer)") logger.info("Bluetooth-Komponenten initialisiert (Advertiser + Tracer)")
# Hier ggf. weitere Initialisierung (z. B. hci0 prüfen) # Hier ggf. weitere Initialisierung (z. B. hci0 prüfen)
from app.state import current_device, current_module, current_hub
def connection_monitor(): def connection_monitor():
""" """
Background-Thread: Prüft alle 5 Sekunden, ob der Hub noch antwortet. Background-Thread: Prüft alle 5 Sekunden, ob der Hub noch antwortet.

View File

@ -1,6 +1,6 @@
# app/routes/admin.py # app/routes/admin.py
from flask import Blueprint, render_template, request, jsonify, redirect, url_for from flask import Blueprint, render_template, request, jsonify, redirect, url_for
from .. import current_config from app.state import current_config
from app.utils.helpers import load_configs, load_default_sounds from app.utils.helpers import load_configs, load_default_sounds
admin_bp = Blueprint('admin', __name__) admin_bp = Blueprint('admin', __name__)

View File

@ -1,6 +1,7 @@
# app/routes/api.py # app/routes/api.py
import pygame
from flask import Blueprint, jsonify, request from flask import Blueprint, jsonify, request
from .. import current_device, current_config, pygame from app.state import current_device, current_config
api_bp = Blueprint('api', __name__) api_bp = Blueprint('api', __name__)

View File

@ -1,7 +1,7 @@
# app/routes/main.py # app/routes/main.py
from flask import Blueprint, render_template, redirect, url_for, request, jsonify from flask import Blueprint, render_template, redirect, url_for, request, jsonify
from .. import current_config
from app.utils.helpers import load_configs, load_default_sounds from app.utils.helpers import load_configs, load_default_sounds
from app.state import current_config, reset_state
main_bp = Blueprint('main', __name__) main_bp = Blueprint('main', __name__)

14
app/state.py Normal file
View File

@ -0,0 +1,14 @@
# app/state.py Zentrale globale Zustände (wird von überall importiert)
current_config = None
current_hub = None
current_module = None
current_device = None
# Optional: Funktionen zum Setzen/Resetten (für Klarheit)
def reset_state():
global current_config, current_hub, current_module, current_device
current_config = None
current_hub = None
current_module = None
current_device = None