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