MCPcopy Create free account
hub / github.com/FastLED/FastLED / main

Function main

ci/autoresearch/test_flexio_rx_objectfled.py:143–239  ·  view source on GitHub ↗
(argv: list[str] | None = None)

Source from the content-addressed store, hash-verified

141
142
143def main(argv: list[str] | None = None) -> int:
144 # `argv` accepted so that unit tests can inject argument lists without
145 # touching the real `sys.argv`. Defaults to `None`, which argparse
146 # interprets as "use sys.argv[1:]".
147 p = argparse.ArgumentParser()
148 p.add_argument("--port", default=DEFAULT_PORT)
149 p.add_argument("--baud", default=DEFAULT_BAUD, type=int)
150 p.add_argument(
151 "--tx-pin", default=3, type=int, help="TX pin driven by ObjectFLED (default: 3)"
152 )
153 p.add_argument(
154 "--rx-pin", default=4, type=int, help="RX pin captured by FLEXIO1 (default: 4)"
155 )
156 p.add_argument(
157 "--capture-ms",
158 default=50,
159 type=int,
160 help="Capture window per test case in ms (default: 50)",
161 )
162 args = p.parse_args(argv)
163
164 if serial is None:
165 print(
166 "ERROR: pyserial not installed. Run: uv pip install pyserial",
167 file=sys.stderr,
168 )
169 return 2
170
171 print(f"[flexio-objectfled] opening {args.port} @ {args.baud}")
172 try:
173 s = serial.Serial(args.port, args.baud, timeout=0.1)
174 except KeyboardInterrupt as ki:
175 # Catch Ctrl-C before the bare `Exception`/`SerialException` block so
176 # interactive users can abort cleanly. `handle_keyboard_interrupt`
177 # routes the signal through the project-wide interrupt handler
178 # (required by the KBI002 lint).
179 handle_keyboard_interrupt(ki)
180 raise
181 except serial.SerialException as e:
182 print(f"ERROR: could not open {args.port}: {e}", file=sys.stderr)
183 return 2
184 with s:
185 s.dtr = True
186 s.rts = True
187 time.sleep(1.0)
188 s.reset_input_buffer()
189
190 ping = send_rpc(s, "ping", request_id=1, timeout=5.0)
191 if not ping or "result" not in ping:
192 print(
193 "ERROR: ping failed; is AutoResearch flashed and running?",
194 file=sys.stderr,
195 )
196 return 2
197 print(
198 f"[flexio-objectfled] ping ok: uptime={ping['result'].get('uptimeMs')} ms"
199 )
200

Callers 1

Calls 6

parse_argsMethod · 0.80
send_rpcFunction · 0.70
evaluateFunction · 0.70
printFunction · 0.50
getMethod · 0.45

Tested by

no test coverage detected