001package jmri.jmrix.can.cbus.swing.modules.base; 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 basic 8 channel servo module 016 * 017 * @author Andrew Crosland Copyright (C) 2021 018 */ 019@ServiceProvider(service = CbusConfigPaneProvider.class) 020public class Servo8BasePaneProvider extends CbusConfigPaneProvider { 021 022 String type = "SERVO8BASE"; 023 024 public static final int CUTOFF = 1; 025 public static final int STARTUP_POS = 2; 026 public static final int STARTUP_MOVE = 3; 027 public static final int SEQUENCE = 4; 028 public static final int OUT1_ON = 5; 029 public static final int OUT1_OFF = 6; 030 public static final int OUT1_ON_SPD = 7; 031 public static final int OUT1_OFF_SPD = 8; 032 public static final int OUT2_ON = 9; 033 public static final int OUT2_OFF = 10; 034 public static final int OUT2_ON_SPD = 11; 035 public static final int OUT2_OFF_SPD = 12; 036 public static final int OUT3_ON = 13; 037 public static final int OUT3_OFF = 14; 038 public static final int OUT3_ON_SPD = 15; 039 public static final int OUT3_OFF_SPD = 16; 040 public static final int OUT4_ON = 17; 041 public static final int OUT4_OFF = 18; 042 public static final int OUT4_ON_SPD = 19; 043 public static final int OUT4_OFF_SPD = 20; 044 public static final int OUT5_ON = 21; 045 public static final int OUT5_OFF = 22; 046 public static final int OUT5_ON_SPD = 23; 047 public static final int OUT5_OFF_SPD = 24; 048 public static final int OUT6_ON = 25; 049 public static final int OUT6_OFF = 26; 050 public static final int OUT6_ON_SPD = 27; 051 public static final int OUT6_OFF_SPD = 28; 052 public static final int OUT7_ON = 29; 053 public static final int OUT7_OFF = 30; 054 public static final int OUT7_ON_SPD = 31; 055 public static final int OUT7_OFF_SPD = 32; 056 public static final int OUT8_ON = 33; 057 public static final int OUT8_OFF = 34; 058 public static final int OUT8_ON_SPD = 35; 059 public static final int OUT8_OFF_SPD = 36; 060 public static final int LAST = 37; 061 062 public Servo8BasePaneProvider() { 063 super(); 064 } 065 066 /** {@inheritDoc} */ 067 @Override 068 @Nonnull 069 public String getModuleType() { 070 return type; 071 } 072 073 /** 074 * Hashmap for decoding NV names 075 */ 076 protected static final Map<Integer, String> nvMap = createNvMap(); 077 078 /* 079 * Populate hashmap with nv strings 080 * 081 */ 082 protected static Map<Integer, String> createNvMap() { 083 Map<Integer, String> result = new HashMap<>(); 084 result.put(0, "Error - invalid NV index"); 085 result.put(CUTOFF, Bundle.getMessage("Cutoff")); 086 result.put(STARTUP_POS, Bundle.getMessage("StartupPosition")); 087 result.put(STARTUP_MOVE, Bundle.getMessage("StartupMove")); 088 result.put(SEQUENCE, Bundle.getMessage("SequentialOp", 4)); 089 result.put(OUT1_ON, Bundle.getMessage("OutputXOnPos", 1)); 090 result.put(OUT1_OFF, Bundle.getMessage("OutputXOffPos", 1)); 091 result.put(OUT1_ON_SPD, Bundle.getMessage("OutputXOnSpd", 1)); 092 result.put(OUT1_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 1)); 093 result.put(OUT2_ON, Bundle.getMessage("OutputXOnPos", 2)); 094 result.put(OUT2_OFF, Bundle.getMessage("OutputXOffPos", 2)); 095 result.put(OUT2_ON_SPD, Bundle.getMessage("OutputXOnSpd", 2)); 096 result.put(OUT2_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 2)); 097 result.put(OUT3_ON, Bundle.getMessage("OutputXOnPos", 3)); 098 result.put(OUT3_OFF, Bundle.getMessage("OutputXOffPos", 3)); 099 result.put(OUT3_ON_SPD, Bundle.getMessage("OutputXOnSpd", 3)); 100 result.put(OUT3_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 3)); 101 result.put(OUT4_ON, Bundle.getMessage("OutputXOnPos", 4)); 102 result.put(OUT4_OFF, Bundle.getMessage("OutputXOffPos", 4)); 103 result.put(OUT4_ON_SPD, Bundle.getMessage("OutputXOnSpd", 4)); 104 result.put(OUT4_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 4)); 105 result.put(OUT5_ON, Bundle.getMessage("OutputXOnPos", 5)); 106 result.put(OUT5_OFF, Bundle.getMessage("OutputXOffPos", 5)); 107 result.put(OUT5_ON_SPD, Bundle.getMessage("OutputXOnSpd", 5)); 108 result.put(OUT5_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 5)); 109 result.put(OUT6_ON, Bundle.getMessage("OutputXOnPos", 6)); 110 result.put(OUT6_OFF, Bundle.getMessage("OutputXOffPos", 6)); 111 result.put(OUT6_ON_SPD, Bundle.getMessage("OutputXOnSpd", 6)); 112 result.put(OUT6_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 6)); 113 result.put(OUT7_ON, Bundle.getMessage("OutputXOnPos", 7)); 114 result.put(OUT7_OFF, Bundle.getMessage("OutputXOffPos", 7)); 115 result.put(OUT7_ON_SPD, Bundle.getMessage("OutputXOnSpd", 7)); 116 result.put(OUT7_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 7)); 117 result.put(OUT8_ON, Bundle.getMessage("OutputXOnPos", 8)); 118 result.put(OUT8_OFF, Bundle.getMessage("OutputXOffPos", 8)); 119 result.put(OUT8_ON_SPD, Bundle.getMessage("OutputXOnSpd", 8)); 120 result.put(OUT8_OFF_SPD, Bundle.getMessage("OutputXOffSpd", 8)); 121 result.put(LAST, Bundle.getMessage("LastPos")); 122 return Collections.unmodifiableMap(result); 123 } 124 125 /** {@inheritDoc} */ 126 @Override 127 public String getNVNameByIndex(int index) { 128 // look for the NV 129 String nv = nvMap.get(index); 130 if (nv == null) { 131 return Bundle.getMessage("UnknownNv"); 132 } else { 133 return nv; 134 } 135 } 136 137 /** {@inheritDoc} */ 138 @Override 139 public AbstractEditNVPane getEditNVFrameInstance() { 140 return _nVarEditFrame; 141 } 142 143 /** {@inheritDoc} */ 144 @Override 145 public AbstractEditNVPane getEditNVFrame(CbusNodeNVTableDataModel dataModel, CbusNode node) { 146 if (_nVarEditFrame == null ){ 147 _nVarEditFrame = new Servo8BaseEditNVPane(dataModel, node); 148 } 149 return _nVarEditFrame.getContent(); 150 } 151 152}