sensorsindex/home/perette/Projects/Skeezball/TestUtilities/sensors.py

This module provides a input-pin to event queue system.

For testing purposes, a script can be used as a source of input events.

Modules

queue sys time

Classes

builtins.object
Sensors
builtins.tuple(builtins.object)
SenseEvent

class SenseEvent(builtins.tuple)

SenseEvent(name: str, time: datetime.datetime, pin: int, extra: Any)

SenseEvent(name, time, pin, extra)

Method resolution order:
SenseEvent
builtins.tuple
builtins.object

Methods defined here:
__getnewargs__(self)

Return self as a plain tuple. Used by copy and pickle.

__repr__(self)

Return a nicely formatted representation string

_asdict(self)

Return a new dict which maps field names to their values.

_replace(self, /, **kwds)

Return a new SenseEvent object replacing specified fields with new values


Class methods defined here:
_make(iterable) from builtins.type

Make a new SenseEvent object from a sequence or iterable


Static methods defined here:
__new__(_cls, name: str, time: datetime.datetime, pin: int, extra: Any)

Create new instance of SenseEvent(name, time, pin, extra)


Data descriptors defined here:
name

Alias for field number 0

time

Alias for field number 1

pin

Alias for field number 2

extra

Alias for field number 3


Data and other attributes defined here:
__annotations__ = {'extra': typing.Any, 'name': <class 'str'>, 'pin': <class 'int'>, 'time': <class 'datetime.datetime'>}
__match_args__ = ('name', 'time', 'pin', 'extra')
__orig_bases__ = (<function NamedTuple>,)
_field_defaults = {}
_fields = ('name', 'time', 'pin', 'extra')

Methods inherited from builtins.tuple:
__add__(self, value, /)

Return self+value.

__contains__(self, key, /)

Return key in self.

__eq__(self, value, /)

Return self==value.

__ge__(self, value, /)

Return self>=value.

__getattribute__(self, name, /)

Return getattr(self, name).

__getitem__(self, key, /)

Return self[key].

__gt__(self, value, /)

Return self>value.

__hash__(self, /)

Return hash(self).

__iter__(self, /)

Implement iter(self).

__le__(self, value, /)

Return self<=value.

__len__(self, /)

Return len(self).

__lt__(self, value, /)

Return self<value.

__mul__(self, value, /)

Return self*value.

__ne__(self, value, /)

Return self!=value.

__rmul__(self, value, /)

Return value*self.

count(self, value, /)

Return number of occurrences of value.

index(self, value, start=0, stop=9223372036854775807, /)

Return first index of value.

Raises ValueError if the value is not present.


Class methods inherited from builtins.tuple:
__class_getitem__(...) from builtins.type

See PEP 585

class Sensors(builtins.object)

Read input sensors and put event notifications into a queue.

Methods defined here:
__del__(self)
__init__(self)

Initialize self. See help(type(self)) for accurate signature.

abortScript(self) -> None

Flag any running script to abort.

addPin(self, pin: int, name: str, *, bounce_time: float | None = None, pull: int, trigger: int, extra: Any = None) -> None

Add a pin to the sensor pool.
pin: The pin number. Negative pins are "virtual", for use only by scripts (generally, to quit.)
name: The event name passed up through the queue.
pull: Configure pin with pull-up, pull-down or neither.
trigger: Whether to trigger on rising edge, falling edge or both
extra: Extra stuff added to the returned event.

clear(self) -> None

Clear all pending events.

eventCallback(self, pin: int) -> None

GPIO.add_detect_event-compliant callback handler. Translates from pin to event name, and inserts a timestampped event in queue.
pin: The pin number triggering the callback.

getEvent(self, timeout: None | float = None) -> None | sensors.SenseEvent

Retrieve an event.
timeout: In seconds, or None to wait indefinitely.
Return value: The event or None upon timeout.

runScript(self, events: list[tuple[float, int]]) -> None

Play out a series of events.
events: The script, with timing and event details.

scriptIsDone(self) -> bool

Check if an event script has completed.
Return value: True if the script is done running. If there is no script running, always returns false; this behavior allows scripted test sessions to exit, but exit checks will not affect non-scripted use.

simulateEvents(self, script_name: str) -> None

Simulate a sequence of events (presumably for testing). Format of script_name is one event per line:
time-offset-in-seconds event-name

Blank lines and # comments are allowed. Events are played in file order. Only one script can be played at a time.
script_name: The file containing the event script.

waitForScriptFinish(self) -> None

Wait for the scripted event trigger thread to join. Asserts when there is no script.


Static methods defined here:
fromConfig(eventConfig: dict[str, typing.Any], sensorConfig: dict[str, typing.Any])

This method accepts two configuration dictionaries, and sets up events and sensors accordingly.


eventConfig: This dictionary defines the inputs and sets any input-specific behaviors. Event names are the keys. Values is a dictionary that may contain:
• member bounceTime: debounce time, during which repeated events will be ignored.
• member pull: Pull-up resistor setup: up, down, or off.
• member detect: What signal to detect: rising, falling, or both.


sensorConfig: This dictionary defines the defaults and the pin assignments.
• members defaultBounce, defaultPull, and defaultDetect specify default behaviors if not specified for specific events. The hard-coded defaults are no debouncing, no pull. It is an error to omit detection.
• member assignments: A dictionary keyed by event names that has GPIO channel numbers as its values.


Data descriptors defined here:
__dict__

dictionary for instance variables (if defined)

__weakref__

list of weak references to the object (if defined)

Data

Any = typing.Any