API
- class Device(*args, startup: str = '\nimport binascii, errno, hashlib, machine, os, time\nfrom machine import ADC, I2C, Pin, PWM, SPI, Timer\nfrom time import sleep\nfrom micropython import const\n', **kwargs)
Belay interface into a micropython device.
- task(f: Optional[Callable[..., None]] = None, /, minify: bool = True, register: bool = True)
Decorator that send code to device that executes when decorated function is called on-host.
- Parameters
f (Callable) -- Function to decorate. Can only accept and return python literals.
minify (bool) -- Minify
cmd
code prior to sending. Defaults toTrue
.register (bool) -- Assign an attribute to
self.task
with same name asf
. Defaults toTrue
.
- thread(f: Optional[Callable[..., None]] = None, /, minify: bool = True, register: bool = True)
Decorator that send code to device that spawns a thread when executed.
- Parameters
f (Callable) -- Function to decorate. Can only accept python literals as arguments.
minify (bool) -- Minify
cmd
code prior to sending. Defaults toTrue
.register (bool) -- Assign an attribute to
self.thread
with same name asf
. Defaults toTrue
.
- __call__(cmd: str, deserialize: bool = True, minify: bool = True) Union[None, bool, bytes, int, float, str, List, Dict, Set]
Execute code on-device.
- Parameters
cmd (str) -- Python code to execute.
deserialize (bool) -- Deserialize the received bytestream to a python literal. Defaults to
True
.minify (bool) -- Minify
cmd
code prior to sending. Reduces the number of characters that need to be transmitted. Defaults toTrue
.
- Return type
Return value from executing code on-device.
- sync(folder: Union[str, Path], minify=True) None
Sync a local directory to the root of remote filesystem.
For each local file, check the remote file's hash, and transfer if they differ. If a file/folder exists on the remote filesystem that doesn't exist in the local folder, then delete it.
- Parameters
folder (str, Path) -- Directory of files to sync to the root of the board's filesystem.
- exception PyboardException
Bases:
Exception
Uncaught exception from the device.
- exception SpecialFilenameError
Bases:
Exception
Reserved filename like
boot.py
ormain.py
that may impact Belay functionality.
- exception SpecialFunctionNameError
Bases:
Exception
Reserved function name that may impact Belay functionality.
Currently limited to:
Names that start and end with double underscore,
__
.Names that start with
_belay
or__belay
- minify(code: str) str
Minify python code.
Naive code minifying that preserves names and linenos. Performs the following:
Removes docstrings.
Removes comments.
Removes unnecessary whitespace.
- Parameters
code (str) -- Python code to minify.
- Returns
Minified code.
- Return type
str