j5.components.derived package

Module contents

Derived components.

A derived component is a component that can take another component as a parameter.

For example, a device may be attached to various pins on the board, and this could vary depending on what the user wants. We solve this by passing the pins to the derived component.

class j5.components.derived.UltrasoundInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required for an UltrasoundSensor.

get_ultrasound_distance(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[float][source]

Get a distance in metres.

Parameters:
  • trigger_pin_identifier – pin number of the trigger pin.
  • echo_pin_identifier – pin number of the echo pin.
Returns:

Distance measured in metres, or None if it timed out.

get_ultrasound_pulse(trigger_pin_identifier: int, echo_pin_identifier: int) → Optional[datetime.timedelta][source]

Get a timedelta for the ultrasound time.

Parameters:
  • trigger_pin_identifier – pin number of the trigger pin.
  • echo_pin_identifier – pin number of the echo pin.
Returns:

Time taken for the pulse, or None if it timed out.

class j5.components.derived.UltrasoundSensor(gpio_trigger: j5.components.gpio_pin.GPIOPin, gpio_echo: j5.components.gpio_pin.GPIOPin, backend: j5.components.derived.ultrasound.UltrasoundInterface, *, distance_mode: bool = True)[source]

Bases: j5.components.component.DerivedComponent

Ultrasonic distance sensor.

A sensor that utilises the reflection of ultrasound to calculate the distance to a nearby object.

distance() → Optional[float][source]

Send a pulse and return the distance to the object.

Returns:Distance measured in metres, or None if it timed out.
Raises:Exception – distance mode is disabled.
static interface_class() → Type[j5.components.component.Interface][source]

Get the interface class that is required to use this component.

Returns:interface class.
pulse() → Optional[datetime.timedelta][source]

Send a pulse and return the time taken.

Returns:Time taken for the pulse, or None if it timed out.