lpf2.local

Ports driven directly by local hub UART (built-in hub sockets).

port = lpf2.port on local LPF2 UART transport. Instances live in C++, exposed via board module (e.g. hub.ports.A).

Classes

mode

Description of one LPF2 device mode (parsed from Port Mode Info).

port

Local (on-hub) LPF2 port.

Package Contents

class lpf2.local.mode[source]

Description of one LPF2 device mode (parsed from Port Mode Info).

Combines the mode’s name, value range (raw/PCT/SI), I/O mapping flags, dataset layout and the latest raw payload received on the mode.

PCTmax: float

Percent-scale maximum.

PCTmin: float

Percent-scale minimum.

SImax: float

SI-scale maximum.

SImin: float

SI-scale minimum.

dataSets: int

Number of datasets per sample.

decimals: int

Decimals shown for display.

figures: int

Total display figures (integer + decimals).

flags: int

Capability/flags bitmask.

format: int

Sample element format (0=int8, 1=int16, 2=int32, 3=float).

inMapping: int

Input-mapping bitmask (see LWP spec).

max: float

Raw value maximum.

min: float

Raw value minimum.

motorBias: int

Motor bias, per LWP.

name: str

Mode name (from the device).

outMapping: int

Output-mapping bitmask (see LWP spec).

rawData: bytes

Latest raw payload for this mode.

class lpf2.local.port[source]

Bases: lpf2.port

Local (on-hub) LPF2 port.

Same public API as lpf2.port; explicit subclass so isinstance checks distinguish local from virtual / remote ports.

getCapabilities() int[source]

Capability bitmask (bit 0x04 = combinable if device has combos).

getDeviceType() int[source]

Reported LPF2 device type (see lpf2.device_type).

getInfoStr() str[source]

Diagnostic dump of port state (device type, modes, versions).

getInputModes() int[source]

Bitmask of modes that produce values.

getMode(num: int) lpf2.mode | None[source]

mode descriptor for mode num or None.

getModeCombo(combo: int) int[source]

Mode-combo bitmask at index combo. Bit N = mode N.

getModeComboCount() int[source]

Number of active mode-combo entries.

getModeCount() int[source]

Total number of modes exposed by the device.

getOutputModes() int[source]

Bitmask of modes that accept values.

getValue(mode: int, dataSet: int) float[source]

Parsed value of dataset dataSet of mode. Format (int8/16/32/float) taken from mode descriptor.

getValueStr(mode: int) str[source]

Human-readable value of mode formatted per mode’s figures/decimals.

getViewCount() int[source]

Number of modes the device would show in the LEGO app.

gotoAbsPosition(absPos: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]

Move motor to absolute encoder position absPos at speed (0..100) then apply endState.

isDeviceConnected() bool[source]

True if a device has been detected on this port.

presetEncoder(pos: int) None[source]

Reset motor encoder to pos. Also stops the motor.

rawToSpeed(raw: int) int[source]

Convert LPF2 raw byte to signed -100..100 speed.

setAccTime(time: int, profile: int) None[source]

Set acceleration time (ms) and profile for the motor.

setDecTime(time: int, profile: int) None[source]

Set deceleration time (ms) and profile for the motor.

setMode(mode: int, delta: float = 1.0) int[source]

Select active input mode. delta = minimum raw-unit change that triggers value-change callback (0 = every update). Returns 0 on success.

setModeCombo(idx: int, deltas: Sequence[float] = ()) int[source]

Activate one of the device’s mode combinations. deltas = per-mode thresholds in bitmask order; empty = default of 1. Returns 0 on success.

setRgbColor(r: int, g: int, b: int) None[source]

Set RGB LED by explicit RGB (0..255, uses mode 1).

setRgbColorIdx(idx: int) None[source]

Set RGB LED by lpf2.color index (uses mode 0).

speedToRaw(speed: int) int[source]

Convert signed -100..100 speed to LPF2 raw byte (0..255).

startPower(pw: int) None[source]

Set motor power. pw in [-100..100]: negative = CCW, positive = CW.

startSpeed(speed: int = 100, maxPower: int = 100, useProfile: int = 0) None[source]

Run motor at speed (-100..100). maxPower caps commanded power (0..100). useProfile selects acc/dec profiles (low nibble = acc, next nibble = dec).

startSpeedForDegrees(degrees: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]

Move motor by degrees (positive; direction from speed sign) then apply endState.

startSpeedForTime(time: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]

Run motor at speed for time ms then apply endState (BrakingStyle: 0 = float, 126 = hold, 127 = brake).

writeData(mode: int, buf: bytes) int[source]

Send raw payload to device on given mode. Returns error code (0 = ok).