Jump to content
The simFlight Network Forums

Recommended Posts

Posted

In Lua, can I discover what joystick number is associated with a given JoyName?  My Honeycomb Alpha will likely always have JoyName "A" but will likely get different joystick numbering as the USB port it gets plugged into varies.  I looked through the manuals and searched through forums but didn't see anything.  

Context is I'm fashioning a Lua plugin similar to TripleUse.lua that turns the trigger button into a shift key.  Basically, sending a held keypress for "click-and-hold" but being a compound modifier for "double-click-and-hold, a different compound modifier for triple-click-and-hold, etc. 

Thanks for the support.

Posted

A calculated guess here, but I do believe FSUIPC can automatically do that for you as long as the following is true in your FSUIPC7.ini ( default) :

[JoyNames]
AutoAssignLetters=Yes

As stated in the v7 Lua Library for event.button :

 “joynum” is a joystick number, the same as shown in
FSUIPC’s Button assignments tab. If you use joystick
lettering, you can put the letter here instead but it must be ""
quotes, as a string. Note, however, that the function is called
with the translated number as its first parameter.

With that you could change just 1 line in TripleUse.lua -
joy = 1 -- around line 21
- change to -
joy = "A" 

If you really need the number for your specialized coding, maybe you could use an "initialization" lua (or placed in your current code) to put the joy number into a user offset or variable within your lua. It does however, require that you press the assigned initialization button at least once to populate the offset/variable before using your own specialized triple use.
 

jn = nil

function getJoyNum(joynum, button, downup)
	ipc.writeUB(0x66C0, joynum)
  	jn = joynum
end

event.button("A", 0, 1, "getJoyNum") -- button 0 on alpha  (assigned "A") is the trigger

0x66C0 or the variable "jn"  will now hold your actual joy number for any of your uses.

Just an idea...

Roman

Posted
9 hours ago, Blake Buhlig said:

In Lua, can I discover what joystick number is associated with a given JoyName?

The mapping from joy letters to joystick IDs is held in your FSUIPC7.ini file, in the [JoyNames] section.
However, you should prefer to use letters over ids, as shown by Roman, as these will be fixed but the joystick IDs may change. If the IDs do change, its easy to update the mapping section to re-enable your assignments when using the Joy Letters facility. There is a section on Joy Letters in the User Guide (P20). This facility was also made active by default in FSUIPC7 - in previous versions it was off by default.

Posted
9 hours ago, spokes2112 said:

As stated in the v7 Lua Library for event.button :

 “joynum” is a joystick number, the same as shown in
FSUIPC’s Button assignments tab. If you use joystick
lettering, you can put the letter here instead but it must be ""
quotes, as a string. Note, however, that the function is called
with the translated number as its first parameter.

 

I completely overlooked the Lua Library docs saying you can pass a joyletter to event.button. That's all I need to do and indeed it is working for me.  Thanks and sorry for the noise.

  • 1 month later...
Posted

This has come up for me in a couple other contexts, for instance I want to set/clear the button flags on one of my buttons in certain circumstances when a different button is pressed. The C1003 and C1004 controls are there for this but I can't pass in a JoyLetter based parameter.

I appreciate the getJoyNum code suggestion and can probably figure a way to ensure some other button on the joystick gets pushed first. But I wonder if parsing the INI in Lua wouldn't be all that difficult, or if it hasn't already been done maybe for some other purpose.

Posted
I found https://github.com/Dynodzzo/Lua_INI_Parser which seems could be a start. Not completely working, but hopefully won't take too much more work.
 
local LIP = require 'LIP'
local ini = LIP.load('FSUIPC7.ini')
ipc.log('DEBUG ini.JoyNames.B:')
ipc.log(ini.JoyNames.B)
ipc.log('DEBUG ini.JoyNames.B.GUID:')
ipc.log(ini.JoyNames.B.GUID)
 
15562 LUA.4: DEBUG ini.JoyNames.B:
15578 LUA.4: Bravo Throttle Quadrant
15594 LUA.4: DEBUG ini.JoyNames.B.GUID:
15594 LUA.4: <bad string>
 
Posted

After making Line 42 of LIP.lua look like...

local param, value = line:match('^([%w|_%.]+)%s-=%s-(.+)$');  -- Added "%." to the line:match() argument

...the below function seems to work for me.

function _convert_joy_letter_to_num(ltr)
   local LIP = require 'LIP'
   local ini = LIP.load('FSUIPC7.ini')
   local guid, key, value
   for key,value in pairs(ini.JoyNames) do
      if key == ltr .. ".GUID" then
         guid = value
      end
   end
   for key,value in pairs(ini.JoyNames) do
      if value == guid and key ~= ltr .. ".GUID" then
         return key:gsub(".GUID","")
      end
   end
   return nil
end

ipc.log("JoyLetter B is JoyNum " .. _convert_joy_letter_to_num('B'))

 Output:

16422 LUA.4: JoyLetter B is JoyNum 2

 

  • Like 1

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.