User Tools

Site Tools


aircraft:tmd:events

This is an old revision of the document!


Events Inside The TMD

Introduction

A very powerful tool in Aerofly FS 2 aircraft programming in the TMD file are events. Though not needed for any conventional aircraft with basic on/off switches, actuators and instruments, the events open the door for more complex avionics. Be it a multi-function display controller, where each button serves a different purpose on each page or a detecting changes in the system, e.g. the disconnection of the autopilot.

Events are usually only triggered every once in a while and are certainly not intended for constant state logic. Inherently the event logic is state-less. Events cannot replace an underlying logic circuit shouldn't be allowed to continue to run for more than one execution. Their purpose is to execute a one time function, reset a timer to zero, play a sound once, change a digital state, etc.

None of the event objects have an Output, except event_pulse, event_timeout (in DynamicObjects) and event_sound (output to sound section).

So what are events then?

An event in the tmd is a function execution, a function that has one input value that is passed on from one element to the next and that returns nothing. The function that is executed and weather or not additional events can be fired depend on the specific element. Such a function is typically called Trigger, Set, Step or Reset.

void Trigger( double a )
{
  // do sth.
}

How are they triggered

The events are triggered by one of three means:

  • input_event - A button press triggers an event.
  • event_edge - A system change is detected, e.g. in the q400 the system senses that the power levers are advanced for takeoff and then sets the spoiler switch to flight mode automatically. This is also used for many lever sounds.
  • Events can trigger other events

Event Generation

input_event

The input_event receives messages from the controls or key and button inputs just like any other TMD input.

Depending on the qualifier of the message (event, step,toggle) either the Events, StepEvents or ToggleEvents list of functions is executed.

Adding the line <[float64][InputValue][1.0]> can filter the incoming messages by exact value.

            <[input_event][Button_Pressed][]
                <[string8][Input][Controls.Button]>
                <[string8][Events][ DEV0.Trigger ]>
            >
            <[input_event][Knob_Stepped][]
                <[string8][Input][Controls.Button]>
                <[string8][StepEvents][ DEV0.Trigger ]>
            >
            <[input_event][Button_Toggled][]
                <[string8][Input][Controls.Button]>
                <[string8][ToggleEvents][ DEV0.Trigger ]>
            >
            <[input_event][Button_Clicked][]
                <[string8][Input][Controls.Button]>
                <[string8][Events]      [ DEV0.Trigger ]>
                <[string8][StepEvents]  [ DEV0.Trigger ]>
                <[string8][ToggleEvents][ DEV0.Trigger ]>
            >

event_edge

The event_edge object constantly monitors the input. When the input passes through the Threshold on either the rising or falling edge it triggers all of the functions listed in the Events list.

  • Rising - when set to true: The input is increasing and passes from below the threshold above the threshold then the Events are fired.
  • Falling - when set to true: The input is moving from above the threshold below it then the Events are fired.
            <[event_edge][State_Changed][]
                <[string8][Input][State.Output]>
                <[string8][Events][ DEV0.Trigger ]>
                <[bool][Rising][true]>
                <[bool][Falling][true]>
                <[float64][Value][0.0]>
                <[float64][Threshold][0.5]>
            >

Event Value Manipulation

When a button, key command or joystick button are pressed they all generate messages and these messages carry a certain value. Most of them are 1.0, some are -1.0 (e.g. when rotated in the other direction) but other values can also exist. In the controls the value of the message can be set as needed.

When the message is received by an input_event the message value is passed on to any subsequently triggered events. And the event objects that are triggered in turn hand the value over to the next objects. The only exceptions are the event_linear, which scales the value and adds an offset, and the event_value which overwrites the value with its' own input.

The value is therefor carried from one event object to the next most of the time and we still have access to the original value way down the event chain.

When a Variable.Set function is called the variable then uses the value carried by the event call.

event_linear

            <[event_linear][StepSomething][]
                <[string8][Events][ DEV0.Trigger ]>
                <[float64][Scaling][1.0]>
                <[float64][Offset][0.0]>
            >

event_value

            <[event_value][SetSomethingToSomeValue][]
                <[string8][Input][SomeValue.Output]>
                <[string8][Events][ Something.Set ]>
            >

Event Value Checks

Depending on the value carried by the event decisions can be made.

event_sequence

Creates a chain of events that are executed one after another. This allows objects like the autopilot, that only trigger a single Event and not multiple Events (note the s at the end!). It also allows events to be reused or multiple things to happen after a decision is made with an event_select or event_demultiplexer.

            <[event_sequence][Sequence][]
                <[string8][Events][ DEV0.Trigger DEV0.Trigger ]>
            >

event_demultiplexer

            <[event_demultiplexer][TriggerIf][]
                <[string8][InputSelect][Condition.Output]>
                <[string8][Events][ DEV0.Trigger DoSomething.Trigger ]>
            >

event_select

When triggered the event_select checks the value of the event call and casts it into an integer. Depending on the integer it selects one of the events from the Events list based on the calculated index. The list starts at index 0 and increases.

This is useful to have when there is a row of buttons, e.g. like a bezel select on an multifunction display and there is only one message name to be used. With an input_event you can receive that message and then call this event_select to do something specific based on the value of the original button message.

Similar logic can be achieved with the InputValue property of the input_event class.
When you are not interested in the value carried with the event then use the event_demultiplexer class.
            <[event_select][EventValueSelect][]
                <[string8][Events][ DoSomethingIfValueIs0.Trigger
                                    DoSomethingIfValueIs1.Trigger
                                    DoSomethingIfValueIs2.Trigger ]>
            >

event_range

When the event range is triggered it checks the value of the event call against the range and triggers either the list of events when inside or outside of the range. E.g. a button could generate a message with value 1.0 which is received by an input_event and then the input_event triggers this event_range. Depending on what the button value was the event_range does one thing within a set range but does something different when the value is outside that range.

            <[event_range][StepWhenValueInRange][]
                <[tmvector2d][Range][ -5.0 5.0 ]>
                <[string8][EventsIn][ StepSomething.Trigger ]>
                <[string8][EventsOut][ DEV0.Trigger ]>
            >

Functions Achieved By Events

DEV0

The do-nothing placeholder is triggered with DEV0.Trigger whenever no action is desired.

            <[event_sound][DEV0][]
            >

event_sound

Normally an event_sound object is used to generate a switch or button sound. Using the trigger function (in this case SwitchSound.Trigger) causes the event_sound to briefly output 1.0 to the sound section of the TMD. Then a short sound can be played.

            <[event_sound][SwitchSound][]
            >

event_pulse

When the pulse is triggered (function Pulse.Trigger is called) the pulse outputs (Output) 1.0 for the given Duration in seconds. Re-triggering it just resets the timer back to the duration value. When the time has run out the Output drops back to 0.0.

            <[event_pulse][Pulse][]
                <[float64][Duration][0.5]>
            >

Variables

The variable class isn't an event class as such, it cannot trigger any further events. But events can manipulate the value of a variable.

Available functions are:

  • Variable.Set - Changes the value of the variable to the value carried by the event (Value = event_value)
  • Variable.Step - The value is increased or decreased by the value carried by the event (Value += event_value)
  • Variable.Reset - The value is set to 0.0 (Value = 0.0)
            <[variable][Variable][]
                <[string8][Value][0.0]>
            >

The value of the variable is available to other tmd objects as Variable.Output and behaves similar to a constant or input_discrete value.

event_timeout

            <[event_timeout][EventDelay][]
                <[float64][Duration][1.0]>
                <[string8][Events][ DEV0.Trigger ]>
            >

event_repeat

            <[event_repeat][DirectionalGyroCorrectionSwitchFunction][]
                <[string8][Input]      [DirectionalGyroCorrectionSwitch.Output]>
                <[string8][InputEnable][DirectionalGyroSlaveModeSwitch.Output]>
                <[string8][EventsUp]   [ DirectionalGyroCorrection.Step ]>
                <[string8][EventsDown] [ DirectionalGyroCorrection.Step ]>
                <[float64][Scaling][0.1]>
            >

event_swap

            <[event_swap][NAV1ManualFrequencySwap][]
                <[string8][Input0][NAV1ManualFrequency.Output]>
                <[string8][Input1][NAV1FrequencyStandby.Output]>
                <[string8][Event0][NAV1ManualFrequency.Set]>
                <[string8][Event1][NAV1FrequencyStandby.Set]>
            >
aircraft/tmd/events.1563629514.txt.gz · Last modified: 2019/07/20 15:31 by jh