Package jmri.jmrit.automat
Class SampleAutomaton2
- java.lang.Object
-
- jmri.jmrit.automat.AbstractAutomaton
-
- jmri.jmrit.automat.SampleAutomaton2
-
- All Implemented Interfaces:
java.lang.Runnable
public class SampleAutomaton2 extends AbstractAutomaton
This sample Automaton watches a Sensor, and adjusts the momentum of a locomotive using ops-mode programming when the sensor state changes.The sensor and decoder are hardcoded, as this is an example of just the Automaton function. Adding a GUI to configure these would be straight-forward. The values could be passed via the constructor, or the constructor (which can run in any required thread) could invoke a dialog.
For test purposes, one of these objects can be created and invoked by a SampleAutomaton2Action.
For more information on JMRI support for automation classes, please see the JMRI Layout Automation in Java page.
- See Also:
SampleAutomaton2Action
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class jmri.jmrit.automat.AbstractAutomaton
AbstractAutomaton.MsgFrame
-
-
Field Summary
Fields Modifier and Type Field Description (package private) booleanlocoLong(package private) intlocoNumberBy default, controls locomotive 1234(long).(package private) intnow(package private) ProgrammerprogrammerReferences the locomotive decoder to be controlled(package private) SensorsensorReferences the sensor to be monitored(package private) java.lang.StringsensorNameBy default, monitors sensor "31"-
Fields inherited from class jmri.jmrit.automat.AbstractAutomaton
debugWaitFrame, message, messageFrame, promptOnWait, waitChangePrecheckBeans, waitChangePrecheckStates, waitChangeQueue
-
-
Constructor Summary
Constructors Constructor Description SampleAutomaton2()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected booleanhandle()Watch "sensor", and when it changes the momentum CV to match.protected voidinit()By default, monitors sensor "32" and controls locomotive 1234(long).(package private) voidsetMomentum(int now)Set CV3, acceleration momentum, to match the sensor state.-
Methods inherited from class jmri.jmrit.automat.AbstractAutomaton
defaultName, done, getCount, getName, getThrottle, getThrottle, getThrottle, getThrottle, isRunning, isWaiting, readServiceModeCV, run, setName, setTurnouts, start, stop, wait, waitChange, waitChange, waitChangePrecheck, waitMsec, waitSensorActive, waitSensorActive, waitSensorChange, waitSensorChange, waitSensorInactive, waitSensorInactive, waitSensorState, waitSensorState, waitSignalHeadState, waitSignalMastState, waitTurnoutConsistent, waitWarrantBlock, waitWarrantBlockChange, waitWarrantRunState, writeOpsModeCV, writeServiceModeCV
-
-
-
-
Field Detail
-
programmer
Programmer programmer
References the locomotive decoder to be controlled
-
sensorName
java.lang.String sensorName
By default, monitors sensor "31"
-
locoNumber
int locoNumber
By default, controls locomotive 1234(long).
-
locoLong
boolean locoLong
-
now
int now
-
-
Constructor Detail
-
SampleAutomaton2
public SampleAutomaton2()
-
-
Method Detail
-
init
protected void init()
By default, monitors sensor "32" and controls locomotive 1234(long).- Overrides:
initin classAbstractAutomaton
-
handle
protected boolean handle()
Watch "sensor", and when it changes the momentum CV to match.- Overrides:
handlein classAbstractAutomaton- Returns:
- Always returns true to continue operation
-
setMomentum
void setMomentum(int now)
Set CV3, acceleration momentum, to match the sensor state. When the sensor is active, set the momentum to 30; when inactive, set the momentum to 0.- Parameters:
now- The current value of the sensor state.
-
-