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