libretro.drivers.sensor.iterable

SensorDriver implementation that replays sensor readings from an iterable.

See also

SensorDriver

The protocol this driver implements.

Classes

IterableSensorDriver

A SensorDriver that feeds input to the core from the output of an iterator.

PortInput

A frozen snapshot of every sensor reading on a single input port.

PortState

Represents the state of all possible sensors on a port.

SensorState

Per-sensor state: whether the core has enabled it and its requested update rate in Hz.

Vector3

An immutable triple of axis values used for accelerometer and gyroscope readings.

class Vector3[source]

Bases: object

An immutable triple of axis values used for accelerometer and gyroscope readings.

x
y
z
__init__(x=0.0, y=0.0, z=0.0)
classmethod __new__(*args, **kwargs)
class SensorState[source]

Bases: object

Per-sensor state: whether the core has enabled it and its requested update rate in Hz.

enabled
rate
__init__(enabled=False, rate=0)
classmethod __new__(*args, **kwargs)
class PortInput[source]

Bases: object

A frozen snapshot of every sensor reading on a single input port.

accelerometer = Vector3(x=0.0, y=0.0, z=0.0)
gyroscope = Vector3(x=0.0, y=0.0, z=0.0)
illuminance
self[item][source]

Return the scalar reading for the axis or sensor identified by item.

Return type:

float

__init__(illuminance=0.0)
classmethod __new__(*args, **kwargs)
class PortState[source]

Bases: object

Represents the state of all possible sensors on a port.

accelerometer
gyroscope
illuminance
self[item][source]

Return the state of a particular sensor on this port.

Return type:

SensorState

__init__(accelerometer=<factory>, gyroscope=<factory>, illuminance=<factory>)
classmethod __new__(*args, **kwargs)
class IterableSensorDriver[source]

Bases: SensorDriver

A SensorDriver that feeds input to the core from the output of an iterator.

__init__(source=None)[source]

Initialize this sensor driver. If a sensor is disabled, then it will always output 0.0.

Parameters:

source (Iterator[float | Vector3 | PortInput | None | Sequence[float | Vector3 | PortInput | None]] | Iterable[float | Vector3 | PortInput | None | Sequence[float | Vector3 | PortInput | None]] | Callable[[], Iterator[float | Vector3 | PortInput | None | Sequence[float | Vector3 | PortInput | None]]] | None) –

An iterator or iterable whose elements are each one of the following:

None

All sensors on all ports will return 0.0.

int | float | bool | Real

All sensors on all ports will return the yielded value converted to a float.

Vector3

Each value be used as the x, y, and z readings for every port’s accelerometer and gyroscope.

PortInput

The fields on the yielded object will be used as each port’s sensor readings.

Sequence [ PortInput | Vector3 | float | None ]

Each element in the sequence will be used for its corresponding port’s sensor readings based on the aforementioned rules.

property sensor_state

A live mapping of input port to its per-sensor enable/rate state.

poll()[source]

Update the sensor driver’s readings.

Return type:

None

set_sensor_state(port, action, rate)[source]

Configure a sensor on a port, possibly with a specific query rate.

Corresponds to retro_set_sensor_state_t.

Note

The EnvironmentDriver should validate port against the maximum number of players (if any), skipping this method and returning False if the port is invalid.

Parameters:
  • port (Port (int)) – The input port to configure the sensors for.

  • action (SensorAction | int) – The action to perform on the sensor.

  • rate (int) – The rate at which to query the sensor.

Return type:

bool

Returns:

Whether the sensor was successfully configured.

get_sensor_input(port, sensor)[source]

Corresponds to retro_sensor_get_input_t.

Return type:

float

classmethod __new__(*args, **kwargs)