Hot-keys on this page
r m x p toggle line displays
j k next/prev highlighted chunk
0 (zero) top of page
1 (one) first highlighted chunk
"""This module wraps the calls to the GPIO interface."""
# TODO: make these functions faster/better? """int2bool
Convert int to tuple of bool.
Parameters ---------- i : int The `int` value to be converted. """
"""bool2int
Convert iterable of bool to int.
Parameters ---------- b : bool The `bool` value to be converted. """
"""Wraps the calls to the GPIO interface."""
def _csv_reader_map(row):
"""Instantiate DGILibInterfaceGPIO object.""" # Set default values for attributes # Add read and write mode to kwargs so they get set in the super class # constructor # Instantiate base class
# Parse arguments # By default augment gpio with delay of self.default_gpio_delay_time "gpio_switch_time" in kwargs: "gpio_delay_time", self.default_gpio_delay_time) self.gpio_augment_edges_streaming.gpio_augment_edges
# NOTE: Might not be the best place to do this self.dgilib_extra.timer_factor is None: self.dgilib_extra.get_time_factor()
"""get_config
Get the pin-mode for the GPIO pins.
The GPIO configuration controls the direction of the pins.
Input pins: Setting a bit to 1 means the pin is monitored. Output pins: Setting a bit to 1 means the pin is set to output and can be controlled by the send command.
Returns ------- tuple(list(bool, bool, bool, bool), list(bool, bool, bool, bool)) Tuple of:
* List of read modes, Setting a pin to True means the pin is \ monitored.
* List of write modes, Setting a pin to True means the pin is set \ to output and can be controlled by the send command. """ # Get the configuration _, config_value = self.dgilib_extra.interface_get_configuration( INTERFACE_GPIO)
# Convert int to lists of bool read_mode = int2bool(config_value[0]) write_mode = int2bool(config_value[1])
return read_mode, write_mode
"""set_config
Set the pin-mode for the GPIO pins.
The GPIO configuration controls the direction of the pins, and enables the interface if needed.
Input pins: Setting a bit to 1 means the pin is monitored. Output pins: Setting a bit to 1 means the pin is set to output and can be controlled by the send command.
If any of the pins are set to read mode or write mode the GPIO interface will be enabled. If none of the pins are set to read mode or write mode the GPIO interface will be disabled.
Parameters ---------- read_mode : list(bool, bool, bool, bool) List of modes. Setting a pin to `True` means the pin is monitored.
write_mode : list(bool, bool, bool, bool) List of modes. Setting a pin to `True` means the pin is set to output and can be controlled by the send command. """ # Set the configuration INTERFACE_GPIO, [0], [bool2int(self.read_mode)]) INTERFACE_GPIO, [1], [bool2int(self.write_mode)])
"""read
Get the state of the GPIO pins.
Clears the buffer and returns the values.
Returns ------- tuple(list(float), list(list(bool, bool, bool, bool))) Tuple of list of timestamps in seconds and list of list of pin states (bool). """ # Read the data from the buffer INTERFACE_GPIO)
"pins per sample)")
interface_data, self.gpio_delay_time, self.gpio_switch_time) else: return InterfaceData(timestamps, pin_values)
"""write
Set the state of the GPIO pins.
Make sure to set the pin to write mode first. Possibly also needs to be configured properly on the board
A maximum of 255 elements can be written each time. An error return code will be given if data hasn’t been written yet.
Parameters ---------- pin_values : list(bool, bool, bool, bool) List of pin values. Has to include all four pins. """ # TODO: Test if it has to include all four pins
# Convert list of bool to int pin_values = bool2int(pin_values)
self.dgilib_extra.interface_write_data(INTERFACE_GPIO, [pin_values])
if self.verbose >= 2: print(f"Sent gpio packet")
"""csv_write_rows
""" zip(interface_data.timestamps, *map(iter, zip(*interface_data.values)))) |