Skip to content

Instantly share code, notes, and snippets.

@devleaks
Created July 2, 2026 09:36
Show Gist options
  • Select an option

  • Save devleaks/13f91e294f270991bd12142b13437f87 to your computer and use it in GitHub Desktop.

Select an option

Save devleaks/13f91e294f270991bd12142b13437f87 to your computer and use it in GitHub Desktop.
Synchronize Flight Factor Airbus MCDU brightness
# Python Plugin To Save Toliss Situations on request.
# Enjoy.
#
import traceback
import xp
# ###########################################################
#
RELEASE = "1.0.0"
#
# 01-JUL-2026: 1.0.0: Initial version
#
BRIGHT_LR = "1-sim/lights/mcdu/Rotery" # float, continuous value [0, 1]
BRIGHT_TL = "AirbusFBW/DUBrightness" # float array length = 8, brightness of MCDU is [6], usually changes in 0.1 increment
CHECK_FREQUENCY = 2.0 # seconds
class PythonInterface:
def __init__(self):
self.Name = "Synchronize MCDU display brightness"
self.Sig = "xppython3.syncmcdubright"
self.Desc = self.Name + " (Rel. " + RELEASE + ")"
self.Info = f"Synchronize MCDU brightness {RELEASE}"
self.enabled = False
self.reffl = 0
self.fl = xp.createFlightLoop(callback=self.sync_brightness, phase=xp.FlightLoop_Phase_AfterFlightModel, refCon=self.reffl)
self.bright_lr = xp.findDataRef(BRIGHT_LR)
self.bright_tl = xp.findDataRef(BRIGHT_TL)
self.brightness = 0.80 # forced initial value
self.trace = True # produces extra debugging in XPPython3.log for this class
def XPluginStart(self):
print(self.Info, "started")
return self.Name, self.Sig, self.Desc
def XPluginStop(self):
print(self.Info, "stopped")
return None
def XPluginEnable(self):
if self.bright_lr is None:
print(self.Info, f"dataref {BRIGHT_LR} not found")
return 0
if self.bright_tl is None:
print(self.Info, f"dataref {BRIGHT_TL} not found")
return 0
try:
xp.setDataf(self.bright_lr, self.brightness)
vb = [self.brightness]
xp.setDatavf(self.bright_tl, vb, 6, 1)
print(self.Info, f"init sync {self.brightness}")
xp.scheduleFlightLoop(self.fl, CHECK_FREQUENCY, 1)
self.enabled = True
print(self.Info, "enabled")
return 1
except:
print(self.Info, "error, not enabled")
traceback.print_exec()
return 0
def XPluginDisable(self):
xp.scheduleFlightLoop(self.fl, 0, 1)
self.enabled = False
print(self.Info, "disabled")
return None
def XPluginReceiveMessage(self, inFromWho, inMessage, inParam):
pass
def sync_brightness(self, elapsedSinceLastCall, elapsedTimeSinceLastFlightLoop, counter, inRefcon) -> float:
if not self.enabled:
print(self.Info, "not enabled.")
return 5.0
try:
b = round(xp.getDataf(self.bright_lr), 1)
vb = [b]
if b != self.brightness:
xp.setDatavf(self.bright_tl, vb, 6, 1)
self.brightness = b
print(self.Info, f"sync from {BRIGHT_LR} {self.brightness}")
return CHECK_FREQUENCY / 10
xp.getDatavf(self.bright_tl, vb, 6, 1)
b = round(vb[0], 1)
if b != self.brightness:
xp.setDataf(self.bright_lr, b)
self.brightness = b
print(self.Info, f"sync from {BRIGHT_TL} {self.brightness}")
return CHECK_FREQUENCY / 10
except:
print(self.Info, "error")
traceback.print_exec()
return CHECK_FREQUENCY
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment