MojoScale Studio Docs
API Reference

system

System runtime native Berry module.

Studio Docs Runtime

import system

The system module provides timers, event dispatch, memory information, reboot, serial-event helpers, and Berry script update helpers. It is the common glue for scheduled device behavior.

Quick example

import system

def tick():
    print(system.heap())

system.schedule("tick", 1000, 1000, -1, tick)
system.cancel("tick")
system.emit("ready", "ok")

importsystem

System runtime native Berry module.

The system module provides timers, event dispatch, memory information, reboot, serial-event helpers, and Berry script update helpers. It is the common glue for scheduled device behavior.

API 11 available

system.schedule(name: str, interval_ms: int, delay_ms: int, repeats: int, callback: callback, *callback_args: any) -> any

Create a named scheduled action.

The name identifies the action and can be passed to system.cancel(name) to stop future runs. Use repeats=-1 for a recurring action that runs forever.

Parameters
Name Type Pass as Required Description
name str positional or keyword Yes Scheduled action name. Use the same name with system.cancel(name).
interval_ms int positional or keyword Yes Interval between executions in milliseconds.
delay_ms int positional or keyword Yes Initial delay before the first execution in milliseconds.
repeats int positional or keyword Yes Number of times to run. Use -1 to run forever.
callback callback positional or keyword Yes Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware.
callback_args any extra positional No Optional positional values passed to the callback.
Returns

any Native scheduling result.

system.once(name: str, delay_ms: int, callback: callback, *callback_args: any) -> any

Schedule a one-shot timer.

Parameters
Name Type Pass as Required Description
name str positional Yes Timer name.
delay_ms int positional Yes Delay before execution in milliseconds.
callback callback positional Yes Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware.
callback_args any extra positional No Optional positional values passed to the callback.
Keyword Arguments

No keyword arguments are supported for this method. Pass callback_args as extra positional arguments after callback.

Returns

any Native scheduling result.

system.subscribe(event: str, callback: callback) -> any

Subscribe a callback to a named system event.

Parameters
Name Type Pass as Required Description
event str positional or keyword Yes Event name.
callback callback positional or keyword Yes Named global function to run. Pass the function without quotes; the transpiler sends its name string to firmware.
Keyword Arguments

No keyword arguments are supported for this method.

Returns

any Native subscription result.

system.emit(event: str, *event_args: any) -> any

Emit a named system event.

Parameters
Name Type Pass as Required Description
event str positional or keyword Yes Event name.
event_args any extra positional No Optional positional values passed to event subscribers.
Returns

any Native emit result.

system.cancel(name: str) -> any

Cancel a named scheduled action.

Pass the same name that was used when creating the action with system.schedule(name, interval_ms, delay_ms, repeats, callback, ...).

Parameters
Name Type Pass as Required Description
name str positional or keyword Yes Scheduled action name to cancel.
Returns

any Native cancel result.

system.heap() -> int

Return free heap memory.

Returns

int Free heap size in bytes.

system.mem_free() -> int

Return free memory.

Returns

int Free memory size in bytes, as reported by firmware.

system.heap_largest() -> bytes

Return the largest allocatable heap block.

Returns

bytes Largest free heap block in bytes.

system.uptime() -> any

Return device uptime.

Returns

any Uptime in milliseconds.

system.reboot() -> None

Reboot the device.

Returns

None Does not normally return after firmware resets.

system.serial_event(event_type: str, state: str = None, reason: str = None, message: str = None) -> any

Emit a serial-status style event.

Parameters
Name Type Pass as Required Description
event_type str positional or keyword Yes Serial event type.
state str positional or keyword No Optional state string.
reason str positional or keyword No Optional reason string.
message str positional or keyword No Optional human-readable message.
Returns

any Native event result.