Class AbstractThrottle
- All Implemented Interfaces:
PropertyChangeFirer,PropertyChangeProvider,DccThrottle,Throttle
- Direct Known Subclasses:
BiDiBThrottle,CbusThrottle,DCCppThrottle,DebugThrottle,EasyDccThrottle,EcosDccThrottle,LocoNetThrottle,MarklinThrottle,MqttThrottle,MrcThrottle,Mx1Throttle,NceThrottle,OlcbThrottle,Pr2Throttle,SerialThrottle,SprogCSThrottle,SprogThrottle,SRCPThrottle,TamsThrottle,Throttle,XNetThrottle,XpaThrottle
Note that this implements DccThrottle, not Throttle directly, so it has some DCC-specific content.
-
Field Summary
FieldsModifier and TypeFieldDescriptionprotected booleanIs this object still usable?protected final SystemConnectionMemo(package private) longprotected static final int[]Constants to represent Function Groups.protected boolean(package private) BasicRosterEntryprotected floatprotected SpeedStepModeQuestion: should we set a default speed step mode so it's never zero?protected longFields inherited from class jmri.beans.PropertyChangeSupport
propertyChangeSupportFields inherited from interface jmri.Throttle
CONNECTED, DISPATCH_ENABLED, F0, F0Momentary, F1, F10, F10Momentary, F11, F11Momentary, F12, F12Momentary, F13, F13Momentary, F14, F14Momentary, F15, F15Momentary, F16, F16Momentary, F17, F17Momentary, F18, F18Momentary, F19, F19Momentary, F1Momentary, F2, F20, F20Momentary, F21, F21Momentary, F22, F22Momentary, F23, F23Momentary, F24, F24Momentary, F25, F25Momentary, F26, F26Momentary, F27, F27Momentary, F28, F28Momentary, F2Momentary, F3, F3Momentary, F4, F4Momentary, F5, F5Momentary, F6, F6Momentary, F7, F7Momentary, F8, F8Momentary, F9, F9Momentary, ISFORWARD, RELEASE_ENABLED, SPEEDINCREMENT, SPEEDSETTING, SPEEDSTEPMODE, SPEEDSTEPS -
Constructor Summary
ConstructorsConstructorDescriptionCreate a new AbstractThrottle with Functions 0-28..AbstractThrottle(SystemConnectionMemo memo, int totalFunctions) Create a new AbstractThrottle with custom number of functions. -
Method Summary
Modifier and TypeMethodDescriptionvoidTemporary behaviour only allowing unique PCLs.voidFinished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else.voidCall from a ThrottleListener to dispose of the throttle instanceprotected voidbooleangetFunction(int fN) Get Loco Function status.booleangetFunctionMomentary(int fN) Get the Momentary Function Value.protected booleangetFunctionMomentaryNoWarn(int fN) Get Momentary Function Number without warning if Throttle does not support.protected booleangetFunctionNoWarn(int fN) Get Function Number without warning if Throttle does not support.boolean[]Get copy of function array.boolean[]Get copy of function momentary status array.booleandirection This is an bound parameter.protected SystemConnectionMemogetMemo()Get the System Connection this throttle is on.floatHandle quantized speed.floatspeed - expressed as a value 0.0 -> 1.0. Negative means emergency stop.Get the current speed step value.protected intintSpeed(float speed) Get an integer speed for the given raw speed value.protected static intintSpeed(float speed, int steps) Get an integer speed for the given raw speed value.protected voidNotify listeners that a Throttle has disconnected and is no longer available for use.voidnotifyThrottleDispatchEnabled(boolean newVal) Notify listeners that a Throttle has Dispatch enabled or disabled.voidnotifyThrottleReleaseEnabled(boolean newVal) Notify listeners that a Throttle has Release enabled or disabled.protected voidrecord(float speed) Processes updated speed from subclasses.voidFinished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else.voidRemove the specified listener from this object.protected voidsendFunctionGroup(int functionNum, boolean momentary) Send whole (DCC) Function Group for a particular function number.protected voidSend the message to set the state of functions F0, F1, F2, F3, F4.protected voidSend the message to set the state of functions F61 - F68.protected voidSend the message to set the state of functions F5, F6, F7, F8.protected voidSend the message to set the state of functions F9, F10, F11, F12.protected voidSend the message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20.protected voidSend the message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28.protected voidSend the message to set the state of functions F29 - F36.protected voidSend the message to set the state of functions F37 - F44.protected voidSend the message to set the state of functions F45 - F52.protected voidSend the message to set the state of functions F53 - F60.protected voidSend the message to set the momentary state of functions F0, F1, F2, F3, F4.protected voidSend the message to set the Momentary state of functions F61 - F68protected voidSend the message to set the momentary state of functions F5, F6, F7, F8.protected voidSend the message to set the Momentary state of functions F9, F10, F11, F12protected voidSend the message to set the Momentary state of functions F13, F14, F15, F16, F17, F18, F19, F20protected voidSend the message to set the Momentary state of functions F21, F22, F23, F24, F25, F26, F27, F28protected voidSend the message to set the Momentary state of functions F29 - F36protected voidSend the message to set the Momentary state of functions F37 - F44protected voidSend the message to set the Momentary state of functions F45 - 52protected voidSend the message to set the Momentary state of functions F53 - F60voidsetFunction(int functionNum, boolean newState) Set Loco Function and send to Layout.voidsetFunctionMomentary(int momFuncNum, boolean state) Sets Momentary Function and sends to layout.voidsetIsForward(boolean forward) Implementing functions should override this function, but should either make a call to super.setIsForward() to notify the listeners, or should notify the listeners themselves.voidvoidsetSpeedSetting(float speed) setSpeedSetting - Implementing functions should override this function, but should either make a call to super.setSpeedSetting() to notify the listeners at the end of their work, or should notify the listeners themselves.voidsetSpeedSetting(float speed, boolean allowDuplicates, boolean allowDuplicatesOnStop) setSpeedSetting - Implementations should override this method only if they normally suppress messages to the system if, as far as JMRI can tell, the new message would make no difference to the system state (eg.voidsetSpeedSettingAgain(float speed) setSpeedSettingAgain - set the speed and don't ever suppress the sending of messages to the systemvoidSet the speed step value.protected void(package private) voidprotected abstract voidDispose when finished with this Throttle.voidupdateFunction(int fn, boolean state) Update the state of a single function.voidupdateFunctionMomentary(int fn, boolean state) Update the Momentary state of a single function.Methods inherited from class jmri.beans.PropertyChangeSupport
addPropertyChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListenerMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListenerMethods inherited from interface jmri.Throttle
getF0, getF0Momentary, getF1, getF10, getF10Momentary, getF11, getF11Momentary, getF12, getF12Momentary, getF13, getF13Momentary, getF14, getF14Momentary, getF15, getF15Momentary, getF16, getF16Momentary, getF17, getF17Momentary, getF18, getF18Momentary, getF19, getF19Momentary, getF1Momentary, getF2, getF20, getF20Momentary, getF21, getF21Momentary, getF22, getF22Momentary, getF23, getF23Momentary, getF24, getF24Momentary, getF25, getF25Momentary, getF26, getF26Momentary, getF27, getF27Momentary, getF28, getF28Momentary, getF2Momentary, getF3, getF3Momentary, getF4, getF4Momentary, getF5, getF5Momentary, getF6, getF6Momentary, getF7, getF7Momentary, getF8, getF8Momentary, getF9, getF9Momentary, getLocoAddress, setF0, setF0Momentary, setF1, setF10, setF10Momentary, setF11, setF11Momentary, setF12, setF12Momentary, setF13, setF13Momentary, setF14, setF14Momentary, setF15, setF15Momentary, setF16, setF16Momentary, setF17, setF17Momentary, setF18, setF18Momentary, setF19, setF19Momentary, setF1Momentary, setF2, setF20, setF20Momentary, setF21, setF21Momentary, setF22, setF22Momentary, setF23, setF23Momentary, setF24, setF24Momentary, setF25, setF25Momentary, setF26, setF26Momentary, setF27, setF27Momentary, setF28, setF28Momentary, setF2Momentary, setF3, setF3Momentary, setF4, setF4Momentary, setF5, setF5Momentary, setF6, setF6Momentary, setF7, setF7Momentary, setF8, setF8Momentary, setF9, setF9Momentary
-
Field Details
-
speedSetting
-
speedStepMode
Question: should we set a default speed step mode so it's never zero? -
isForward
-
FUNCTION_GROUPS
Constants to represent Function Groups.The are the same groupings for both normal Functions and Momentary.
-
active
Is this object still usable? Set false after dispose, this variable is used to check for incorrect usage. -
adapterMemo
-
durationRunning
long durationRunning -
start
-
re
-
-
Constructor Details
-
AbstractThrottle
Create a new AbstractThrottle with Functions 0-28..All function and momentary functions set to Off.
- Parameters:
memo- System Connection.
-
AbstractThrottle
Create a new AbstractThrottle with custom number of functions.All function and momentary functions set to Off.
- Parameters:
memo- System Connection this throttle is ontotalFunctions- total number of functions available, including 0
-
-
Method Details
-
getMemo
Get the System Connection this throttle is on.- Returns:
- non-null system connection.
-
getSpeedSetting
speed - expressed as a value 0.0 -> 1.0. Negative means emergency stop. This is a bound parameter.- Specified by:
getSpeedSettingin interfaceThrottle- Returns:
- speed
-
setSpeedSetting
setSpeedSetting - Implementing functions should override this function, but should either make a call to super.setSpeedSetting() to notify the listeners at the end of their work, or should notify the listeners themselves.- Specified by:
setSpeedSettingin interfaceThrottle- Parameters:
speed- the speed as a 0.0 -> 1.0. fraction of maximum possible speed or -1 for emergency stop.
-
setSpeedSetting
setSpeedSetting - Implementations should override this method only if they normally suppress messages to the system if, as far as JMRI can tell, the new message would make no difference to the system state (eg. the speed is the same, or effectivly the same, as the existing speed). Then, the boolean options can affect this behaviour.- Specified by:
setSpeedSettingin interfaceThrottle- Parameters:
speed- the new speedallowDuplicates- don't suppress messagesallowDuplicatesOnStop- don't suppress messages if the new speed is 'stop'
-
setSpeedSettingAgain
setSpeedSettingAgain - set the speed and don't ever suppress the sending of messages to the system- Specified by:
setSpeedSettingAgainin interfaceThrottle- Parameters:
speed- the new speed
-
getIsForward
direction This is an bound parameter.- Specified by:
getIsForwardin interfaceThrottle- Returns:
- true if locomotive is running forward
-
setIsForward
Implementing functions should override this function, but should either make a call to super.setIsForward() to notify the listeners, or should notify the listeners themselves.- Specified by:
setIsForwardin interfaceThrottle- Parameters:
forward- true if forward; false otherwise
-
getFunctions
Get copy of function array. Typically returns array length of 29, i.e. 0-28.- Specified by:
getFunctionsin interfaceThrottle- Returns:
- function array, length dependant by hardware type.
-
getFunctionsMomentary
Get copy of function momentary status array. Typically returns array length of 29, i.e. 0-28.- Specified by:
getFunctionsMomentaryin interfaceThrottle- Returns:
- momentary function array, length dependant by hardware type.
-
getFunction
Get Loco Function status.- Specified by:
getFunctionin interfaceThrottle- Parameters:
fN- Function Number, 0-28- Returns:
- Function State. True on, false off.
-
getFunctionNoWarn
Get Function Number without warning if Throttle does not support. When sending a whole Function Group, a function number may not be present.- Parameters:
fN- Function Number- Returns:
- Function value, or false if not present.
-
getFunctionMomentary
Get the Momentary Function Value.- Specified by:
getFunctionMomentaryin interfaceThrottle- Parameters:
fN- Momentary function number- Returns:
- true if momentary function is on, else false.
-
getFunctionMomentaryNoWarn
Get Momentary Function Number without warning if Throttle does not support. When sending a whole Function Group, a function number may not be present.- Parameters:
fN- Function Number- Returns:
- Function value, or false if not present.
-
notifyThrottleDisconnect
Notify listeners that a Throttle has disconnected and is no longer available for use.For when throttles have been stolen or encounter hardware error, and a normal release / dispose is not possible.
-
notifyThrottleDispatchEnabled
Notify listeners that a Throttle has Dispatch enabled or disabled.For systems where dispatch availability is variable.
Does not notify if existing value is unchanged.
- Specified by:
notifyThrottleDispatchEnabledin interfaceThrottle- Parameters:
newVal- true if Dispatch enabled, else false
-
notifyThrottleReleaseEnabled
Notify listeners that a Throttle has Release enabled or disabled.For systems where release availability is variable.
Does not notify if existing value is unchanged.
- Specified by:
notifyThrottleReleaseEnabledin interfaceThrottle- Parameters:
newVal- true if Release enabled, else false
-
addPropertyChangeListener
Temporary behaviour only allowing unique PCLs. To support Throttle PCL's ( eg. WiThrottle Server ) that rely on the previous behaviour of only allowing 1 unique PCL instance. To be removed when WiThrottle Server has been updated. Add aPropertyChangeListenerto the listener list.- Specified by:
addPropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
addPropertyChangeListenerin classPropertyChangeSupport- Parameters:
l- The PropertyChangeListener to be added
-
removePropertyChangeListener
Remove the specified listener from this object.- Specified by:
removePropertyChangeListenerin interfacePropertyChangeProvider- Overrides:
removePropertyChangeListenerin classPropertyChangeSupport- Parameters:
l- ThePropertyChangeListenerto remove.
-
dispose
Call from a ThrottleListener to dispose of the throttle instance -
dispatch
Finished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else. If possible, tell the layout that this locomotive has been dispatched to another user. Not all layouts will implement this, in which case it is synonymous withThrottle.release(jmri.ThrottleListener).After this, further usage of this Throttle object will result in a JmriException.
Normally, dispatch ends with a call to dispose.
- Specified by:
dispatchin interfaceThrottle- Parameters:
l-ThrottleListenerto dispatch
-
release
Finished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else.After this, further usage of this Throttle object will result in a JmriException. Do not call dispose after release.
Normally, release ends with a call to dispose.
- Specified by:
releasein interfaceThrottle- Parameters:
l-ThrottleListenerto release. May be null if noThrottleListeneris currently held.
-
throttleDispose
Dispose when finished with this Throttle. May be used in tests for cleanup. Throttles normally callfinishRecord()here. -
getSpeedIncrement
Handle quantized speed. Note this can change! Value returned is always positive.- Specified by:
getSpeedIncrementin interfaceDccThrottle- Returns:
- 1 divided by the number of speed steps this DCC throttle supports
-
sendFunctionGroup
Send whole (DCC) Function Group for a particular function number.- Parameters:
functionNum- Function Numbermomentary- False to send normal function status, true to send momentary.
-
setFunction
Set Loco Function and send to Layout.- Specified by:
setFunctionin interfaceThrottle- Parameters:
functionNum- Function Number, 0-28newState- New Function State. True on, false off.
-
updateFunction
Update the state of a single function. Updates function value and ChangeListener. Does not send outward message TO hardware.- Parameters:
fn- Function Number 0-28state- On - True, Off - False
-
updateFunctionMomentary
Update the Momentary state of a single function. Updates function value and ChangeListener. Does not send outward message TO hardware.- Parameters:
fn- Momentary Function Number 0-28state- On - True, Off - False
-
sendFunctionGroup1
Send the message to set the state of functions F0, F1, F2, F3, F4.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup2
Send the message to set the state of functions F5, F6, F7, F8.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup3
Send the message to set the state of functions F9, F10, F11, F12.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup4
Send the message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup5
Send the message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup6
Send the message to set the state of functions F29 - F36.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup7
Send the message to set the state of functions F37 - F44.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup8
Send the message to set the state of functions F45 - F52.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup9
Send the message to set the state of functions F53 - F60.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
sendFunctionGroup10
Send the message to set the state of functions F61 - F68.This is used in the setFn implementations provided in this class, but a real implementation needs to be provided.
-
setFunctionMomentary
Sets Momentary Function and sends to layout. Set Momentary Loco Function and send to Layout.- Specified by:
setFunctionMomentaryin interfaceThrottle- Parameters:
momFuncNum- Momentary Function Number, 0-28state- New Function State. True on, false off.
-
sendMomentaryFunctionGroup1
Send the message to set the momentary state of functions F0, F1, F2, F3, F4.This is used in the setFnMomentary implementations provided in this class, a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup2
Send the message to set the momentary state of functions F5, F6, F7, F8.This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup3
Send the message to set the Momentary state of functions F9, F10, F11, F12This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup4
Send the message to set the Momentary state of functions F13, F14, F15, F16, F17, F18, F19, F20This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup5
Send the message to set the Momentary state of functions F21, F22, F23, F24, F25, F26, F27, F28This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup6
Send the message to set the Momentary state of functions F29 - F36This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup7
Send the message to set the Momentary state of functions F37 - F44This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup8
Send the message to set the Momentary state of functions F45 - 52This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup9
Send the message to set the Momentary state of functions F53 - F60This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
sendMomentaryFunctionGroup10
Send the message to set the Momentary state of functions F61 - F68This is used in the setFnMomentary implementations provided in this class, but a real implementation needs to be provided if the hardware supports setting functions momentary.
-
setSpeedStepMode
Set the speed step value. Default should be 128 speed step mode in most cases.Specific implementations should override this function.
- Specified by:
setSpeedStepModein interfaceDccThrottle- Parameters:
mode- the current speed step mode
-
getSpeedStepMode
Description copied from interface:DccThrottleGet the current speed step value.- Specified by:
getSpeedStepModein interfaceDccThrottle- Returns:
- the current speed step mode
-
record
Processes updated speed from subclasses. Tracks total operating time for the roster entry by starting the clock if speed is non-zero or stopping the clock otherwise.- Parameters:
speed- the current speed
-
startClock
-
stopClock
void stopClock() -
finishRecord
-
setRosterEntry
- Specified by:
setRosterEntryin interfaceThrottle
-
getRosterEntry
- Specified by:
getRosterEntryin interfaceThrottle
-
intSpeed
Get an integer speed for the given raw speed value. This is a convenience method that callsintSpeed(float, int)with a maxStep of 127.- Parameters:
speed- the speed as a percentage of maximum possible speed; negative values indicate a need for an emergency stop- Returns:
- an integer in the range 0-127
-
intSpeed
Get an integer speed for the given raw speed value.- Parameters:
speed- the speed as a percentage of maximum possible speed; negative values indicate a need for an emergency stopsteps- number of possible speeds; values less than 2 will cause errors- Returns:
- an integer in the range 0-steps
-