Jump to content
The simFlight Network Forums

Initial button and other button related questions


Recommended Posts

We have a Cessna 172/182 simulator at our Museum. It’s available for short flights for our visitors. We have a Simkits 32 digital IO board with switches connected for the usual stuff like Master, lights, Avionics and so on.

 

As we have multiple pilots in our sim  we have established a routine where the “instructor” resets the flight between pilots to expedite things. The plane is set on Rwy, engine running and ready for TO.

 

We often experience a mismatch between the physical switches in the cockpit and the state of the simulator.

As I understand FSUIPC does not read the actual state or position of the switch, but reads the change of state.

Is it some way we can come around this issue?

 

A couple of other questions.

Can we use multiple InitialButton?

Will initialButton be invoked on a simulator reset? Or is it only first load of the sim?

 

Regards

Frode

(Now on up to date FSUIPC version)

Link to comment
Share on other sites

As I understand FSUIPC does not read the actual state or position of the switch, but reads the change of state.

Is it some way we can come around this issue?

 

You can have a Lua plug-in to read the states of switches initially, using the HID facilities built into the CMO library. At present this would be the only way. The normal joystick interface is designed for buttons, really, not switches, so it is assumed that they are normally "off" (un-pressed).

 

There are some examples in the Lua examples ZIP of reading HID devices and interpreting the data for button states and so on -- for example Rotaries.lua and HidDemo.lua. Both offer much more than you'd need for this, though.

 

I'll make a note, though, and may consider some way to build in initial switch state actions. The problem would be to try to do it in a user-friendly manner without being over-restrictive. Maybe it will just have to be an INI parameter to list those buttons (actually switches) which should be treated as if "changed" initially.

 

A couple of other questions.

Can we use multiple InitialButton?

 

 

There's only one initial button parameter, with one button press. But of course you can have multiple actions resulting from that button. And that button need not be a real one. There's really no need for there to be more than one.

 

Will initialButton be invoked on a simulator reset? Or is it only first load of the sim?

 

Only on first load, when first "ready to fly", exactly as documented. I think it is described clearly enough, no?

 

Regards

Pete

Link to comment
Share on other sites

I'll make a note, though, and may consider some way to build in initial switch state actions. The problem would be to try to do it in a user-friendly manner without being over-restrictive. Maybe it will just have to be an INI parameter to list those buttons (actually switches) which should be treated as if "changed" initially.

 

 

I've had a look at this, and I can really see no way to add such a facility without jeopardising the stability of FSUIPC. The code for handling button changes is now very old and has grown to encompass virtual buttons, POVs, Goflight and VRI devices, and many of these things also on WideFS clients. Handling it all correctly without making an error is really not something I want to risk at this stage.

 

So, the only answer is to use a Lua plug-in. I thin this would be more efficient and more flexible also, in that not only could you have it running automatically each time you loaded a different aircraft, you could also have a button or keypress to run it so you could synchronize buttons and aircraft switches at any time. To start you off I've made a template / example. You'd need to put the Product and Vendor names in (use HidScanner to find those -- see the Lua thread in Download Links subforum) and then add the programming for the actions you need in the case of each Switch being on or off.

 

Here I've done it for a GoFlight 8-toggle switch panel, the GF-T8:

Vendor = "GoFlight"
Product = "GF-T8"
Device = 0  -- Multiple devices of the same name need increasing Device numbers
Switches = 8 -- Number of switches to check

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

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

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

-- 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)            
    buttonbit = 1
    j = 0
    while j < Switches do
       if logic.And(Buttons, buttonbit) ~= 0 then
          -- HERE DO WHATEVER ACTION IS NEEDED WHEN SWITCH j IS ON
          -- E.G ipc.control, or ipc.keypress, or ipc.runlua, or ipc.macro, etc.
       else
          -- HERE DO WHATEVER ACTION IS NEEDED WHEN SWITCH j IS OFF
          -- E.G ipc.control, or ipc.keypress, or ipc.runlua, or ipc.macro, etc.
       end
       j = j+1
       buttonbit = 2 * buttonbit
    end
end
com.close(dev)

Save your result as a lua file in the FS Modules folder (eg scanT8.lua for this one), and either assign a keypress or button to "Lua scanT8" (or whatever), or, for automatic action, add [Auto] section(s) to the INI file containing

 

1=Lua scanT8

 

Hope this is clear? Let me know how you get on -- it might be worth adding this into one of the SunForum's as a helpful permanent hint.

 

Regards

Pete

Link to comment
Share on other sites

Hi Pete!

Thanks for your effort to help!

 

I’ll look into this and hopefully I can sort it out. (: I have no experience of Lua at the moment, but I’ll dive into this to try to get a grip on it.

I may be a little “slow” , but to be sure I get this right, what you are saying is that the Lua plugin can read the status of the switches and set the aircraft accordingly? The normal operation of switches during flight will still be handled by FSUIPC as they are today?

This certainly opens up possibilities.

 

Thanks!

Regards Frode

Link to comment
Share on other sites

... what you are saying is that the Lua plugin can read the status of the switches and set the aircraft accordingly? The normal operation of switches during flight will still be handled by FSUIPC as they are today?

 

Yes, just look at the example. Documentation for the functions there is found in the Lua library PDF in the Lua package in your FSUIPC Documents folder.

 

Pete

Link to comment
Share on other sites

Hi, I’m heading over to our sim this afternoon to try out the scripting. I think I get the programming part where I isolate the correct bit for determining status of the switch and looping thru the switches. Beein a FSUIPC noviceI’m a little confused about the controls and parameters. Here is a part of your template with a ipc.control statement inserted.

 

 while j < Switches do
       if logic.And(Buttons, buttonbit) ~ 0 then
          -- Button 1, Master ALT = ON
          ipc.control(66242, 1)
           ipc.log("Master ALT set to ON")
          -- E.G ipc.control, or ipc.keypress, or ipc.runlua, or ipc.macro, etc.
       else
          -- Button 1, Master ALT =  OFF
          ipc.control(66242, 0)
          ipc.log("Master ALT set to OFF")
          -- E.G ipc.control, or ipc.keypress, or ipc.runlua, or ipc.macro, etc.
       end

Is it possible to control a toggle in this manner? Or will it just go to the opposite state whenever it’s invoked. Many of the controls I need exist only as a toggle.

Regards

Frode

Link to comment
Share on other sites

Is it possible to control a toggle in this manner? Or will it just go to the opposite state whenever it’s invoked. Many of the controls I need exist only as a toggle.

 

 

No. The "toggle master alternator" control will ignore the parameter. All Toggle controls do is toggle.  If you want a definite on or off action you'd either have to control is by writing to fSUIPC offsets, or at least determine its current staste by reading FSUIPC offsets.

 

The offset list is provided in your FSUIPC Documents folder. I just searched for Alternator and came up with:offset 3101, a 1 byte offset. So you could try:

 

ipc.writeUB(0x3101, 0) -- turn alternator off

ipc.writeUB(0x3101, 1) -- turn alternator on

 

"UB" here means "Unsigned Byte".  Other types of values have their own abbreviations as described in the Lua library documentation.

 

You'll find similar solutions to most other toggle controls.

 

Pete

Link to comment
Share on other sites

Dear Peter, thanks again!

 

One more thing if I may.

The script fails on this statement:

 

          if logic.And(Buttons, buttonbit) ~ 0 then

 

Syntax checker says: 'Then' expected near '~' (41) 

 

FSUIPC log says the same

 

Sorry for pestering You!

 

Regards Frode

Link to comment
Share on other sites

The script fails on this statement:

 

          if logic.And(Buttons, buttonbit) ~ 0 then

 

Syntax checker says: 'Then' expected near '~' (41) 

 

The symbol "~" is not correct here. You want "not equals to" which is ~=.

 

I see it was my fault, a typo in my original (now fixed). You'll see in a few lines before the use of ~= for "not equals".

 

Pete

Link to comment
Share on other sites

Hi again, New hurdle on my way for this script..

I have run hidscanner, and here is the output for the 32Digital board-

 

Vendor=0D59, Product=0120 (Version 0.1)

  Manufacturer= TRC

  Product= TRC 32DIGITAL IN 00

  Serial Number=

  Usage Page: 1

 

I have tried all combinations and Vendor and Product, with and without quotes in the script, but it reports that it can not open HID.

Am I missing something here?

Thanks

/Frode

Link to comment
Share on other sites

I have run hidscanner, and here is the output for the 32Digital board-

 

Vendor=0D59, Product=0120 (Version 0.1)

  Manufacturer= TRC

  Product= TRC 32DIGITAL IN 00

  Serial Number=

  Usage Page: 1

 

Is that all there is for the device? No details of report lengths, input and output values etc?

 

I have tried all combinations and Vendor and Product, with and without quotes in the script, but it reports that it can not open HID.

 

Can't you show me what "combinations" you tried? As far as I can see there's only

 

Vendor=0x0D59

Product=0x0120

 

or

 

Vendor="TRC"

Product="TRC 32DIGITAL IN 00"

 

though you could shorten the last to something like

 

Product="32DIGITAL"

 

if you wanted. Providing it's unique.

 

Pete

Link to comment
Share on other sites

Hi Pete, hope you have some patience left for newbie questions..

I’m still fiddling with my button read script. I’ve sort of got it to work , but I can’t quite get it to perform consistent.   Sometimes it starts and going thru the looping sequence as designed, other times it just skips to the bottom of the script. Setting FSUIPC to run script in debug mode seems to help. In debug mode it goes thru the switch loop every time. Does this make sense? Will it help to add some delay in the script?

 

An other question, What offset or control should I use to set Carb. Heat on/off? (Single piston engine)

Is the offset 66488 (anti ice eng 1 SET) the same as Carb Heat? Or will the offsets 66030,66029 set carb. Heat on/off?

 

Thanks

/Frode

Link to comment
Share on other sites

Sometimes it starts and going thru the looping sequence as designed, other times it just skips to the bottom of the script. Setting FSUIPC to run script in debug mode seems to help. In debug mode it goes thru the switch loop every time. Does this make sense? Will it help to add some delay in the script?

 

Seems that sometimes the device isn't ready to supply data, so it returns none -- making n = 0 so the program exits. The solution is to place the whole thing in a never-ending loop with a small delay to poll the device regularly. In other woords:

 

Before this:

-- read any data available from the device (only need most recent report)
data, n = com.readlast(dev, rd)

insert

while true do

and before this line:

com.close(dev)

insert

ipc.sleep(200)
end

with a sleep of 200 mSecs you'll be checking it 5 times per second. Adjhust as needed.

 

An other question, What offset or control should I use to set Carb. Heat on/off? (Single piston engine)

Is the offset 66488 (anti ice eng 1 SET) the same as Carb Heat? Or will the offsets 66030,66029 set carb. Heat on/off?

 

 

 

You are very confused still -- you really must differentiate between "offsets", which are tokens (actually places in FSUIPC memory) for data held by and manipulated in FSUIPC, and "controls" (FS calls then "events") which are numbers assigned to buttons and switches and sent to FS to make it do things. Offsets represent data, controls repearesent actions.

 

Offsets range from 0000 to FFFF (hexadecimal), so have a maximum decimal number of 65535 -- but are always referred to in hexadecimal. They are listed in the Offserts List in your FSUIPC Documents folder.

 

Controls can be almost any number, and also have names -- all of the FSX controls are listed in the List of FSX Controls document in your FSUIPC Documents folder, but there are also lots of ones added by FSUIPC and other add-ons like the PMDG 737NGX.

 

In Lua, offsets are read by ipc.readXXX functions and written by ipc.writeXXX functions, where XXX defines the type of value -- byte, word, string, etc etc.

In Lua, controls are sent to fS using the ipc.control function.

 

I'm sure I've tried to make this clear before!

 

I'm afraid I don't know which control your aircraft uses. Maybe either. Why not simply log controls in FSUIPC and operate it on the panel, then see which control it used?

 

Pete

Link to comment
Share on other sites

Hi, The script is working like a charm (: Switches are read and FSX is set accordingly.

One small snag, the Auto function works fine for initial load of FS. The sim comes up with all switches in sync with FSX. A Reset simulation does not trigger the Auto function in FSUIPC.  This is not a big problem as I have a lot of spare switches I can set up to trigger the script after a reset.

 

Big thank you to Pete for pointing us in the right direction and helping my understand (a little) of FSUIPC programming!!

 

Regards

Frode

Link to comment
Share on other sites

One small snag, the Auto function works fine for initial load of FS. The sim comes up with all switches in sync with FSX. A Reset simulation does not trigger the Auto function in FSUIPC.  This is not a big problem as I have a lot of spare switches I can set up to trigger the script after a reset.

 

Correct. I'm not sure what you mean by a "reset", but if you mean a Flight file loading, you could have it triggering on an event. For example, enclose the whole existing code as a functin, i.e.

 

function initswitches()

...

end

 

then add this afterwards:

 

event.sim(FLIGHTLOAD, "initswitches")

 

Then it will stay resident and be executed each time you load a flight. I'm not sure if this will operate initially, for the first flight 9as it might be loaded too late), but if not just also inster

 

initswitches()

 

before the event line so that it will run at least once initially.

 

You can do the same for aircraft changes (but not same aircraft re-loading) by using the AIRCRAFTCHANGE event type instead. See the Lua library document.

 

Pete

Link to comment
Share on other sites

Correct. I'm not sure what you mean by a "reset",

 

Pete

 

We are resetting the sim in two ways. (maybe the actual function in FSX is the same)

We have a pushbutton in the cockpit linked to Sim reset in FSUIPC (66586), we also use Instructor station on a separate PC, IS has a reset simulation function in the Simulator control tab.

 

I’ll look into using a function.

 

Thanks

Frode

Link to comment
Share on other sites

We are resetting the sim in two ways. (maybe the actual function in FSX is the same)

We have a pushbutton in the cockpit linked to Sim reset in FSUIPC (66586), we also use Instructor station on a separate PC, IS has a reset simulation function in the Simulator control tab.

 

I'm afraid I have no idea what that 'reset' does so I can't really help further. There's no specific facility in FS called "reset". You can reload (or 'reset') the current flight (maybe this is what you mean?), or load a different flight, or load an aircraft, or simply close the current flight in which case it goes to the menu.

 

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.