maartentamboer / X-Touch-Mini-FS2020

Control FS2020 with a Behringer X-Touch Mini
https://dev-tty.nl/X-Touch-Mini-FS2020/
MIT License
59 stars 19 forks source link

Global Variables - init #57

Closed SQLSammy closed 3 years ago

SQLSammy commented 3 years ago

Is it possible to add an init section for every aircraft running when aircraft/flight load to

SQLSammy commented 3 years ago

After thinking about it, the last two points are a problem, because sometime we load the tool later in flight. Then it would be needed to detect a preflight load in menu vs. later load in aircraft.

maartentamboer commented 3 years ago

The init for global variables is definitely something I will add to this. Because I have also run into the issue of a variable initially being None. Regarding the aircraft setting, that is a bit challenging because of load times. Basically when you select the aircraft and click fly the simconnect API already notifies which aircraft is selected, but the sim is still loading. So any changes you make are probably overwritten.

SQLSammy commented 3 years ago

The "none" problem was my initial intention for this request

maartentamboer commented 3 years ago

I have 2 options in mind for this. Option 1 enables you to add the variables directly in the config file. Option 2 enables you to call a jinja2 script file.

Option 1 (part of the config_a320.json):

"initialization": {
    "global_variables": [
      {
        "name": "MFD_RANGE",
        "value": 10
      },
      {
        "name": "OTHER_VAR",
        "value": false
      }
    ],
  }

Option 2 (part of the config_a320.json):

"initialization": {
    "on_config_load": "Functions/A320/init.jinja2"
  }

Functions/A320/init.jinja2:

{{ data.set_global_variable('MFD_RANGE', 10) }}
{{ data.set_global_variable('OTHER_VAR', False) }}

Any preference?

SQLSammy commented 3 years ago

I wouldnt split the config to too many files, makes it more complex to share

FraSie commented 3 years ago

I would prefer to have it in one file. I also experiment with assigning the initialization to a button, e.g. pressing button 32 means initialize (so I have the control. In my experiments I sometimes have the problem, that the state of the airplane differs from the state in the python. Initializing would have the advantage, to align them...)

SQLSammy commented 3 years ago

Great idea, button 32 long press = init aircraft, but this can be done already

FraSie commented 3 years ago

...ok, you are right, this can be done already. I think it would be good implement it in a way, that the initialization can be evoked flexible: by an event, like "on_config_load" in option 2 (if I understand it right), or by pressing a button or someting else. It is good to have the initialization in one single block (function, method, ...I am not a python specialist).

reimuell commented 3 years ago

Many of my plane settings habe common rotary/buttons. Is it possible to have a common config file and only plane specific values in other files (other languages have something like a perform) . I'm not talking about global values. Yes I understand the problem of aircraft load time, we would have to wait until the flight/plan is really loaded. thx

maartentamboer commented 3 years ago

Many of my plane settings habe common rotary/buttons. Is it possible to have a common config file and only plane specific values in other files (other languages have something like a perform) . I'm not talking about global values. Yes I understand the problem of aircraft load time, we would have to wait until the flight/plan is really loaded. thx

I've made a seperate issue to track this request regarding the common config file. It is quite a big change so It's probably not coming too soon

maartentamboer commented 3 years ago

This has been released in https://github.com/maartentamboer/X-Touch-Mini-FS2020/releases/tag/v1.5.0 An example can be found in https://github.com/maartentamboer/X-Touch-Mini-FS2020/blob/main/Configurations/config_a320.json#L177 Documentation will be update later