Jump to content
The simFlight Network Forums

Lua Rotaries help needed


Recommended Posts

Dear Pete,

 

I need some help to fix the rotaries.lua file in order to use it with project magenta fcu (heading speed and altitude offsets).

The buttons I want to use are connected to "DTA Rotary Encoder". I have run the hid scanner and the results are:

 

  **************************************************************************
 
  Device at "\\?\hid#vid_16c0&pid_27cb#6&2239c13c&0&0000#{4d1e55b2-f16f-11cf-88cb-001111000030}"
  Vendor=16C0, Product=27CB (Version 1.33)
  Manufacturer= Desktop Aviator
  Product= DTA Rotary Encoder
  Serial Number= A25300
  Usage Page: 1
  Input Report Byte Length: 5
  Output Report Byte Length: 0
  Feature Report Byte Length: 18
  Number of Link Collection Nodes: 3
  Number of Input Button Caps: 1
  Number of InputValue Caps: 0
  Number of InputData Indices: 32
  Number of Output Button Caps: 0
  Number of Output Value Caps: 0
  Number of Output Data Indices: 0
  Number of Feature Button Caps: 0
  Number of Feature Value Caps: 1
  Number of Feature Data Indices: 1
  Buttons range 1 -> 32 at indices 0 -> 31
  **************************************************************************

 

Also from fsuipc the corresponding offsets I want to use are:

 

 

[JoyNames]
AutoAssignLetters=Yes

.

.

.

.

.

6=DTA Rotary Encoder
6.GUID={9E7DA880-54D5-11E4-8007-444553540000}

.

.

.

.

G=DTA Rotary Encoder
G.GUID={9E7DA880-54D5-11E4-8007-444553540000}

.

.

 

[buttons]
PollInterval=20
ButtonRepeat=10,40

.

.

.

.

.

26=PG,7,Cx52005408,x01670001
27=PG,6,Cx62005408,x01670001
28=PG,9,Cx32005406,x015E0001

.

.

.

33=PG,8,Cx42005406,x00640001
34=PG,5,Cx3200540A,x01F40005
35=PG,4,Cx4200540A,x00050005

.

.

.

 

 

Also I have added into fsuipc the following command:

 

[Auto]
1=Lua Rotaries

 

And I have added inside the modules folder the rotaries.lua file edited as following:

 

Vendor = "Desktop Aviator"
Product = "DTA Rotary Encoder"
Device = 0  -- Multiple devices of the same name need increasing Device numbers

-- Use separate Lua plug-ins for separate cards!

-- NOTE: this can handle up to 16 rotaries only, using the first 64 "virtual buttons"
-- List the pairs here:

Rotaries = { 26, 27, 28, 33, 34, 35 }

-- Example { 31, 30, 25, 22 } would be 31+30 for one, 25+22 for the next, and so on
-- Which is clockwise and which counterclockwise doesn't matter -- you'll get
-- fast and slow of each in any case

dev, rd, wrf, wr, init = com.openhid(Vendor, Product, Device, Report)

if dev == 0 then
   ipc.log("Could not open HID")
   ipc.exit()
end

-- Set the boundary time in milliseconds between
-- "fast" (shorter) and "slow" (longer) signalling

FastTimeLimit = 80 -- Adjust to taste

-- Polling time in milliseconds: should be much shorter than
-- the boundary time

Pollrate = 20  -- same as 50 times per second

-- Initialise variables used to keep track of things
LastTimes = {}
Buttons = 0
PrevButtons = 0
Diff = 0

-- This function will be called by a time event, set at the end of the program before exit.
function poll(Time)
 -- read any data available from the device (only need most recent report)
  data, n = com.readlast(dev, rd)

 if n ~= 0 then
   -- Data was returned, so get the status of all the possible "buttons" we are using
   -- one value of 32 bits
  Buttons = com.gethidbuttons(dev, data)           

   -- See if any changes occurred:
   Diff = logic.Xor(Buttons, PrevButtons)
   PrevButtons = Buttons
         
    if Diff ~= 0 then
     offset = 0x3340
     buttonbit = 1
    j = 1
     while Rotaries[j] ~= nil do
    mask = logic.Shl(1, Rotaries[j]-1)      
    if logic.And(Diff,mask) ~= 0 then
     -- This one changed
       -- See if changed in less than the "boundary" time
       thisbutton = buttonbit
       if (LastTimes[j] ~= nil) and ((Time - LastTimes[j]) < FastTimeLimit) then
           thisbutton = buttonbit + buttonbit  -- Use next higher button for fast
         end
         LastTimes[j] = Time
                       
        -- Toggle a virtual button accordingly
         ipc.togglebitsUB(offset, thisbutton)
    end
    
    j = j + 1
    buttonbit = 4 * buttonbit
    if logic.And(j,15) == 0 then
       buttonbit = 1
       offset = offset + 4
    end
    end
  end
 end
end

event.timer(Pollrate, "poll")

 

But it seems not working. What I am doing wrong? Many thanks in advance.

 

 

 

 

 

Link to comment
Share on other sites

I need some help to fix the rotaries.lua file in order to use it with project magenta fcu (heading speed and altitude offsets).

The buttons I want to use are connected to "DTA Rotary Encoder". I have run the hid scanner and the results are:

 

...

 

And I have added inside the modules folder the rotaries.lua file edited as following:

 

Vendor = "Desktop Aviator"

Product = "DTA Rotary Encoder"

...

 

But it seems not working. What I am doing wrong? Many thanks in advance.

 

Sorry, I've no idea. Have you tried logging? Did you look at the FSUIPC log to see if there were any errors? Does it actually get the device? What did you edit apart from the Vendor and Product names? Is that Lua otherwise the very latest one, installed by a current version of FSUIPC4?

 

Pete

Link to comment
Share on other sites

Dear Pete,

 

How I can make the fsuipc to log if so I can see if there are any errors? Also if the code is correct maybe the "FastTimeLimit = 80" is making the encoder turns very slow in the same speed  I am having now and I need to adjust this to 200 or 300 for faster speed? Many thanks in advance.

Link to comment
Share on other sites

How I can make the fsuipc to log if so I can see if there are any errors?

 

FSUIPC always makes a log! If any Lua contains bad lines the Lua will terminate and FSUIPC log will show the Error! Have you never looked in the FS Modules folder. Look now. See the FSUIPC4.LOG file?

 

For line-by-line logging of the Lua plug in you just set the option for this in FSUIPC's logging tab. This must be done BEFORE starting the Lua, so either restart it afterwards with an assignment to a key or button, or restart FS after setting the option.

 

Also if the code is correct maybe the "FastTimeLimit = 80" is making the encoder turns very slow in the same speed  I am having now and I need to adjust this to 200 or 300 for faster speed? Many thanks in advance.

 

 

The Lua program cannot control how fast you turn the rotary!!! I don't understand "making the encoder turns very slow in the same speed".

 

By all means experiment. Are you saying you get results, but just not differnt ones for fast and slow? I thought you said itjust didn't work at all?

 

Pete

Link to comment
Share on other sites

Dear Pete,

 

Of course Lua cannot control how fast the rotary is working. I meant how fast the button repeats ( the polling). About now for the commands "FastTimeLimit" and "Pollrate" which numbers will give me faster and more repeats?

I mean that if I put for the Pollrate=1 and for FastTimeLimit=10 I will get faster and more repeats? When I said I don't know if it is working I mean that I am not sure if it is working or not because I had the same repeats as before add the lua file.

Maybe the lua file is working fine but the repeats they need adjustment so I was getting the same results as before. Sorry if you don't understand what I am try to say because my English are bad. Many thanks in advance.

Link to comment
Share on other sites

  • 2 weeks later...

Of course Lua cannot control how fast the rotary is working. I meant how fast the button repeats ( the polling).

 

The changes seen from the rotary cannot be made faster other than by turning the rotary faster. Increasing the poll rate will merely make the program look for changes more often. If your rotary can provide more than 50 changes every second I would be very surprised indeed -- 50 is your current poll rate. But by all means experiment.

 

Whether the turn rate is regarded as "fast" or "slow" depends only on the "FastTimeLimit". If you set that to 10 as you suggest then you would have to turn it fast enough to get 100 pulses every second to get the fast indication, otherwise it would only be slow (> 10 miliseconds). If you want a slower speed (a possible speed!) you need to increase the time not decrease it!

 

I think maybe you are thinking this program is for something completely different from what it is intended to do?

 

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.