From 667bb3800956ebdada39c16606eb68f751c34a59 Mon Sep 17 00:00:00 2001 From: jedgarpark Date: Mon, 4 Aug 2025 11:49:28 -0700 Subject: [PATCH] fixed status_label looping and error message timing --- ESP-NOW_basics/espnow_transceiver.py | 17 +++++++++++++---- 1 file changed, 13 insertions(+), 4 deletions(-) mode change 100755 => 100644 ESP-NOW_basics/espnow_transceiver.py diff --git a/ESP-NOW_basics/espnow_transceiver.py b/ESP-NOW_basics/espnow_transceiver.py old mode 100755 new mode 100644 index aa43b417a..39f828645 --- a/ESP-NOW_basics/espnow_transceiver.py +++ b/ESP-NOW_basics/espnow_transceiver.py @@ -19,7 +19,7 @@ group = displayio.Group() # Create background rectangles like your example -background_rect = Rect(0, 0, display.width, display.height, fill=000000) +background_rect = Rect(0, 0, display.width, display.height, fill=0x000000) group.append(background_rect) # Set up a button on pin D0/BOOT @@ -100,10 +100,12 @@ def get_sender_color(rx_message): # Show the display display.root_group = group -# Button debouncing +# Button debouncing and status tracking last_button_time = 0 button_debounce = 0.2 # 200ms debounce message_count = 0 +status_reset_time = 0 +status_needs_reset = False while True: current_time = time.monotonic() @@ -123,18 +125,23 @@ def get_sender_color(rx_message): sent_label.text = "TX'd: " # Keep this tomato colored sent_counter_label.text = str(message_count) # Color with sender color sent_counter_label.color = SENDER_COLORS.get(DEVICE_ID, WHITE) + status_reset_time = current_time + 0.5 # Reset after 0.5 seconds + status_needs_reset = True except Exception as ex: # pylint: disable=broad-except print(f"Send failed: {ex}") status_label.text = "xxx" status_label.color = RED + status_reset_time = current_time + 2.0 # Show error for 2 seconds + status_needs_reset = True last_button_time = current_time - # Reset status after a moment - if current_time - last_button_time > 0.2: + # Reset status only when needed and after appropriate delay + if status_needs_reset and current_time >= status_reset_time: status_label.text = "press D0 to send" status_label.color = TOMATO + status_needs_reset = False # Check for incoming packets if e: @@ -153,5 +160,7 @@ def get_sender_color(rx_message): received_label.text = "RX'd: " # Keep this tomato colored received_message_label.text = message[-12:] # Color just the message received_message_label.color = sender_color + status_reset_time = current_time + 0.5 # Reset after 0.5 seconds + status_needs_reset = True time.sleep(0.05) # Light polling