com.qualcomm.ftccommon

## Class FtcEventLoop

- java.lang.Object
- - com.qualcomm.ftccommon.FtcEventLoopBase
  - - com.qualcomm.ftccommon.FtcEventLoop

- All Implemented Interfaces:
    EventLoop

      public class FtcEventLoop
      extends FtcEventLoopBase

  Main event loop to control the robot

  Modify this class with your own code, or create your own event loop by implementing EventLoop.

- - ### Nested Class Summary

    Nested Classes
    Modifier and Type | Class and Description
    --- | ---
    `class` | `FtcEventLoop.DefaultUsbModuleAttachmentHandler`

    - ### Nested classes/interfaces inherited from class com.qualcomm.ftccommon.FtcEventLoopBase

      `FtcEventLoopBase.LynxUsbDeviceContainer`

  - ### Field Summary

    Fields
    Modifier and Type | Field and Description
    --- | ---
    `protected OpModeManagerImpl` | `opModeManager`
    `protected java.util.concurrent.atomic.AtomicReference<OpMode>` | `opModeStopRequested`
    `protected java.util.Map<java.lang.String,java.lang.Long>` | `recentlyAttachedUsbDevices`
    `protected UsbModuleAttachmentHandler` | `usbModuleAttachmentHandler`
    `protected Utility` | `utility`

    - ### Fields inherited from class com.qualcomm.ftccommon.FtcEventLoopBase

      `activityContext, ftcEventLoopHandler, networkConnectionHandler, programmingModeController, registeredOpModes, robotCfgFileMgr, runningOnDriverStation, TAG, usbScanManager, userOpmodeRegister`

    - ### Fields inherited from interface com.qualcomm.robotcore.eventloop.EventLoop

      `TELEMETRY_DEFAULT_INTERVAL`

  - ### Constructor Summary

    Constructors
    Constructor and Description
    `FtcEventLoop(HardwareFactory hardwareFactory, OpModeRegister userOpmodeRegister, UpdateUI.Callback callback, Activity activityContext, ProgrammingModeController programmingModeController)`

  - ### Method Summary

    All Methods Static Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `protected static OpModeManagerImpl` | `createOpModeManager(Activity activityContext)`
    `OpModeManagerImpl` | `getOpModeManager()` Returns the OpModeManager associated with this event loop
    `protected SerialNumber` | `getSerialNumberOfUsbDevice(UsbDevice usbDevice)`
    `UsbModuleAttachmentHandler` | `getUsbModuleAttachmentHandler()`
    `protected void` | `handleCommandDiscoverLynxModules(java.lang.String extra)`
    `protected void` | `handleCommandInitOpMode(java.lang.String extra)`
    `protected void` | `handleCommandRunOpMode(java.lang.String extra)`
    `protected void` | `handleCommandScan(java.lang.String extra)`
    `protected void` | `handleCommandSetMatchNumber(java.lang.String extra)`
    `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
    `void` | `loop()` Loop method, this will be called repeatedly while the robot is running.
    `void` | `onUsbDeviceAttached(UsbDevice usbDevice)` Deal with the fact that a UsbDevice has recently attached to the system
    `void` | `pendUsbDeviceAttachment(SerialNumber serialNumber, long time, java.util.concurrent.TimeUnit unit)`
    `CallbackResult` | `processCommand(Command command)` If the driver station sends over a command, it will be routed to this method.
    `void` | `processedRecentlyAttachedUsbDevices()` Process any usb devices that might have recently attached.
    `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
    `protected void` | `sendUIState()` The driver station is requesting our opmode list/ UI state.
    `void` | `setUsbModuleAttachmentHandler(UsbModuleAttachmentHandler handler)`
    `void` | `teardown()` Teardown method

    - ### Methods inherited from class com.qualcomm.ftccommon.FtcEventLoopBase

      `checkForChangedOpModes, enterFirmwareUpdateMode, getLynxUsbDeviceForFirmwareUpdate, getUSBAccessibleLynxDevices, handleCommandActivateConfiguration, handleCommandClearRememberedGroups, handleCommandDeleteConfiguration, handleCommandDisconnectWifiDirect, handleCommandDismissAllDialogs, handleCommandDismissDialog, handleCommandDismissProgress, handleCommandGetCandidateLynxFirmwareImages, handleCommandGetUSBAccessibleLynxModules, handleCommandLynxChangeModuleAddresses, handleCommandLynxFirmwareUpdate, handleCommandRequestAboutInfo, handleCommandRequestConfigurations, handleCommandRequestConfigurationTemplates, handleCommandRequestInspectionReport, handleCommandRequestParticularConfiguration, handleCommandRequestRememberedGroups, handleCommandRestartRobot, handleCommandSaveConfiguration, handleCommandShowDialog, handleCommandShowProgress, handleCommandShowToast, handleCommandStartDriverStationProgramAndManage, handleCommandStartProgrammingMode, handleCommandStopProgrammingMode, handleCommandVisuallyIdentify, startUsbScanMangerIfNecessary, talkToParentLynxModule, updateFirmwareOnce, updateLynxFirmware`

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

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

- - ### Field Detail

    - #### utility

          protected final Utility utility

    - #### opModeManager

          protected final OpModeManagerImpl opModeManager

    - #### usbModuleAttachmentHandler

          protected UsbModuleAttachmentHandler usbModuleAttachmentHandler

    - #### recentlyAttachedUsbDevices

          protected final java.util.Map<java.lang.String,java.lang.Long> recentlyAttachedUsbDevices

    - #### opModeStopRequested

          protected final java.util.concurrent.atomic.AtomicReference<OpMode> opModeStopRequested

  - ### Constructor Detail

    - #### FtcEventLoop

          public FtcEventLoop(HardwareFactory hardwareFactory,
                              OpModeRegister userOpmodeRegister,
                              UpdateUI.Callback callback,
                              Activity activityContext,
                              ProgrammingModeController programmingModeController)

  - ### Method Detail

    - #### createOpModeManager

          protected static OpModeManagerImpl createOpModeManager(Activity activityContext)

    - #### getOpModeManager

          public OpModeManagerImpl getOpModeManager()

      Description copied from interface: `EventLoop`
      Returns the OpModeManager associated with this event loop
      Returns:
        the OpModeManager associated with this event loop

    - #### getUsbModuleAttachmentHandler

          public UsbModuleAttachmentHandler getUsbModuleAttachmentHandler()

    - #### setUsbModuleAttachmentHandler

          public void setUsbModuleAttachmentHandler(UsbModuleAttachmentHandler handler)

    - #### init

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

      Init method

      This code will run when the robot first starts up. Place any initialization code in this method.

      It is important to save a copy of the event loop manager from this method, as that is how you'll get access to the gamepad.

      If an Exception is thrown then the event loop manager will not start the robot.

      Caller synchronizes: called on RobotSetupRunnable.run() thread

      Specified by:
        `init` in interface `EventLoop`
      Overrides:
        `init` in class `FtcEventLoopBase`
      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

          public void loop()
                    throws RobotCoreException

      Loop method, this will be called repeatedly while the robot is running.

      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.
      See Also:
        `

        Caller synchronizes: called on EventLoopRunnable.run() thread.

        `

    - #### refreshUserTelemetry

          public void refreshUserTelemetry(TelemetryMessage telemetry,
                                           double sInterval)

      Description copied from interface: `EventLoop`
      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

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

      Teardown method

      This method will be called when the robot is being shut down. This method should stop the robot. There will be no more changes to write to the hardware after this method is called.

      If an exception is thrown, then the event loop manager will attempt to shut down the robot without the benefit of this method.

      Specified by:
        `teardown` in interface `EventLoop`
      Overrides:
        `teardown` in class `FtcEventLoopBase`
      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`
      See Also:
        `

        Caller synchronizes: called on EventLoopRunnable.run() thread.

        `

    - #### processCommand

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

      If the driver station sends over a command, it will be routed to this method. You can choose what to do with this command, or you can just ignore it completely.

      Called on RecvRunnable.run() thread. Method is thread safe, non-interfering

      Specified by:
        `processCommand` in interface `EventLoop`
      Overrides:
        `processCommand` in class `FtcEventLoopBase`
      Parameters:
        `command` - command to process
      Throws:
        `java.lang.InterruptedException`
        `RobotCoreException`

    - #### handleCommandScan

          protected void handleCommandScan(java.lang.String extra)
                                    throws RobotCoreException,
                                           java.lang.InterruptedException

      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`
      See Also:
        `FtcConfigurationActivity#doUSBScanAndUpdateUI()`

    - #### handleCommandDiscoverLynxModules

          protected void handleCommandDiscoverLynxModules(java.lang.String extra)
                                                   throws RobotCoreException,
                                                          java.lang.InterruptedException

      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`

    - #### sendUIState

          protected void sendUIState()

      The driver station is requesting our opmode list/ UI state. Build up an appropriately-delimited list and send it back to them. Also take this opportunity to forcibly refresh their error/warning state: the opmode list is only infrequently requested (so sending another datagram isn't a traffic burden) and it's requested just after a driver station reconnects after a disconnect (so doing the refresh now is probably an opportune thing to do).
      Overrides:
        `sendUIState` in class `FtcEventLoopBase`

    - #### handleCommandSetMatchNumber

          protected void handleCommandSetMatchNumber(java.lang.String extra)

    - #### handleCommandInitOpMode

          protected void handleCommandInitOpMode(java.lang.String extra)

    - #### handleCommandRunOpMode

          protected void handleCommandRunOpMode(java.lang.String extra)

    - #### requestOpModeStop

          public void requestOpModeStop(OpMode opModeToStopIfActive)

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

    - #### onUsbDeviceAttached

          public void onUsbDeviceAttached(UsbDevice usbDevice)

      Deal with the fact that a UsbDevice has recently attached to the system
      Parameters:
        `usbDevice` -
      See Also:
        `EventLoop.processedRecentlyAttachedUsbDevices()`

    - #### getSerialNumberOfUsbDevice

          protected SerialNumber getSerialNumberOfUsbDevice(UsbDevice usbDevice)

    - #### pendUsbDeviceAttachment

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

    - #### processedRecentlyAttachedUsbDevices

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

      Process any usb devices that might have recently attached. Called on the event loop thread.
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`
      See Also:
        `EventLoop.handleUsbModuleDetach(RobotUsbModule)`, `EventLoop.onUsbDeviceAttached(UsbDevice)`

    - #### handleUsbModuleDetach

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

      Description copied from interface: `EventLoop`
      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.
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`
      See Also:
        `EventLoop.processedRecentlyAttachedUsbDevices()`

    - #### handleUsbModuleAttach

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

      Description copied from interface: `EventLoop`
      Process the fact that (we believe) that the indicated module has now reappeared after a previously observed detachment.
      Throws:
        `RobotCoreException`
        `java.lang.InterruptedException`