Replace BoardButtons with direct Pin polling in demo_audio_loopback.py to avoid interrupt storms on mechanical button release
This commit is contained in:
@@ -2,7 +2,6 @@ import time
|
||||
import machine
|
||||
from machine import Pin, I2S
|
||||
import board_config
|
||||
from button_util import BoardButtons
|
||||
import audio_util
|
||||
|
||||
def play_raw_pcm(filename, channels=2, rate=16000, bits=16, volume=90):
|
||||
@@ -62,16 +61,15 @@ def main():
|
||||
print("=== Dynamic Audio Loopback Utility Script ===")
|
||||
print(f"Board Detected: {board_config.BOARD_TYPE}")
|
||||
|
||||
# Initialize buttons
|
||||
buttons = BoardButtons()
|
||||
# Initialize buttons using polling Pins instead of BoardButtons class (to avoid edge-triggered interrupt storms)
|
||||
key_pin = Pin(18, Pin.IN, Pin.PULL_UP)
|
||||
boot_pin = Pin(0, Pin.IN, Pin.PULL_UP)
|
||||
|
||||
# Helper to check if trigger is active
|
||||
def is_talk_trigger_active():
|
||||
if board_config.touch:
|
||||
return board_config.touch.is_touched()
|
||||
elif buttons and buttons.key:
|
||||
return buttons.key.is_pressed()
|
||||
return False
|
||||
return key_pin.value() == 0
|
||||
|
||||
filename = "local_audio_test.pcm"
|
||||
|
||||
@@ -95,7 +93,7 @@ def main():
|
||||
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:
|
||||
if boot_pin.value() == 0 or time.ticks_diff(time.ticks_ms(), start_wait) > 120000:
|
||||
print("Exit condition met. Deleting flag and resetting...")
|
||||
if display:
|
||||
display.clear(0)
|
||||
|
||||
Reference in New Issue
Block a user