Jump to content
The simFlight Network Forums

Using On/Off button with events


DaveSCUSA

Recommended Posts

I am currently coding myevents.txt to use with a keypress mini keypad. I plan to use Presets to attach the keypad. I want each key to perform two actions based on a keypress. Could you help with a technique to use these keys as an on/off switch. One keypress turns on a variable to use other keypresses as ATC Menu input then turns it off. If the variable is off, another preset is executed. The presets are listed in the attached file.

For most buttons, I want an on/off function. Could you help in how to use the on/off values on one push and off on the next push. Not press and release. I'm not sure how to use a local variable in presets as one would use in a module. I find presets are more accurate and active than some ipc.execCalcCode() executions in Lua.

 

a question. Are input events variable type B:, as in  (B:LIGHTING_POTENTIOMETER_30,  Enum)

Thanks

myevents.txt

Link to comment
Share on other sites

4 hours ago, DaveSCUSA said:

Are input events variable type B:, as in  (B:LIGHTING_POTENTIOMETER_30,  Enum)

I'm sorry, but I don't understand what you are trying to do with the mini-keypad, but perhaps I can help a little until John is available.

1. Yes, the MSFS SDK defines Bvars as input events.

2. looked at your myevents.txt file a bit and would like to mention a few things I don't understand. Just for example, consider the entry:

C510_ATC_2#(>(A:TAILWHEEL LOCK ON, Bool) 1 == if {  (>K:ATC_MENU_2) 0 (K:TAILWHEELOCK)  }

i. Why is there a > in front of the Avar (A:TAILWHEEL LOCK ON, Bool)? You would put a > in front of the A: itself if trying to write a value to an Avar, but the SDK would have to say it was a writeable Avar (although some Avars are writeable, most are not). In this case it does not seem you are even trying to write to the Avar at all.

ii. It looks like you are trying to put a value of 0 into a K event called (K:TAILWHEELOCK). If so, you would need a >in front of the K: (in fact K events routinely have a > in front of the K:).  But in this case I cannot find a K event called TAILWHEELOCK in the SDK. Where did you find that K event?  I did find a K event called TOGGLE_TAILWHEEL_LOCK.

If I'm off base here, sorry and please ignore!

Al

Link to comment
Share on other sites

Thanks. Both typos.

Just looking for a technique to use a key to turn on if off and off in on using the presets. Not sure how to define a local var with the preset code in the myevents.txt file.

I guess I could use lua to define several LVars but was hoping there was a cleaner way.

Also, can the RPN code following the preset name (preset#.....) take more than one line, if so how to indicate a continuation if needed?

Thanks again.

Link to comment
Share on other sites

1 hour ago, DaveSCUSA said:

Also, can the RPN code following the preset name (preset#.....) take more than one line, if so how to indicate a continuation if needed?

My understanding is Presets have to be one line, but can be a long line.

If you want to use a toggle K event like TOGGLE_TAILWHEEL_LOCK, you typicality do not write a value into such K events since executing the K event actions the toggle function.

It may be that simply using an Lvar in a preset in effect defines the Lvar.  I seem to recall that being the case with calculator code, so maybe similar for Presets.

1 hour ago, DaveSCUSA said:

Just looking for a technique to use a key to turn on if off and off if on using the presets.

I"m still not sure what you are saying here. But if you want to toggle the value of an Lvar between 0 and 1 each time a key is pressed, then one way to do this is to assign that key to a Preset similar to:

MyPresetToggleName#(L:myLvar, bool) ! (>L:myLvar, bool)  

Then each time the preset is executed ( the key is pressed) the value of the Lvar will toggle between 0 and 1. I think the initial value of the Lvar will be 0 (and not undefined), but I would have to experiment a bit to confirm that. If it turns out the Lvar is undefined, then you would need to create and initialize it elsewhere before using the preset.

Al

Link to comment
Share on other sites

15 hours ago, DaveSCUSA said:

I find presets are more accurate and active than some ipc.execCalcCode() executions in Lua.

Executing a preset is exactly the same as executing the preset calculator code using  ipc.execCalcCode() - they both resolve to the same underlying function.

15 hours ago, DaveSCUSA said:

a question. Are input events variable type B:, as in  (B:LIGHTING_POTENTIOMETER_30,  Enum)

B-type variables are Input Events, bur not all such variables are currently accessible using the Input Events interface. You cannot control B-vars directly using calculator code.

7 hours ago, DaveSCUSA said:

Also, can the RPN code following the preset name (preset#.....) take more than one line, if so how to indicate a continuation if needed?

No, all on one line.

@ark1320 is correct in his analysis of your calc code presets and how to toggle an lvar.

But looking at your presets in the myevents.txt file they fon'y make much sense. As well as the errors pointed out by @ark1320, why are you using A:TAILWHEEL LOCK ON (and also K:TAILWHEELOCK) for almost everything?

Maybe you could explain one function that you want to implement and I can show you how to do that, and you can take it from there. Note that there are known issues in trying to control the ATC menu - see here for example: https://devsupport.flightsimulator.com/t/sdk-0-23-1-event-id-atc-menu-open-not-recognized/8538

John

 

Link to comment
Share on other sites

5 hours ago, John Dowson said:

As well as the errors pointed out by @ark1320, why are you using A:TAILWHEEL LOCK ON (and also K:TAILWHEELOCK) for almost everything?

Great response, thanks.

I have a key on the keypad that tells the other keys to be used to send an ATC Menu number or, if it's off, send an exec command.

I have two activities I want to execute with each key, a key that push on and release off as in the starter button:

C510_Starter1_On#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  1 (>K:TOGGLE_STARTER1) }

C510_Starter1_Off#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  0 (>K:TOGGLE_STARTER1) }

In another case, I want the key on when pushed and off when pushed again:

C510_Ign1_On#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  1 (>K:TURBINE_IGNITION_SWITCH_SET1) }

C510_Ign1_Off#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  0 (>K:TURBINE_IGNITION_SWITCH_SET1) }

In the first case, I use the key press assignment push for on and release for off, if the ATC selection, TAILWHEEL LOCK ON is off.

Without using an LVar, I'm not sure I can manipulate the action in the second case. Push on then push off.

Is there some other method to accomplish the second activity. I would appreciate it.

If I'm using LVars, I may as well use one to activate ATC pushes.

Is there a way to send a keyboard keypress with a preset like you can in Lua? There is an entry to bypass windows with a keypress in the FSUIPC7.ini file. May I assume that FSUIPC7 intercept the keypress and sends it directly to MSFS? 

Is a semi-colon used in events for a comment line or can there be just a blank line between the presets?

One comment on assignments thru the UI. It would be more efficient if a searched control could appear at the top of the list instead of the bottom. Often the control is beyond the results of the search unless one keys in the whole control name.

Thanks

Link to comment
Share on other sites

2 minutes ago, DaveSCUSA said:

Is there a way to send a keyboard keypress with a preset like you can in Lua?

Yes, by using the key assignments panel, and checking Select for Preset. Are your key presses recognised in that window? It has been reported that some special keyboard-type controllers (i.e. controllers that send key presses but are not actual keyboards) can have issues with key assignments. To fix this, you can use a keyboard hook by setting:
     UseKeyboardHook=Yes
in the [General] section of your FSUIPC7.ini file.  Don't set this if the keys are recognised without this setting.

8 minutes ago, DaveSCUSA said:

There is an entry to bypass windows with a keypress in the FSUIPC7.ini file.

Not sure what this means...

8 minutes ago, DaveSCUSA said:

May I assume that FSUIPC7 intercept the keypress and sends it directly to MSFS? 

FSUIPC7 normally receives key presses from MSFS to trigger its key press assignments. It only sends key presses when configured to do so, and will only get the key presses from windows (not MSFS via simconnect) if a keyboard hook is being used.

I don't have time to look into your other questions at the moment, I will take a look tomorrow. But why are you checking the status of the tail lock before controlling the starter/ignition? And rather than checking this in the preset, you can use an offset condition in offset 0z2A90 (see Advanced User guide for details on how to use offset conditions).

More tomorrow....

John

Link to comment
Share on other sites

7 hours ago, John Dowson said:

Yes, by using the key assignments panel, and checking Select for Preset. Are your key presses recognised in that window? It has been reported that some special keyboard-type controllers (i.e. controllers that send key presses but are not actual keyboards) can have issues with key assignments. To fix this, you can use a keyboard hook by setting:
     UseKeyboardHook=Yes
in the [General] section of your FSUIPC7.ini file.  Don't set this if the keys are recognised without this setting.

Not sure what this means...

FSUIPC7 normally receives key presses from MSFS to trigger its key press assignments. It only sends key presses when configured to do so, and will only get the key presses from windows (not MSFS via simconnect) if a keyboard hook is being used.

I don't have time to look into your other questions at the moment, I will take a look tomorrow. But why are you checking the status of the tail lock before controlling the starter/ignition? And rather than checking this in the preset, you can use an offset condition in offset 0z2A90 (see Advanced User guide for details on how to use offset conditions).

More tomorrow....

John

Thanks John,

I set the tail hook to true in the apron.cfg and hangar.cfg files. All other .cfg files (runway.cfg, cruise.cfg, etc.) is set to false.

I couldn't find a MFSF variable that could tell me whether a flight is prestart cold or started. I use this to tell the difference. So I can use the start checklist to start the aircraft. And since I prefer using switch and button panels instead of a mouse in the cockpit, I use as many techniques as possible to engage the sim with buttons and switches.

Also, in one case, the DA62, of an aircraft I like to fly, the internal developed templates start of a flight on the apron has some controls already turned on that the real aircraft would turn off at shutdown (e.g. fuel valve, Pitot Heat, etc.). I turn them off when the aircraft starts on the apron or hangar. Using the complete manufacturer provided (not MSFS provided) checklist.

I haven't been able to find how to set an offset using the preset code.

I prefer to keep all buttons/switches from a piece of hardware in the same media. Yoke and throttle buttons set thru button assignments to FSUIPC controls or presets (using presets where I would use ipc.execCalcCode() in Lua (e.g events or variables with 2 indices). Or in the keypress case, where an activity is dependent on the action of another keypress.

I learned how this could be done with buttons in the Appendix but can't find out how with keypress input.

Many of us cockpit builders are choosing these keypads. They can be programmed to output keypress combinations. And they are much cheaper than Flight Sim button hardware. $34 for a keypad vs. $1,000 for a CDU. One pad I have has rotary switches which sends a specific keypress on a click in a direction. I can increase or decrease for example ADF input. And using the pushbutton in the rotary, one can tell the sim to increase or decrease the unit by 1, 10, 100, 1000 depending on the use.

Link to comment
Share on other sites

13 hours ago, John Dowson said:

 

@ark1320  @ark1320

Note that there are known issues in trying to control the ATC menu - see here for example: https://devsupport.flightsimulator.com/t/sdk-0-23-1-event-id-atc-menu-open-not-recognized/8538

 

PS - I'm not using ATC menu on or off in a preset. I have a button on one throttle handle to toggle the menu. The presets are to send ATC_MENU_0 to 9 commands to MSFS. The above url states that the ATC_MENU_x commands work.

If I push button 1 (to send an ATC Menu command) button 2 will send ATC_MENU_0 and clear button 1. If button 2 is pushed and button 1 hasn't been pushed, button 2 will engage the starter for the left engine. Once released, then the starter is shut down. Also, the starter will shut down after 20 seconds or when N1 reaches a certain value.

Link to comment
Share on other sites

10 hours ago, DaveSCUSA said:

I haven't been able to find how to set an offset using the preset code.

You cannot do this. Offsets are in FSUIPC7 only, and calculator code is executed in the FS. To change an offset that holds a simvar (a-type variable), then you would just set that variable and this would then update the corresponding offset.

10 hours ago, DaveSCUSA said:

I learned how this could be done with buttons in the Appendix but can't find out how with keypress input.

As I said, use the key assignments dialog. And if the key presses are not recognised, you will have to try with a keyboard hook.
 

17 hours ago, DaveSCUSA said:

I have two activities I want to execute with each key, a key that push on and release off as in the starter button:

C510_Starter1_On#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  1 (>K:TOGGLE_STARTER1) }

C510_Starter1_Off#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  0 (>K:TOGGLE_STARTER1) }

Looks like you haven't taken @ark1320's comments into account. You don't need the '>' symbol when reading an simvar (only for setting), and the k event TOGGLE_STARTER1 does NOT take a parameter (at least according to the documentation https://docs.flightsimulator.com/flighting/html/Programming_Tools/Event_IDs/Aircraft_Engine_Events.htm). So they should be:
    C510_Starter1_On#(A:TAILWHEEL LOCK ON, Bool) 0 == if { (>K:TOGGLE_STARTER1) }
    C510_Starter1_Off#(A:TAILWHEEL LOCK ON, Bool) 0 == if { (>K:TOGGLE_STARTER1) }
but then they are exactly the same!

17 hours ago, DaveSCUSA said:

In another case, I want the key on when pushed and off when pushed again:

C510_Ign1_On#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  1 (>K:TURBINE_IGNITION_SWITCH_SET1) }

C510_Ign1_Off#(>A:TAILWHEEL LOCK ON, Bool) 0 == if {  0 (>K:TURBINE_IGNITION_SWITCH_SET1) }

If you want a toggle function on a button for this, then you would need to know the current state of the ignition switch. Maybe try TURB ENG IGNITION SWITCH:index or TURB ENG IGNITION SWITCH EX1:index (see https://docs.flightsimulator.com/flighting/html/Programming_Tools/SimVars/Aircraft_SimVars/Aircraft_Engine_Variables.htm). Also maybe take a look how these work in the presets defined for other aircraft - for example, this is the calc code for the C208 Engine Starter Switch Start preset:

1 s0 (A:TURB ENG IGNITION SWITCH EX1:1, enum) != if{ 
   l0 (>K:TURBINE_IGNITION_SWITCH_SET1) } 
(A:GENERAL ENG STARTER:1, Bool) ! if{ 1 (>K:SET_STARTER1_HELD) } 

I can and do help out with preset definitions when I have time, but I am very busy at the moment with various issues and don't really have time for this at the moment. The best place to discuss presets for specific aircraft would be on the HubHop discord server, in the msfs2020 channel. Otherwise I can take a deeper look maybe later in the week (or next week), when things calm down a bit...

If you only want your assignments to work when the tailwheel lock is off, it is better to remove this check from the actual presets and add this as an offset condition to your assignments. So remove this check from your preset code for the time being. Once your assignments are working, you can add an offset condition to your FSUIPC7.ini. To do this, find the assignment, e.g.:
    46=PS,14,CPC510_Starter1_On,0     -{Preset Control}-
then add an offset condition for the tailwheel lock which is 0x2A90:
     46=D2A90=0 PS,14,CPC510_Starter1_On,0     -{Preset Control}-

John

 

Link to comment
Share on other sites

Which aircraft are you actually using? There is no Asobo C510, as far as I am aware. I have the Cockspur C510 Mustang, and for the starter/ignition switches for this aircraft you should use the Input Events, not presets:
    ENGINE_Starter_1<;FLOAT64>
    ENGINE_Starter_2<;FLOAT64>
    ENGINE_Starter_Disengage<>
    ENGINE_Ignition_1<;FLOAT64>
    ENGINE_Ignition_2<;FLOAT64>
Input Events are used to control the B-type variables, which you cannot use via calculator code.

Link to comment
Share on other sites

You are right, Cockspur vs. Asobo. Oversight during copy and I changed them.

As far as the coding of >K: and >A:, I was using events.txt for examples:

PA24_250_Pitot_Heat_Off#1 (>K:PITOT_HEAT_OFF)
PA24_250_Pitot_Heat_On#1 (>K:PITOT_HEAT_ON)

PA24_250_Primer_Prime#1 (>K:TOGGLE_PRIMER1)

Please let me know where and how to use ENGINE_Starter_1<;FLOAT64> or ENGINE_Ignition_1<;FLOAT64>. I know how to assign the input events in the Assignment UI to a keypress but don't see how to use the key to press to on and the second press to off.

As I said, I use input techniques by hardware unit. E.g. Honeycomb Alpha switches uses the button assignments to FSUIPC controls. For the keypad, I prefer to use Presets. One to tie one key to other keypresses and, two, to perform (variable) x == if { condition } to know if the previous press was on or off. I find once you use preset, then fs control assignment, then hardcode a keypress in FSUIPC7.ini, one loses track of where a button or keypress is defined and assigned for the hardware units.

Where else can one manipulate input events, e.g. add or subtract a value to an input event. The Cockspur C510 input to modify the brightness of the panel light is input event LIGHTING_PANEL_1. The brightness of the Display is input event LIGHTING_POTENTIOMETER_30. Both have values 0 to 100. I have two rotary switches on the keypad left or right rotation. Each click sends a key combination. I want to change the value of the above input events by 10, left - 10, right + 10. Can't figure out how to do it in FSUIPC other than an Lua.

Mobiflight and Air Manager both can manipulate input events but can't take keypad/keypress input. FSUIPC does a great job with keypresses but how to manipulate input events.

Thanks, John.

Link to comment
Share on other sites

1 hour ago, DaveSCUSA said:

As far as the coding of >K: and >A:, I was using events.txt for examples:

PA24_250_Pitot_Heat_Off#1 (>K:PITOT_HEAT_OFF)
PA24_250_Pitot_Heat_On#1 (>K:PITOT_HEAT_ON)

PA24_250_Primer_Prime#1 (>K:TOGGLE_PRIMER1)

Some events take a parameter (e.g. all *_SET events), others not. If you do not know, check the documentation: https://docs.flightsimulator.com/flighting/html/Programming_Tools/Event_IDs/Event_IDs.htm
Those presets are incorrect as those events do not take a parameter. They will work, but the parameter is not necessary and is ignored.

1 hour ago, DaveSCUSA said:

Please let me know where and how to use ENGINE_Starter_1<;FLOAT64> or ENGINE_Ignition_1<;FLOAT64>. I know how to assign the input events in the Assignment UI to a keypress but don't see how to use the key to press to on and the second press to off.

If you want different/alternating commands to be sent on successive keypresses, you would need to overload the key press assignment (i.e. have both assignments on the same keypress) and then use an offset condition to only send one of these at a time, depending on the state of the offset. So, for the ignition switches,  for example, you can use offset 0x02C0 (TURB ENG IGNITION SWITCH EX1:1) for the left switch, and 0x02C1 for the right switch. These offsets will hold 1 when the switch is off/NORM, and 2 when on.

1 hour ago, DaveSCUSA said:

Where else can one manipulate input events, e.g. add or subtract a value to an input event.

You cannot currently read the value of an Input Event- this is something I would like to add. You need to determine if there is something else that also holds the value (a simvar or lvar) and use that - as I showed above with the ignition switch.

1 hour ago, DaveSCUSA said:

The Cockspur C510 input to modify the brightness of the panel light is input event LIGHTING_PANEL_1. The brightness of the Display is input event LIGHTING_POTENTIOMETER_30. Both have values 0 to 100. I have two rotary switches on the keypad left or right rotation. Each click sends a key combination. I want to change the value of the above input events by 10, left - 10, right + 10. Can't figure out how to do it in FSUIPC other than an Lua.

It is easier to use an axis for such controls, and you would assign the axis value to an offset and use a lua script to pick-up changes to the offset value, calibrate this to the required range and then  send the input event with the calibrated parameter. If using a rotary, this will use buttons and you need to use button assignments, and you will need to know the current  value so that it can be incremented/decremented. 

Note that LIGHTING_PANEL_1 is also available as an lvar, so it would be easier to use this. Just add that to  a free/spare FSUIPC offset (using the facilities provided), and then you can just assign your rotary buttons assigned to the offset inc/dec controls.

Link to comment
Share on other sites

1 hour ago, John Dowson said:

Note that LIGHTING_PANEL_1 is also available as an lvar, so it would be easier to use this. Just add that to  a free/spare FSUIPC offset (using the facilities provided), and then you can just assign your rotary buttons assigned to the offset inc/dec controls.

This lvar holds the correct value, but if you manually change the value of this lvar it does not change the lighting. Therefore you cannot use this to control the lighting, but you  can use it to get the current value of the lighting, then increment/decrement this and send the new value via  an Input Event. You would need to write a lua script to do this. The script should wait for a button press on your rotary buttons (event.button), and in the button press handling function it can read the current lvar value (ipc.readLvar), inc/dec the value to the new value and then send this on using ipc.execInputEvent.

Link to comment
Share on other sites

@DaveSCUSA Have you managed to set this up yet (and I can consider this closed) or are you still having issues? If so, please let me know and I can provide further details on how to configure assignments for the C510.

I will soon be looking into updating the Input Event functionality to store the current values of the Input Events, and this will make incrementing/decrementing these far easier. But until then, work-arounds are necessary for this.

John

Link to comment
Share on other sites

Hi John, Sorry I haven't answered. I'm still struggling with communicating with the C510. I changed the communication to button and kepress programming in the profile C510.ini. The entries, for the most part, exercise presets.

Nothing seems to work. Can't see a log entry to show that a profile is used. I'll be testing more tomorrow. I'll move the programming back to the FSUIPC7.ini.

I moved the switches off the Luas to the profile programming for the Alpha, Bravo and Keypad. As I said, nothing seems to work. The events show in the log. 

I am also using a C510 panel from Air Manager I downloaded and tested on a tablet. It works fine. I used the same MSFS Events and Variables that AM uses. An example, the battery, AV, Alt1 and Alt2 switches on the Alpha. The AM switches turn the PFD and MFD turns on (also the cockpit animation). The Alpha switches do not.

I also turned on the buttons and keys log functions but don't know how to interpret the log entries.

I am not near a PC right now (my phone). After I yest tomorrow, I'll send FSUIPC7 files.

Thanks

C510 Panel.png

Link to comment
Share on other sites

Today I found maybe i messed up as the profiles in the Profiles folder weren't working. Not sure why. 

I moved the button definitions to the FSUIPC7.ini file outside the profile and seemed to work with some bugs. 

I'll test more tomorrow.

Thanks 

Link to comment
Share on other sites

9 hours ago, DaveSCUSA said:

i messed up as the profiles in the Profiles folder weren't working.

Are you using "profiles in separate files" then? The usual reason for profiles not loading is that the aircraft name doesn't match the names of the aircraft in the profile entry, usually due to a different livery being used. To prevent this, when you add an aircraft to a profile, you should edit the name of the aircraft in the profile section of the ini file to a shorter substring to catch all variants of the aircraft. This is my entry for the C510:

Quote

[Profile.C510]
DontLogThese=67227,65568,65962,66523
1=Cockspur C510

The profile used is not logged, but if general button or key definitions are overridden by a profile, then this should be logged.

If you are having issues, please explain and attach both your FSUIPC7.ini, your FSUIPC7.log and also your profile ini, if using profiles-in-separate-files.

John

Link to comment
Share on other sites

Thanks John,

I became familiar with Air Manager. Their code is in Lua. I use it to test (there is a C510 panel). Variables, Events.

I use FSUIPC7 for it's keypress capability.

I noticed the DontLogThese in the profile.

Got the button/keypress programming to work. Now struggling wit the keypress to Lua. 

No need to answer this post. I'll start a new topic after further testing.

Thanks again

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.