Page 1 of 1

Using Lua Script to Control Landing Lights

Posted: Thu Jul 05, 2018 12:42 am
by Chris.Laughery
Hello All:

I thought I'd share a simple script I wrote that can be used to toggle the C310's landing lights using a hardware switch.

I have been wanting to utilize my CH Products Throttle Quadrant to control several systems on the C310 Redux.

After having recent success using FSUIPC and Lua script to get the 310 props to go into feather range using the quadrant prop axis, I set out to use my new found scripting knowledge to toggle the 310's landing light switch and light extend / retract animation using a switch on my CH Throttle quadrant.

Note: The 310 prop feather script can be found in the 310 Support Forum.

If you want to assign the 310's landing lights to a hardware button:
  • Create a Lua Script file and place it in the Modules folder
  • Use FSUIPC to run the Lua script when your button hardware is pressed
  • When programming the button use a parameter of "0" for OFF, and a parameter of "1" for ON

The end result behavior is this:

In the the virtual cockpit-
  • If Landing Light Switch is in the OFF POSITION, pressing your hardware ON button EXTENDS the lights and moves the virtual switch to the CENTER POSITION
  • If Landing Light Switch is in the CENTER POSITION, pressing your hardware ON button turns the lights ON and moves the virtual switch to the ON POSITION
  • If Landing Light Switch is in the ON POSITION, pressing your hardware OFF button turns the lights OFF and moves the virtual switch to the CENTER POSITION
  • If Landing Light Switch is in the CENTER POSITION, pressing your hardware OFF button RETRACTS the lights and moves the virtual switch to the OFF POSITION
Here's the script you need:

--Set C310 Landing Light Switch State

--Control Codes
--66059 LANDING_LIGHTS_ON
--66060 LANDING_LIGHTS_OFF

--ipcPARAM = 0 is moving to OFF
--ipcPARAM = 1 is moving to ON

--Switch States
--0 = Off
--1 = Extended
--2 = On

ipc.log("ipcPARAM: "..ipcPARAM)

SwitchState = ipc.readLvar("L:SwitchLL")

if ipcPARAM == 0 then

ipc.log("Moving to OFF")

if SwitchState == 2 then

ipc.log("Switch state is 2, so move to 1 'extended' and turn off light")

--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)

--Turn the lights off
ipc.control(66060)

end

if SwitchState == 1 then

ipc.log("Switch state is 1, so move to 0 'retracted'")

--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 0)

end

end

if ipcPARAM == 1 then

ipc.log("Moving to ON")

if SwitchState == 1 then

ipc.log("Switch state is 1, so move to 2 and turn on light")

--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 2)

--Turn the light on
ipc.control(66059)

end

if SwitchState == 0 then

ipc.log("Switch state is 0, so move to 1 'extended'")

--Write the new SwitchLL value to our variable
ipc.writeLvar("SwitchLL", 1)

end

end

ipc.log("Toggle Landing Light Switch Done")

Re: Using Lua Script to Control Landing Lights

Posted: Fri Jul 06, 2018 7:21 am
by ThomasAH
Thank you!
Here is your (unchanged) code marked with [code]...[/code] to keep indentation and such.

Code: Select all

--Set C310 Landing Light Switch State

--Control Codes
--66059   LANDING_LIGHTS_ON
--66060   LANDING_LIGHTS_OFF

--ipcPARAM = 0 is moving to OFF
--ipcPARAM = 1 is moving to ON
 
--Switch States
--0 = Off
--1 = Extended
--2 = On

	ipc.log("ipcPARAM: "..ipcPARAM)
	
	SwitchState = ipc.readLvar("L:SwitchLL")

	if ipcPARAM == 0 then
		
		ipc.log("Moving to OFF")

		if SwitchState == 2 then

			ipc.log("Switch state is 2, so move to 1 'extended' and turn off light")

			--Write the new SwitchLL value to our variable
			ipc.writeLvar("SwitchLL", 1)

			--Turn the lights off
            		ipc.control(66060)

		end

		if SwitchState == 1 then

			ipc.log("Switch state is 1, so move to 0 'retracted'")

			--Write the new SwitchLL value to our variable
			ipc.writeLvar("SwitchLL", 0)

		end

	end

	if ipcPARAM == 1 then
		
		ipc.log("Moving to ON")

		if SwitchState == 1 then

			ipc.log("Switch state is 1, so move to 2 and turn on light")

			--Write the new SwitchLL value to our variable
			ipc.writeLvar("SwitchLL", 2)

			--Turn the light on
            		ipc.control(66059)

		end

		if SwitchState == 0 then

			ipc.log("Switch state is 0, so move to 1 'extended'")

			--Write the new SwitchLL value to our variable
			ipc.writeLvar("SwitchLL", 1)

		end

	end

ipc.log("Toggle Landing Light Switch Done")

Re: Using Lua Script to Control Landing Lights

Posted: Fri Jul 06, 2018 4:34 pm
by Chris.Laughery
Thank you Thomas, I was not aware of the tag.

Good stuff!

--Chris

Re: Using Lua Script to Control Landing Lights

Posted: Fri Jul 06, 2018 5:18 pm
by N4GIX
Chris.Laughery wrote:
Fri Jul 06, 2018 4:34 pm
Thank you Thomas, I was not aware of the tag.
You select the indicated icon either before pasting your code/script in between the tags, or you can highlight the code/script and then click the button. Of course you could also just type in the "code box" tags manually:
Image