Class AbstractThrottle
- All Implemented Interfaces:
PropertyChangeFirer
,PropertyChangeProvider
,DccThrottle
,Throttle
- Direct Known Subclasses:
CbusThrottle
,DCCppThrottle
,DebugThrottle
,EasyDccThrottle
,EcosDccThrottle
,LocoNetThrottle
,MarklinThrottle
,MrcThrottle
,Mx1Throttle
,NceThrottle
,OlcbThrottle
,Pr2Throttle
,SerialThrottle
,SprogCSThrottle
,SprogThrottle
,SRCPThrottle
,TamsThrottle
,Throttle
,XNetThrottle
,XpaThrottle
public abstract class AbstractThrottle extends PropertyChangeSupport implements DccThrottle
Note that this implements DccThrottle, not Throttle directly, so it has some DCC-specific content.
-
Field Summary
Fields Modifier and Type Field Description protected boolean
active
Is this object still usable?protected SystemConnectionMemo
adapterMemo
System Connection.(package private) long
durationRunning
protected boolean
isForward
(package private) BasicRosterEntry
re
protected float
speedSetting
protected SpeedStepMode
speedStepMode
Question: should we set a default speed step mode so it's never zero?protected long
start
Fields inherited from interface jmri.Throttle
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, FUNCTION_GROUPS, ISFORWARD, SPEEDINCREMENT, SPEEDSETTING, SPEEDSTEPMODE, SPEEDSTEPS
-
Constructor Summary
Constructors Constructor Description AbstractThrottle(SystemConnectionMemo memo)
Create 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 Type Method Description void
addPropertyChangeListener(PropertyChangeListener l)
Temporary behaviour only allowing unique PCLs.void
dispatch(ThrottleListener l)
Finished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else.void
dispose(ThrottleListener l)
Call from a ThrottleListener to dispose of the throttle instanceprotected void
finishRecord()
boolean
getFunction(int fN)
Get Loco Function status.boolean
getFunctionMomentary(int fN)
Get the Momentary Function Value.boolean[]
getFunctions()
Get copy of function array.boolean[]
getFunctionsMomentary()
Get copy of function momentary status array.boolean
getIsForward()
direction This is an bound parameter.List<PropertyChangeListener>
getListeners()
Deprecated.BasicRosterEntry
getRosterEntry()
float
getSpeedIncrement()
to handle quantized speed.float
getSpeedSetting()
speed - expressed as a value 0.0 -> 1.0. Negative means emergency stop.SpeedStepMode
getSpeedStepMode()
Get the current speed step value.protected int
intSpeed(float speed)
Get an integer speed for the given raw speed value.protected int
intSpeed(float speed, int steps)
Get an integer speed for the given raw speed value.protected void
notifyPropertyChangeListener(String property, Object oldValue, Object newValue)
Deprecated.since 4.19.5; usePropertyChangeSupport.firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)
insteadprotected void
notifyThrottleDisconnect()
Notify listeners that a Throttle has disconnected and is no longer available for use.void
notifyThrottleDispatchEnabled(boolean newVal)
Notify listeners that a Throttle has Dispatch enabled or disabled.void
notifyThrottleReleaseEnabled(boolean newVal)
Notify listeners that a Throttle has Release enabled or disabled.protected void
record(float speed)
Processes updated speed from subclasses.void
release(ThrottleListener l)
Finished with this Throttle, tell the layout that the locomotive is available for reuse/reallocation by somebody else.void
removePropertyChangeListener(PropertyChangeListener l)
Remove the specified listener from this object.protected void
sendFunctionGroup(int functionNum, boolean momentary)
Send whole (DCC) Function Group for a particular function number.protected void
sendFunctionGroup1()
Send the message to set the state of functions F0, F1, F2, F3, F4.protected void
sendFunctionGroup2()
Send the message to set the state of functions F5, F6, F7, F8.protected void
sendFunctionGroup3()
Send the message to set the state of functions F9, F10, F11, F12.protected void
sendFunctionGroup4()
Send the message to set the state of functions F13, F14, F15, F16, F17, F18, F19, F20.protected void
sendFunctionGroup5()
Send the message to set the state of functions F21, F22, F23, F24, F25, F26, F27, F28.protected void
sendMomentaryFunctionGroup1()
Send the message to set the momentary state of functions F0, F1, F2, F3, F4.protected void
sendMomentaryFunctionGroup2()
Send the message to set the momentary state of functions F5, F6, F7, F8.protected void
sendMomentaryFunctionGroup3()
Send the message to set the Momentary state of functions F9, F10, F11, F12protected void
sendMomentaryFunctionGroup4()
Send the message to set the Momentary state of functions F13, F14, F15, F16, F17, F18, F19, F20protected void
sendMomentaryFunctionGroup5()
Send the message to set the Momentary state of functions F21, F22, F23, F24, F25, F26, F27, F28void
setFunction(int functionNum, boolean newState)
Set Loco Function and send to Layout.void
setFunctionMomentary(int momFuncNum, boolean state)
Sets Momentary Function and sends to layout.void
setIsForward(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.void
setRosterEntry(BasicRosterEntry re)
void
setSpeedSetting(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.void
setSpeedSetting(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.void
setSpeedSettingAgain(float speed)
setSpeedSettingAgain - set the speed and don't ever supress the sending of messages to the systemvoid
setSpeedStepMode(SpeedStepMode mode)
Set the speed step value.protected void
startClock()
(package private) void
stopClock()
protected abstract void
throttleDispose()
Dispose when finished with this Throttle.void
updateFunction(int fn, boolean state)
Update the state of a single function.void
updateFunctionMomentary(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, removePropertyChangeListener
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface jmri.beans.PropertyChangeProvider
addPropertyChangeListener, getPropertyChangeListeners, getPropertyChangeListeners, removePropertyChangeListener
Methods 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
-
active
Is this object still usable? Set false after dispose, this variable is used to check for incorrect usage. -
adapterMemo
System Connection. -
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.totalFunctions
- total number of functions available, including 0.
-
-
Method Details
-
getSpeedSetting
speed - expressed as a value 0.0 -> 1.0. Negative means emergency stop. This is an bound parameter.- Specified by:
getSpeedSetting
in 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:
setSpeedSetting
in 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:
setSpeedSetting
in 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 supress the sending of messages to the system- Specified by:
setSpeedSettingAgain
in interfaceThrottle
- Parameters:
speed
- the new speed
-
getIsForward
direction This is an bound parameter.- Specified by:
getIsForward
in 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:
setIsForward
in 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:
getFunctions
in 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:
getFunctionsMomentary
in interfaceThrottle
- Returns:
- momentary function array, length dependant by hardware type.
-
getFunction
Get Loco Function status.- Specified by:
getFunction
in interfaceThrottle
- Parameters:
fN
- Function Number, 0-28- Returns:
- Function State. True on, false off.
-
getFunctionMomentary
Get the Momentary Function Value.- Specified by:
getFunctionMomentary
in interfaceThrottle
- Parameters:
fN
- Momentary function number- Returns:
- true if momentary function is on, else false.
-
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:
notifyThrottleDispatchEnabled
in 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:
notifyThrottleReleaseEnabled
in 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 aPropertyChangeListener
to the listener list.- Specified by:
addPropertyChangeListener
in interfacePropertyChangeProvider
- Overrides:
addPropertyChangeListener
in classPropertyChangeSupport
- Parameters:
l
- The PropertyChangeListener to be added
-
removePropertyChangeListener
Remove the specified listener from this object.- Specified by:
removePropertyChangeListener
in interfacePropertyChangeProvider
- Overrides:
removePropertyChangeListener
in classPropertyChangeSupport
- Parameters:
l
- ThePropertyChangeListener
to remove.
-
notifyPropertyChangeListener
@Deprecated protected void notifyPropertyChangeListener(String property, Object oldValue, Object newValue)Deprecated.since 4.19.5; usePropertyChangeSupport.firePropertyChange(java.lang.String, java.lang.Object, java.lang.Object)
insteadTrigger the notification of all PropertyChangeListeners. Will only notify if oldValue and newValue are not equal and non-null.- Parameters:
property
- the name of the property to send notifications foroldValue
- the old value of the propertynewValue
- the new value of the property
-
getListeners
Deprecated.Get a list of property change listeners.- Specified by:
getListeners
in interfaceThrottle
- Returns:
- a list of listeners
-
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:
dispatch
in interfaceThrottle
- Parameters:
l
-ThrottleListener
to 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:
release
in interfaceThrottle
- Parameters:
l
-ThrottleListener
to release. May be null if noThrottleListener
is currently held.
-
throttleDispose
Dispose when finished with this Throttle. Abstract Throttles normally call finishRecord(); here. -
getSpeedIncrement
to handle quantized speed. Note this can change! Valued returned is always positive.- Specified by:
getSpeedIncrement
in 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:
setFunction
in 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.
-
setFunctionMomentary
Sets Momentary Function and sends to layout. Set Momentary Loco Function and send to Layout.- Specified by:
setFunctionMomentary
in 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.
-
setSpeedStepMode
Set the speed step value. Default should be 128 speed step mode in most cases.Specific implementations should override this function.
- Specified by:
setSpeedStepMode
in interfaceDccThrottle
- Parameters:
mode
- the current speed step mode
-
getSpeedStepMode
Description copied from interface:DccThrottle
Get the current speed step value.- Specified by:
getSpeedStepMode
in 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:
setRosterEntry
in interfaceThrottle
-
getRosterEntry
- Specified by:
getRosterEntry
in 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
-