brilliantlabsAR / monocle-micropython

Micropython ported to the Monocle
ISC License
221 stars 27 forks source link

Fix serial console #242

Closed josuah closed 1 year ago

josuah commented 1 year ago

The previous edit of fix-serial-console landed on the main branch by mistake.

This one brings these changes as well as extra changes back to dev.

After this commit, it will be possible to automate the app this way:

arGPT-test-suite.py

import sys
import pexpect
import time

def monocle_send_raw(data, timeout=30):
    global monocle
    monocle.send("\x16")
    monocle.expect("TX: ", timeout=1)
    monocle.send(data)
    monocle.send("\r")

print("info: connecting to the monocle")
monocle = pexpect.spawn(sys.argv[1])
monocle.expect("connected", timeout=5)

print("info: waiting for the app startup")
monocle.expect("Welcome", timeout=2)
monocle.expect("Connected", timeout=6)
monocle.expect("WaitForTap", timeout=2)
monocle.expect("(b'rdy:')", timeout=1)

print("info: press TOUCH_BUTTON_A or TOUCH_BUTTON_B")
monocle.expect("StartRecording", timeout=10)
monocle.expect("(b'ast:')", timeout=1)
monocle.expect("SendAudio", timeout=2)
monocle.expect("(b'aen:')", timeout=1)

print("info: sending ChatGPT response")
text = "ChatGPT response"
monocle.expect("WaitForPing", timeout=1)
monocle_send_raw("pin:automated-testing-with-expect", timeout=1)
monocle.expect("(b'pon:automated-testing-with-expect')", timeout=1)
monocle.expect("WaitForResponse", timeout=1)
monocle_send_raw(f"res:{text}", timeout=1)
monocle.expect("PrintResponse", timeout=1)

print("done")

To be run as python3 arGPT-test-suite.py tools/serial_console.py. The Monocle must have the arGPT scripts loaded first, and be freshly restarted: https://github.com/brilliantlabsAR/argpt-for-ios/tree/main/ios/arGPT/arGPT/Script%20Assets