lpf2.local
The physical ports on your hub (hub.ports.A …).
They work exactly like lpf2.port, plus a few extras such as
port.forceDeviceType() for motors that don’t identify themselves.
Classes
Advanced: turn one of your hub's ports around, so it acts like a device. |
|
Advanced: describes one "mode" of a device — one kind of value it can report or accept. |
|
A physical port on your hub, like |
Package Contents
- class lpf2.local.emulated_port(port: emulated_port.__init__.port)[source]
Advanced: turn one of your hub’s ports around, so it acts like a device.
Connect that port with a cable to another LEGO hub, and the other hub sees whatever pretend device you attach (see
lpf2.virtual.device). For example, your hub can pretend to be a port expander.Use
port(e.g.hub.ports.F) as a device port.The port stops detecting devices; call
port.enable()later to use it normally again.- attachDevice(device: lpf2.virtual.device) None[source]
Choose the pretend device the other hub will see — a
lpf2.virtual.deviceor a port expander.
- init() None[source]
Start waiting for the other hub to connect. Call once, after
attachDevice().
- isHostConnected() bool[source]
Trueonce the other hub has recognised the device and is talking to it.
- isSlowEnumeration() bool[source]
Trueif set up for an EV3 (seesetSlowEnumeration()).
- class lpf2.local.mode[source]
Advanced: describes one “mode” of a device — one kind of value it can report or accept.
For example a color sensor has a mode for color, one for reflected light, and so on. Holds the mode’s name and value ranges.
- class lpf2.local.port[source]
Bases:
lpf2.portA physical port on your hub, like
hub.ports.A.Everything from
lpf2.portworks here too.- forceDeviceType(type: int) None[source]
Tell the port what’s plugged in, for motors that can’t say it themselves.
For example LEGO MINDSTORMS EV3 motors:
hub.ports.A.forceDeviceType(device_type.EV3_LARGE_MOTOR), then drive them withstartPower(). Callenable()to go back to detecting devices automatically.
- getCapabilities() int[source]
Capability bitmask (bit 0x04 = combinable, if the device has combos).
- getDeviceType() int[source]
A number saying what kind of device is plugged in — compare it with
lpf2.device_type.
- getInfoStr() str[source]
Everything the port knows about its device, as text. Handy to
printwhile exploring.
- getValue(mode: int, dataSet: int) float[source]
Read a value from the device: value number
dataSet(starting at 0) ofmode.Use this for devices that have no special class in
lpf2.devices; otherwise their own functions are easier.
- gotoAbsPosition(absPos: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Turn the motor to position
absPosdegrees, then stop.Position 0 is where it was at start-up or where you last called
presetEncoder().speedis 0..100.endStatesays what the motor does afterwards:0= let it spin freely (coast),127= brake,126= hold its position.
- presetEncoder(pos: int) None[source]
Stop the motor and say “this position is now
posdegrees” (usually 0).
- rawToSpeed(raw: int) int[source]
Advanced: convert a device byte (0..255) back to a -100..100 speed.
- setAccTime(time: int, profile: int) None[source]
How long (milliseconds) the motor takes to speed up, stored in slot
profile(0..15).Use it with the
useProfileoption of the speed functions.
- setDecTime(time: int, profile: int) None[source]
How long (milliseconds) the motor takes to slow down, stored in slot
profile(0..15).
- setMode(mode: int, delta: float = 1.0) int[source]
Advanced: choose which kind of value the device should report (its “mode”).
deltais how much the value must change before an update is sent (0 = always). Returns 0 if it worked. The device classes inlpf2.devicespick modes for you.
- setModeCombo(idx: int, deltas: Sequence[float] = ()) int[source]
Advanced: have the device report several modes at once.
idxpicks one of the device’s built-in combinations;deltasgives the minimum change for each mode in it. Returns 0 if it worked.
- setRgbColor(r: int, g: int, b: int) None[source]
Set a light to any color by mixing red, green and blue, each 0..255.
- setRgbColorIdx(idx: int) None[source]
Set a light to one of the colors in
lpf2.color, e.g.color.RED.
- speedToRaw(speed: int) int[source]
Advanced: convert a -100..100 speed to the byte (0..255) the device uses.
- startPower(pw: int) None[source]
Run a motor at a power from -100 to 100.
Positive turns one way, negative the other,
0stops. Works with every motor, even simple ones without a rotation sensor.
- startSpeed(speed: int = 100, maxPower: int = 100, useProfile: int = 0) None[source]
Run the motor at a steady
speedfrom -100 to 100 until told otherwise.Unlike
startPower()the motor works harder uphill to keep its speed (needs a motor with a rotation sensor).maxPower(0..100) limits how hard it may push.useProfilepicks the speed-up/slow-down times set withsetAccTime()/setDecTime()(0x21= speed up with slot 1, slow down with slot 2).
- startSpeedForDegrees(degrees: int, speed: int = 100, maxPower: int = 100, endState: int = 0, useProfile: int = 0) None[source]
Turn the motor by
degrees(360 = one full turn), then stop.Give a positive number of degrees; make
speednegative to turn the other way.endStatesays what the motor does afterwards:0= let it spin freely (coast),127= brake,126= hold its position.