Source code for libretro.drivers.sensor.driver
"""
:class:`~typing.Protocol` definition for accelerometer/gyroscope sensor drivers.
.. seealso::
:mod:`libretro.api.sensor`
The matching :mod:`ctypes` types and callback definitions.
"""
from abc import abstractmethod
from typing import Protocol, runtime_checkable
from libretro.api.input.device import Port
from libretro.api.sensor import Sensor, SensorAction
[docs]
@runtime_checkable
class SensorDriver(Protocol):
"""
Describes the interface for input from a device's sensors.
.. note::
Corresponds to ``RETRO_ENVIRONMENT_GET_SENSOR_INTERFACE``.
"""
[docs]
@abstractmethod
def set_sensor_state(self, port: Port, action: SensorAction, rate: int) -> bool:
"""
Configure a sensor on a port,
possibly with a specific query rate.
Corresponds to :obj:`.retro_set_sensor_state_t`.
.. note ::
The :class:`.EnvironmentDriver` should validate ``port``
against the maximum number of players (if any),
skipping this method and returning :obj:`False`
if the port is invalid.
:param port: The input port to configure the sensors for.
:param action: The action to perform on the sensor.
:param rate: The rate at which to query the sensor.
:return: Whether the sensor was successfully configured.
"""
[docs]
@abstractmethod
def poll(self):
"""Update the sensor driver's readings."""
...
__all__ = [
"SensorDriver",
]