Skip to content
View in the app

A better way to browse. Learn more.

The AVSIM Community

A full-screen app on your home screen with push notifications, badges and more.

To install this app on iOS and iPadOS
  1. Tap the Share icon in Safari
  2. Scroll the menu and tap Add to Home Screen.
  3. Tap Add in the top-right corner.
To install this app on Android
  1. Tap the 3-dot menu (⋮) in the top-right corner of the browser.
  2. Tap Add to Home screen or Install app.
  3. Confirm by tapping Install.

Toggle switch question

Featured Replies

Hi to all, not been on here for a while but back with questions once again.

 

This is more of a LUA question but this seem the best place to post my query.

 

I haven't yet got seriously into LINDA but I am playing around with some LUA Plugins handled by FSUIPC to get myself started with things.

 

I've run into problems with toggle switches. I have at the moment 11 physical switches which are SPST - so either on or off. I'm struggling to keep these synchronized in FSX. They operate a start panel on Aerosoft's F3 Lightning.

 

The following code works to move the switches up and down in the sim:

while 1 do
--
--	Prgramming Starter Panel Switches
--
--Pitot Heater
if ipc.testflag(0) then
	clearflag(0)
	ipc.control(65858)
--Fuel Cock No 1
elseif ipc.testflag(1) then
	clearflag(1)
	if (ipc.readLvar("L:Lpcock1") == 0) then
		ipc.writeLvar("L:Lpcock1", 1)
		ipc.control(66494)
	else
		ipc.writeLvar("L:Lpcock1", 0)
		ipc.control(66494)
	end
--Fuel Cock No 2
elseif ipc.testflag(2) then 
	clearflag(2)
	if (ipc.readLvar("L:Lpcock2") == 0) then
		ipc.writeLvar("L:Lpcock2", 1)
		ipc.control(66495)
	else
		ipc.writeLvar("L:Lpcock2", 0)
		ipc.control(66495)
	end
--D.C. Pumps Port
elseif ipc.testflag(3) then 
	clearflag(3)
	if (ipc.readLvar("L:Pump01") == 0) then
		ipc.writeLvar("L:Pump01", 1)
		ipc.control(66340)
	else
		ipc.writeLvar("L:Pump01", 0)
		ipc.control(66340)
	end
--D.C Pumps Starboard
elseif ipc.testflag(4) then 
	clearflag(4)
	if (ipc.readLvar("L:Pump02") == 0) then
		ipc.writeLvar("L:Pump02", 1)
		ipc.control(66341)
	else
		ipc.writeLvar("L:Pump02", 0)
		ipc.control(66341)
	end
--Battery
elseif ipc.testflag(5) then
	clearflag(5)
	ipc.control(66241)
--Cabin Air
elseif ipc.testflag(6) then 
	clearflag(6)
	if (ipc.readLvar("L:Lit01") == 0) then
		ipc.writeLvar("L:Lit01", 1)
	else
		ipc.writeLvar("L:Lit01", 0)
	end
--Instrument Master
elseif ipc.testflag(7) then 
	clearflag(7)
	if (ipc.readLvar("L:instsw") == 0) then
		ipc.writeLvar("L:instsw", 1)
		ipc.writeLvar("L:oxy", 1)
		ipc.writeLvar("L:hyd", 1)
		ipc.writeLvar("L:gen", 1)
	else
		ipc.writeLvar("L:instsw", 0)
		ipc.writeLvar("L:oxy", 0)
		ipc.writeLvar("L:hyd", 0)
		ipc.writeLvar("L:gen", 0)
	end
--Engine Master
elseif ipc.testflag(8) then 
	clearflag(8)
	if (ipc.readLvar("L:eng_master") == 0) then
		ipc.writeLvar("L:eng_master", 1)
	else
		ipc.writeLvar("L:eng_master", 0)
	end
--Windscreen Side
elseif ipc.testflag(9) then 
	clearflag(9)
	if (ipc.readLvar("L:Lit03") == 0) then
		ipc.writeLvar("L:Lit03", 1)
	else
		ipc.writeLvar("L:Lit03", 0)
	end
--Windscreen Front
elseif ipc.testflag(10) then 
	clearflag(10)
	if (ipc.readLvar("L:Lit04") == 0) then
		ipc.writeLvar("L:Lit04", 1)
	else
		ipc.writeLvar("L:Lit04", 0)
	end
end
ipc.sleep(50)
end

However I'm not sure if this is keeping in sink all the time and I'm ending up with switches that are appearing ON in the virtual cockpit, but act as if they are OFF!

 

As windows can easily recognise if a switch is actually on or off, is there a way to code this in LUA so things don't get reversed? What would be really nice is to be able to read the state of the physical switches when FSX starts up and set the correct 'on' or 'off' value from the start.


I'll just add the FSX controls used as it isn't always easy to read the FSUIPC values

 

For the first six switches are:

 

PITOT_HEAT_TOGGLE

TOGGLE_FUEL_VALVE_ENG1

TOGGLE_FUEL_VALVE_ENG2

TOGGLE_ELECT_FUEL_PUMP1

TOGGLE_ELECT_FUEL_PUMP2

TOGGLE_MASTER_BATTERY

 

The remaining 5 switches have no FSX control, using only Lvars.

What would be really nice is to be able to read the state of the physical switches when FSX starts up and set the correct 'on' or 'off' value from the start.

 

Have a look at this for (I hope) some inspiration...

MarkH

https://www.youtube.com/@AlmostAviation
AMD Ryzen 7 9800X3D / 64Gb DDR5 / Zotac RTX 5070 Ti / 2560 x 1440 display

  • Author

Thanks Mark, will take a good look at your code.  :smile:

Create an account or sign in to comment

Account

Navigation

Search

Search

Configure browser push notifications

Chrome (Android)
  1. Tap the lock icon next to the address bar.
  2. Tap Permissions → Notifications.
  3. Adjust your preference.
Chrome (Desktop)
  1. Click the padlock icon in the address bar.
  2. Select Site settings.
  3. Find Notifications and adjust your preference.