From d5f2abf2b88317ee288bf038f35a5325255a0a82 Mon Sep 17 00:00:00 2001 From: Adolfo Reyna Date: Wed, 17 Jun 2026 23:07:58 -0400 Subject: [PATCH] Implement safe, non-conflicting loopback boot method with BOOT button exit and automatic 120s timeout reset --- demo_audio_loopback.py | 20 ++++++++++++++++++++ main.py | 11 +++++++++++ 2 files changed, 31 insertions(+) diff --git a/demo_audio_loopback.py b/demo_audio_loopback.py index 416614c..afef1c4 100644 --- a/demo_audio_loopback.py +++ b/demo_audio_loopback.py @@ -93,7 +93,27 @@ def main(): display.show() print("Ready: Press and hold key/screen to record...") + start_wait = time.ticks_ms() while not is_talk_trigger_active(): + if buttons.boot.is_pressed() or time.ticks_diff(time.ticks_ms(), start_wait) > 120000: + print("Exit condition met. Deleting flag and resetting...") + if display: + display.clear(0) + if board_config.BOARD_TYPE == 'WAVESHARE_RLCD': + display.text("Exiting test...", 15, 60, 1) + display.text("Rebooting to normal...", 15, 80, 1) + else: + display.text("Exiting test...", 10, 50, 1) + display.text("Rebooting to normal...", 10, 70, 1) + display.show() + time.sleep(1) + try: + import os + os.remove("run_loopback.txt") + except: + pass + import machine + machine.reset() time.sleep_ms(30) print("Recording started! Speak into the microphone...") diff --git a/main.py b/main.py index 0b66129..1cbb6be 100644 --- a/main.py +++ b/main.py @@ -69,6 +69,17 @@ led_modes = [ local_led_mode_idx = 1 # Green breathing def main(): + # Check if we should run the audio loopback test instead + import os + try: + os.stat("run_loopback.txt") + print("run_loopback.txt found! Starting local audio loopback test...") + import demo_audio_loopback + demo_audio_loopback.main() + return + except OSError: + pass + global local_led_mode_idx import board_config