Package jmri.jmrix.bachrus.speedmatcher
Class SpeedMatcher
java.lang.Object
jmri.jmrix.bachrus.speedmatcher.SpeedMatcher
- All Implemented Interfaces:
EventListener,ProgListener,ThrottleListener
- Direct Known Subclasses:
BasicSpeedMatcher,SpeedStepScaleSpeedMatcher
Abstract class defining the basic operations of a speed matcher. All speed
matcher implementations must extend this class.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprotected static enumprotected static enumstatic enumNested classes/interfaces inherited from interface jmri.ThrottleListener
ThrottleListener.DecisionType -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected final floatprotected intprotected floatprotected DccLocoAddressprotected final intprotected AddressedProgrammerprotected PowerManagerprotected SpeedMatcher.ProgrammerStateprotected final intprotected final intprotected floatprotected intprotected JButtonprotected JLabelprotected intprotected booleanprotected intprotected intFields inherited from interface jmri.ProgListener
CommError, ConfirmFailed, FailedTimeout, NoAck, NoLocoDetected, NotImplemented, OK, ProgrammerBusy, ProgrammingShort, SequenceError, UnknownError, UserAborted -
Constructor Summary
ConstructorsConstructorDescriptionSpeedMatcher(SpeedMatcherConfig config) Constructor for the abstract SpeedMatcher at the core of any Speed Matcher -
Method Summary
Modifier and TypeMethodDescriptionprotected voidCleans up the speed matcher when speed matching is stopped or is finishedprotected intgetNextSpeedMatchValue(int lastValue, int max, int min) Gets the next value to try for speed matchingprotected booleaninitializeAndStartSpeedMatcher(ActionListener timerActionListener) Shared code to initialize the speed matcher's programmer and throttle and start the speed matching timer.abstract booleanIndicates if the speed matcher is idle (not currently speed matching)voidnotifyDecisionRequired(LocoAddress address, ThrottleListener.DecisionType question) Called when we must decide whether to steal the throttle for the requested address.voidnotifyFailedThrottleRequest(LocoAddress address, String reason) Called when a throttle could not be obtainedvoidCalled when a throttle is found Implementers must override, call super, and start speed matcher in implementationvoidprogrammingOpReply(int value, int status) Called when the programmer has completed its operationprotected voidresetSpeedMatcher(int initialValueDelta) Resets the speed matcher with the given value deltaprotected voidsetSpeedMatchError(float speedTarget) Sets the current speed match errorprotected voidsetSpeedMatchStateTimerDuration(int timerDuration) Sets the duration for the speed match timerprotected voidsetThrottle(boolean isForward, int speedStep) Sets the speed matcher's throttle direction and speed safely within timers to protect against executing a throttle change to close to setting a CVabstract booleanStarts the speed matching processprotected voidStarts the speed match state timerabstract voidStops the speed matching processprotected voidStops the speed match state timervoidupdateCurrentSpeed(float currentSpeedKPH) Updates the locomotive's current speed in the speed matcherprotected abstract booleanvalidate()Validates the speed matcher's configurationprotected voidwriteForwardTrim(int value) Starts writing forward trim (CV 66) using the ops mode programmerprotected voidwriteMomentumAccel(int value) Starts writing acceleration momentum (CV 3) using the ops mode programmerprotected voidwriteMomentumDecel(int value) Starts writing deceleration momentum (CV 4) using the ops mode programmerprotected voidwriteReverseTrim(int value) Starts writing reverse trim (CV 95) using the ops mode programmerprotected voidwriteSpeedTableStep(SpeedMatcher.SpeedTableStep step, int value) Starts writing a Speed Table Step CV (CV 67-94) using the ops mode programmerprotected voidwriteVHigh(int value) Starts writing vHigh (CV 5) using the ops mode programmerprotected voidwriteVMid(int value) Starts writing vMid (CV 6) using the ops mode programmerprotected voidwriteVStart(int value) Starts writing vStart (CV 2) using the ops mode programmer
-
Field Details
-
INITIAL_MOMENTUM
- See Also:
-
REVERSE_TRIM_MAX
- See Also:
-
REVERSE_TRIM_MIN
- See Also:
-
ALLOWED_SPEED_MATCH_ERROR
- See Also:
-
attempt
-
speedMatchError
-
speedMatcherValueDelta
-
trimReverseSpeed
-
warmUpForwardSeconds
-
warmUpReverseSeconds
-
stepDuration
-
currentSpeedKPH
-
dccLocoAddress
-
opsModeProgrammer
-
powerManager
-
statusLabel
-
startStopButton
-
programmerState
-
-
Constructor Details
-
SpeedMatcher
Constructor for the abstract SpeedMatcher at the core of any Speed Matcher- Parameters:
config- SpeedMatcherConfig for initializing the SpeedMatcher
-
-
Method Details
-
startSpeedMatcher
Starts the speed matching process- Returns:
- true if speed matching started successfully, false otherwise
-
stopSpeedMatcher
Stops the speed matching process -
isSpeedMatcherIdle
Indicates if the speed matcher is idle (not currently speed matching)- Returns:
- true if idle, false otherwise
-
updateCurrentSpeed
Updates the locomotive's current speed in the speed matcher- Parameters:
currentSpeedKPH- the locomotive's current speed in KPH
-
validate
Validates the speed matcher's configuration- Returns:
- true if the configuration is valid, false otherwise
-
cleanUpSpeedMatcher
Cleans up the speed matcher when speed matching is stopped or is finished -
initializeAndStartSpeedMatcher
Shared code to initialize the speed matcher's programmer and throttle and start the speed matching timer. Expected to be called in an implementing speed matcher's Start function.- Parameters:
timerActionListener- callback to fire when the timer times out- Returns:
- true if initialization and start is successful, false otherwise
-
startSpeedMatchStateTimer
Starts the speed match state timer -
stopSpeedMatchStateTimer
Stops the speed match state timer -
setSpeedMatchStateTimerDuration
Sets the duration for the speed match timer- Parameters:
timerDuration- timer duration in milliseconds
-
setThrottle
Sets the speed matcher's throttle direction and speed safely within timers to protect against executing a throttle change to close to setting a CV- Parameters:
isForward- true for forward, false for reversspeedStep- 0-28 or 0-128 depending on mode
-
setSpeedMatchError
Sets the current speed match error- Parameters:
speedTarget- - target speed in KPH
-
getNextSpeedMatchValue
Gets the next value to try for speed matching- Parameters:
lastValue- the last speed match CV value triedmax- the maximum valuemin- the minimum value- Returns:
- the next value to try for speed matching [min:max]
-
resetSpeedMatcher
Resets the speed matcher with the given value delta- Parameters:
initialValueDelta- the value delta to use for the next use of the speed matcher
-
writeVStart
Starts writing vStart (CV 2) using the ops mode programmer- Parameters:
value- vStart value (0-255 inclusive)
-
writeVMid
Starts writing vMid (CV 6) using the ops mode programmer- Parameters:
value- vMid value (0-255 inclusive)
-
writeVHigh
Starts writing vHigh (CV 5) using the ops mode programmer- Parameters:
value- vHigh value (0-255 inclusive)
-
writeMomentumAccel
Starts writing acceleration momentum (CV 3) using the ops mode programmer- Parameters:
value- acceleration value (0-255 inclusive)
-
writeMomentumDecel
Starts writing deceleration momentum (CV 4) using the ops mode programmer- Parameters:
value- deceleration value (0-255 inclusive)
-
writeForwardTrim
Starts writing forward trim (CV 66) using the ops mode programmer- Parameters:
value- forward trim value (0-255 inclusive)
-
writeReverseTrim
Starts writing reverse trim (CV 95) using the ops mode programmer- Parameters:
value- reverse trim value (0-255 inclusive)
-
writeSpeedTableStep
Starts writing a Speed Table Step CV (CV 67-94) using the ops mode programmer- Parameters:
step- the SpeedTableStep to setvalue- speed table step value (0-255 inclusive)
-
programmingOpReply
Called when the programmer has completed its operation- Specified by:
programmingOpReplyin interfaceProgListener- Parameters:
value- value from a read operation, or value written on a writestatus- denotes the completion code. Note that this is a bitwise combination of the various states codes defined in this interface. (see ProgListener.java for possible values)
-
notifyThrottleFound
Called when a throttle is found Implementers must override, call super, and start speed matcher in implementation- Specified by:
notifyThrottleFoundin interfaceThrottleListener- Parameters:
t- the requested DccThrottle
-
notifyDecisionRequired
Called when we must decide whether to steal the throttle for the requested address. This is an automatically stealing implementation, so the throttle will be automatically stolen- Specified by:
notifyDecisionRequiredin interfaceThrottleListener- Parameters:
address- the requested addressquestion- the question being asked, steal / cancel, share / cancel, steal / share / cancel
-
notifyFailedThrottleRequest
Called when a throttle could not be obtained- Specified by:
notifyFailedThrottleRequestin interfaceThrottleListener- Parameters:
address- the requested addressreason- the reason the throttle could not be obtained
-