add button mapings
This commit is contained in:
parent
cafd5064dc
commit
66cd01b4a6
@ -5,8 +5,16 @@
|
|||||||
# ANDROID AUTO: Play, Pause, Toggle play, Next track, Previous track, Home, Phone, Call end,
|
# ANDROID AUTO: Play, Pause, Toggle play, Next track, Previous track, Home, Phone, Call end,
|
||||||
# Voice command, Left, Right, Up, Down, Scroll wheel, Back, Enter
|
# Voice command, Left, Right, Up, Down, Scroll wheel, Back, Enter
|
||||||
|
|
||||||
BUTTON_MAPPINGS = {
|
def send_to_radio(btn):
|
||||||
|
tunerlist.send_button(btn)
|
||||||
|
|
||||||
|
def send_to_aa(btn):
|
||||||
|
queue.put_nowait(dumps({"button": btn}))
|
||||||
|
|
||||||
|
BUTTON_MAPPINGS = {
|
||||||
|
"VOL_UP": (send_to_radio, "VOL_UP"),
|
||||||
|
"VOL_DOWN": (send_to_radio, "VOL_DOWN"),
|
||||||
|
"PAUSE": (send_to_radio, "PAUSE")
|
||||||
}
|
}
|
||||||
|
|
||||||
# -----------------------------------------------------------------------------------------
|
# -----------------------------------------------------------------------------------------
|
||||||
@ -21,12 +29,6 @@ from fastapi.responses import PlainTextResponse, JSONResponse
|
|||||||
from asyncio import create_task, CancelledError, Queue
|
from asyncio import create_task, CancelledError, Queue
|
||||||
from uvicorn import run
|
from uvicorn import run
|
||||||
|
|
||||||
def send_to_radio(btn):
|
|
||||||
tunerlist.send_button(btn)
|
|
||||||
|
|
||||||
def send_to_aa(btn):
|
|
||||||
queue.put_nowait(dumps({"button": btn}))
|
|
||||||
|
|
||||||
app = FastAPI()
|
app = FastAPI()
|
||||||
background_tasks = []
|
background_tasks = []
|
||||||
|
|
||||||
@ -75,10 +77,9 @@ async def button_listener():
|
|||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
button = await buttons.queue.get()
|
button = await buttons.queue.get()
|
||||||
if button in ("VOL_UP", "VOL_DOWN", "PAUSE"):
|
if button in BUTTON_MAPPINGS:
|
||||||
create_task(tunerlist.send_button(button))
|
func, arg = BUTTON_MAPPINGS[button]
|
||||||
else:
|
func(arg)
|
||||||
pass
|
|
||||||
except CancelledError:
|
except CancelledError:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
@ -113,18 +114,11 @@ async def websocket_endpoint(websocket: WebSocket):
|
|||||||
async def state_endpoint():
|
async def state_endpoint():
|
||||||
return dumps(state_to_send)
|
return dumps(state_to_send)
|
||||||
|
|
||||||
@app.get("/button", response_class=PlainTextResponse)
|
|
||||||
async def button_endpoint(request: Request):
|
|
||||||
btn = request.query_params.get("btn")
|
|
||||||
if btn is None:
|
|
||||||
return "No button specified"
|
|
||||||
await tunerlist.send_button(btn)
|
|
||||||
return btn
|
|
||||||
|
|
||||||
@app.get("/btn", response_class=PlainTextResponse)
|
@app.get("/btn", response_class=PlainTextResponse)
|
||||||
async def emulated_button(request: Request):
|
async def emulated_button(request: Request):
|
||||||
btn = request.query_params.get("btn")
|
btn = request.query_params.get("btn")
|
||||||
print("CD Changer button: ", btn)
|
print("CD Changer button: ", btn)
|
||||||
|
buttons.queue.put_nowait(btn)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
run(app=app, host="0.0.0.0", port=5959, log_level="info")
|
run(app=app, host="0.0.0.0", port=5959, log_level="info")
|
||||||
|
Loading…
x
Reference in New Issue
Block a user