Sign in to follow this  
Piggles

Toggle switch question

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Help AVSIM continue to serve you!
Please donate today!

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...

  • Upvote 1

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
Sign in to follow this