From 573b6d2ff7751d0d13222059fa292bb71194c5e3 Mon Sep 17 00:00:00 2001 From: marios8543 Date: Thu, 15 May 2025 23:17:36 +0300 Subject: [PATCH] button press bugfix --- tunerlistd/buttondecoder.py | 2 +- tunerlistd/main.py | 16 ++++++++++------ 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/tunerlistd/buttondecoder.py b/tunerlistd/buttondecoder.py index 00a2b96..38a6a03 100644 --- a/tunerlistd/buttondecoder.py +++ b/tunerlistd/buttondecoder.py @@ -60,7 +60,7 @@ class ButtonDecoder: for byte in data: if byte == 0xFF: self._process_line(buffer) - print(buffer) + #print(buffer) buffer.clear() else: buffer.append(byte) diff --git a/tunerlistd/main.py b/tunerlistd/main.py index f3fd47a..ddd4d44 100644 --- a/tunerlistd/main.py +++ b/tunerlistd/main.py @@ -4,10 +4,12 @@ # ANDROID AUTO: ENTER, LEFT, RIGHT, UP, DOWN, BACK, HOME, PHONE, CALL_END, PLAY, PAUSE, PREV_TRACK, NEXT_TRACK, TOGGLE_PLAY, VOICE, WHEEL_LEFT, WHEEL_RIGHT def send_to_radio(btn): + print("Sending to radio ", btn) tunerlist.send_button(btn) def send_to_aa(btn): - queue.put_nowait(dumps({"button": btn})) + print("Sending to AA ", btn) + queue.put_nowait({'button': {'btn': btn, 'state': 2}}) BUTTON_MAPPINGS = { "VOL_UP": (send_to_radio, "VOL_UP"), @@ -96,10 +98,12 @@ async def button_listener(): try: while True: button = await buttons.queue.get() - print(button) - if button in BUTTON_MAPPINGS: - func, arg = BUTTON_MAPPINGS[button] - func(arg) + if button.button in BUTTON_MAPPINGS and button.state == 0: + try: + func, arg = BUTTON_MAPPINGS[button.button] + func(arg) + except Exception as e: + print(e) except CancelledError: pass @@ -157,7 +161,7 @@ async def state_endpoint(): async def emulated_button(request: Request): btn = request.query_params.get("btn") print("CD Changer button: ", btn) - buttons.queue.put_nowait(btn) + buttons.queue.put_nowait(btn.strip()) @app.get("/settext", response_class=JSONResponse) async def set_text(request: Request):