Skip to content

03. Types of switches

Jorg Neves Bliesener edited this page Jan 13, 2019 · 12 revisions

Controlling X-Plane

X-Plane can be controlled in two different ways: by writing to datarefs or by sending commands. It is a common mistake trying to write to datarefs when actually X-Plane must be controlled through commands, see the specific wiki page about this issue. However, some third-party aircrafts in X-Plane must be controlled through datarefs, while others use commands.

For this reason, both methods are supported by the library. This page lists they available objects and shows how to use them.

Types of switches

The libary provides three basic set of switches, that map to the most common switch types in X-Plane:

  • A two position switch. That's the basic on/off switch used, for example, for landing lights.

    Two position switches Two Position Switches

    Two position switches are supported through the following objects:

  • A multi-position switch. These are, for example, rotary switches or toggle switches with a center position.

    Multi position switches

    The following objects of this library support multi-position switches:

  • Pushbuttons. These are buttons or switches that do not lock when they're actuated, like FMC keys or cabin crew call

    Pushbuttons Pushbuttons

    The FlightSimPushbutton object sends a single command with "BEGIN" and "END" to X-Plane when the pushbutton is pressed or released.

Switch Features

Common Features

All switches have some common methods that can be used for debugging or to implement special handling:

switch.setDebug(boolean debugOn);

Enables or disables debugging functions for this switch. Check the debug section for further information.

float switch.getValue();

Returns the current value of the switch. This can be 0 and 1 for two-position switches and pushbuttons or a specific value for multi-position switches.

void switch.onChange(void (*fptr)(float value));
void switch.onChange(void (*fptr)(float value, void *context), void *context);

These functions register a callback function that is called whenever the switch position changes. The first form allows to specify a callback function that only receives the new value of the switch. The second form permits specifying an additional context, which allows sharing the same callback function between various switches.

The Demo_Callbacks from the library examples shows how to use the onChange functions.