001/*
002 *  @author Gregory J. Bedlek Copyright (C) 2018, 2019
003 */
004package jmri.jmrit.ctc;
005
006import jmri.Sensor;
007
008public class SignalDirectionLever {
009    public static class LNR_NBHSensors {   // L = Left, N = Normal, R = Right.
010        public final NBHSensor _mLeftSensor;
011        public final NBHSensor _mNormalSensor;
012        public final NBHSensor _mRightSensor;
013        public LNR_NBHSensors(NBHSensor leftSensor, NBHSensor normalSensor, NBHSensor rightSensor) {
014            _mLeftSensor = leftSensor;
015            _mNormalSensor = normalSensor;
016            _mRightSensor = rightSensor;
017        }
018    }
019
020    private NBHSensor _mLeftSensor;
021    private NBHSensor _mNormalSensor;
022    private NBHSensor _mRightSensor;
023
024    public SignalDirectionLever(String userIdentifier, NBHSensor leftSensor, NBHSensor normalSensor, NBHSensor rightSensor) {
025        _mLeftSensor = leftSensor;
026        _mNormalSensor = normalSensor;
027        _mRightSensor = rightSensor;
028        if (!_mLeftSensor.valid() && !_mRightSensor.valid()) {
029            new CTCException("SignalDirectionLever", userIdentifier, Bundle.getMessage("SignalDirectionLeverMustHaveOne"), Bundle.getMessage("SignalDirectionLeverOneOrBoth")).logError();
030        }
031        _mLeftSensor.setKnownState(Sensor.INACTIVE);
032        _mNormalSensor.setKnownState(Sensor.ACTIVE);
033        _mRightSensor.setKnownState(Sensor.INACTIVE);
034    }
035
036    public void removeAllListeners() {}   // None done.
037    public LNR_NBHSensors getLevers() { return new LNR_NBHSensors(_mLeftSensor, _mNormalSensor, _mRightSensor); }
038
039    public int getPresentSignalDirectionLeverState() {
040        if (_mLeftSensor.getKnownState() == Sensor.ACTIVE) return CTCConstants.LEFTTRAFFIC;
041        if (_mNormalSensor.getKnownState() == Sensor.ACTIVE) return CTCConstants.SIGNALSNORMAL;
042        if (_mRightSensor.getKnownState() == Sensor.ACTIVE) return CTCConstants.RIGHTTRAFFIC;
043        return CTCConstants.OUTOFCORRESPONDENCE;    // Huh?
044    }
045}