#!/usr/bin/env python3
"""Drop the badge-paint firmware to the MicroPython REPL so mpremote works
(the app disables Ctrl-C handling to stay binary-safe).

Usage: python exit_badge.py COM5
"""
import sys
import time

import serial

port = sys.argv[1] if len(sys.argv) > 1 else "COM5"
with serial.Serial(port, 115200, timeout=2) as ser:
    ser.write(b"BPNT-EXIT")
    ser.flush()
    time.sleep(0.5)
    print(ser.read(200).decode(errors="replace"))
print("badge is at the REPL now - mpremote will work until the next reset")
