|
|
@ -45,7 +45,6 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
private static final String CV = "cv"; |
|
|
|
private static final String CV = "cv"; |
|
|
|
private static final String NUM_FUNCTIONS = "numFunctions"; |
|
|
|
private static final String NUM_FUNCTIONS = "numFunctions"; |
|
|
|
private String type; |
|
|
|
private String type; |
|
|
|
private Locomotive loco; |
|
|
|
|
|
|
|
private int numFunctions = 2; |
|
|
|
private int numFunctions = 2; |
|
|
|
private int step; |
|
|
|
private int step; |
|
|
|
private boolean reverse; |
|
|
|
private boolean reverse; |
|
|
@ -78,22 +77,26 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Window dismount() { |
|
|
|
private Window dismount() { |
|
|
|
if (isNull(loco)) return properties(); |
|
|
|
Locomotive locomotive = parent(); |
|
|
|
Locomotive locomotive = loco; |
|
|
|
if (isNull(locomotive)) return properties(); |
|
|
|
locomotive.removeDecoder(this); |
|
|
|
locomotive.removeDecoder(this); |
|
|
|
loco = null; |
|
|
|
parent(null); |
|
|
|
addLogEntry(t("Removed decoder from \"{}\".",locomotive)); |
|
|
|
addLogEntry(t("Removed decoder from \"{}\".",locomotive)); |
|
|
|
return locomotive.properties(); |
|
|
|
return locomotive.properties(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public StringBuilder functions() { |
|
|
|
public StringBuilder functions() { |
|
|
|
HashSet<Integer> enabledFunctions = new HashSet<>(); |
|
|
|
Locomotive loco = parent(); |
|
|
|
for (Function fun : loco.functions()) { |
|
|
|
|
|
|
|
if (fun.enabled(this)) enabledFunctions.add(fun.index()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
StringBuilder sb = new StringBuilder(); |
|
|
|
for (int i=1; i<=numFunctions; i++) sb.append(" ").append(enabledFunctions.contains(i)?1:0); |
|
|
|
|
|
|
|
|
|
|
|
if (isSet(loco)) { |
|
|
|
|
|
|
|
HashSet<Integer> enabledFunctions = new HashSet<>(); |
|
|
|
|
|
|
|
for (Function fun : loco.functions()) { |
|
|
|
|
|
|
|
if (fun.enabled(this)) enabledFunctions.add(fun.index()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
for (int i=1; i<=numFunctions; i++) sb.append(" ").append(enabledFunctions.contains(i)?1:0); |
|
|
|
|
|
|
|
} |
|
|
|
return sb; |
|
|
|
return sb; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
@ -162,6 +165,12 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
public int numFunctions() { |
|
|
|
public int numFunctions() { |
|
|
|
return numFunctions ; |
|
|
|
return numFunctions ; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
|
|
|
public Locomotive parent() { |
|
|
|
|
|
|
|
BaseClass p = super.parent(); |
|
|
|
|
|
|
|
return p instanceof Locomotive ? (Locomotive) p : null; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private Window program(Params params) { |
|
|
|
private Window program(Params params) { |
|
|
|
String error = null; |
|
|
|
String error = null; |
|
|
@ -239,6 +248,7 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
formInputs.add(t("Protocol"),div); |
|
|
|
formInputs.add(t("Protocol"),div); |
|
|
|
formInputs.add(t("Address"),new Tag("span").content(""+address())); |
|
|
|
formInputs.add(t("Address"),new Tag("span").content(""+address())); |
|
|
|
formInputs.add(t("Number of functions"),new Input(NUM_FUNCTIONS,numFunctions).numeric()); |
|
|
|
formInputs.add(t("Number of functions"),new Input(NUM_FUNCTIONS,numFunctions).numeric()); |
|
|
|
|
|
|
|
Locomotive loco = parent(); |
|
|
|
if (isSet(loco)) formInputs.add(t("Locomotive"),loco.button(loco.name())); |
|
|
|
if (isSet(loco)) formInputs.add(t("Locomotive"),loco.button(loco.name())); |
|
|
|
postForm.add(programming()); |
|
|
|
postForm.add(programming()); |
|
|
|
return super.properties(preForm, formInputs, postForm, errorMessages); |
|
|
|
return super.properties(preForm, formInputs, postForm, errorMessages); |
|
|
@ -270,15 +280,15 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
selector.addOption(-1,t("no decoder")); |
|
|
|
selector.addOption(-1,t("no decoder")); |
|
|
|
selector.addOption(0,t("new decoder")); |
|
|
|
selector.addOption(0,t("new decoder")); |
|
|
|
for (Decoder d: decoders) { |
|
|
|
for (Decoder d: decoders) { |
|
|
|
if (freeOnly && isSet(d.loco)) continue; |
|
|
|
if (freeOnly && isSet(d.parent())) continue; |
|
|
|
selector.addOption(d.id(), d); |
|
|
|
selector.addOption(d.id(), d); |
|
|
|
} |
|
|
|
} |
|
|
|
return selector; |
|
|
|
return selector; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public Decoder setLoco(Locomotive locomotive, boolean log) { |
|
|
|
public Decoder setLoco(Locomotive locomotive, boolean log) { |
|
|
|
loco = locomotive; |
|
|
|
parent(locomotive); |
|
|
|
if (log) addLogEntry(t("Mounted into \"{}\".",loco)); |
|
|
|
if (log) addLogEntry(t("Mounted into \"{}\".",locomotive)); |
|
|
|
locomotive.setDecoder(this,log); |
|
|
|
locomotive.setDecoder(this,log); |
|
|
|
return this; |
|
|
|
return this; |
|
|
|
} |
|
|
|
} |
|
|
@ -332,11 +342,7 @@ public class Decoder extends BaseClass implements Constants, Device { |
|
|
|
if (params.containsKey(TYPE)) type = params.getString(TYPE); |
|
|
|
if (params.containsKey(TYPE)) type = params.getString(TYPE); |
|
|
|
if (params.containsKey(Device.PROTOCOL)) setProtocol(Protocol.valueOf(params.getString(Device.PROTOCOL))); |
|
|
|
if (params.containsKey(Device.PROTOCOL)) setProtocol(Protocol.valueOf(params.getString(Device.PROTOCOL))); |
|
|
|
if (params.containsKey(NUM_FUNCTIONS)) numFunctions = params.getInt(NUM_FUNCTIONS); |
|
|
|
if (params.containsKey(NUM_FUNCTIONS)) numFunctions = params.getInt(NUM_FUNCTIONS); |
|
|
|
|
|
|
|
Locomotive loco = parent(); |
|
|
|
return isSet(loco) ? loco.properties() : properties(); |
|
|
|
return isSet(loco) ? loco.properties() : properties(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|