Skip to content

EXRAIL proposal: Add UNTIL(vpin) function to wait for pin deactivation (complement to AT/AFTER) #493

@kallelix

Description

@kallelix

Summary

I propose adding a new function UNTIL(vpin) as a complement to the existing AFTER(vpin).

Currently:

  • AT(vpin) blocks until the pin becomes active.
  • AFTER(vpin) blocks until a complete activation–deactivation cycle occurs.

There is no function that waits only for deactivation, which limits certain use cases involving single sensors.

Motivation

The existing AT/AFTER logic was primarily designed for two-sensor track sections, such as using light barriers or entry/exit detectors. However, in many layouts, current detection sensors (Gleisbelegtmelder) are used to monitor track occupancy. These sensors activate a pin as long as current is flowing — meaning a train is present — and deactivate it when the track becomes clear.

In this case:

  • There is only one sensor per block.
  • AFTER(vpin) is not suitable, because it expects both an activation and deactivation event within the same call.
  • A dedicated UNTIL(vpin) would allow waiting specifically for the track to become clear again. This is especially useful in scripts like:
AT(BLOCK1) // wait until block is occupied 
PRINT("Train detected") 
UNTIL(BLOCK1) // wait until block is clear 
PRINT("Block clear"); 

Proposed Behavior

UNTIL(vpin) should:

  • Block execution until the given virtual pin becomes inactive.
  • Not require a prior activation event (unlike AFTER(vpin)).
  • Use the same internal debounce logic as AFTER(vpin) to handle brief signal drops (e.g., short current interruptions when wheels cross insulation gaps).
  • Mirror the timing and event-handling structure of existing pin wait functions for consistency.

Benefits

  • Extends EXRAIL for track-occupancy-based automation scenarios.
  • Enables clean handling of single-sensor sections using current detectors.
  • Avoids polling loops and redundant logic for waiting until a track becomes clear.
  • Keeps consistency with the design of AT and AFTER.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions