fixing input device
This commit is contained in:
+10
-17
@@ -13,27 +13,23 @@ from fastapi.staticfiles import StaticFiles
|
|||||||
from fastapi.responses import FileResponse
|
from fastapi.responses import FileResponse
|
||||||
from pydantic import BaseModel
|
from pydantic import BaseModel
|
||||||
import uvicorn
|
import uvicorn
|
||||||
from ctypes import CFUNCTYPE, c_char_p, c_int, cdll
|
|
||||||
|
|
||||||
# Load environment variables
|
# Load environment variables
|
||||||
load_dotenv()
|
load_dotenv()
|
||||||
ENV_PATH = ".env"
|
ENV_PATH = ".env"
|
||||||
|
|
||||||
# Logic to suppress ALSA/JACK error spam on Linux
|
from contextlib import asynccontextmanager
|
||||||
def suppress_alsa_errors():
|
|
||||||
def py_error_handler(filename, line, function, err, fmt):
|
|
||||||
pass
|
|
||||||
ERROR_HANDLER_FUNC = CFUNCTYPE(None, c_char_p, c_int, c_char_p, c_int, c_char_p)
|
|
||||||
c_error_handler = ERROR_HANDLER_FUNC(py_error_handler)
|
|
||||||
try:
|
|
||||||
asound = cdll.LoadLibrary('libasound.so.2')
|
|
||||||
asound.snd_lib_error_set_handler(c_error_handler)
|
|
||||||
except Exception:
|
|
||||||
pass
|
|
||||||
|
|
||||||
suppress_alsa_errors()
|
@asynccontextmanager
|
||||||
|
async def lifespan(app: FastAPI):
|
||||||
|
# Startup: Start the background loop
|
||||||
|
start_interaction_loop()
|
||||||
|
yield
|
||||||
|
# Shutdown: Cleanup if needed
|
||||||
|
if interaction_task:
|
||||||
|
interaction_task.cancel()
|
||||||
|
|
||||||
app = FastAPI(title="Home-Bro Satellite")
|
app = FastAPI(title="Home-Bro Satellite", lifespan=lifespan)
|
||||||
app.mount("/static", StaticFiles(directory="static"), name="static")
|
app.mount("/static", StaticFiles(directory="static"), name="static")
|
||||||
|
|
||||||
class Config(BaseModel):
|
class Config(BaseModel):
|
||||||
@@ -206,9 +202,6 @@ async def save_config(config: Config, background_tasks: BackgroundTasks):
|
|||||||
background_tasks.add_task(restart_interaction_loop)
|
background_tasks.add_task(restart_interaction_loop)
|
||||||
return {"status": "ok"}
|
return {"status": "ok"}
|
||||||
|
|
||||||
@app.on_event("startup")
|
|
||||||
async def startup_event():
|
|
||||||
start_interaction_loop()
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
uvicorn.run(app, host="0.0.0.0", port=8080)
|
uvicorn.run(app, host="0.0.0.0", port=8080)
|
||||||
|
|||||||
Reference in New Issue
Block a user