Skip to content

sensors_base

frog.hardware.plugins.sensors.sensors_base ¤

Provides a base class for communicating sensor readings.

Attributes¤

Classes¤

SensorsBase(poll_interval=float('nan')) ¤

Bases: Device

Base device class for sensors devices.

These devices can be polled with the request_readings() method and should respond by calling send_readings_message() with new sensor values (at some point).

Create a new SensorsBase.

Parameters:

Name Type Description Default
poll_interval float

How often to poll the sensor device (seconds). If set to nan, the device will only be polled once on device open

float('nan')
Source code in frog/hardware/plugins/sensors/sensors_base.py
26
27
28
29
30
31
32
33
34
35
36
37
def __init__(self, poll_interval: float = float("nan")) -> None:
    """Create a new SensorsBase.

    Args:
        poll_interval: How often to poll the sensor device (seconds). If set to nan,
                       the device will only be polled once on device open
    """
    super().__init__()

    self._poll_timer = QTimer()
    self._poll_timer.timeout.connect(self.request_readings)
    self._poll_interval = poll_interval
Functions¤
close() ¤

Close the device.

Source code in frog/hardware/plugins/sensors/sensors_base.py
52
53
54
55
def close(self) -> None:
    """Close the device."""
    self._poll_timer.stop()
    super().close()
request_readings() abstractmethod ¤

Request new sensor readings from the device.

Source code in frog/hardware/plugins/sensors/sensors_base.py
44
45
46
@abstractmethod
def request_readings(self) -> None:
    """Request new sensor readings from the device."""
send_readings_message(readings) ¤

Send a pubsub message containing new readings from the sensors.

Source code in frog/hardware/plugins/sensors/sensors_base.py
48
49
50
def send_readings_message(self, readings: Sequence[SensorReading]) -> None:
    """Send a pubsub message containing new readings from the sensors."""
    self.send_message("data", readings=readings)
start_polling() ¤

Begin polling the device.

Source code in frog/hardware/plugins/sensors/sensors_base.py
39
40
41
42
def start_polling(self) -> None:
    """Begin polling the device."""
    if not isnan(self._poll_interval):
        self._poll_timer.start(int(self._poll_interval * 1000))