lpf2.virtual
In-firmware emulated LPF2 ports and devices.
Pair a port with a device (typically a subclass) to
present a fake device to the rest of the stack — used by
lpf2.hub_emulation to expose Python-implemented devices to
LEGO apps, and by the port expander to synthesise sub-ports.
Classes
Emulated LPF2 device backed by a |
|
Static descriptor for a device (modes + firmware/hardware versions). |
|
LPF2 port whose transport is a Python-side |
Package Contents
- class lpf2.virtual.device(descriptor: lpf2.device_descriptor)[source]
Emulated LPF2 device backed by a
device_descriptor.Subclass to implement custom behaviour: override
startPower(),setMode(),writeData()etc. The default overrides on this class call the C++ default logging implementation, so it is safe to callsuper().startPower(pw)from a subclass — recursion into Python is prevented on the C++ side.Registers itself with the firmware’s update registry at construction, so any C++
update()behaviour runs each tick automatically. Python code does not need to poll the device.Build a device from a
lpf2.device_descriptor.The descriptor defines the modes, versions and I/O masks the emulated device advertises.
- gotoAbsPosition(absPos: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Move to absolute encoder position. Default: log the call.
- setAccTime(time: int, profile: int) None[source]
Set acceleration time/profile. Default: log the call.
- setDecTime(time: int, profile: int) None[source]
Set deceleration time/profile. Default: log the call.
- setMode(mode: int, delta: float = 1.0) int[source]
Select the active input mode. Default: log the call. Returns 0.
- setModeCombo(idx: int, deltas: Sequence[float] = ()) int[source]
Select a mode combination. Default: log the call. Returns 0.
- setModeData(mode: int, buf: bytes) None[source]
Store
bufas the latest raw payload formodeand fire the value-change callback.
- setWriteDataCallback(cb: object) None[source]
Install a callback
cb(mode, data, userData)that intercepts writes made viawriteData()before the default logging implementation runs.
- startSpeed(speed: int = 100, maxPower: int = 100, useProfile: int = 0) None[source]
Run at
speedfor as long as commanded. Default: log the call.
- startSpeedForDegrees(degrees: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Rotate by
degrees. Default: log the call.
- class lpf2.virtual.device_descriptor[source]
Static descriptor for a device (modes + firmware/hardware versions).
Used to build virtual devices without a live LPF2 handshake.
- class lpf2.virtual.port[source]
Bases:
lpf2.portLPF2 port whose transport is a Python-side
device.attachDevicebinds adeviceinstance; from then on calls to the port’s motor/sensor methods are forwarded to the device’s overrides.