<commit_before>from IoTPy.pyuper.pinouts import CAP_GPIO
from IoTPy.pyuper.utils import IoTPy_APIError, errmsg


class Interrupt:
    """
    GPIO interrupt pin module.

    :param board: IoBoard to which the pin belongs to.
    :type board: :class:`IoTPy.pyuper.ioboard.IoBoard`
    :param pin: GPIO pin number.
    :type pin: int
    """

    LEVEL_LOW = 0
    LEVEL_HIGH = 1
    EDGE_CHANGE = 2
    EDGE_RISE = 3
    EDGE_FALL = 4

    def __init__(self, board, pin):
        self.board = board
        if self.board.pinout[pin].capabilities & CAP_GPIO:
            self.logical_pin = self.board.pinout[pin].pinID
        else:
            errmsg("UPER API: Pin No:%d is not GPIO pin, can't attach interrupt.", pin)
            raise IoTPy_APIError("Wrong Pin number.")

    def attach(self, mode, callback, user_object=None, debounce_time=50):
        """
        Attach (enable) or reconfigure GPIO interrupt event.

        :param mode: GPIO interrupt mode.
        :param callback: User callback function. This function is executed when the interrupt event is received.
        :param user_object: Optional user defined object, which will be passed back to the callback function.
        :param debounce_time: Interrupt disable time in milliseconds after the triggering event. This is used to "debounce" buttons or \
        to protect communication channel from data flood. Optional, default is 50ms.

        :return: True
        :raise: IoTPy_APIError
        """
        try:
            interruptID = self.board.interrupts.index(self.logical_pin)
            self.board.uper_io(0, self.board.encode_sfp(7, [interruptID])) 	#detach interrupt<commit_msg>Documentation for interrupt callback function<commit_after>from IoTPy.pyuper.pinouts import CAP_GPIO
from IoTPy.pyuper.utils import IoTPy_APIError, errmsg


class Interrupt:
    """
    GPIO interrupt pin module.

    :param board: IoBoard to which the pin belongs to.
    :type board: :class:`IoTPy.pyuper.ioboard.IoBoard`
    :param pin: GPIO pin number.
    :type pin: int
    """

    LEVEL_LOW = 0
    LEVEL_HIGH = 1
    EDGE_CHANGE = 2
    EDGE_RISE = 3
    EDGE_FALL = 4

    def __init__(self, board, pin):
        self.board = board
        if self.board.pinout[pin].capabilities & CAP_GPIO:
            self.logical_pin = self.board.pinout[pin].pinID
        else:
            errmsg("UPER API: Pin No:%d is not GPIO pin, can't attach interrupt.", pin)
            raise IoTPy_APIError("Wrong Pin number.")

    def attach(self, mode, callback, user_object=None, debounce_time=50):
        """
        Attach (enable) or reconfigure GPIO interrupt event.

        :param mode: GPIO interrupt mode. Can have one of these values: Interrupt.EDGE_RISE, Interrupt.EDGE_FALL, \
        Interrupt.EDGE_CHANGE, Interrupt.LEVEL_LOW or Interrupt.LEVEL_HIGH.
        :param callback: User callback function. This function is executed when the interrupt event is received. \
        It should take two arguments: interrupt event description and user object. Interrupt event descriptor is \
        dictionary with three fields: 'id' - the interrupt ID (interrupt channel), 'type' - interrupt event type \
        (same meaning as mode) and 'values' - the logical values on each of interrupt channel (N-th bit represents  \
        logical pin value of interrupt channel N). User object is the same object as user_object.
        :param user_object: User defined object, which will be passed back to the callback function. Optional,  \
        default is None.
        :param debounce_time: Interrupt disable time in milliseconds after the triggering event. This is used to \
        "debounce" buttons or to protect communication channel from data flood. Optional, default is 50ms.

        :return: True
        :raise: IoTPy_APIError
        """
        try:
            interruptID = self.board.interrupts.index(self.logical_pin)
            self.board.uper_io(0, self.board.encode_sfp(7, [interruptID])) 	#detach interrupt
{'fraction_non_alphanumeric': 0.07971922787666082, 'fraction_numerical': 0.0055151667084482325, 'mean_word_length': 2.771266540642722, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1649151', 'n_tokens_mistral': 1171, 'n_tokens_neox': 1118, 'n_words': 403}