Skip to content
Permalink
Browse files

Better handle feedback initial state

  • Loading branch information...
bobjacobsen committed Sep 18, 2018
1 parent 3aa6902 commit 6724e026b1d1a0b75940e2dc6f8c766071205b1e
@@ -293,6 +293,7 @@ public void setFeedbackMode(String mode) throws IllegalArgumentException {
for (int i = 0; i < _validFeedbackNames.length; i++) {
if (mode.equals(_validFeedbackNames[i])) {
setFeedbackMode(_validFeedbackModes[i]);
setInitialKnownStateFromFeedback();
return;
}
}
@@ -667,7 +668,7 @@ public void provideFirstFeedbackNamedSensor(@Nonnull NamedBeanHandle<Sensor> s)
temp.addPropertyChangeListener(this, s.getName(), "Feedback Sensor for " + getDisplayName());
}
// set initial state
sensorPropertyChange(new PropertyChangeEvent(temp, "KnownState", 0, temp.getKnownState()));
setInitialKnownStateFromFeedback();
}

@Override
@@ -712,8 +713,8 @@ public void provideSecondFeedbackNamedSensor(@Nonnull NamedBeanHandle<Sensor> s)
if (temp != null) {
temp.addPropertyChangeListener(this, s.getName(), "Feedback Sensor for " + getDisplayName());
}
// set initial state
sensorPropertyChange(new PropertyChangeEvent(temp, "KnownState", 0, temp.getKnownState()));
// set initial state
setInitialKnownStateFromFeedback();
}

@Override
@@ -240,17 +240,8 @@ public boolean loadTurnouts(Element shared, Element perNode) {
// Load common parts
loadCommon(t, elem);

// now add feedback if needed
// now configure feedback if needed
Attribute a;
a = elem.getAttribute("feedback");
if (a != null) {
try {
t.setFeedbackMode(a.getValue());
} catch (IllegalArgumentException e) {
log.error("Can not set feedback mode: '" + a.getValue() + "' for turnout: '" + sysName + "' user name: '" + (userName == null ? "" : userName) + "'");
result = false;
}
}
a = elem.getAttribute("sensor1");
if (a != null) {
try {
@@ -267,6 +258,15 @@ public boolean loadTurnouts(Element shared, Element perNode) {
result = false;
}
}
a = elem.getAttribute("feedback");
if (a != null) {
try {
t.setFeedbackMode(a.getValue());
} catch (IllegalArgumentException e) {
log.error("Can not set feedback mode: '" + a.getValue() + "' for turnout: '" + sysName + "' user name: '" + (userName == null ? "" : userName) + "'");
result = false;
}
}

// check for turnout inverted
t.setInverted(getAttributeBool(elem, "inverted", false));
@@ -216,9 +216,9 @@ public void testOneSensorFeedback() throws jmri.JmriException {
public void testTwoSensorFeedback() throws jmri.JmriException {
Sensor s1 = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("IS1");
Sensor s2 = InstanceManager.getDefault(jmri.SensorManager.class).provideSensor("IS2");
t.setFeedbackMode(Turnout.TWOSENSOR);
t.provideFirstFeedbackSensor("IS1");
t.provideSecondFeedbackSensor("IS2");
t.setFeedbackMode(Turnout.TWOSENSOR);
Assert.assertEquals("known state for TWOSENSOR feedback (UNKNOWN,UNKNOWN)",Turnout.UNKNOWN,t.getKnownState());

s1.setKnownState(Sensor.ACTIVE);

0 comments on commit 6724e02

Please sign in to comment.
You can’t perform that action at this time.