Cockpit lights logic for warning lights, power and lights test function - MobiFlight/MobiFlight-Connector GitHub Wiki

An aircraft warning light reacts to two things (or well, three): electrical power, the actual thing it is a warning for, like "Engine 1 is on fire", and in many cases a lights test button that is useful during the preflight checks to see that all warning lights are working.

For obvious reasons the warning light test button cannot set the engine on fire for real, so that the fire warning light can be checked, so there is a separate, parallel logic using a different simulator variable just for the test case.

Additional checks

We need to do the same logic in MobiFlight: Use variables or the light test button state, and to check if the aircraft panel actually is powered up. These can differ per airplane a bit, but "Microsoft > Generic > Miscellaneous > CIRCUIT GENERAL PANEL ON" is a good starting point. This will also make sure your cockpit is "cold and dark" when power is off, all lights work only when you have power.

The "lights test" might be a simvar in your particular aircraft (like a L-var), or if you are not sure, or want to do it from scratch for generic use, you can use a MobiFlight variable instead, so it is just internal to our own use and does not get shared with the simulator.

image

Config References

While the actual config refers to a simvar like our "ENGINE IS ON FIRE!!", config references lets you bring in additional things you can compare and check your simvar against.

"Dumb" outputs are actually smart

While outputs usually are tied to actual leds or displays, it's often also useful to just configure some simulator variables as "outputs" but just leave the LED / display hardware unconfigured. They will still work for our purposes. You can see their state in the "Flight Sim value" column, and they should be either 0 or 1 depending on the state of panel power, and whether the "lights test" button is pressed. And by using those configs from other configs, you can create more complicated schemes for things like electricity and so on.

Use these two things as additional config references for your warning light, you can very easily take care of the two additional cases your warning light should react to.

image

Now, the image above has a lot to unpack, but pay attention to two things:

  • Transform field with the cryptic code we will explain next, and
  • the Config references and their symbols A and B.

The config references are on the bottom: panel is powered and light test. Those are given two symbols, they are by default special characters like ! and # but they can be changed, and I find A and B to be more clear in the example. Just remember the symbols cannot be characters that are used in other function names etc in the Transform, like if you use Round() you should not use "R" as a reference name.

In the Transform field, "$" refers always to the sim variable the current config is referring to, the "ENG ON FIRE" state in this case.

Then we have logical OR, represented by the pipe character "|" between $ and B, basically stating "light this light up if engine is on fire, OR, if lights test is pressed".

The final multiplication is with the logical state of power: If power is zero, multiplication results in a zero, so there is no light no matter how much fire there is on the engine, or if the test button is being pressed.

The transform field uses NCalc mathematical expression library that has quite a few useful functions and operators, you can check out the NCalc GitHub page for more documentation on the syntax.