Class SampleAutomaton

  • All Implemented Interfaces:
    java.lang.Runnable

    public class SampleAutomaton
    extends AbstractAutomaton
    This sample Automaton watches a Sensor, and adjusts the state of a Turnout so that it matches the Sensor's state.

    The sensor and turnout id's 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 SampleAutomatonAction.

    For more information on JMRI support for automation classes, please see the JMRI Layout Automation in Java page.

    See Also:
    SampleAutomatonAction
    • Field Detail

      • sensor

        Sensor sensor
        References the sensor to be monitored
      • sensorName

        java.lang.String sensorName
        By default, monitors sensor "31"
      • turnoutName

        java.lang.String turnoutName
        By default, controls turnout "26".
    • Method Detail

      • init

        protected void init()
        This also sets the turnout to the current (initial) state to make sure everything is consistent at the start.
        Overrides:
        init in class AbstractAutomaton
      • handle

        protected boolean handle()
        Watch "sensor", and when it changes adjust "turnout" to match.
        Overrides:
        handle in class AbstractAutomaton
        Returns:
        Always returns true to continue operation
      • setTurnout

        void setTurnout​(int now)
        Set "turnout" to match the sensor state
        Parameters:
        now - The current value of the sensor state.