Jump to content
The simFlight Network Forums

Recommended Posts

Posted

Hi, I am trying to write a LUA module to basically disconnect the rudder when a switch selection is made. I have never written in LUA before (or any other development software) and having read the notes that came with FSUIPC I was a little confused. If somebody could offer there assistance I would be eternally grateful.

When the switch is pressed offset 0x310A gives an active (I think its a 1(Rudder steering inactive)), I would then like this offset to repeat setting 1every 9 seconds, until the switch is then released to stop the process and go back to 0 (Rudder steering active). The reason I want this repeating every 9 seconds, is that the command resets itself every 10-12 seconds.

Thankyou in advance for any help you can offer

Chris

Posted
Hi, I am trying to write a LUA module to basically disconnect the rudder when a switch selection is made. I have never written in LUA before (or any other development software) and having read the notes that came with FSUIPC I was a little confused. If somebody could offer there assistance I would be eternally grateful.

There are no notes with FSUIPC which explain the Lua language -- you need to refer to their website where the documentation is pretty good. The FSUIPC notes only describe the additional library functions provided by FSUIPC.

What is actually confusing for you? I need to know about things like that so I can write clarifications into it. That is the only way I can improve it.

When the switch is pressed offset 0x310A gives an active (I think its a 1(Rudder steering inactive))

Where are you reading that a 1 will disconnect the rudder? That is bit number 0. According to the offsets list the bit for the rudder is bit 2, in other words 2^2 or value 4.

I would then like this offset to repeat setting 1every 9 seconds, until the switch is then released to stop the process and go back to 0 (Rudder steering active). The reason I want this repeating every 9 seconds, is that the command resets itself every 10-12 seconds.

Okay. There are two different ways of doing this. You can make a rather complex loop to watch the button and do the timing of 9 seconds. Doing it this way you can have just the one Lua program and call it "ipcReady.lua" so that it runs when FS is ready to run. If it is programmed with the actual button number you want to use then you don't even have to assign anything to it -- it will run and loop continuously, sending a value to offset 310A whilst the button is pressed, sending 0 when released, and sending nothing otherwise. It would "sleep" most of the time to avoid impinging on FS performance.

However, much easier to program would be a simple loop setting the offset, assigned to your button in FSUIPC, which tests not the button but a flag, which is set by assignment when you release the button.

This simpler solution would look something like this:

[EDITED ON 5th MARCH to correct omission of last line]

seconds = 9							     -- counter for 9 seconds
while ipc.testflag(0) == false do	 -- loop until flag is set (all flags are clear when a Lua program starts)
		if seconds == 9 then
				ipc.writeUB(0x310A, 4)	-- update the offset every 9 seconds
				seconds = 0				  -- restart the 9 second counter
		end
		ipc.sleep(1000)				    -- give up the processor for a second
		seconds = seconds + 1		    -- count that second
end
ipc.writeUB(0x310A,0)                -- restore the rudder operation before exit

Save this as, say, "NoRudder.lua", then assign your button press to "Lua NoRudder", and its release to "LuaSet NoRudder" with parameter 0 (for flag 0).

Written this way it could take a second after you release the button before you get the rudder back. If that's no good, reduce the sleep time and increase the count proportionally. For example a sleep of 100 milliseconds would need a count of 90 to get to 9 seconds.

Okay? I hope this all makes sense to you?

Regards

Pete

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
×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.