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