Model Train-related Notes Blog -- these are personal notes and musings on the subject of model train control, automation, electronics, or whatever I find interesting. I also have more posts in a blog dedicated to the maintenance of the Randall Museum Model Railroad.

2023-04-24 - Conductor 2: DSL Throttle onLight / onSound / onBell

Category Rtac

Here’s the new syntax:

        val T1 = throttle(1001) {

            onLight { b -> throttle.f0( b) }

            onSound { b -> throttle.f8(!b) }

            onBell  { throttle.f1(it) }

        } named "Throttle1"

        on { S1 } then {

            T1.light(true)

            T1.sound(true)

            T1.bell(true)

            T1.horn()

        }

Note that it seems quite annoying to have to place the “named ‘Xyz’” after the function block, so this syntax is also allowed:

        val T1 = throttle(1001) {

            name = "Throttle1"

            onLight { b -> throttle.f0( b) }

            onSound { b -> throttle.f8(!b) }

            onBell  { throttle.f1(it) }

        }

        on { S1 } then {

            T1.light(true)

            T1.sound(true)

            T1.bell(true)

            T1.horn()

        }

The current implementation for each method is to call the callback function if it exists, otherwise defer to the IJmriThrottle corresponding function. The JMRI provider has methods in Conductor.py which toggle the default DCC functions (F0, F1, and a mute F8 by default), but they also do so with repeats and delays -- something these callbacks above do not provide. So there’s a bit of a difference right there.

The other aspect is the simulator and the UI display. The new UI window can display status for light and sound for an engine… and it does so by checking the IThrottle’s internal light/sound status (rather than the actual IJmriThrottle state). Thus it should be in sync with the new calls above. So in an amusing way, having these DSL methods does fix the display case.


 Generated on 2024-04-22 by Rig4j 0.1-Exp-e7e2d73