|
7 | 7 |
|
8 | 8 | from .__version__ import get_version
|
9 | 9 | from .constants import DEFAULT_WS_URL
|
| 10 | +from .control import set_control |
10 | 11 | from .event_queue import EventQueue
|
11 | 12 | from .file_ops import upload, upload_file
|
| 13 | +from .pins import pin_listen, pin_read |
12 | 14 | from .protocol_types import EventMessage, ResponseMessage
|
13 |
| -from .serial import monitor_lines |
| 15 | +from .serial import monitor_lines, write_serial |
14 | 16 | from .simulation import pause, restart, resume, start
|
15 | 17 | from .transport import Transport
|
16 | 18 |
|
@@ -191,5 +193,41 @@ async def serial_monitor_cat(self, decode_utf8: bool = True, errors: str = "repl
|
191 | 193 | else:
|
192 | 194 | print(line, end="", flush=True)
|
193 | 195 |
|
| 196 | + async def serial_write(self, data: bytes | str | list[int]) -> None: |
| 197 | + """Write data to the simulation serial monitor interface.""" |
| 198 | + await write_serial(self._transport, data) |
| 199 | + |
194 | 200 | def _on_pause(self, event: EventMessage) -> None:
|
195 | 201 | self.last_pause_nanos = int(event["nanos"])
|
| 202 | + |
| 203 | + async def read_pin(self, part: str, pin: str) -> ResponseMessage: |
| 204 | + """Read the current state of a pin. |
| 205 | +
|
| 206 | + Args: |
| 207 | + part: The part id (e.g. "uno"). |
| 208 | + pin: The pin name (e.g. "A2"). |
| 209 | + """ |
| 210 | + return await pin_read(self._transport, part=part, pin=pin) |
| 211 | + |
| 212 | + async def listen_pin(self, part: str, pin: str, listen: bool = True) -> ResponseMessage: |
| 213 | + """Start or stop listening for changes on a pin. |
| 214 | +
|
| 215 | + When enabled, "pin:change" events will be delivered via the transport's |
| 216 | + event mechanism. |
| 217 | +
|
| 218 | + Args: |
| 219 | + part: The part id. |
| 220 | + pin: The pin name. |
| 221 | + listen: True to start listening, False to stop. |
| 222 | + """ |
| 223 | + return await pin_listen(self._transport, part=part, pin=pin, listen=listen) |
| 224 | + |
| 225 | + async def set_control(self, part: str, control: str, value: int | bool | float) -> ResponseMessage: |
| 226 | + """Set a control value (e.g. simulate button press). |
| 227 | +
|
| 228 | + Args: |
| 229 | + part: Part id (e.g. "btn1"). |
| 230 | + control: Control name (e.g. "pressed"). |
| 231 | + value: Control value to set (float). |
| 232 | + """ |
| 233 | + return await set_control(self._transport, part=part, control=control, value=value) |
0 commit comments