Class Notifier

java.lang.Object
org.wpilib.system.Notifier
All Implemented Interfaces:
AutoCloseable

public class Notifier extends Object implements AutoCloseable
Notifiers run a user-provided callback function on a separate thread.

If startSingle() is used, the callback will run once. If startPeriodic() is used, the callback will run repeatedly with the given period until stop() is called.

  • Constructor Details

    • Notifier

      public Notifier(Runnable callback)
      Create a Notifier with the given callback.

      Configure when the callback runs with startSingle() or startPeriodic().

      Parameters:
      callback - The callback to run.
  • Method Details

    • close

      public void close()
      Specified by:
      close in interface AutoCloseable
    • setName

      public void setName(String name)
      Sets the name of the notifier. Used for debugging purposes only.
      Parameters:
      name - Name
    • setCallback

      public void setCallback(Runnable callback)
      Change the callback function.
      Parameters:
      callback - The callback function.
    • startSingle

      public void startSingle(double delay)
      Run the callback once after the given delay.
      Parameters:
      delay - Time in seconds to wait before the callback is called.
    • startSingle

      public void startSingle(Time delay)
      Run the callback once after the given delay.
      Parameters:
      delay - Time to wait before the callback is called.
    • startPeriodic

      public void startPeriodic(double period)
      Run the callback periodically with the given period.

      The user-provided callback should be written so that it completes before the next time it's scheduled to run.

      Parameters:
      period - Period in seconds after which to call the callback starting one period after the call to this method.
    • startPeriodic

      public void startPeriodic(Time period)
      Run the callback periodically with the given period.

      The user-provided callback should be written so that it completes before the next time it's scheduled to run.

      Parameters:
      period - Period after which to call the callback starting one period after the call to this method.
    • startPeriodic

      public void startPeriodic(Frequency frequency)
      Run the callback periodically with the given frequency.

      The user-provided callback should be written so that it completes before the next time it's scheduled to run.

      Parameters:
      frequency - Frequency at which to call the callback, starting one period after the call to this method.
    • stop

      public void stop()
      Stop further callback invocations.

      No further periodic callbacks will occur. Single invocations will also be cancelled if they haven't yet occurred.