libretro.api.sensor

Types for providing sensor input to cores.

See also

SensorDriver

The Protocol that uses these types to implement sensor support in libretro.py.

libretro.drivers.sensor

libretro.py’s included SensorDriver implementations.

Module Attributes

retro_sensor_action

Corresponds to retro_sensor_action in libretro.h.

retro_set_sensor_state_t

Adjust the state of a sensor on a controller.

retro_sensor_get_input_t

Return the current value reported by a sensor.

Classes

Sensor

Individual sensor axis or value identifiers.

SensorAction

Action to enable or disable a sensor.

SensorType

Type of sensor hardware.

retro_sensor_interface

Provides functions for managing sensor input.

retro_set_sensor_state_t

Adjust the state of a sensor on a controller.

Registered by the frontend and called by the core to enable or disable a particular sensor and request an update rate. Cores should only enable sensors while they are actively in use, since sensors can drain the host device’s battery.

Parameters:
  • port – Index of the controller port whose sensor will be addressed.

  • action – A SensorAction describing which sensor to enable or disable.

  • rate – Desired sensor update rate, in Hz. Treated as a hint; the actual rate may differ depending on the device.

Returns:

True if the sensor state was successfully adjusted, False otherwise (most commonly because the sensor is unavailable).

Corresponds to retro_set_sensor_state_t in libretro.h.

retro_sensor_get_input_t

Return the current value reported by a sensor.

Registered by the frontend and called by the core.

Parameters:
  • port – Index of the controller port whose sensor will be queried.

  • id – A Sensor value that selects the sensor reading (e.g. an accelerometer axis or the illuminance sensor).

Returns:

The current sensor value; semantics depend on id, and 0.0 is returned for invalid arguments.

Corresponds to retro_sensor_get_input_t in libretro.h.

class retro_sensor_interface[source]

Bases: Structure

Provides functions for managing sensor input.

Corresponds to retro_sensor_interface in libretro.h.

>>> from libretro.api import retro_sensor_interface
>>> s = retro_sensor_interface()
>>> s.set_sensor_state is None
True
set_sensor_state

Enables or disables a sensor for a given port.

get_sensor_input

Reads a sensor value for a given port and sensor ID.

__deepcopy__(_)[source]

Return a copy of this object. Intended for use with copy.deepcopy().

>>> import copy
>>> from libretro.api import retro_sensor_interface
>>> copy.deepcopy(retro_sensor_interface()).set_sensor_state is None
True
__init__(*args, **kwargs)
classmethod __new__(*args, **kwargs)
class SensorAction[source]

Bases: IntEnum

Action to enable or disable a sensor.

>>> from libretro.api import SensorAction
>>> SensorAction.GYROSCOPE_ENABLE.enabled
True
ACCELEROMETER_ENABLE = 0
ACCELEROMETER_DISABLE = 1
GYROSCOPE_ENABLE = 2
GYROSCOPE_DISABLE = 3
ILLUMINANCE_ENABLE = 4
ILLUMINANCE_DISABLE = 5
property sensor_type

Returns the SensorType this action applies to.

>>> from libretro.api import SensorAction, SensorType
>>> SensorAction.ACCELEROMETER_ENABLE.sensor_type == SensorType.ACCELEROMETER
True
property enabled

Returns True if this action enables the sensor.

>>> from libretro.api import SensorAction
>>> SensorAction.GYROSCOPE_DISABLE.enabled
False
__new__(value)
classmethod value in self

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod self[name]

Return the member matching name.

__init__()
classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

class SensorType[source]

Bases: IntEnum

Type of sensor hardware.

>>> from libretro.api import SensorType
>>> SensorType.ACCELEROMETER
<SensorType.ACCELEROMETER: 0>
ACCELEROMETER = 0
GYROSCOPE = 3
ILLUMINANCE = 6
__new__(value)
classmethod value in self

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod self[name]

Return the member matching name.

__init__()
classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

class Sensor[source]

Bases: IntEnum

Individual sensor axis or value identifiers.

>>> from libretro.api import Sensor, SensorType
>>> Sensor.GYROSCOPE_X.type == SensorType.GYROSCOPE
True
ACCELEROMETER_X = 0
ACCELEROMETER_Y = 1
ACCELEROMETER_Z = 2
GYROSCOPE_X = 3
__new__(value)
GYROSCOPE_Y = 4
classmethod value in self

Return True if value is in cls.

value is in cls if: 1) value is a member of cls, or 2) value is the value of one of the cls’s members. 3) value is a pseudo-member (flags)

classmethod self[name]

Return the member matching name.

__init__()
classmethod iter(self)

Return members in definition order.

classmethod len(self)

Return the number of members (no aliases)

GYROSCOPE_Z = 5
ILLUMINANCE = 6
property type

Returns the SensorType for this sensor reading.

>>> from libretro.api import Sensor, SensorType
>>> Sensor.ILLUMINANCE.type == SensorType.ILLUMINANCE
True
retro_sensor_action

Corresponds to retro_sensor_action in libretro.h.