001package com.ctre.phoenix.sensors;
002
003import java.util.HashMap;
004
005/** 
006* Enum for velocity periods used for CANifier 
007*/ 
008public enum SensorVelocityMeasPeriod { 
009        /**
010         * 1ms velocity measurement period
011         */
012        Period_1Ms(1), 
013        /**
014         * 2ms velocity measurement period
015         */
016        Period_2Ms(2), 
017        /**
018         * 5ms velocity measurement period
019         */
020        Period_5Ms(5), 
021        /**
022         * 10ms velocity measurement period
023         */
024        Period_10Ms(10), 
025        /**
026         * 20ms velocity measurement period
027         */
028        Period_20Ms(20), 
029        /**
030         * 25ms velocity measurement period
031         */
032        Period_25Ms(25), 
033        /**
034         * 50ms velocity measurement period
035         */
036        Period_50Ms(50), 
037        /**
038         * 100ms velocity measurement period
039         */
040        Period_100Ms(100); 
041
042        /** Value of velocity period */
043        public final int value; 
044
045        /** 
046         * Create a SensorVelocityMeasPeriod of initValue
047         * @param initValue Value of SensorVelocityMeasPeriod
048         */
049        SensorVelocityMeasPeriod(int initValue) { 
050                this.value = initValue; 
051        } 
052    /** Keep singleton map to quickly lookup enum via int */
053    private static HashMap<Integer, SensorVelocityMeasPeriod> _map = null;
054        /** static c'tor, prepare the map */
055    static {
056        _map = new HashMap<Integer, SensorVelocityMeasPeriod>();
057                for (SensorVelocityMeasPeriod type : SensorVelocityMeasPeriod.values()) {
058                        _map.put(type.value, type);
059                }
060    }
061        /**
062         * Get SensorVelocityMeasPeriod of specified value
063         * @param value value of SensorVelocityMeasPeriod
064         * @return SensorVelocityMeasPeriod of specified value
065         */
066        public static SensorVelocityMeasPeriod valueOf(int value) {
067                SensorVelocityMeasPeriod retval = _map.get(value);
068                if (retval != null)
069                        return retval;
070                return Period_100Ms;
071        }
072        /**
073         * Get SensorVelocityMeasPeriod of specified value
074         * @param value value of SensorVelocityMeasPeriod
075         * @return SensorVelocityMeasPeriod of specified value
076         */
077    public static SensorVelocityMeasPeriod valueOf(double value) {
078        return valueOf((int) value); 
079        }
080        /**
081         * @return String representation of specified SensorVelocityMeasPeriod
082         */
083    public String toString() {
084        switch(value) {
085            case 1 : return "SensorVelocityMeasPeriod.Period_1Ms";
086            case 2 : return "SensorVelocityMeasPeriod.Period_2Ms";
087            case 5 : return "SensorVelocityMeasPeriod.Period_5Ms";
088            case 10 : return "SensorVelocityMeasPeriod.Period_10Ms";
089            case 20 : return "SensorVelocityMeasPeriod.Period_20Ms";
090            case 25 : return "SensorVelocityMeasPeriod.Period_25Ms";
091            case 50 : return "SensorVelocityMeasPeriod.Period_50Ms";
092            case 100 : return "SensorVelocityMeasPeriod.Period_100Ms";
093            default : return "InvalidValue";
094        }
095    }
096}