> ## Documentation Index
> Fetch the complete documentation index at: https://docs.dairy.foundation/llms.txt
> Use this file to discover all available pages before exploring further.

# EnhancedBooleanSupplier

EnhancedBooleanSupplier is a Feature that updates once / loop and tracks some
additional data about a boolean that is frequently needed in FTC.

Constructing:

<CodeGroup>
  ```java Java theme={null}
  EnhancedBooleanSupplier enhancedBooleanSupplier = new EnhancedBooleanSupplier(() -> true);
  // or, apply debounce at construction
  new EnhancedBooleanSupplier(() -> true, 0.02, 0.02);
  ```

  ```kt Kotlin theme={null}
  val enhancedBooleanSupplier = EnhancedBooleanSupplier { true }
  // or, apply debounce at construction
  EnhancedBooleanSupplier({ true }, 0.02, 0.02)
  ```
</CodeGroup>

State:

<CodeGroup>
  ```java Java theme={null}
  // current state
  enhancedBooleanSupplier.state();
  // rising edge
  enhancedBooleanSupplier.onTrue();
  // falling edge
  enhancedBooleanSupplier.onFalse();
  // toggle that changes on rising edge
  enhancedBooleanSupplier.toggleTrue();
  // toggle that changes on falling edge
  enhancedBooleanSupplier.toggleFalse();
  ```

  ```kt Kotlin theme={null}
  // current state
  enhancedBooleanSupplier.state
  // rising edge
  enhancedBooleanSupplier.onTrue
  // falling edge
  enhancedBooleanSupplier.onFalse
  // toggle that changes on rising edge
  enhancedBooleanSupplier.toggleTrue
  // toggle that changes on falling edge
  enhancedBooleanSupplier.toggleFalse
  ```
</CodeGroup>

Debouncing:

Debounce is basically a filter. This means that a state needs to be true for
that long before it changes. I.e. with a leading debounce of 0.02 seconds, you
need to hold down the gamepad button for 0.02 seconds before it will change to
true in the code.

The arguments are in seconds.

<CodeGroup>
  ```java Java theme={null}
  // debounce both edges
  enhancedBooleanSupplier.debounce(0.02);
  // debounce both edges rising, then falling
  enhancedBooleanSupplier.debounce(0, 0.02);
  enhancedBooleanSupplier.debounceRisingEdge(0);
  enhancedBooleanSupplier.debounceFallingEdge(0.02);
  ```

  ```kt Kotlin theme={null}
  // debounce both edges
  enhancedBooleanSupplier.debounce(0.02);
  // debounce both edges rising, then falling
  enhancedBooleanSupplier.debounce(0.0, 0.02);
  enhancedBooleanSupplier.debounceRisingEdge(0.0);
  enhancedBooleanSupplier.debounceFallingEdge(0.02);
  ```
</CodeGroup>

Combining:

<CodeGroup>
  ```java Java theme={null}
  enhancedBooleanSupplier.and(() -> false);
  enhancedBooleanSupplier.or(() -> false);
  enhancedBooleanSupplier.xor(() -> false);
  enhancedBooleanSupplier.not();
  ```

  ```kt Kotlin theme={null}
  enhancedBooleanSupplier and BooleanSupplier { false }
  enhancedBooleanSupplier or BooleanSupplier { false }
  enhancedBooleanSupplier xor BooleanSupplier { false }
  enhancedBooleanSupplier.not()
  ```
</CodeGroup>

Both debouncings and combinations return **new** EnhancedBooleanSuppliers,
rather than mutating the existing one.

Manual update management:

<CodeGroup>
  ```java Java theme={null}
  // you can enable / disable the feature based auto updates
  enhancedBooleanSupplier.getAutoUpdates();
  enhancedBooleanSupplier.setAutoUpdates(false);

  // you can invalidate the current update to get a new update next time you get state
  enhancedBooleanSupplier.invalidate();
  ```

  ```kt Kotlin theme={null}
  // you can enable / disable the feature based auto updates
  enhancedBooleanSupplier.autoUpdates
  enhancedBooleanSupplier.autoUpdates = false

  // you can invalidate the current update to get a new update next time you get state
  enhancedBooleanSupplier.invalidate()
  ```
</CodeGroup>
