001package jmri.jmrix.can.cbus.swing.modules.sprogdcc;
002
003import java.util.*;
004
005import javax.annotation.Nonnull;
006
007import jmri.jmrix.can.cbus.node.CbusNode;
008import jmri.jmrix.can.cbus.node.CbusNodeNVTableDataModel;
009import jmri.jmrix.can.cbus.swing.modules.AbstractEditNVPane;
010import jmri.jmrix.can.cbus.swing.modules.CbusConfigPaneProvider;
011
012import org.openide.util.lookup.ServiceProvider;
013
014/**
015 * Returns configuration objects for a SPROG DCC [Pi-]SPROG 3 [v2|Plus]
016 *
017 * @author Andrew Crosland Copyright (C) 2021
018 */
019@ServiceProvider(service = CbusConfigPaneProvider.class)
020public class PiSprog3PaneProvider extends CbusConfigPaneProvider {
021    
022    String type = "Pi-SPROG 3";
023    
024    public static final int SETUP = 1;
025    public static final int ZTC_MODE = 2;
026    public static final int BLUELINE_MODE = 3;
027    public static final int ACK_SENSITIVITY = 4;
028    public static final int CMD_STATION_MODE = 5;
029    public static final int CURRENT_LIMIT = 6;
030    public static final int INPUT_VOLTAGE = 7;
031    public static final int TRACK_CURRENT = 8;
032    public static final int ACCY_PACKET_REPEAT_COUNT = 9;
033    public static final int MULTIMETER_MODE = 10;
034    public static final int DCC_PREAMBLE = 11;
035    public static final int USER_FLAGS = 12;
036    public static final int OPERATIONS_FLAGS = 13;
037    
038    // These may be overridden in scripts for unusual use cases
039    public static int MIN_CANID = 100;
040    public static int MAX_CANID = 127;
041    public static int MIN_NN = 65520;
042    public static int MAX_NN = 65535;
043
044    public PiSprog3PaneProvider() {
045        super();
046    }
047    
048    /** {@inheritDoc} */
049    @Override
050    @Nonnull
051    public String getModuleType() {
052        return type;
053    }
054
055    /**
056     * Hashmap for decoding NV names
057     */
058    private static final Map<Integer, String> nvMap = createNvMap();
059
060    /*
061     * Populate hashmap with nv strings
062     *
063     */
064    private static Map<Integer, String> createNvMap() {
065        Map<Integer, String> result = new HashMap<>();
066        result.put(0, "Error - invalid NV index");
067        result.put(SETUP, Bundle.getMessage("SetupMode"));
068        result.put(ZTC_MODE, Bundle.getMessage("ZtcMode"));
069        result.put(BLUELINE_MODE, Bundle.getMessage("BluelineMode"));
070        result.put(ACK_SENSITIVITY, Bundle.getMessage("AckSensitivity"));
071        result.put(CMD_STATION_MODE, Bundle.getMessage("CmdStaMode"));
072        result.put(CURRENT_LIMIT, Bundle.getMessage("CurrentLimit"));
073        result.put(INPUT_VOLTAGE, Bundle.getMessage("InputVoltage"));
074        result.put(TRACK_CURRENT, Bundle.getMessage("TrackCurrent"));
075        result.put(ACCY_PACKET_REPEAT_COUNT, Bundle.getMessage("AccessoryPacketRepeatCount"));
076        result.put(MULTIMETER_MODE, Bundle.getMessage("MultimeterMode"));
077        result.put(DCC_PREAMBLE, Bundle.getMessage("DccPreambleBits"));
078        result.put(USER_FLAGS, Bundle.getMessage("UserFlags"));
079        result.put(OPERATIONS_FLAGS, Bundle.getMessage("OperationsFlags"));
080        result.put(USER_FLAGS, Bundle.getMessage("UserFlags"));
081        result.put(OPERATIONS_FLAGS, Bundle.getMessage("OperationsFlags"));
082        return Collections.unmodifiableMap(result);
083    }
084    
085    /** {@inheritDoc} */
086    @Override
087    public String getNVNameByIndex(int index) {
088        // look for the NV
089        String nv = nvMap.get(index);
090        if (nv == null) {
091            return Bundle.getMessage("UnknownNv");
092        } else {
093            return nv;
094        }
095    }
096
097    /** {@inheritDoc} */
098    @Override
099    public AbstractEditNVPane getEditNVFrameInstance() {
100        return _nVarEditFrame;
101    }
102
103    /** {@inheritDoc} */
104    @Override
105    public AbstractEditNVPane getEditNVFrame(CbusNodeNVTableDataModel dataModel, CbusNode node) {
106        _nVarEditFrame = new PiSprog3EditNVPane(dataModel, node);
107        return _nVarEditFrame.getContent();
108    }
109}