001package jmri.jmrix.zimo; 002 003import jmri.Turnout; 004import jmri.implementation.AbstractTurnout; 005import org.slf4j.Logger; 006import org.slf4j.LoggerFactory; 007 008/** 009 * New Zimo Binary implementation of the Turnout interface 010 * 011 * @author Kevin Dickerson Copyright (C) 2014 012 */ 013public class Mx1Turnout extends AbstractTurnout /*implements Mx1TrafficListener*/ { 014 015 // Private data member to keep track of what turnout we control. 016 int _number; 017 Mx1TrafficController tc = null; 018 String prefix = ""; 019 020 /** 021 * Mx1 turnouts use any address allowed as an accessory decoder address on 022 * the particular command station. 023 * 024 * @param number the address 025 * @param tc the controller for traffic to the layout 026 * @param p the system connection prefix 027 */ 028 public Mx1Turnout(int number, Mx1TrafficController tc, String p) { 029 super(p + "T" + number); 030 _number = number; 031 this.prefix = p + "T"; 032 //tc.addMx1Listener(Mx1Interface.TURNOUTS, null); 033 } 034 035 public int getNumber() { 036 return _number; 037 } 038 039 /** 040 * {@inheritDoc} 041 * Sends a formatted DCC packet 042 */ 043 @Override 044 protected void forwardCommandChangeToLayout(int newState) { 045 // sort out states 046 if ((newState & Turnout.CLOSED) != 0) { 047 // first look for the double case, which we can't handle 048 if ((newState & Turnout.THROWN) != 0) { 049 // this is the disaster case! 050 log.error("Cannot command both CLOSED and THROWN {}", newState); // NOI18N 051 } else { 052 // send a CLOSED command 053 forwardToCommandStation(jmri.Turnout.THROWN); 054 } 055 } else { 056 // send a THROWN command 057 forwardToCommandStation(jmri.Turnout.CLOSED); 058 } 059 } 060 061 void forwardToCommandStation(int state) { 062 Mx1Message m = Mx1Message.getSwitchMsg(_number, state, true); 063 tc.sendMx1Message(m, null); 064 } 065 066 @Override 067 protected void turnoutPushbuttonLockout(boolean pushButtonLockout) { 068 } 069 070 private final static Logger log = LoggerFactory.getLogger(Mx1Turnout.class); 071 072}