Class TrcPriorityIndicator<T>

java.lang.Object
trclib.driverio.TrcPriorityIndicator<T>
Type Parameters:
T - specifies the device dependent indicator pattern type.
Direct Known Subclasses:
FtcGamepadRumble, TrcAddressableLED, TrcGobildaIndicatorLight, TrcRevBlinkin

public abstract class TrcPriorityIndicator<T> extends Object
This class implements a priority indicator device that supports priority list. A priority list specifies a list of indicator patterns in priority order. This means that if the indicator is set to a given pattern, it will be updated only if the pattern being set has a higher priority than the pattern that is already active. This allows the indicator to be used to display important status that will not be overwritten by unimportant status change. This class is intended to be extended by a device dependent subclass that provides device dependent methods to set and get indicator patterns.
  • Field Details

  • Constructor Details

    • TrcPriorityIndicator

      public TrcPriorityIndicator(String instanceName)
      Constructor: Create an instance of the object.
      Parameters:
      instanceName - specifies the instance name.
  • Method Details

    • getPattern

      public abstract T getPattern()
      This method gets the current set pattern.
      Returns:
      currently set pattern.
    • setPattern

      public abstract void setPattern(T pattern)
      This method sets the pattern to the physical indicator device in a device dependent way.
      Parameters:
      pattern - specifies the indicator pattern. If null, turn off the indicator pattern.
    • toString

      public String toString()
      This method returns the instance name.
      Overrides:
      toString in class Object
      Returns:
      instance name.
    • setTaskEnabled

      private void setTaskEnabled(boolean enabled)
      This method enables/disables the Indicator Task that periodically updates the indicator states.
      Parameters:
      enabled - specifies true to enable task, false to disable.
    • printPatternPriorityTable

      public void printPatternPriorityTable(TrcDbgTrace msgTracer)
      This method prints the Pattern Priority table to the given trace output for debugging purpose.
      Parameters:
      msgTracer - specifies the tracer object to use to print the info.
    • reset

      public void reset()
      This method turns the indicator off.
    • setPatternState

      public void setPatternState(T pattern, boolean enabled, double onDuration, double offDuration)
      This method enables/disables the pattern in the priority list.
      Parameters:
      pattern - specifies the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
      onDuration - specifies the time in seconds the pattern remains ON, zero to turn it ON indefinitely.
      offDuration - specifies the time in seconds the pattern remains OFF, then turn the LED back ON. Zero for disabling after onDuration expires.
    • setPatternState

      public void setPatternState(T pattern, boolean enabled, double onDuration)
      This method enables/disables the pattern in the priority list.
      Parameters:
      pattern - specifies the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
      onDuration - specifies the time in seconds the pattern remains ON, zero to turn it ON indefinitely.
    • setPatternState

      public void setPatternState(T pattern, boolean enabled)
      This method enables/disables the pattern in the priority list.
      Parameters:
      pattern - specifies the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
    • setPatternState

      public void setPatternState(String patternName, boolean enabled, double onDuration, double offDuration)
      This method enables/disables the pattern in the priority list.
      Parameters:
      patternName - specifies the name of the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
      onDuration - specifies the time in seconds the pattern remains ON, zero to turn it ON indefinitely.
      offDuration - specifies the time in seconds the pattern remains OFF, then turn the LED back ON. Zero for disabling after onDuration expires.
      Throws:
      IllegalAccessError - when patternName is not found in the map.
    • setPatternState

      public void setPatternState(String patternName, boolean enabled, double onDuration)
      This method enables/disables the pattern in the priority list.
      Parameters:
      patternName - specifies the name of the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
      onDuration - specifies the time in seconds the pattern remains ON, zero to turn it ON indefinitely.
      Throws:
      IllegalAccessError - when patternName is not found in the map.
    • setPatternState

      public void setPatternState(String patternName, boolean enabled)
      This method enables/disables the pattern in the priority list.
      Parameters:
      patternName - specifies the name of the pattern in the priority list.
      enabled - specifies true to turn the pattern ON, false to turn it OFF.
      Throws:
      IllegalAccessError - when patternName is not found in the map.
    • getPatternState

      public boolean getPatternState(T pattern)
      This method returns the pattern state if it is in the priority list. If the pattern is not in the list, it returns false.
      Parameters:
      pattern - specifies the pattern in the priority list.
      Returns:
      true if the pattern is ON, false if it is OFF.
    • getPatternState

      public boolean getPatternState(String patternName)
      This method returns the pattern state if it is in the priority list. If the pattern is not in the list, it returns false.
      Parameters:
      patternName - specifies the name of the pattern in the priority list.
      Returns:
      true if the pattern is ON, false if it is OFF.
      Throws:
      IllegalAccessError - when patternName is not found in the map.
    • resetAllPatternStates

      public void resetAllPatternStates()
      This method resets all pattern states in the pattern priority list and set the indicator device to non-active state.
    • getPatternPriority

      public int getPatternPriority(T pattern)
      This method searches the given pattern priorities array for the given pattern. If found, its index is the priority and will be returned. If the pattern is not found in the array, -1 will be return which also means the lowest priority.
      Parameters:
      pattern - specifies the indicator pattern to be searched in the pattern priorities array.
      Returns:
      the pattern priority if found, -1 if not found.
    • setPatternPriorities

      public void setPatternPriorities(T[] priorities)
      This method sets the pattern priority list for operations that need it. The priority list must be sorted in decreasing priorities.
      Parameters:
      priorities - specifies the pattern priority list or null to disregard the previously set list.
    • updateIndicator

      private void updateIndicator()
      This method is called to update the pattern according to the patternPriorities list. It will turn on the highest priority pattern if enabled. If none of the patterns in the priority list is enabled, it will set the indicator device to non-active state.
    • indicatorTask

      private void indicatorTask(TrcTaskMgr.TaskType taskType, TrcRobot.RunMode runMode, boolean slowPeriodicLoop)
      This task when enabled runs every 100 msec to update the indicator states.
      Parameters:
      taskType - specifies the task type (not used).
      runMode - specifies the robot run mode (not used).
      slowPeriodicLoop - specifies true if it is running the slow periodic loop on the main robot thread, false otherwise.