001// Copyright (c) FIRST and other WPILib contributors.
002// Open Source Software; you can modify and/or share it under the terms of
003// the WPILib BSD license file in the root directory of this project.
004
005package org.wpilib.hardware.hal;
006
007/** An individual opmode option. */
008public class OpModeOption {
009  /** Unique id. Encodes robot mode in bits 57-56, LSB 56 bits is hash of name. */
010  @SuppressWarnings("MemberName")
011  public final long id;
012
013  @SuppressWarnings("MemberName")
014  public final String name;
015
016  @SuppressWarnings("MemberName")
017  public final String group;
018
019  @SuppressWarnings("MemberName")
020  public final String description;
021
022  @SuppressWarnings("MemberName")
023  public final int textColor;
024
025  @SuppressWarnings("MemberName")
026  public final int backgroundColor;
027
028  /**
029   * Constructor.
030   *
031   * @param id id
032   * @param name name
033   * @param group group
034   * @param description description
035   * @param textColor text color (0x00RRGGBB or -1 for default)
036   * @param backgroundColor background color (0x00RRGGBB or -1 for default)
037   */
038  public OpModeOption(
039      long id, String name, String group, String description, int textColor, int backgroundColor) {
040    this.id = id;
041    this.name = name;
042    this.group = group;
043    this.description = description;
044    this.textColor = textColor;
045    this.backgroundColor = backgroundColor;
046  }
047
048  /**
049   * Gets the robot mode encoded in the ID.
050   *
051   * @return robot mode
052   */
053  public RobotMode getMode() {
054    return RobotMode.fromInt((int) ((id >> 56) & 0x3));
055  }
056
057  /**
058   * Makes an ID from a robot mode and a hash.
059   *
060   * @param mode robot mode
061   * @param hash hash of name
062   * @return ID
063   */
064  public static long makeId(RobotMode mode, long hash) {
065    return ((mode.getValue() & 0x3L) << 56) | (hash & 0x00FFFFFFFFFFFFFFL);
066  }
067}