working on new function mapping
This commit is contained in:
@@ -246,6 +246,25 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
return proto;
|
||||
}
|
||||
|
||||
public void queue() {
|
||||
init();
|
||||
plan.queue(new Command("SET {} GL "+address()+" "+(reverse ? 0 : 1)+" "+step+" "+protocol().steps+functions()) {
|
||||
|
||||
@Override
|
||||
public void onFailure(Reply reply) {
|
||||
super.onFailure(reply);
|
||||
plan.stream(t("Failed to send command to {}: {}",this,reply.message()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
public void queue(double speed, boolean reverse) {
|
||||
step = (int)(speed*proto.steps);
|
||||
this.reverse = reverse;
|
||||
queue();
|
||||
}
|
||||
|
||||
|
||||
public static Select selector(boolean freeOnly) {
|
||||
Select selector = new Select(REALM_DECODER);
|
||||
List<Decoder> decoders = BaseClass.listElements(Decoder.class);
|
||||
@@ -258,6 +277,12 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
return selector;
|
||||
}
|
||||
|
||||
public void setFunction(Integer function, boolean enabled) {
|
||||
if (enabled) {
|
||||
if (enabledFunctions.add(function)) queue();
|
||||
} else if (enabledFunctions.remove(function)) queue();
|
||||
}
|
||||
|
||||
public Decoder setLoco(Locomotive locomotive, boolean log) {
|
||||
loco = locomotive;
|
||||
if (log) addLogEntry(t("Mounted into \"{}\".",loco));
|
||||
@@ -316,21 +341,8 @@ public class Decoder extends BaseClass implements Constants, Device {
|
||||
return isSet(loco) ? loco.properties() : properties();
|
||||
}
|
||||
|
||||
public void queue(double speed, boolean reverse) {
|
||||
step = (int)(speed*proto.steps);
|
||||
this.reverse = reverse;
|
||||
queue();
|
||||
}
|
||||
|
||||
public void queue() {
|
||||
init();
|
||||
plan.queue(new Command("SET {} GL "+address()+" "+(reverse ? 0 : 1)+" "+step+" "+protocol().steps+functions()) {
|
||||
|
||||
@Override
|
||||
public void onFailure(Reply reply) {
|
||||
super.onFailure(reply);
|
||||
plan.stream(t("Failed to send command to {}: {}",this,reply.message()));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -37,6 +37,10 @@ public class Function extends BaseClass{
|
||||
if (json.has(DIRECTION)) json.getJSONArray(DIRECTION).forEach(o -> setDirection(o.toString(), true));
|
||||
}
|
||||
|
||||
public boolean is(String type) {
|
||||
return this.type.equals(type);
|
||||
}
|
||||
|
||||
public boolean isDirectional() {
|
||||
return directional;
|
||||
}
|
||||
@@ -50,7 +54,6 @@ public class Function extends BaseClass{
|
||||
}
|
||||
|
||||
|
||||
|
||||
public JSONObject json() {
|
||||
JSONArray directions = new JSONArray();
|
||||
if (directional) directions.put(DIRECTIONAL);
|
||||
@@ -99,9 +102,13 @@ public class Function extends BaseClass{
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return type+"("+(forward?BaseClass.t("forward"):"")+(reverse?" "+BaseClass.t("reverse"):"")+(directional?" "+BaseClass.t("directional"):"").trim()+")";
|
||||
return (BaseClass.isSet(name)?name+":":"") +type+"("+(forward?BaseClass.t("forward"):"")+(reverse?" "+BaseClass.t("reverse"):"")+(directional?" "+BaseClass.t("directional"):"").trim()+")";
|
||||
}
|
||||
|
||||
|
||||
public String type() {
|
||||
return type;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user