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