Locomotive function handling

In my layout control software, I keep track of what functions each locomotive has, and naturally what number they are. This enables the software to activate any function that is present as needed, without the user having to remember function numbers or trying to make all similar functions map to the same numbers. Thus, for example, if I wish to have trains blow their whistle at a certain place, I simply define that as a requirement for the track in question, and then all trains running through that track will be made to blow their whistle, if that function is present. That may mean F3 for one loco and F5 on another.

Most of my locomotives have all their functions in the range, F0 to F8 but one loco, the Baden IV, has a short whistle sound (which I call 'Toot') on F3 of a secondary decoder address. My software did not support secondary decoder addresses so I have now added that facility. While I was busy with that feature I decided to also solve the issue of different sounds and functions being activated in different manners.

The classic example of how functions demand different types of activation is the switching on and off of the acceleration feature in some decoders. Some decoders present the function as something to be switched on (i.e. switch the acceleration feature on), others present it as a feature to switch off (i.e. suppress acceleration). So some locos have to have the function switched on, others need it switched off to achieve the same effect! Some of these decoders do not have the capability to have the behavior reversed either.

To get around this problem, I previously defined two different type of function:
  • Acceleration ON
  • Acceleration OFF
When trains are running in hidden areas, I like to switch acceleration effects off, so that I can accelerate and decelerate trains quickly. I would thus switch the "Acceleration ON" function off, and also the "Acceleration OFF" function on, for any locomotive. This worked fine, but was not very elegant.

In addition, some functions are activated any time the decoder function is switched on, but others will activate if there is any change in the function status, from on to off or off to on!

A further, even worse example turned up. The previously mentioned "Toot" sound on my nice Baden IV locomotive can only be activated when F3 is switched from 'off' to 'on'. If the software sends a command to switch F3 on, and F3 is already on, nothing happens. (They assumed a non-latching button would be used to activate it, ignoring software control.) To reliably activate that function, I have to ensure it is off first, then switch it on.

So I decided to enhance my function definitions to allow every function to also have it's invocation defined, - how does it get switched on? I came up with the following possibilities:
  • On
  • Off
  • Toggle
  • Switch from Off to On
  • Switch from On to Off
I can now select any of those methods for any of the possible functions, like this:

User interface design Copyright Dale Schultz, 2018

This allows me to indicate if 'acceleration' is enabled by switching the function on, or, as in the example above, off.  It also allows me to define a sound effect that is activated with any change to the function (F3 above) or a move from off to on (F2 in the example).

Implementation was complex, I found for example that simply sending F3-OFF, F3-ON commands to the Intellibox does not give the loco decoder time to actually go off, before it it switched on again. I have to send the initial command to switch the function off and then a second later, send the followup command to switch it on again. My software has no wait states (delay loops) so I had to place the second command into a queue to be sent out later in cases where I find the function is already on.

Given these new enhancements, whenever a train is about to start off in a visible area, it will give a 'toot' and a 'hiss', if those capabilities are present by any locos in the train. It works reliably no matter what state the decoder is in.

I have also simplified the track definitions that switch acceleration functionality, to use a single type of function, and the software now knows how to switch it correctly for the various locomotives.

2018-06-15 Update

I have added the ability to have the functions switched on for definable time periods. One can select times from 1 second, up to 10 minutes. This is useful for whistle and bell functions that get switched on when the function is turned on, and they then tail off when the function is turned off again. Nobody wants to hear a continuous whistle blast, but 2 seconds (plus the lead-out at the end) out is reasonable.