Package jmri.jmrit.withrottle
Class ThrottleController
- java.lang.Object
-
- jmri.jmrit.withrottle.ThrottleController
-
- All Implemented Interfaces:
java.beans.PropertyChangeListener,java.util.EventListener,ThrottleListener
- Direct Known Subclasses:
MultiThrottleController
public class ThrottleController extends java.lang.Object implements ThrottleListener, java.beans.PropertyChangeListener
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<ControllerInterface>controllerListeners(package private) DccThrottlefunctionThrottle(package private) booleanisAddressSet(package private) booleanisMomF2protected java.util.Queue<java.lang.Float>lastSentSpeed(package private) DccLocoAddressleadAddress(package private) ConsistFunctionControllerleadLocoFprotected java.util.ArrayList<ThrottleControllerListener>listeners(package private) java.lang.StringlocoKeyprotected floatnewSpeed(package private) RosterEntryrosterLoco(package private) floatspeedMultiplier(package private) DccThrottlethrottle(package private) booleanuseLeadLocoF(package private) charwhichThrottle
-
Constructor Summary
Constructors Constructor Description ThrottleController()ThrottleController(char whichThrottleChar, ThrottleControllerListener tcl, ControllerInterface cl)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddControllerListener(ControllerInterface listener)Add a listener to handle: listener.sendPacketToDevice(message);voidaddressDispatch()voidaddressRelease()Receive notification that an address has been released/dispatchedvoidaddThrottleControllerListener(ThrottleControllerListener l)protected java.lang.StringbuildFStatesHeader()protected voideStop()RosterEntryfindRosterEntry(DccThrottle t)protected voidforceFunction(java.lang.String inPackage)DccLocoAddressgetCurrentAddress()java.lang.StringgetCurrentAddressString()Get the string representation of this throttles address.java.lang.StringgetCurrentRosterIdString()Get the string representation of this Roster ID.DccThrottlegetFunctionThrottle()DccThrottlegetThrottle()protected voidhandleFunction(java.lang.String inPackage)protected voidhandleMomentary(java.lang.String inPackage)protected voidhandleRequest(java.lang.String inPackage)protected voidhandleSpeedStepMode(SpeedStepMode newMode)protected voididle()voidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)calls notifyFailedThrottleRequest, Steal RequiredvoidnotifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)Get notification that an attempt to request a throttle has failed.voidnotifyThrottleFound(DccThrottle t)Receive notification that a DccThrottle has been found and is in use.voidpropertyChange(java.beans.PropertyChangeEvent event)voidremoveControllerListener(ControllerInterface listener)voidremoveThrottleControllerListener(ThrottleControllerListener l)voidrequestEntryFromID(java.lang.String id)voidsendAddress()voidsendAllFunctionStates(DccThrottle t)send all function states, primarily for initial status Current Format: RPF}|{whichThrottle]\[function}|{state]\[function}|{state...protected voidsendAllMomentaryStates(DccThrottle t)protected voidsendCurrentDirection(DccThrottle t)protected voidsendCurrentSpeed(DccThrottle t)voidsendFunctionLabels(RosterEntry re)Send function labels for a roster entry, using old format.protected voidsendSpeedStepMode(DccThrottle t)protected voidsetAddress(int number, boolean isLong)protected voidsetDirection(boolean isForward)voidsetFunctionThrottle(DccThrottle t)voidsetLocoForConsistFunctions(java.lang.String inPackage)voidsetRosterLocoForConsistFunctions(java.lang.String id)protected voidsetSpeed(int rawSpeed)handle the conversion from rawSpeed to the float value needed in the DccThrottlevoidsetWhichThrottle(char c)voidshutdownThrottle()booleansort(java.lang.String inPackage)Figure out what the received command means, where it has to go, and translate to a jmri method.voidsyncThrottleFunctions(DccThrottle t, RosterEntry re)
-
-
-
Field Detail
-
throttle
DccThrottle throttle
-
functionThrottle
DccThrottle functionThrottle
-
rosterLoco
RosterEntry rosterLoco
-
leadAddress
DccLocoAddress leadAddress
-
whichThrottle
char whichThrottle
-
speedMultiplier
float speedMultiplier
-
lastSentSpeed
protected java.util.Queue<java.lang.Float> lastSentSpeed
-
newSpeed
protected float newSpeed
-
isAddressSet
boolean isAddressSet
-
listeners
protected java.util.ArrayList<ThrottleControllerListener> listeners
-
controllerListeners
protected java.util.ArrayList<ControllerInterface> controllerListeners
-
useLeadLocoF
boolean useLeadLocoF
-
leadLocoF
ConsistFunctionController leadLocoF
-
locoKey
java.lang.String locoKey
-
isMomF2
final boolean isMomF2
-
-
Constructor Detail
-
ThrottleController
public ThrottleController()
-
ThrottleController
public ThrottleController(char whichThrottleChar, ThrottleControllerListener tcl, ControllerInterface cl)
-
-
Method Detail
-
setWhichThrottle
public void setWhichThrottle(char c)
-
addThrottleControllerListener
public void addThrottleControllerListener(ThrottleControllerListener l)
-
removeThrottleControllerListener
public void removeThrottleControllerListener(ThrottleControllerListener l)
-
addControllerListener
public void addControllerListener(ControllerInterface listener)
Add a listener to handle: listener.sendPacketToDevice(message);- Parameters:
listener- handle of listener to add
-
removeControllerListener
public void removeControllerListener(ControllerInterface listener)
-
addressRelease
public void addressRelease()
Receive notification that an address has been released/dispatched
-
addressDispatch
public void addressDispatch()
-
notifyThrottleFound
public void notifyThrottleFound(DccThrottle t)
Receive notification that a DccThrottle has been found and is in use.- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
t- The throttle which has been found
-
notifyFailedThrottleRequest
public void notifyFailedThrottleRequest(LocoAddress address, java.lang.String reason)
Description copied from interface:ThrottleListenerGet notification that an attempt to request a throttle has failed.- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- address of the failed requestreason- failure cause
-
notifyDecisionRequired
public void notifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question)
calls notifyFailedThrottleRequest, Steal RequiredGet notification that a throttle request is in use by another device, and a "steal", "share", or "steal/share" decision may be required.
- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- The LocoAddress that needs the decision.question- The question being asked, steal / cancel, share / cancel, steal / share / cancel
-
propertyChange
public void propertyChange(java.beans.PropertyChangeEvent event)
- Specified by:
propertyChangein interfacejava.beans.PropertyChangeListener
-
findRosterEntry
public RosterEntry findRosterEntry(DccThrottle t)
-
syncThrottleFunctions
public void syncThrottleFunctions(DccThrottle t, RosterEntry re)
-
sendFunctionLabels
public void sendFunctionLabels(RosterEntry re)
Send function labels for a roster entry, using old format. This implementation is legacy and should not change from the limit of 29 functions.- Parameters:
re- The roster entry to get the labels from.
-
sendAllFunctionStates
public void sendAllFunctionStates(DccThrottle t)
send all function states, primarily for initial status Current Format: RPF}|{whichThrottle]\[function}|{state]\[function}|{state... This implementation is legacy and should not change from the limit of 29 functions.- Parameters:
t- throttle to send functions to
-
buildFStatesHeader
protected java.lang.String buildFStatesHeader()
-
sendCurrentSpeed
protected void sendCurrentSpeed(DccThrottle t)
-
sendCurrentDirection
protected void sendCurrentDirection(DccThrottle t)
-
sendSpeedStepMode
protected void sendSpeedStepMode(DccThrottle t)
-
sendAllMomentaryStates
protected void sendAllMomentaryStates(DccThrottle t)
-
sort
public boolean sort(java.lang.String inPackage)
Figure out what the received command means, where it has to go, and translate to a jmri method.- Parameters:
inPackage- The package minus its prefix which steered it here.- Returns:
- true to keep reading in run loop.
-
setFunctionThrottle
public void setFunctionThrottle(DccThrottle t)
-
setLocoForConsistFunctions
public void setLocoForConsistFunctions(java.lang.String inPackage)
-
setRosterLocoForConsistFunctions
public void setRosterLocoForConsistFunctions(java.lang.String id)
-
shutdownThrottle
public void shutdownThrottle()
-
setSpeed
protected void setSpeed(int rawSpeed)
handle the conversion from rawSpeed to the float value needed in the DccThrottle- Parameters:
rawSpeed- Value sent from mobile device, range 0 - 126
-
setDirection
protected void setDirection(boolean isForward)
-
eStop
protected void eStop()
-
idle
protected void idle()
-
setAddress
protected void setAddress(int number, boolean isLong)
-
requestEntryFromID
public void requestEntryFromID(java.lang.String id)
-
getThrottle
public DccThrottle getThrottle()
-
getFunctionThrottle
public DccThrottle getFunctionThrottle()
-
getCurrentAddress
public DccLocoAddress getCurrentAddress()
-
getCurrentAddressString
public java.lang.String getCurrentAddressString()
Get the string representation of this throttles address. Returns 'Not Set' if no address in use.- Returns:
- string value of throttle address
-
getCurrentRosterIdString
public java.lang.String getCurrentRosterIdString()
Get the string representation of this Roster ID. Returns empty string if no address in use. since 4.15.4- Returns:
- string value of throttle Roster ID
-
sendAddress
public void sendAddress()
-
handleFunction
protected void handleFunction(java.lang.String inPackage)
-
forceFunction
protected void forceFunction(java.lang.String inPackage)
-
handleSpeedStepMode
protected void handleSpeedStepMode(SpeedStepMode newMode)
-
handleMomentary
protected void handleMomentary(java.lang.String inPackage)
-
handleRequest
protected void handleRequest(java.lang.String inPackage)
-
-