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