Jump to content
The simFlight Network Forums

Rotaries.lua


Recommended Posts

Oh dear!

 

I've spent the day trying to understand this but failed miserably.

 

I'm sure it's simple, but how to get this .lua script to work on my system is evading me.

 

So, I need a kind soul to show me, step-by-step, how to get rotaries.lua to work.

 

I've searched lua tutorials online till I'm blue in the face, downloaded lua IDE's akimbo, but it's still opaque to me. It's not as if I'm uninitiated in the programming world. I can program in VB, Basic, SIOC etc. But I can't find a lua tutorial which makes sense to me.

 

OK, rant over. Please can someone help me run through the rotaries.lua script and understand how ti works?

 

Thanks,

 

Roger.

Link to comment
Share on other sites

OK so the frustration has abated somewhat.

 

I think I am definitely getting the script to run. I've started FSUIPC logging and it does not tell me "could not open HID"

 

Instead it tells me it's waiting for input from rotaries.lua, so I'm assuming the script is running.

 

As far as I can tell, the script waits for input from a 'real' joystick (or in this case a BU0836X card) and outputs it to one of the 'Virtual' Joysticks, which start at Offset 0x3340

 

Right. How do I ensure the script is going to get the input from the 'real' joystick?

 

At the beginning of the script, one defines the Vendor and Product - I have "Bodnar" and "BU0836X" in these entries.

 

Then we have the entry for "Device= ". The notes in the script say "-- Multiple devices of the same name need increasing Device numbers"... and "-- Use separate Lua plug-ins for separate cards!"

 

I have two BU0836X cards connected,so I've created a second Lua script called rotaries2.lua.

 

In rotaries.lua I have the Device = 0 and in roatraies2.lua I have Device = 1. My reasoning here is that if numbering starts at 0 I'll catch the card with at least one of the scripts!

 

Then we have "Rotaries = { 1,2,3,4,5,6,7,8}" - I am assuming this table refers to the 'real' joystick button numbers. So my BU0835X has button numbers starting at 1, whereas FSUIPC starts the numebring at 0. I've allowed for this in my script, giving the "Rotaries = " table numbers one-less than those of the actual card. So if the card has two buttons defined as an encoder, and they are 12 and 13, in the "Rotaries = " table I have {... 11, 12...}

 

The next section of the script is not clear to me but I think it polls the device defined at the top of the script and compares the state of the buittons with the previous state. If my undestanding explained above is correct, then at this stage when I turn the encoder attached to buttons 12 and 13 of the BU0836X card (defined as 11 and 12 for FSUIPC), then the script will 'see' that change of state.

 

After this, I get lost - how does the script send information back to FS? Offset 0x3340 is the first of the 'virtual' joysticks, so somehow the script is writing values to the 'buttons' of the virtual joystick - but which button, and how do I tell FSUIPC what to do when that 'button' is pressed?

 

Help...?

Link to comment
Share on other sites

Hi Roger,

 

Pete's on holiday at the moment, but I might be able to shed some light on this...

 

After this, I get lost - how does the script send information back to FS?

 

 

It doesn't send information to FS, it just triggers a virtual joystick button that is recognised internally by FSUIPC.

 

Offset 0x3340 is the first of the 'virtual' joysticks, so somehow the script is writing values to the 'buttons' of the virtual joystick - but which button,

 

 

It just starts at button 0 of the first virtual joystick (numbered from 64) and goes up from there. The actual number doesn't really matter.

 

and how do I tell FSUIPC what to do when that 'button' is pressed?

 

 

 

Via the FSUIPC interface in FS. Go into the buttons tab, rotate your rotary in each direction, fast and slow (so four buttons to assign per rotary). As you rotate them the virtual joystick button assigned by the LUA script is recognised (if the script is working) and displayed in the interface. The joystick number will be 64 or above. Then just assign an FS control as you would any other joystick button.

 

Paul

Link to comment
Share on other sites

Paul, thanks so much for helping!

 

OK I thought that was probably it - and indeed tried exactly that, but FSUIPC saw the actual buttons, not the virtual ones.

 

Since I believe the script is running, then I'm guessing I haven't got the assignments correct in the Rotaries { } table. My buttons show as 1,2  3,4  5,6  7,8 and 12,13 in Leo's Encoders configuration program. I've got them all defined as 1:1 and with a slow turn they go one degree (or one knot, 100ft etc.) with each click.

 

I said in my first (rational) post that I'm allowing for the fact that FSUIPC numbers the buttons from 0 and not 1. So I think my roatries entry should read:

 

Rotaries {0,1,2,3,4,5,6,7,11,12) - would that be correct?

 

Also, I have two of Leo's BU0836X cards attached, so I'm numbering them 0 and 1 in the Device = entry. Again, would that be correct?

 

Thanks again for your kind help :-)

 

Roger.

Link to comment
Share on other sites

I'm afraid I can't help much further as I don't know anything about Leo's boards.

 

However there is a previous thread which seems to be similar if not the same as what you want to do. in this thread Pete wrote a different version of the rotaries.lua that uses the same board that you have.

 

You'll have to follow it through and maybe run the hidscanner program as described to check ids etc.

 

http://forum.simflight.com/topic/68260-rotary-encoder-input-speed/?hl=bu0836x#entry426604

 

This is probably your best chance until Pete gets back or someone more knowledgeable than me jumps in.

 

Paul

Link to comment
Share on other sites

Hi Paul.

 

Thanks again for your help - much appreciated.

 

I've had a look at the thread you suggested and it has helped somewhat.

 

Having had a look at things I'm beginning to understand the script better - I've been going through it and referring to the Lua library pdf as supplied with the download from this forum.

 

I'm stuck on the line

 

mask = logic.Shl(1, Rotaries[j])

 

I know it means you shift Rotaries[j] left by one, and compare that with  Diff later, but i can't see the logic myself...

 

I just can't for the life of me see what it's doing - can you (or anyone else reading this) shed any light?

 

I have two separate scripts now, rotaries.lua and rotaries2.lua, which successfully get input from the two BU0836X cards and send them to separate Virtual Joystick numbers 64 and 65.

 

I did this by remming out the  lines

 

 --        if logic.And(j,15) == 0 then
 --           buttonbit = 1
 --           offset = offset + 4
 --        end

 

... thus preventing the script from jumping to the next Virtual Joystick - effectively just limiting it to one. I then modified the line

 

offset = 0x3340

 

to read

 

offset = 0x3344

 

for the second script.

 

I now have Virtual Joystick responses for both BU0836X cards, from Virtual Joiystick numbers 64 and 65.

 

So far so good.

 

The issue I have now is that I get a "fast" button every time I click the encoder round by one detent. If I do it slowly, it follows with a "slow" button. So, if I turn the encoder knob quickly, it changes the valie of the Auotpilot Speed Offset by 10. If i move the knob slowly, it changes it by 11, lol!

 

I'm struggling with the values for FastTimeLimit and Pollrate, plus of course Leo's card allows me to change the duration of the pulse sent by the encoder.

 

I'm hoping to find the 'sweet spot' where it all works beautifully...

Link to comment
Share on other sites

The issue I have now is that I get a "fast" button every time I click the encoder round by one detent. If I do it slowly, it follows with a "slow" button. So, if I turn the encoder knob quickly, it changes the valie of the Auotpilot Speed Offset by 10. If i move the knob slowly, it changes it by 11, lol!

 

 

 

Can you paste the entire lua script you are using in here? I can take a look and see if there's anything I can spot that might be causing this to happen.

 

Paul

Link to comment
Share on other sites

Hi Guys, thanks again for the help! Paul, I'll post the script when I can transfer it back over to this machine - it's on the FS machine at the mo.

 

Thomas - I have been using the rotariy encoders with Leo's board for some time, but have never managed to get them to react quickly when I turn the knob quickly. A search on this forum showed there are others who've had the same issues, and cured it with a Lua script. When i turn my encoders quickly they actually slow down - the best way to change a value quickly is to turn the knob slowly. I hope that makes sense?

 

I'd love to know what encoders Pete uses - he seems to say he has no problem there?

 

Thanks,

 

Roger.

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.