Jump to content
The simFlight Network Forums

kamarad

Members
  • Content count

    7
  • Joined

  • Last visited

  • Days Won

    2

kamarad last won the day on October 20 2015

kamarad had the most liked content!

Community Reputation

2 Neutral

About kamarad

  • Rank
    Newbie
  1. Introduction This post explains how you can use a LUA routine to access the status of the buttons/switches/selectors/gear and flaps lever and trim wheel (herewith named collectively as Buttons) on 3 Saitek panels using FSUIPC and Linda. The first section presents a quick instruction to start gathering information based on lua program attached to this post. The second section gives a simple example of a Lua program that access the Saitek panel buttons status and select specific FSX/P3D actions accordingly. The third section goes more into the details about how this LUA programs was made. You need a registered version of FSUIPC for this to work. Section 1 – Quick Start Download and install the relevant LUA routines; Attached to this post are 3 Lua programs corresponding to the 3 Saitek panels. You just need to install the ones corresponding to the panel you own. The 3 Lua programs are: - HIDRadio.lua - HIDMulti.lua - HIDSwitch.lua Note; I have renamed the 3 programs with a .txt exension for upload as the system doesnt allow to upload .lua files. You will need to change the extension back to .lua before using them. To install them, just drop the ones corresponding to the panel you own into the “module” directory of FSX/P3D. Automatic start of the LUA programs The LUA programs selected above must run in permanence to scan the status of the buttons and map (copy) this information into specific address of the FSUIPC offsets. To inform FSUIPC that those programs must start and run continuously, it is necessary to add the following lines to the FSUIPC.ini files (located in the module directory of FSX/P3D). [Auto] 1=lua HIDRadio 2=lua HIDMulti 3=lua HIDSwitch On the next start-up of FSUIPC, the Lua program will start to scan the status of the buttons and selector on Saitek panels. Checking with FSUIPC logging facility that the Lua programs are in place and operating FSUIPC has a built in logging facility that can be useful to check the proper operation of the Lua programs and the correct mapping of switches to the offset address. Go to the FSUIPC Logging tab and on the right part of the screen, enter the following information: Offset Type of data Remark 3358 U32 Saitek Radio panel offset address 335C U32 Saitek Multi Panel offset address 3360 U32 Saitek Switches Panel offset address Then click on “FS window” and you should have a green message on the top left of your screen. Move some selectors or push buttons on each of your panels and see if the values on screen change according to the position of the buttons. An annex at the end of this post gives the value of each button. Note1 : The knob just send a short pulse so the number on screen will just change very rapidly and come back to the value prior to moving the knob when you stop moving it. Note 2: The buttons just change status while they are pressed, they doesn’t indicate the status of the corresponding function. Ex: the Autopilot button will just send a ON status when you press the button. So this is not intended to test if functions like the AP are engaged or not. It’s just to test the instantaneous position of the hardware buttons. Make sure you have version 4.934 as the previous one has a problem that killed lua programs on start-up and caused me a couple of evening of head scratching... 4.934 solved this as soon as I installed it. Accessing the information from within a LUA program in Linda Now everything is in place and you have the possibility to access the information on your panel switch. For simple assignation of a single button, you usually doesn’t need complex programming as FSX, Spad or Linda menu all allow you to directly select FSX/P3D commands. On the other hand, if you want to combine the status from different buttons to trigger a specific FSX/P3D action, then you need to use a Lua program (you can also use FSUIPC conditional button programming but Lua is more flexible). Using Linda, it is possible to assign user created Lua program to a button so the program is called when the button is push (or a switch is move to the “on” position or a selector is put in a specific position). The Lua program allows you to test the status of others buttons and makes your program act accordingly to send the proper FSX/P3D command. In Linda, you can create individual LUA program module (a module can contain several Lua program) for each aircraft. Linda includes also a text editor that makes creation of Lua program easy. Some functions in the Lua library allow reading specific address in FSUIPC offsets. Each address that will be assigned to the 3 Saitek panels covered here will contain between 18 to 20 bits of useful information (not considering the LED display) that correspond to all the buttons, switches, selectors and gear and flaps lever of the panel. The switches panel for instance contains 20 bits of information that you can test. The address to use in order to read each panel information are: 0x3358 = Radio panel 0x335C = Multi panel 0x3360 = Switch panel Note : You can assign other address if those one are already used for other purposed on your setup. You will need to modify the HIDxxx.lua program that correspond to the device you want to change. Note: The "0x" in the adress above just means that its written in hexadecimal notation. You will need to include the 0x within Lua program otherwise it will consider that the address provided is decimal. Please note that in the FSUIPC logging page, you don’t need to include the 0x as this page always consider that the value entered is hexadecimal. There are two main functions within Lua programs that can help you to read buttons status. First, the following Lua program line read all the bytes of information from the Saitek Radio panel and put it in a variable named “pos”. pos = ipc.readUB(0x3358) But the value returned is not quite useful by itself as it represents the cumulative sum of all the individual bits for switches that are in the “on” position resulting in a large number of possible values. You then need to isolate the value that you are specifically interested by using the following function (here represented in a separate line). pos = logic.And(pos,mask). Here mask correspond to the specific value (or sum of values) you are interested in. For instance, if you are interested to test if the position of the magneto switch is at the “right” position on the Saitek switch panel, then the value for the mask is 32768 (see annex for all possible values) and the Lua program line becomes Pos = logic.And(pos,32768) Section 2 : Example for the Duke piston or Douglas C-47 Magneto selector In the Duke Piston from Real air (and Douglas C-47 from Manfred Jahn), the magneto animation in the VC are reversed compared to the Saitek switch magneto button for the “left” and “right” position which create a weird jump in the VC while you move the magneto selector on your Saitek panel. - Duke Piston/Douglas C-47 VC magneto selector order: Off – Left – Right – Both – Start - Saitek Switch panel magneto selector order: Off – Right – Left – Both - Start So the objective is to program a function in a Linda module that will reverse the operation of the left and right magneto position between the Saitek panel and the VC. In addition, we want to test the position of the upper mode button for the Saitek radio panel to determine if we want to operate the motor 1 or 2. Spad has a built-in functionality that allows using several switches (ex: Aternator, fuel pump, cowl, de ice) to act on motor 1 or on motor 2 according to the position of the top selector on the Radio panel and we want to replicate this functionality here. First you need to create a module for your targeted aircraft if it’s not already existing. See Linda documentation to do this. Then you need to copy the following program (or use the Magneto.txt file provided) into the aircraft module using Linda editor screen. Again, refer to Linda documentation to see how to open the editor. The title between double hash characters is recognized by Linda as a heading separator for functions. It makes easier to identify function you have created. Comments (text preceded by --) in the program below provide detailed comments for each steps. -- ## Magneto ## Function MagLeftVC () -- This function handle the reversal of the magneto in the VC panel compared to the Saitek selector. -- It is activated when the selector on the Saitek switch panel will be put at the left position. -- It will result in positionning the VC magneto selector to the "right" position. -- The Saitek Radio top left selector at position COM1 means that the left engine is considered. If the selector is at the COM2 position, then the right engine will be treated. -- The information about the radio panel status is at offset 0x3358 -- reading the offset to get all Radio panel switches current status pos = ipc.readUB(0x3358) -- The next line of lua code will isolate the bits of information we are interested in -- mask = 1 would be usefull ot test if the top left selector at the COM1 position -- mask = 2 would be appropriate to test if the top left selector at the COM2 position -- Mask = 3 accept both COM1 and COM2 and will return either 1 or 2 as the selector -- can be only in one of the two positions at a given time. -- If the selector is not at COM1 or COM2, then the logic.And function will return zero and no action will be done. pos = logic.And(pos,3) -- the next group of lines will send the command to put the magneto for left or right motor in the right position in the VC. -- 66400 is the Magneto1_set command for FSX/P3D -- 66401 is the Magneto2_set command for FSX/P3D -- The parameter 2 is for the “right” position of the magneto if pos ==1 then ipc.control(66400,2) else if pos ==2 then ipc.control(66401,2) end end Function MagRightVC () -- same approach as for the left mag function, without comments here pos = ipc.readUB(0x3358) pos = logic.And(pos,3) if pos ==1 then ipc.control(66400,1) elseif pos ==2 then ipc.control(66401,1) end end Section 3 – Nut and Bolts. This section provides some additional explanation on how the HIDRadio.lua program was created from the HIDDemo.lua program provided by Peter. Step 1: Obtain HIDDemo.lua We need to have a Lua program running continuously to scan the Saitek panel switch status then map this information in FSUIPC offset. The offset can then be read from a Lua program in a Linda module for an aircraft. Peter Dowson provided an example of a Lua program that scan HID device like the Saitek panels and write the information on offset. We just want to use his demo and modify it a bit. The HidDemo.lua program is available in the complete install of FSUIPC4. Or you can download the latest HidDemo.lua example from : http://forum.simflight.com/topic/68257-latest-lua-package-for-fsuipc-and-wideclient/ Step 2: Create HIDRadio.lua Make a copy of HIDDemo.lua and name it HIDRadio.lua (we will give only one example herewith but the same approach works for the switch and the multi panel also). Step 3 – Adjust HID device identification At the beginning of the HIDDemo.lua program, there is two lines that identify the Saitek panel (HID device) you want to communicate with. You have to insert the hexadecimal code for the vendor and for the product. For instance the lines for the Saitek radio panel are: -- Saitek Radio panel Vendor = 0x06A3 Product = 0x0D05 If you dont know the HID device codes, there is a utility provided by Peter Dowson called HIDscanner.exe that gives a report about all devices connected to your PC and their vendor rand product codes. I already run this utility to find the relevant information of the 3 following Saitek Products. Radio Panel : Vendor = 0x06A3 Product = 0x0D05 Multi Panel : Vendor =0x06A3 Product = 0x0D06 Switch Panel : Vendor =0x06A3 Product = 0x0D67 The HIDScanner.exe utility is available at the same link provided above on Peter support page. Step 4 : Change the size and destination of information blocks In HIDDemo.exe, you will find a loop of instruction toward the end of the program that read the status of the buttons on your HID device and copy it to a specific offset. The loop is initially programmed for reading 8 blocks composed of 4 Bytes of information. For the Saitek panel switches, you only need to do it once as all information fit into a double world (32 bits of information). So I cleaned the iteration loop (from 1 to 8 and adjusted the HIDDemo.lua program to do a single read of a 32 bits of information that is sufficient for the Saitek panels. Next, you need to select the destination for the button information in the FSUIPC offset table. There is an ipc.writeUD instruction in the HIDDemo.lua program that was modified to correspond to an offset that was used for mapping. The possible offset for the 9 contiguous blocks of 4 bytes (32 bits of information) are: 0x3340, 0x3344, 0x3348, 0x334C, 0x3350, 0x3354, 0x3358, 0x335C, 0x3360. See the “FSUIPC4 Offset Status.pdf” document provided with FSUIPC documentation. The Saitek version of HIDDemo.lua use the 3 last virtual joystick addresses so Joystick 71,72 and 73 located at 0x3358, 0x335C and 0x3360 respectively. Step 5 : Install your newly created Lua program Just copy them it in the “module” directory of FSX or P3D. If you have started with the quick start portion of this document, you have already done this. Step 6 : Automatic startup of HIDRadio.lua To start automatically your Lua program add the following lines in FSUIPC.ini. If you have applied the quick start instruction, its already done. [Auto] 1=lua HidRadio Step 7 : Create custom lua program See the example provided for the Duke above. Annex: Saitek panels reference of “buttons” value Saitek Radio Panel (20 bit of information + 2 bit unused) Top left mode selector 1= Com1 2= Com2 4= Nav1 8= Nav2 16= Adf 32= Dme 64= Xpdr Bottom Left mode selector 128= Com1 256= Com2 512= Nav1 1024= Nav2 2048= Adf 4096= Dme 8192= Xpdr 16384 = Top right ACT/STB button 32768 = Bottom right ACT/STB button 65536 = Clockwise turn of the top knob 131072 (2E17)=Counter-clockwise turn of the top knob 1048576 (2E20) = Clockwise turn of the bottom knob 2097152 (2E21) = Counter-clockwise turn of the bottom knob Saitek Multi Panel (20 bit of information) Selector button 1= Alt 2= VS 4= IAS 8=HDG 16=CRS 32= Clockwise rotation of knob 64= Counter clockwise rotation of knob 128= AP button 256= HDG button 512= NAV button 1024= IAS button 2048= ALT button 4096= VS button 8192= APR button 16384= REV button 32768= Auto Throttle switch ON 65536= Flaps up (2^16) 131072= Flaps down (2^17) 262144= Elevator Trim Pitch up (2^18) 524288= Elevator Trim Pitch Down (2^19) Saitek Switch panel (20 bit of information) Note: The minimum value returned corresponds to the position of the landing gear handle plus the position of the magneto knob. 262144 is returned if the gear lever is UP and 524288 if the gear lever is DOWN. 1= Battery 2= Alternator 4= Avionic 8= Pump 16= De Ice 32= Pitot heat 64= Cowl 128= Panel 256= Beacon 512= Nav 1024= Strobe 2048= Taxi 4096= Landing Magneto selector 8192= Off magneto 16384= Left Magneto 32768= Right Magneto 65536= Both Magneto 131072= Start Magneto Landing gear lever 262144= Landing gear Up 524288 (2E19)= Landing Gear Down Magneto.txt HidMulti.txt HidRadio.txt HidSwitch.txt
  2. HIDdemo testing

    Hi Pete, Was abroad for a couple of week so didn't had time to post the information in the user contribution. I will do it eventually but I have now problem to have a consistent access to the Saitek modules. At the beginning of this week, I made a fresh install of Prepar3dV2.2 on a new SSD drive and tried my 3 modules again just to find that their behavior was now erratic. I get access to the Radio panel most of the time (but not always), Multi is so so.. .about 50% success and I'm not able anymore to access the Switch panel. I took a couple of hours on the last two evening to investigate but still puzzled as the changes made to HidDemo are minimal (in the last try I made yesterday, I just changed the vendor and product number, the loop to 1 iteration as all information fit in one 32 bit button and the destination offset address). And I did restart P3D about 50 times yesterday evening and the success of connecting is random.... I finally gave up yesterday after the last 5 tries didn't succeed to access the 3 panels. I will see if I can investigate further this week-end. Pierre
  3. HIDdemo testing

    And if it may help others people to get access to their Saitek panel, here is the mapping of the value returned by each switches and button. they fit in 17 or 19 bytes so reading a single double world is sufficient to get the complete status of the panel. Note: The value returned is the sum of the value associated with all switch position and button that are pushed. Saitek Radio Panel Button 1 (top left) 1= com1 2= com2 4= nav1 8= nav2 16= adf 32= dme 64= xpdr Button 2 (bottom left) 128= com1 256= com2 512= nav1 1024= nav2 2048= adf 4096= dme 8192= xpdr 16384 = ACT/STB button 1 (top right) 32768 = ACT/STB button 2 (bottom right) 65534 = Turn right (top dial button) 131072 (2E17)= Turn left (top dial button) Saitek Multi Panel Selector button 1= Alt 2= VS 4= IAS 8=HDG 16=CRS 32= Dial turn right 64= Dial turn left 128= AP button 256= HDG button 512= NAV button 1024= IAS button 2048= ALT button 4096= VS button 8192= APR button 16384= REV button 32768= Auto Throttle switch 65536= Flaps up (2e16) 131072= Flaps down (2e17) 262144= Pitch up (elevator trim) 524288 (2E19)= Pitch down (elevator trim) Saitek Switch panel Note: The minimum value for saitek value correspond to the position of the landing gear handle. 262144 is returned in the UP gear position and 524288 for down Gear. 1= Battery 2= Alternator 4= Avionic 8= pump 16= DeIce 32= Pitot heat 64= Cowl 128= Panel 256= Beacon 512= Nav 1024= Strobe 2048= Taxi 4096= Landing 8192= OFF magneto 16384= Left Magneto 32768= Right Magneto 65536= Both Magneto 131072= Start Magneto 262144= Landing gear Up 524288 (2E19)= Landing Gear Down
  4. HIDdemo testing

    It works fine for the Saitek Radio, Saitek Multi and Saitek Switch panel. I create 3 different versions of HIDDemo, one for each panel that write at different offset as you mention. Thanks for the fast and very informative support..
  5. HIDdemo testing

    Thanks Pete for the fast return and the clarification of the multiplier. Now it makes perfect sense. As for reading 32 bit at the time, I'm fine with that approach. I was not suggesting to make more read operation with smaller quantity of byte each. As for the quantity of information returned, if my Saitek multi panel for instance fit in 2 x 32 bits, I will have to modify the GehidButtons line of code as follow risk of causing errors because I just have two destination variables button[1] and [2] instead of 8 in the initial code? buttons[1], buttons[2] = com.GetHidButtons(dev, CurrentData) If it is as simple as that, no need for a function that return the quantity of information from the Panel as I can test this already using the Hiddemo and adjust the code accordingly. I will try to give a go to my first trial in lua programming.... I will need indeed to modify the program and destination offset for each of my 3 panels but that should not be too complex.
  6. Hi, I’m trying to build a lua routine to scan my 3 Saitek panels (Multi, Switch, Radio) and I use as a template the example HIDDemo.lua. While reviewing the code, there is a point needing clarification. I was able to access the panels and took note of each button value. The next step for me was to assign different virtual joystick to each of the 3 panels and that is where I have some problems. On the writing button loop of HIDDemo, I don’t understand why in the ipc.write line the increment is 8. I was expecting that writing a double world 4 bytes x 8 bit = 32 buttons will requires a 4 bytes increment between each button write. The last loop when I=8 here will give an increment of 64 bytes over the base address of 0x3340 which seems larger than the block of offset associated with virtual buttons. I’m missing something? i = 1 while i <= 8 do if buttons ~= prevbuttons then fbutton = true -- flag change for logging prevbuttons = buttons -- Send to FSUIPC as a set of 32 virtual buttons -- i.e. DWORD offsets 3340 onwards ipc.writeUD(0x3340 + ((i-1) * 8), buttons) end i = i + 1 end Also, I was wandering why in this example, the decision was to read 8 buttons x 32 bit each instead of less? How can we know what is the quantity of button that will be returned by a HID device? Is it the “wr” parameters in the com.openhid command? For instance, I know from testing that the Saitek radio panel use 17 bits and the Multi panel 19 bit of information. So I expect to be able to assign the 3 first block of 4 bytes in the 0x3340 offset to my 3 panels. Does it makes sense?
  7. Hi, I use FSUICP with a CH product yoke and I try to assing a button to the zoom in and zoom out functions. I went to the Button & Switches screen of the FSUIPC and pushed the switch I wanted for zoom in. It worked fine and I defined it as a key to be sent when the button is pressed. this is the key 0 that i use on my keyboard for zoom out. The same for zoom in where I wanted to use the + key (FSUIPC identify it as the =+ key which seems fine. The problem is when using those button in fsx. It work on entry then regularly stop to work. Often it seems related to zooming out to 0.3 then it seems to stop accepting any change. The weird things is that it does not accept direct key press from the keyboard for zooming. If I want to restore proper function, I have to open a new view, the zoom will work in this one. If I close the new view, it restore the proper operation of the zoom button in the main view. Any clue what is happening? Pierre
×