lpf2.virtual
Advanced: pretend devices that you program yourself in Python.
Make a device (usually your own class based on it), put it in a
port, and it behaves like a real LEGO device. Combine it with
lpf2.hub_emulation so a LEGO app can “see” your custom
gadget, or put it behind a port expander.
Classes
A pretend device whose behaviour you write in Python. |
|
Advanced: describes a pretend device — its modes and version numbers. |
|
A pretend port that holds a pretend |
Package Contents
- class lpf2.virtual.device(descriptor: lpf2.device_descriptor)[source]
A pretend device whose behaviour you write in Python.
Make your own class based on it and write functions like
startPower()to decide what happens when someone drives your “motor”. By default every command is just printed to the log, and callingsuper().startPower(pw)from your version does the same. Describe its modes with alpf2.device_descriptor.Create a pretend device described by
descriptor(its modes and versions).- gotoAbsPosition(absPos: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Called when someone asks to go to a position. Default: print it to the log.
- presetEncoder(pos: int) None[source]
Called when someone resets the position. Default: print it to the log.
- setAccTime(time: int, profile: int) None[source]
Called when someone sets the speed-up time. Default: print it to the log.
- setDecTime(time: int, profile: int) None[source]
Called when someone sets the slow-down time. Default: print it to the log.
- setMode(mode: int, delta: float = 1.0) int[source]
Called when someone picks a mode. Default: print it to the log. Returns 0.
- setModeCombo(idx: int, deltas: Sequence[float] = ()) int[source]
Called when someone picks a mode combination. Default: print it to the log. Returns 0.
- setModeData(mode: int, buf: bytes) None[source]
Publish a new value (as raw bytes) for
mode— like a sensor reporting a reading.
- setWriteDataCallback(cb: object) None[source]
Run
cb(mode, data, userData)whenever raw data is sent to the device.
- startPower(pw: int) None[source]
Called when someone sets the motor power (-100..100). Default: print it to the log.
- startSpeed(speed: int = 100, maxPower: int = 100, useProfile: int = 0) None[source]
Called when someone asks for a steady speed. Default: print it to the log.
- startSpeedForDegrees(degrees: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Called when someone asks to turn by some degrees. Default: print it to the log.
- class lpf2.virtual.device_descriptor[source]
Advanced: describes a pretend device — its modes and version numbers.
Used together with
lpf2.virtual.device.
- class lpf2.virtual.port[source]
Bases:
lpf2.portA pretend port that holds a pretend
device.It works like any other
lpf2.port; commands sent to it go to your device’s functions.