Skip to content

Commit 11fb234

Browse files
authored
Merge pull request #3097 from jedgarpark/espnow-basics
fixed status_label looping and error message timing
2 parents 4919e36 + 667bb38 commit 11fb234

File tree

1 file changed

+13
-4
lines changed

1 file changed

+13
-4
lines changed

ESP-NOW_basics/espnow_transceiver.py

100755100644
Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
group = displayio.Group()
2020

2121
# Create background rectangles like your example
22-
background_rect = Rect(0, 0, display.width, display.height, fill=000000)
22+
background_rect = Rect(0, 0, display.width, display.height, fill=0x000000)
2323
group.append(background_rect)
2424

2525
# Set up a button on pin D0/BOOT
@@ -100,10 +100,12 @@ def get_sender_color(rx_message):
100100
# Show the display
101101
display.root_group = group
102102

103-
# Button debouncing
103+
# Button debouncing and status tracking
104104
last_button_time = 0
105105
button_debounce = 0.2 # 200ms debounce
106106
message_count = 0
107+
status_reset_time = 0
108+
status_needs_reset = False
107109

108110
while True:
109111
current_time = time.monotonic()
@@ -123,18 +125,23 @@ def get_sender_color(rx_message):
123125
sent_label.text = "TX'd: " # Keep this tomato colored
124126
sent_counter_label.text = str(message_count) # Color with sender color
125127
sent_counter_label.color = SENDER_COLORS.get(DEVICE_ID, WHITE)
128+
status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
129+
status_needs_reset = True
126130

127131
except Exception as ex: # pylint: disable=broad-except
128132
print(f"Send failed: {ex}")
129133
status_label.text = "xxx"
130134
status_label.color = RED
135+
status_reset_time = current_time + 2.0 # Show error for 2 seconds
136+
status_needs_reset = True
131137

132138
last_button_time = current_time
133139

134-
# Reset status after a moment
135-
if current_time - last_button_time > 0.2:
140+
# Reset status only when needed and after appropriate delay
141+
if status_needs_reset and current_time >= status_reset_time:
136142
status_label.text = "press D0 to send"
137143
status_label.color = TOMATO
144+
status_needs_reset = False
138145

139146
# Check for incoming packets
140147
if e:
@@ -153,5 +160,7 @@ def get_sender_color(rx_message):
153160
received_label.text = "RX'd: " # Keep this tomato colored
154161
received_message_label.text = message[-12:] # Color just the message
155162
received_message_label.color = sender_color
163+
status_reset_time = current_time + 0.5 # Reset after 0.5 seconds
164+
status_needs_reset = True
156165

157166
time.sleep(0.05) # Light polling

0 commit comments

Comments
 (0)