001package com.ctre.phoenix.motorcontrol; 002 003import java.util.HashMap; 004 005/** 006 * Choose the sensor term for a motor controller 007 */ 008public enum SensorTerm { 009 /** 010 * Choose Sum0 for a term 011 */ 012 Sum0(0), 013 /** 014 * Choose Sum1 for a term 015 */ 016 Sum1(1), 017 /** 018 * Choose Diff0 for a term 019 */ 020 Diff0(2), 021 /** 022 * Choose Diff1 for a term 023 */ 024 Diff1(3); 025 026 /** 027 * Value of SensorTerm 028 */ 029 public int value; 030 /** 031 * Create SensorTerm of specified value 032 * @param value Value of SensorTerm 033 */ 034 SensorTerm(int value) 035 { 036 this.value = value; 037 } 038 /** Keep singleton map to quickly lookup enum via int */ 039 private static HashMap<Integer, SensorTerm> _map = null; 040 /** static c'tor, prepare the map */ 041 static { 042 _map = new HashMap<Integer, SensorTerm>(); 043 for (SensorTerm type : SensorTerm.values()) { 044 _map.put(type.value, type); 045 } 046 } 047 /** 048 * Get SensorTerm of specified value 049 * @param value Value of SensorTerm 050 * @return SensorTerm of specified value 051 */ 052 public static SensorTerm valueOf(int value) { 053 SensorTerm retval = _map.get(value); 054 if (retval != null) 055 return retval; 056 return Sum0; 057 } 058 /** 059 * Get SensorTerm of specified value 060 * @param value Value of SensorTerm 061 * @return SensorTerm of specified value 062 */ 063 public static SensorTerm valueOf(double value) { 064 return valueOf((int) value); 065 } 066 /** 067 * @return string representation of SensorTerm 068 */ 069 public String toString() { 070 switch(value) { 071 case 0 : return "SensorTerm.Sum0"; 072 case 1 : return "SensorTerm.Sum1"; 073 case 2 : return "SensorTerm.Diff0"; 074 case 3 : return "SensorTerm.Diff1"; 075 default : return "InvalidValue"; 076 } 077 } 078};