j5.components package

Submodules

j5.components.battery_sensor module

Classes for Battery Sensing Components.

class j5.components.battery_sensor.BatterySensor(identifier: int, backend: j5.components.battery_sensor.BatterySensorInterface)[source]

Bases: j5.components.component.Component

A sensor capable of monitoring a battery.

current

Get the current of the battery sensor.

static interface_class() → Type[j5.components.battery_sensor.BatterySensorInterface][source]

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

voltage

Get the voltage of the battery sensor.

class j5.components.battery_sensor.BatterySensorInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to read data from a BatterySensor.

get_battery_sensor_current(identifier: int) → float[source]

Get the current of a battery sensor.

get_battery_sensor_voltage(identifier: int) → float[source]

Get the voltage of a battery sensor.

j5.components.button module

Classes for Button.

class j5.components.button.Button(identifier: int, backend: j5.components.button.ButtonInterface)[source]

Bases: j5.components.component.Component

A button.

static interface_class() → Type[j5.components.button.ButtonInterface][source]

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

is_pressed

Get the current pushed state of the button.

wait_until_pressed() → None[source]

Halt the program until this button is pushed.

class j5.components.button.ButtonInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required for a button.

get_button_state(identifier: int) → bool[source]

Set the state of a button.

wait_until_button_pressed(identifier: int) → None[source]

Halt the program until this button is pushed.

j5.components.component module

Base classes for components.

class j5.components.component.Component[source]

Bases: object

A component is the smallest logical part of some hardware.

static interface_class() → Type[j5.components.component.Interface][source]

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

class j5.components.component.Interface[source]

Bases: object

A base class for interfaces to inherit from.

exception j5.components.component.NotSupportedByHardwareError[source]

Bases: Exception

This is thrown when hardware does not support the action that is attempted.

j5.components.gpio_pin module

Classes for GPIO Pins.

exception j5.components.gpio_pin.BadGPIOPinModeError[source]

Bases: Exception

The pin is not in the correct mode.

class j5.components.gpio_pin.GPIOPin(identifier: int, backend: j5.components.gpio_pin.GPIOPinInterface, supported_modes: List[j5.components.gpio_pin.GPIOPinMode] = [<GPIOPinMode.DIGITAL_OUTPUT: 3>], initial_mode: Optional[j5.components.gpio_pin.GPIOPinMode] = None)[source]

Bases: j5.components.component.Component

A GPIO Pin.

analogue_value

Get the scaled analogue reading of the pin.

digital_state

Get the digital state of the pin.

static interface_class() → Type[j5.components.gpio_pin.GPIOPinInterface][source]

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

mode

Get the hardware mode of this pin.

class j5.components.gpio_pin.GPIOPinInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required for a GPIO Pin.

get_gpio_pin_digital_state(identifier: int) → bool[source]

Get the last written state of the GPIO pin.

get_gpio_pin_mode(identifier: int) → j5.components.gpio_pin.GPIOPinMode[source]

Get the hardware mode of a GPIO pin.

read_gpio_pin_analogue_value(identifier: int) → float[source]

Read the scaled analogue value of the GPIO pin.

read_gpio_pin_digital_state(identifier: int) → bool[source]

Read the digital state of the GPIO pin.

set_gpio_pin_mode(identifier: int, pin_mode: j5.components.gpio_pin.GPIOPinMode) → None[source]

Set the hardware mode of a GPIO pin.

write_gpio_pin_dac_value(identifier: int, scaled_value: float) → None[source]

Write a scaled analogue value to the DAC on the GPIO pin.

write_gpio_pin_digital_state(identifier: int, state: bool) → None[source]

Write to the digital state of a GPIO pin.

write_gpio_pin_pwm_value(identifier: int, duty_cycle: float) → None[source]

Write a scaled analogue value to the PWM on the GPIO pin.

class j5.components.gpio_pin.GPIOPinMode[source]

Bases: enum.IntEnum

Hardware modes that a GPIO pin can be set to.

ANALOGUE_INPUT = 4

The analogue voltage of the pin can be read.

ANALOGUE_OUTPUT = 5

The analogue voltage of the pin can be set using a DAC.

DIGITAL_INPUT = 0

The digital state of the pin can be read

DIGITAL_INPUT_PULLDOWN = 2

Same as DIGITAL_INPUT but internal pull-down is enabled

DIGITAL_INPUT_PULLUP = 1

Same as DIGITAL_INPUT but internal pull-up is enabled

DIGITAL_OUTPUT = 3

The digital state of the pin can be set.

PWM_OUTPUT = 6

A PWM output signal can be created on the pin.

j5.components.led module

Classes for the LED support.

class j5.components.led.LED(identifier: int, backend: j5.components.led.LEDInterface)[source]

Bases: j5.components.component.Component

A standard Light Emitting Diode.

static interface_class() → Type[j5.components.led.LEDInterface][source]

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

state

Get the current state of the LED.

class j5.components.led.LEDInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control an LED.

get_led_state(identifier: int) → bool[source]

Get the state of an LED.

set_led_state(identifier: int, state: bool) → None[source]

Set the state of an LED.

j5.components.motor module

Classes for Motor support.

class j5.components.motor.Motor(identifier: int, backend: j5.components.motor.MotorInterface)[source]

Bases: j5.components.component.Component

Brushed DC motor output.

static interface_class() → Type[j5.components.component.Interface][source]

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

state

Get the current state of this output.

class j5.components.motor.MotorInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a motor board.

get_motor_state(identifier: int) → Union[float, j5.components.motor.MotorSpecialState][source]

Get the motor state.

set_motor_state(identifier: int, power: Union[float, j5.components.motor.MotorSpecialState]) → None[source]

Set the motor state.

class j5.components.motor.MotorSpecialState[source]

Bases: enum.Enum

An enum of the special states that a motor can be set to.

BRAKE = 1
COAST = 0

j5.components.piezo module

Classes for Piezo support.

class j5.components.piezo.Note[source]

Bases: float, enum.Enum

An enumeration of notes.

An enumeration of notes from scientific pitch notation and their related frequencies in Hz.

A6 = 1760.0
A7 = 3520.0
B6 = 1975.5
B7 = 3951.1
C6 = 1047.0
C7 = 2093.0
C8 = 4186.0
D6 = 1174.7
D7 = 2349.3
E6 = 1318.5
E7 = 2637.0
F6 = 1396.9
F7 = 2793.8
G6 = 1568.0
G7 = 3136.0
class j5.components.piezo.Piezo(identifier: int, backend: j5.components.piezo.PiezoInterface)[source]

Bases: j5.components.component.Component

A standard piezo.

buzz(duration: datetime.timedelta, pitch: Union[int, float, j5.components.piezo.Note]) → None[source]

Queue a note to be played.

static interface_class() → Type[j5.components.piezo.PiezoInterface][source]

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

static verify_duration(duration: datetime.timedelta) → None[source]

Verify that a duration is valid.

static verify_pitch(pitch: Union[int, float, j5.components.piezo.Note]) → None[source]

Verify that a pitch is valid.

class j5.components.piezo.PiezoInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control an piezo.

buzz(identifier: int, duration: datetime.timedelta, frequency: float) → None[source]

Queue a pitch to be played.

j5.components.power_output module

Classes for supporting toggleable power output channels.

class j5.components.power_output.PowerOutput(identifier: int, backend: j5.components.power_output.PowerOutputInterface)[source]

Bases: j5.components.component.Component

A power output channel.

It can be enabled/disabled, and the current being drawn on this channel can be measured.

current

Get the current being drawn on this power output, in amperes.

static interface_class() → Type[j5.components.power_output.PowerOutputInterface][source]

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

is_enabled

Get whether the output is enabled.

class j5.components.power_output.PowerOutputGroup(outputs: Mapping[T, j5.components.power_output.PowerOutput])[source]

Bases: object

A group of PowerOutputs.

power_off() → None[source]

Disable all outputs in the group.

power_on() → None[source]

Enable all outputs in the group.

class j5.components.power_output.PowerOutputInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a power output channel.

get_power_output_current(identifier: int) → float[source]

Get the current being drawn on a power output, in amperes.

get_power_output_enabled(identifier: int) → bool[source]

Get whether a power output is enabled.

set_power_output_enabled(identifier: int, enabled: bool) → None[source]

Set whether a power output is enabled.

j5.components.servo module

Classes for supporting Servomotors.

class j5.components.servo.Servo(identifier: int, backend: j5.components.servo.ServoInterface)[source]

Bases: j5.components.component.Component

A standard servomotor.

static interface_class() → Type[j5.components.servo.ServoInterface][source]

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

position

Get the current position of the Servo.

class j5.components.servo.ServoInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a Servo.

get_servo_position(identifier: int) → Optional[float][source]

Get the position of a Servo.

set_servo_position(identifier: int, position: Optional[float]) → None[source]

Set the position of a Servo.

Module contents

This module contains components, which are the smallest logical element of hardware.

class j5.components.BatterySensor(identifier: int, backend: j5.components.battery_sensor.BatterySensorInterface)[source]

Bases: j5.components.component.Component

A sensor capable of monitoring a battery.

current

Get the current of the battery sensor.

static interface_class() → Type[j5.components.battery_sensor.BatterySensorInterface][source]

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

voltage

Get the voltage of the battery sensor.

class j5.components.BatterySensorInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to read data from a BatterySensor.

get_battery_sensor_current(identifier: int) → float[source]

Get the current of a battery sensor.

get_battery_sensor_voltage(identifier: int) → float[source]

Get the voltage of a battery sensor.

class j5.components.Button(identifier: int, backend: j5.components.button.ButtonInterface)[source]

Bases: j5.components.component.Component

A button.

static interface_class() → Type[j5.components.button.ButtonInterface][source]

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

is_pressed

Get the current pushed state of the button.

wait_until_pressed() → None[source]

Halt the program until this button is pushed.

class j5.components.ButtonInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required for a button.

get_button_state(identifier: int) → bool[source]

Set the state of a button.

wait_until_button_pressed(identifier: int) → None[source]

Halt the program until this button is pushed.

class j5.components.Component[source]

Bases: object

A component is the smallest logical part of some hardware.

static interface_class() → Type[j5.components.component.Interface][source]

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

class j5.components.GPIOPin(identifier: int, backend: j5.components.gpio_pin.GPIOPinInterface, supported_modes: List[j5.components.gpio_pin.GPIOPinMode] = [<GPIOPinMode.DIGITAL_OUTPUT: 3>], initial_mode: Optional[j5.components.gpio_pin.GPIOPinMode] = None)[source]

Bases: j5.components.component.Component

A GPIO Pin.

analogue_value

Get the scaled analogue reading of the pin.

digital_state

Get the digital state of the pin.

static interface_class() → Type[j5.components.gpio_pin.GPIOPinInterface][source]

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

mode

Get the hardware mode of this pin.

class j5.components.GPIOPinInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required for a GPIO Pin.

get_gpio_pin_digital_state(identifier: int) → bool[source]

Get the last written state of the GPIO pin.

get_gpio_pin_mode(identifier: int) → j5.components.gpio_pin.GPIOPinMode[source]

Get the hardware mode of a GPIO pin.

read_gpio_pin_analogue_value(identifier: int) → float[source]

Read the scaled analogue value of the GPIO pin.

read_gpio_pin_digital_state(identifier: int) → bool[source]

Read the digital state of the GPIO pin.

set_gpio_pin_mode(identifier: int, pin_mode: j5.components.gpio_pin.GPIOPinMode) → None[source]

Set the hardware mode of a GPIO pin.

write_gpio_pin_dac_value(identifier: int, scaled_value: float) → None[source]

Write a scaled analogue value to the DAC on the GPIO pin.

write_gpio_pin_digital_state(identifier: int, state: bool) → None[source]

Write to the digital state of a GPIO pin.

write_gpio_pin_pwm_value(identifier: int, duty_cycle: float) → None[source]

Write a scaled analogue value to the PWM on the GPIO pin.

class j5.components.GPIOPinMode[source]

Bases: enum.IntEnum

Hardware modes that a GPIO pin can be set to.

ANALOGUE_INPUT = 4

The analogue voltage of the pin can be read.

ANALOGUE_OUTPUT = 5

The analogue voltage of the pin can be set using a DAC.

DIGITAL_INPUT = 0

The digital state of the pin can be read

DIGITAL_INPUT_PULLDOWN = 2

Same as DIGITAL_INPUT but internal pull-down is enabled

DIGITAL_INPUT_PULLUP = 1

Same as DIGITAL_INPUT but internal pull-up is enabled

DIGITAL_OUTPUT = 3

The digital state of the pin can be set.

PWM_OUTPUT = 6

A PWM output signal can be created on the pin.

class j5.components.Interface[source]

Bases: object

A base class for interfaces to inherit from.

class j5.components.LED(identifier: int, backend: j5.components.led.LEDInterface)[source]

Bases: j5.components.component.Component

A standard Light Emitting Diode.

static interface_class() → Type[j5.components.led.LEDInterface][source]

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

state

Get the current state of the LED.

class j5.components.LEDInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control an LED.

get_led_state(identifier: int) → bool[source]

Get the state of an LED.

set_led_state(identifier: int, state: bool) → None[source]

Set the state of an LED.

class j5.components.Motor(identifier: int, backend: j5.components.motor.MotorInterface)[source]

Bases: j5.components.component.Component

Brushed DC motor output.

static interface_class() → Type[j5.components.component.Interface][source]

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

state

Get the current state of this output.

class j5.components.MotorInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a motor board.

get_motor_state(identifier: int) → Union[float, j5.components.motor.MotorSpecialState][source]

Get the motor state.

set_motor_state(identifier: int, power: Union[float, j5.components.motor.MotorSpecialState]) → None[source]

Set the motor state.

class j5.components.MotorSpecialState[source]

Bases: enum.Enum

An enum of the special states that a motor can be set to.

BRAKE = 1
COAST = 0
exception j5.components.NotSupportedByHardwareError[source]

Bases: Exception

This is thrown when hardware does not support the action that is attempted.

class j5.components.Piezo(identifier: int, backend: j5.components.piezo.PiezoInterface)[source]

Bases: j5.components.component.Component

A standard piezo.

buzz(duration: datetime.timedelta, pitch: Union[int, float, j5.components.piezo.Note]) → None[source]

Queue a note to be played.

static interface_class() → Type[j5.components.piezo.PiezoInterface][source]

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

static verify_duration(duration: datetime.timedelta) → None[source]

Verify that a duration is valid.

static verify_pitch(pitch: Union[int, float, j5.components.piezo.Note]) → None[source]

Verify that a pitch is valid.

class j5.components.PiezoInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control an piezo.

buzz(identifier: int, duration: datetime.timedelta, frequency: float) → None[source]

Queue a pitch to be played.

class j5.components.PowerOutput(identifier: int, backend: j5.components.power_output.PowerOutputInterface)[source]

Bases: j5.components.component.Component

A power output channel.

It can be enabled/disabled, and the current being drawn on this channel can be measured.

current

Get the current being drawn on this power output, in amperes.

static interface_class() → Type[j5.components.power_output.PowerOutputInterface][source]

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

is_enabled

Get whether the output is enabled.

class j5.components.PowerOutputInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a power output channel.

get_power_output_current(identifier: int) → float[source]

Get the current being drawn on a power output, in amperes.

get_power_output_enabled(identifier: int) → bool[source]

Get whether a power output is enabled.

set_power_output_enabled(identifier: int, enabled: bool) → None[source]

Set whether a power output is enabled.

class j5.components.PowerOutputGroup(outputs: Mapping[T, j5.components.power_output.PowerOutput])[source]

Bases: object

A group of PowerOutputs.

power_off() → None[source]

Disable all outputs in the group.

power_on() → None[source]

Enable all outputs in the group.

class j5.components.Servo(identifier: int, backend: j5.components.servo.ServoInterface)[source]

Bases: j5.components.component.Component

A standard servomotor.

static interface_class() → Type[j5.components.servo.ServoInterface][source]

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

position

Get the current position of the Servo.

class j5.components.ServoInterface[source]

Bases: j5.components.component.Interface

An interface containing the methods required to control a Servo.

get_servo_position(identifier: int) → Optional[float][source]

Get the position of a Servo.

set_servo_position(identifier: int, position: Optional[float]) → None[source]

Set the position of a Servo.