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 public final long id; 011 012 public final String name; 013 014 public final String group; 015 016 public final String description; 017 018 public final int textColor; 019 020 public final int backgroundColor; 021 022 /** 023 * Constructor. 024 * 025 * @param id id 026 * @param name name 027 * @param group group 028 * @param description description 029 * @param textColor text color (0x00RRGGBB or -1 for default) 030 * @param backgroundColor background color (0x00RRGGBB or -1 for default) 031 */ 032 public OpModeOption( 033 long id, String name, String group, String description, int textColor, int backgroundColor) { 034 this.id = id; 035 this.name = name; 036 this.group = group; 037 this.description = description; 038 this.textColor = textColor; 039 this.backgroundColor = backgroundColor; 040 } 041 042 /** 043 * Gets the robot mode encoded in the ID. 044 * 045 * @return robot mode 046 */ 047 public RobotMode getMode() { 048 return RobotMode.fromInt((int) ((id >> 56) & 0x3)); 049 } 050 051 /** 052 * Makes an ID from a robot mode and a hash. 053 * 054 * @param mode robot mode 055 * @param hash hash of name 056 * @return ID 057 */ 058 public static long makeId(RobotMode mode, long hash) { 059 return ((mode.getValue() & 0x3L) << 56) | (hash & 0x00FFFFFFFFFFFFFFL); 060 } 061}