Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
283 changes: 283 additions & 0 deletions tests/scenarios/board_buttons.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,283 @@
type: board
Comment thread
nedseb marked this conversation as resolved.
name: "board_buttons"

# --- Polling tests (one per button) ---
# LED_GREEN signals when the board is ready to read the button.

tests:
- name: "Button A press (polling)"
action: hardware_script
Comment thread
nedseb marked this conversation as resolved.
pre_prompt: "Test polling boutons : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par A."
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("A_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
Comment thread
nedseb marked this conversation as resolved.
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button B press (polling)"
action: hardware_script
pre_prompt: "Bouton B"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("B_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
Comment thread
nedseb marked this conversation as resolved.
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button MENU press (polling)"
action: hardware_script
pre_prompt: "Bouton MENU"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("MENU_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if btn.value() == 0:
detected = True
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
led.off()
result = detected
expect_true: true
mode: [hardware]

# --- D-PAD buttons via MCP23009E (I2C 0x20, GPIO register 0x09) ---
# Read directly via I2C without importing the driver.
# Bit mapping: UP=bit7, DOWN=bit5, LEFT=bit6, RIGHT=bit4.

- name: "D-PAD UP press (polling)"
action: hardware_script
pre_prompt: "Test polling D-PAD : appuyez sur chaque bouton quand la LED verte s'allume (5s). Commençons par UP."
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 7
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD DOWN press (polling)"
action: hardware_script
pre_prompt: "Bouton DOWN"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 5
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD LEFT press (polling)"
action: hardware_script
pre_prompt: "Bouton LEFT"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 6
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "D-PAD RIGHT press (polling)"
action: hardware_script
pre_prompt: "Bouton RIGHT"
wait: false
script: |
from machine import Pin, I2C
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
i2c = I2C(1)
bit = 4
led.on()
detected = False
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
gpio = i2c.readfrom_mem(0x20, 0x09, 1)[0]
if not (gpio & (1 << bit)):
detected = True
break
sleep_ms(20)
led.off()
result = detected
expect_true: true
mode: [hardware]

# --- Interrupt tests (GPIO direct buttons) ---
# LED_GREEN signals when the board is ready; uses Pin.irq() to detect press.

- name: "Button A press (interrupt)"
action: hardware_script
pre_prompt: "Test interrupt boutons : appuyez brièvement sur chaque bouton quand la LED verte s'allume (5s). Commençons par A."
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("A_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button B press (interrupt)"
action: hardware_script
pre_prompt: "Bouton B"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("B_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]

- name: "Button MENU press (interrupt)"
action: hardware_script
pre_prompt: "Bouton MENU"
wait: false
script: |
from machine import Pin
from time import sleep_ms, ticks_ms, ticks_diff
led = Pin("LED_GREEN", Pin.OUT)
btn = Pin("MENU_BUTTON", Pin.IN, Pin.PULL_UP)
t_rel = ticks_ms()
while btn.value() == 0:
if ticks_diff(ticks_ms(), t_rel) > 3000:
break
sleep_ms(20)
Comment thread
nedseb marked this conversation as resolved.
detected = False
def on_press(pin):
global detected
detected = True
btn.irq(trigger=Pin.IRQ_FALLING, handler=on_press)
led.on()
t0 = ticks_ms()
while ticks_diff(ticks_ms(), t0) < 5000:
if detected:
break
sleep_ms(20)
btn.irq(handler=None)
led.off()
result = detected
expect_true: true
mode: [hardware]