fix long press detection
This commit is contained in:
@@ -384,24 +384,25 @@ def get_position(deck: StreamDeck, key: int) -> SDButtonPosition:
|
|||||||
|
|
||||||
async def long_press_callback(key: int):
|
async def long_press_callback(key: int):
|
||||||
"""Handle callback after long press seconds."""
|
"""Handle callback after long press seconds."""
|
||||||
print("Long press detected")
|
|
||||||
|
button = get_button(key)
|
||||||
|
|
||||||
|
now = datetime.now()
|
||||||
|
|
||||||
# Check state of button
|
# Check state of button
|
||||||
for deck in streamdecks:
|
db_button_state = get_button_state(key)
|
||||||
if not deck.is_visual():
|
|
||||||
continue
|
|
||||||
|
|
||||||
if not deck.is_open():
|
if not isinstance(db_button_state, tuple):
|
||||||
deck.open()
|
print("ERROR reading state")
|
||||||
|
return
|
||||||
|
|
||||||
states = deck.key_states()
|
last_update: str = db_button_state[1]
|
||||||
|
last_update_datetime = datetime.strptime(last_update, DATETIME_FORMAT)
|
||||||
|
diff = now - last_update_datetime
|
||||||
|
|
||||||
button = get_button(key)
|
if db_button_state[0] is True and diff.seconds >= LONG_PRESS_SECONDS:
|
||||||
if not isinstance(button, SDButton):
|
print("Long press detected")
|
||||||
return
|
await websocket_broadcast(encode({"event": "longPress", "args": button.uuid}))
|
||||||
|
|
||||||
if states[key] is True:
|
|
||||||
await websocket_broadcast(encode({"event": "longPress", "args": button.uuid}))
|
|
||||||
|
|
||||||
|
|
||||||
async def on_key_change(_: StreamDeck, key: int, state: bool):
|
async def on_key_change(_: StreamDeck, key: int, state: bool):
|
||||||
@@ -428,18 +429,16 @@ async def on_key_change(_: StreamDeck, key: int, state: bool):
|
|||||||
write_button_state(key, state, now.strftime(DATETIME_FORMAT))
|
write_button_state(key, state, now.strftime(DATETIME_FORMAT))
|
||||||
return
|
return
|
||||||
|
|
||||||
|
write_button_state(key, state, now.strftime(DATETIME_FORMAT))
|
||||||
|
|
||||||
last_state: bool = db_button_state[0]
|
last_state: bool = db_button_state[0]
|
||||||
last_update: str = db_button_state[1]
|
last_update: str = db_button_state[1]
|
||||||
last_update_datetime = datetime.strptime(last_update, DATETIME_FORMAT)
|
last_update_datetime = datetime.strptime(last_update, DATETIME_FORMAT)
|
||||||
diff = now - last_update_datetime
|
diff = now - last_update_datetime
|
||||||
|
|
||||||
if last_state is True and state is False and diff.seconds < LONG_PRESS_SECONDS:
|
if last_state is True and state is False and diff.seconds < LONG_PRESS_SECONDS:
|
||||||
await websocket_broadcast(
|
print("Single Tap detected")
|
||||||
encode({"event": "singleTap", "args": button.uuid}))
|
await websocket_broadcast(encode({"event": "singleTap", "args": button.uuid}))
|
||||||
write_button_state(key, state, now.strftime(DATETIME_FORMAT))
|
|
||||||
return
|
|
||||||
|
|
||||||
write_button_state(key, state, now.strftime(DATETIME_FORMAT))
|
|
||||||
|
|
||||||
|
|
||||||
def update_button_icon(uuid: str, svg: str):
|
def update_button_icon(uuid: str, svg: str):
|
||||||
|
|||||||
Reference in New Issue
Block a user