com.qualcomm.robotcore.eventloop

## Interface EventLoop

- All Known Implementing Classes:
    FtcEventLoop, FtcEventLoopBase, FtcEventLoopIdle

      public interface EventLoop

  Event loop interface

  Event loops need to implement this interface. Contains methods for managing the life cycle of your robot.

- - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `static double` | `TELEMETRY_DEFAULT_INTERVAL` The value to pass to `refreshUserTelemetry(TelemetryMessage, double)` as the time interval parameter in order to cause a system default interval to be used.

  - ### Method Summary

    All Methods Instance Methods Abstract Methods
    Modifier and Type | Method and Description
    --- | ---
    `OpModeManagerImpl` | `getOpModeManager()` Returns the OpModeManager associated with this event loop
    `void` | `handleUsbModuleAttach(RobotUsbModule module)` Process the fact that (we believe) that the indicated module has now reappeared after a previously observed detachment.
    `void` | `handleUsbModuleDetach(RobotUsbModule module)` Process the fact that a usb module has now become detached from the system.
    `void` | `init(EventLoopManager eventLoopManager)` Init method, this will be called before the first call to loop.
    `void` | `loop()` This method will be repeatedly called by the event loop manager.
    `void` | `onUsbDeviceAttached(UsbDevice usbDevice)` Notifies the event loop that a UsbDevice has just been attached to the system.
    `void` | `pendUsbDeviceAttachment(SerialNumber serialNumber, long time, java.util.concurrent.TimeUnit unit)`
    `CallbackResult` | `processCommand(Command command)` Process command method, this will be called if the event loop manager receives a user defined command.
    `void` | `processedRecentlyAttachedUsbDevices()` Process the batch of newly arrived USB devices.
    `void` | `refreshUserTelemetry(TelemetryMessage telemetry, double sInterval)` Update's the user portion of the driver station screen with the contents of the telemetry object here provided if a sufficiently long duration has passed since the last update.
    `void` | `requestOpModeStop(OpMode opModeToStopIfActive)` Requests that an OpMode be stopped if it's the currently active one
    `void` | `teardown()` Teardown method, this will be called after the last call to loop.

- - ### Field Detail

    - #### TELEMETRY_DEFAULT_INTERVAL

          static final double TELEMETRY_DEFAULT_INTERVAL

      The value to pass to `refreshUserTelemetry(TelemetryMessage, double)` as the time interval parameter in order to cause a system default interval to be used.
      See Also:
        Constant Field Values

  - ### Method Detail

    - #### init

          void init(EventLoopManager eventLoopManager)
             throws RobotCoreException,
                    java.lang.InterruptedException

      Init method, this will be called before the first call to loop. You should set up your hardware in this method. Threading: called on the RobotSetupRunnable.run() thread, before the EventLoopRunnable.run() thread is created.
      Parameters:
        `eventLoopManager` - event loop manager that is responsible for this event loop
      Throws:
        `RobotCoreException` - if a RobotCoreException is thrown, it will be handled by the event loop manager. The manager will report that the robot failed to start.
        `java.lang.InterruptedException`

    - #### loop

          void loop()
             throws RobotCoreException,
                    java.lang.InterruptedException

      This method will be repeatedly called by the event loop manager. Threading: called on the EventLoopRunnable.run() thread.
      Throws:
        `RobotCoreException` - if a RobotCoreException is thrown, it will be handled by the event loop manager. The manager may decide to either stop processing this iteration of the loop, or it may decide to shut down the robot.
        `java.lang.InterruptedException`

    - #### refreshUserTelemetry

          void refreshUserTelemetry(TelemetryMessage telemetry,
                                    double sInterval)

      Update's the user portion of the driver station screen with the contents of the telemetry object here provided if a sufficiently long duration has passed since the last update.
      Parameters:
        `telemetry` - the telemetry object to send
        `sInterval` - the required minimum interval. NaN indicates that a system default interval should be used.

    - #### teardown

          void teardown()
                 throws RobotCoreException,
                        java.lang.InterruptedException

      Teardown method, this will be called after the last call to loop. You should place your robot into a safe state before this method exits, since there will be no more changes to communicate with your robot. Threading: called on the EventLoopRunnable.run() thread.
      Throws:
        `RobotCoreException` - if a RobotCoreException is thrown, it will be handled by the event loop manager. The manager will then attempt to shut down the robot without the benefit of the teardown method.
        `java.lang.InterruptedException`

    - #### onUsbDeviceAttached

          void onUsbDeviceAttached(UsbDevice usbDevice)

      Notifies the event loop that a UsbDevice has just been attached to the system. User interface activities that receive UsbManager.ACTION_USB_DEVICE_ATTACHED notifications should retrieve the UsbDevice using intent.getParcelableExtra(UsbManager.EXTRA_DEVICE) then pass that along to this method in their event loop for processing.

      Implementations of this method should avoid doing significant processing during this notification. Rather, they should squirrel the device away for processing during a later processedRecentlyAttachedUsbDevices call.

      Parameters:
        `usbDevice` - the newly arrived device
      See Also:
        `processedRecentlyAttachedUsbDevices()`

    - #### pendUsbDeviceAttachment

          void pendUsbDeviceAttachment(SerialNumber serialNumber,
                                       long time,
                                       java.util.concurrent.TimeUnit unit)

    - #### processedRecentlyAttachedUsbDevices

          void processedRecentlyAttachedUsbDevices()
                                            throws RobotCoreException,
                                                   java.lang.InterruptedException

      Process the batch of newly arrived USB devices. This is called on the EventLoop thread by the EventLoopManager; there is sufficient time and correct context to, e.g., fully arm the associated module software to make the device operational within the app.
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`
      See Also:
        `handleUsbModuleDetach(RobotUsbModule)`, `onUsbDeviceAttached(UsbDevice)`

    - #### handleUsbModuleDetach

          void handleUsbModuleDetach(RobotUsbModule module)
                              throws RobotCoreException,
                                     java.lang.InterruptedException

      Process the fact that a usb module has now become detached from the system. This is called on the EventLoop thread by the EventLoopManager; there is sufficient time and correct context to, e.g., fully disarm and 'pretend' the associated module.
      Parameters:
        `module` -
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`
      See Also:
        `processedRecentlyAttachedUsbDevices()`

    - #### handleUsbModuleAttach

          void handleUsbModuleAttach(RobotUsbModule module)
                              throws RobotCoreException,
                                     java.lang.InterruptedException

      Process the fact that (we believe) that the indicated module has now reappeared after a previously observed detachment.
      Parameters:
        `module` -
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`

    - #### processCommand

          CallbackResult processCommand(Command command)
                                 throws java.lang.InterruptedException,
                                        RobotCoreException

      Process command method, this will be called if the event loop manager receives a user defined command. How this command is handled is up to the event loop implementation. Threading: called on the RecvRunnable.run() thread.
      Parameters:
        `command` - command to process
      Throws:
        `java.lang.InterruptedException`
        `RobotCoreException`

    - #### getOpModeManager

          OpModeManagerImpl getOpModeManager()

      Returns the OpModeManager associated with this event loop
      Returns:
        the OpModeManager associated with this event loop

    - #### requestOpModeStop

          void requestOpModeStop(OpMode opModeToStopIfActive)

      Requests that an OpMode be stopped if it's the currently active one
      Parameters:
        `opModeToStopIfActive` - the OpMode to stop if it's currently active