edu.wpi.first.wpilibj

## Class InterruptableSensorBase

- java.lang.Object
- - edu.wpi.first.wpilibj.SensorBase
  - - edu.wpi.first.wpilibj.InterruptableSensorBase

- Direct Known Subclasses:
    DigitalSource

      public abstract class InterruptableSensorBase
      extends SensorBase

  Base for sensors to be used with interrupts.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `static class` | `InterruptableSensorBase.WaitResult`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected int` | `m_interrupt` The interrupt resource.
    `protected boolean` | `m_isSynchronousInterrupt` Flags if the interrupt being allocated is synchronous.

    - ### Fields inherited from class edu.wpi.first.wpilibj.SensorBase

      `kAnalogInputChannels, kAnalogOutputChannels, kDigitalChannels, kPCMModules, kPDPChannels, kPDPModules, kPwmChannels, kRelayChannels, kSolenoidChannels, kSystemClockTicksPerMicrosecond`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `InterruptableSensorBase()` Create a new InterrupatableSensorBase.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected void` | `allocateInterrupts(boolean watcher)` Allocate the interrupt.
    `void` | `cancelInterrupts()` Cancel interrupts on this device.
    `void` | `disableInterrupts()` Disable Interrupts without without deallocating structures.
    `void` | `enableInterrupts()` Enable interrupts to occur on this input.
    `abstract int` | `getAnalogTriggerTypeForRouting()` If this is an analog trigger.
    `abstract int` | `getPortHandleForRouting()` The channel routing number.
    `double` | `readFallingTimestamp()` Return the timestamp for the falling interrupt that occurred most recently.
    `double` | `readRisingTimestamp()` Return the timestamp for the rising interrupt that occurred most recently.
    `void` | `requestInterrupts()` Request one of the 8 interrupts synchronously on this digital input.
    `void` | `requestInterrupts(InterruptHandlerFunction<?> handler)` Request one of the 8 interrupts asynchronously on this digital input.
    `void` | `setUpSourceEdge(boolean risingEdge, boolean fallingEdge)` Set which edge to trigger interrupts on.
    `InterruptableSensorBase.WaitResult` | `waitForInterrupt(double timeout)` In synchronous mode, wait for the defined interrupt to occur.
    `InterruptableSensorBase.WaitResult` | `waitForInterrupt(double timeout, boolean ignorePrevious)` In synchronous mode, wait for the defined interrupt to occur.

    - ### Methods inherited from class edu.wpi.first.wpilibj.SensorBase

      `checkAnalogInputChannel, checkAnalogOutputChannel, checkDigitalChannel, checkPDPChannel, checkPDPModule, checkPWMChannel, checkRelayChannel, checkSolenoidChannel, checkSolenoidModule, free, getDefaultSolenoidModule, setDefaultSolenoidModule`

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Field Detail

    - #### m_interrupt

          protected int m_interrupt

      The interrupt resource.

    - #### m_isSynchronousInterrupt

          protected boolean m_isSynchronousInterrupt

      Flags if the interrupt being allocated is synchronous.

  - ### Constructor Detail

    - #### InterruptableSensorBase

          public InterruptableSensorBase()

      Create a new InterrupatableSensorBase.

  - ### Method Detail

    - #### getAnalogTriggerTypeForRouting

          public abstract int getAnalogTriggerTypeForRouting()

      If this is an analog trigger.
      Returns:
        true if this is an analog trigger.

    - #### getPortHandleForRouting

          public abstract int getPortHandleForRouting()

      The channel routing number.
      Returns:
        channel routing number

    - #### requestInterrupts

          public void requestInterrupts(InterruptHandlerFunction<?> handler)

      Request one of the 8 interrupts asynchronously on this digital input.
      Parameters:
        `handler` - The `InterruptHandlerFunction` that contains the method `InterruptHandlerFunction.interruptFired(int, Object)` that will be called whenever there is an interrupt on this device. Request interrupts in synchronous mode where the user program interrupt handler will be called when an interrupt occurs. The default is interrupt on rising edges only.

    - #### requestInterrupts

          public void requestInterrupts()

      Request one of the 8 interrupts synchronously on this digital input. Request interrupts in synchronous mode where the user program will have to explicitly wait for the interrupt to occur using `waitForInterrupt(double, boolean)`. The default is interrupt on rising edges only.

    - #### allocateInterrupts

          protected void allocateInterrupts(boolean watcher)

      Allocate the interrupt.
      Parameters:
        `watcher` - true if the interrupt should be in synchronous mode where the user program will have to explicitly wait for the interrupt to occur.

    - #### cancelInterrupts

          public void cancelInterrupts()

      Cancel interrupts on this device. This deallocates all the chipobject structures and disables any interrupts.

    - #### waitForInterrupt

          public InterruptableSensorBase.WaitResult waitForInterrupt(double timeout,
                                                                     boolean ignorePrevious)

      In synchronous mode, wait for the defined interrupt to occur.
      Parameters:
        `timeout` - Timeout in seconds
        `ignorePrevious` - If true, ignore interrupts that happened before waitForInterrupt was called.
      Returns:
        Result of the wait.

    - #### waitForInterrupt

          public InterruptableSensorBase.WaitResult waitForInterrupt(double timeout)

      In synchronous mode, wait for the defined interrupt to occur.
      Parameters:
        `timeout` - Timeout in seconds
      Returns:
        Result of the wait.

    - #### enableInterrupts

          public void enableInterrupts()

      Enable interrupts to occur on this input. Interrupts are disabled when the RequestInterrupt call is made. This gives time to do the setup of the other options before starting to field interrupts.

    - #### disableInterrupts

          public void disableInterrupts()

      Disable Interrupts without without deallocating structures.

    - #### readRisingTimestamp

          public double readRisingTimestamp()

      Return the timestamp for the rising interrupt that occurred most recently. This is in the same time domain as getClock(). The rising-edge interrupt should be enabled with `setUpSourceEdge(boolean, boolean)`.
      Returns:
        Timestamp in seconds since boot.

    - #### readFallingTimestamp

          public double readFallingTimestamp()

      Return the timestamp for the falling interrupt that occurred most recently. This is in the same time domain as getClock(). The falling-edge interrupt should be enabled with `setUpSourceEdge(boolean, boolean)`.
      Returns:
        Timestamp in seconds since boot.

    - #### setUpSourceEdge

          public void setUpSourceEdge(boolean risingEdge,
                                      boolean fallingEdge)

      Set which edge to trigger interrupts on.
      Parameters:
        `risingEdge` - true to interrupt on rising edge
        `fallingEdge` - true to interrupt on falling edge