use of jmri.SensorManager in project JMRI by JMRI.
the class DCCppSensorManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
// ask for a Sensor, and check type
SensorManager t = jmri.InstanceManager.sensorManagerInstance();
Sensor o = t.newSensor("DCCPPS21", "my name");
if (log.isDebugEnabled()) {
log.debug("received sensor value " + o);
}
Assert.assertTrue(null != (DCCppSensor) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("DCCPPS21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("DCCPPS21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
use of jmri.SensorManager in project JMRI by JMRI.
the class XNetSensorManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
jmri.InstanceManager.setSensorManager(l);
// ask for a Sensor, and check type
SensorManager t = jmri.InstanceManager.sensorManagerInstance();
Sensor o = t.newSensor("XS21", "my name");
if (log.isDebugEnabled()) {
log.debug("received sensor value " + o);
}
Assert.assertTrue(null != (XNetSensor) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("XS21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("XS21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
use of jmri.SensorManager in project JMRI by JMRI.
the class LnSensorManagerTest method testAsAbstractFactory.
@Test
public void testAsAbstractFactory() {
// ask for a Sensor, and check type
SensorManager t = jmri.InstanceManager.sensorManagerInstance();
Sensor o = t.newSensor("LS21", "my name");
if (log.isDebugEnabled()) {
log.debug("received sensor value " + o);
}
Assert.assertTrue(null != (LnSensor) o);
// make sure loaded into tables
if (log.isDebugEnabled()) {
log.debug("by system name: " + t.getBySystemName("LS21"));
}
if (log.isDebugEnabled()) {
log.debug("by user name: " + t.getByUserName("my name"));
}
Assert.assertTrue(null != t.getBySystemName("LS21"));
Assert.assertTrue(null != t.getByUserName("my name"));
}
use of jmri.SensorManager in project JMRI by JMRI.
the class PositionableShape method setControlSensor.
/**
* Attach a named sensor to shape
*
* @param pName Used as a system/user name to lookup the sensor object
* @param hide true if sensor should be hidden
* @param level level at which sensor is placed
* @return error message, if any
*/
public String setControlSensor(String pName, boolean hide, int level) {
String msg = null;
if (pName == null || pName.trim().isEmpty()) {
setControlSensorHandle(null);
return null;
}
NamedBeanHandle<Sensor> senHandle = null;
_saveLevel = super.getDisplayLevel();
Optional<SensorManager> sensorManager = InstanceManager.getOptionalDefault(SensorManager.class);
if (sensorManager.isPresent()) {
Sensor sensor = sensorManager.get().getSensor(pName);
Optional<NamedBeanHandleManager> nbhm = InstanceManager.getOptionalDefault(NamedBeanHandleManager.class);
if (sensor != null) {
if (nbhm.isPresent()) {
senHandle = nbhm.get().getNamedBeanHandle(pName, sensor);
}
_doHide = hide;
_changeLevel = level;
if (_changeLevel <= 0) {
_changeLevel = super.getDisplayLevel();
}
} else {
// NOI18N
msg = Bundle.getMessage("badSensorName", pName);
}
} else {
// NOI18N
msg = Bundle.getMessage("NoSensorManager");
}
if (msg != null) {
log.warn("{} for {} sensor", msg, Bundle.getMessage("VisibleSensor"));
}
setControlSensorHandle(senHandle);
return msg;
}
use of jmri.SensorManager in project JMRI by JMRI.
the class AbstractTurnout method provideFirstFeedbackSensor.
@Override
public void provideFirstFeedbackSensor(String pName) throws jmri.JmriException, IllegalArgumentException {
if (InstanceManager.getNullableDefault(SensorManager.class) != null) {
if (pName == null || pName.equals("")) {
provideFirstFeedbackNamedSensor(null);
} else {
Sensor sensor = InstanceManager.sensorManagerInstance().provideSensor(pName);
provideFirstFeedbackNamedSensor(jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(pName, sensor));
}
} else {
log.error("No SensorManager for this protocol");
throw new jmri.JmriException("No Sensor Manager Found");
}
}
Aggregations