Jump to content
The simFlight Network Forums

Increase L:Var, conditions


Recommended Posts

Hi,

I've searched this forum, but I might have missed the right question...

 

I've got the majestic Dash 8 Q400 and I'm building kind of a dashboard with switches and buttons.

 

The states of the pedestal pushbuttons is saved in L:PEDESTAL_PUSHBUTTONS

There are 9 pushbuttons which states are logged by adding powers of 2, for example "auto feather" is 128, MTOP is 4 and so on.

So the variable is 0 when no buttons are pushed, 128 with just autofeather and 132 with autofeather ans MTOP...

 

Now I need functions for my buttons so I can add and subtract those numbers from the variable.

 

How do I do that?

Is it possible with the built in functions?

Is there a way to increase/ decrease with a parameter? That would be the most elegant way I think. But as I understand "increase" only works "by one", the parameter setting the limit.

 

Do I need to create a LUA-script?

 

Thanks for the help, any pointers in the right direction are very appreciated!

 

Christian

Link to comment
Share on other sites

The states of the pedestal pushbuttons is saved in L:PEDESTAL_PUSHBUTTONS

There are 9 pushbuttons which states are logged by adding powers of 2, for example "auto feather" is 128, MTOP is 4 and so on.

So the variable is 0 when no buttons are pushed, 128 with just autofeather and 132 with autofeather ans MTOP...

 

It's far easier to think in terms of one bit for each button.  In your example bit 7 = autofeather, bit 2 = MTOP. Please see the FAQ subforum thread about Bits and Numbers if you don't understand bit representation. Bit use for buttons and switches pervades all of FS and FSUIPC.

 

Now I need functions for my buttons so I can add and subtract those numbers from the variable.

 

Forget adding and subtracting numbers, think in terms of setting and clearing bits.

 

How do I do that?

Is it possible with the built in functions?

Is there a way to increase/ decrease with a parameter? That would be the most elegant way I think. But as I understand "increase" only works "by one", the parameter setting the limit.

 

 

You can't really do it with the existing L:Var functions. You'd need "Setbits", "Clearbits" and "Togglebits" functions, with the parameter giving the mask to be logically Anded, Ord or Exclusive Or'd with the current value.

 

This would be easy enough to implement, provided there's room in the L:Var macro encoding for me to include it. I'd need to look at the code.

 

Do I need to create a LUA-script?

 

Currently, yes, it would be the only way. Read the L:Var, change the bits and write it back. But don't rush into anything. I'll have a look at the code first and let you know. Is this for FSUIPC4?

 

Regards

Pete

Link to comment
Share on other sites

But don't rush into anything. I'll have a look at the code first and let you know. Is this for FSUIPC4?

 

Okay. There was just enough room for two more functions, so I've added facilities to set bits and clear bits. No toggle I'm afraid, but set and clear should do just what you want.

 

Download FSUIPC4912.zip

 

The format for Setbits is L:name,Sbits,param, and Clearbits is L:name,Cbits,param. Note that if you use these on an L:Var which includes fractions, those will be lost -- the result is always a 32-bit integer.

 

Let me know how you get on, please. I've not put 4.912 on general release yet.

 

Pete

Link to comment
Share on other sites

Thanks for the extraordinary support. It works as it's supposed to do.

Unfortunately it only operates the buttons visually, the cockpit functions do not work.

I'll have to try to figure out how to do that...

 

Actually, I just figured out how to do it.

As the Mouse Macro only pressed the button and i couldn't unpress it, i added a "release left mouse button" macro to be executed when I release the button. And then it worked! I really love your software, and the great support you're providing!

Edited by CCole
Link to comment
Share on other sites

Hello,

I have one _maybe_ similar problem which I am trying to solve using the LUA script. I have joystick with one axis and I have L:var which I am trying to write. My L:var describes a knob position which has 13 positions. My joystick is sensing real hardware knob. The task is to move the L:var knob between its 13 positions according to real knob movement (which is linear).

 

I was thinking about such code:

while 1 do

	ipc.sleep(100) 
	KnobPosition=ipc.axis(1,X)
		if math.abs(255 - KnobPosition) > 235
			 ipc.writeLvar(dc9_ap_turn_knob, 1)
		end

		if math.abs(255 - KnobPosition) > 216 logic.and math.abs(255 - KnobPosition) < 235
			 ipc.writeLvar(dc9_ap_turn_knob, 2)
		end

		if math.abs(255 - KnobPosition) > 196 logic.and math.abs(255 - KnobPosition) < 216
			 ipc.writeLvar(dc9_ap_turn_knob, 3)
		end	

                --and so far up to 13 I think

end

Is my approach even possible? I think the axis has positions 1 - 255 which divided to 13 parts gives about 19,6 for each part. So I am trying to make 13 if conditions where all the time just one would be true and the LUA would set the L:var to my desired position. 

 

I am pretty sure I am wrong handling the logic.and operator - how can I combine two conditions like I am trying to?

 

Sorry for lame questions, just first attempt ever to use LUA script...

 

Pavel

www.dc-9.eu

Link to comment
Share on other sites

I have one _maybe_ similar problem which I am trying to solve using the LUA script. I have joystick with one axis and I have L:var which I am trying to write. My L:var describes a knob position which has 13 positions. My joystick is sensing real hardware knob. The task is to move the L:var knob between its 13 positions according to real knob movement (which is linear).

 

Is my approach even possible? I think the axis has positions 1 - 255 which divided to 13 parts gives about 19,6 for each part. So I am trying to make 13 if conditions where all the time just one would be true and the LUA would set the L:var to my desired position. 

 

I am pretty sure I am wrong handling the logic.and operator - how can I combine two conditions like I am trying to?

 

Sorry for lame questions, just first attempt ever to use LUA script...

 

Pavel

www.dc-9.eu

 

For good Lua operation you'd be better off assigning the Axis to LuaValue <name of plug-in>, with the Lua pre-loaded by an [Auto] section in the FSUIPC INI. Then have an event.param calling a function which does the computation.

 

If the axis is a standard one processed by Windows joystick drivers it should be giving you a range of something like -16380 to +16380. Whatever it is (measure it in Axis assignments), set the Delta value in the axis assignments page to something which will give you your 13 steps.

 

Then, assuming these steps are equally spread out, the function merely needs to do one computation. eg:

ADDN = ? -- Need to work this out
DIVN = ? -- Need to work this out

function setposition(x)
    pos = (x + ADDN) / DIVN
    if (pos > 13) then pos = 13 end
    if (pos < 1) then pos = 1 end
    ipc.writeLvar("dc9_ap_turn_knob", pos)
end

event.param("setposition")

Once you have the full range then it's just a matter of arithmentic to work out how to adjust it (with ADDN) and divide it (with DIVN) to get a result of 1-13. For example, if the range rally is -16380 to +16380 then

 

DIVN = 32760 / 13

ADDN = 16380 + DIVN

 

would get you close, but would still probably need an adjustment.

 

BTW, note that the name of the L:var is a string and needs those "".

 

Regards

Pete

Link to comment
Share on other sites

  • 1 month later...

Hello Pete,

sorry for late reply, I have been busy with other works in our cockpit.

 

I added an Auto section to my FSUIPC ini (should there be the .lua?)

[Auto]
1=DC9AP

The DC9AP.lua contains what you have recently posted here.

 

Now I wonder how I should assign the axis to LuaValue <name of plug-in>  - by writing somewhere in the FSUIPC.ini or by user interface in running FSX? I have tried it by 

[Axes]
1=0X,2520,LuaValue DC9AP

as my joystick is 0 and the axis is X and the delta should be 2520. 

 

I also wonder if I should call the DC9AP.lua again in the LuaFiles section or if it is sufficient when it was pre-loaded by Auto.

 

Actually it does something, after the airplane was loaded the turn knob was turned into some strange position (which can not be achieved by clicking the knob in cockpit), but it did not respond to the potentiometer. After moving the knob by mouse it returned to standard position where it stood regardless of the joy.

 

What I think that even that the knob has 13 positions for mouse click, the variable values can be different from 1 - 13, dont you think? Maybe I should try first reading the dc9_ap_turn_knob value to determine the range...

 

Thank you for your advice,

Pavel

 

Edit: I wanted to use the log lvars.lua for the range check of the variable, so I placed the file into the Modules folder, added to FSUIPC.ini - but where can I find the actual log with L variables?

Link to comment
Share on other sites

Now I wonder how I should assign the axis to LuaValue <name of plug-in>  - by writing somewhere in the FSUIPC.ini or by user interface in running FSX? I have tried it by 
[Axes]
1=0X,2520,LuaValue DC9AP

as my joystick is 0 and the axis is X and the delta should be 2520. 

 

Ouch! Don't mess in the INI file, just assign it in the Axis assignments. The stuff in the [Axes] section is encoded to access Lua files by number, just as in the Buttons and Keys sections!

 

I also wonder if I should call the DC9AP.lua again in the LuaFiles section or if it is sufficient when it was pre-loaded by Auto.

 

 

The LuaFiles section simply Lists the Lua files. It doen't do anything else. The numbers there are the references used in assignments. ALL of the Lua files ever seen in your modules folder will get listed there!

 

What I think that even that the knob has 13 positions for mouse click, the variable values can be different from 1 - 13, dont you think? Maybe I should try first reading the dc9_ap_turn_knob value to determine the range...

 

Sorry i've no idea about that.

 

Edit: I wanted to use the log lvars.lua for the range check of the variable, so I placed the file into the Modules folder, added to FSUIPC.ini

 

Added to modules INI? What does that mean? You have to either start it in an [Auto] section, or run it by assigning a Key or Button to it. PLEASE please please read some of the documentation.

 

- but where can I find the actual log with L variables?

 

Unless you elect to have a separate log file for Lua plug-ins (an option in the Log tab -- as documented) all logging goes to the FSUIPC LOG file, of course.

 

Pete

Link to comment
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
×
×
  • 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.