BitsAndDroids / FlightConnector-Rust

Connect and interface your diy hardware to mfs2020.
3 stars 0 forks source link

User Support: Custom Input or Predefined Input #168

Closed elliotth30 closed 4 months ago

elliotth30 commented 5 months ago

Hey there, sorry to bother you again!

Been following the updates and really great to see, currently working on my project and thoroughly enjoying using the connector and library.

I had a question regarding a specific input and was unable to tell if it was already implemented into the library and thought I best check before reinventing the wheel - as I want to make sure it's as applicable to as many aircraft as possible.

I am trying to use a custom input to control the "Altimeter Calibration", but I also wanted to check if you knew if the "connector.getIndicatedAltitude()" is directly connected to this or if the game has a variable for like a global altitude. Sorry to bother but thought you may immediately know the answer? I did see something about "KOHLSMAN_SET" etc and was wondering if this is somewhere you may start?

I have attached a screenshot of the input.

alt-calibrated

After looking through your docs regarding custom events, if there is not a native way of doing it I see two approached:

  1. Reading the current altimeter setting, and then outputting an increase or decrease based on my encoder's movement (i.e read x = 950, then x = x + 10).

  2. Automatically adding or subtracting from the current altimeter setting based on the direction of the encoder movement (using an action).

Apologies I'm just trying to wrap my head around the documentation and hope you're able to help. Thanks again for all the work you've put into this. It clearly shows.

Thanks Again, Elliott H

BitsAndDroids commented 5 months ago

Hi Elliot, no need to apologize. I do believe the kohlmans set command might be what you're looking for. If I'm not mistaken this functionality was implemented last week (but forgot to document it so that is why you couldn't find it). I'll take a look tomorrow morning and post an update here (and the docs) on how to use it. Just to be sure what aircraft are you using? I'll have a look if it uses the default or requires a custom command.

elliotth30 commented 5 months ago

Thank you very very much! greatly appreicated. I am very capable with microcontrollers but realising I am way out of my depth with the sim knowledge - thought it would be a "how hard can it be" haha.

I also wanted to check a few things. With a custom output. I have made one, as seen in the screenshot below that I believe will read a value I am after.

My question is, within my microcontroller code, how do I retrieve this? I am sure it'll be along the lines of 'connector.getID(8000);' or something of the lines, but just wanted to confirm! :)

Custom-Calibrated-Reading

Thanks again!

BitsAndDroids commented 5 months ago

Today I've added the option to generate a custom library that contains your events. https://bitsanddroids.github.io/FlightConnector-Rust/ch07-01-library-generator.html if you use the custom library you should be able to retrieve the value with connector.getOutput8000(). But since this is a default simconnect event I will also add it to the default outputs (should be 1 minute work done in the morning).

BitsAndDroids commented 5 months ago

So, as promised, an update. I've added three new functions to the library:

  1. sendSetKohlmanAltimeterInHg(float value) // sets the value based on the inhg value passed -> converts it to MB -> multiplies by 16 (the sim expects the *16)
  2. sendSetKohlmanAltimeterMb(float value) // sets the value based on the Mb value passed (*16 see above)
  3. getIndicatedAltitudeCalibrated() //returns the indicated altitude calibrated

Regarding your use case, I'd recommend either going the route of setting the altimeter manually or using the 2 other functions:

  1. connector.send(sendKohlmanInc) / connector.send(375)
  2. connector.send(sendKohlmanDec) / connector.send(376)

After second thought, in your case, the increment-decrement commands should be the way to go when using an encoder. Setting the values directly would better suit other input methods like a touchscreen or Numpad.

I usually use the encoder library for ease of development. In this blog post, I've included an example demonstrating how I implement the com frequency. Theoretically, your problem can be solved by replacing the send(com1Inc..) with the abovementioned events.

The indicated altitude should reflect the changes when changing the altimeter. If you provide the name of the plane you're using, I can find out if it uses generic events or if they implemented some custom commands.

elliotth30 commented 5 months ago

Thank you so much for this that's super super appreciated. Really looking forward to having a go this evening after work. Regarding the plane I am using it's either one of the stock two gliders for msfs2020.

Really again, I appreciate the help!

BitsAndDroids commented 5 months ago

Ah... Good news and bad news. I tested that specific plane, and it uses another implementation besides the default. But it can be altered using a custom command: Increase:

2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 + 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

Decrease:

2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 - 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

There might be another more straightforward command that needs to be documented, but these should do the trick. I believe this takes the current value from the instrument and increments/decrements before passing it back to the instrument. image

elliotth30 commented 5 months ago

Thank you so much for really taking a look into this, so just to confirm in this case I would be running connector.send(6666) (for the example you've set, obviously this can of course be any ID number)

I just wanted to confirm that for the custom commands it would be something like this:

(INPUT) connector.send(ID_NUM) (OUTPUT) connector.getOutput8000()

Apologies once I wrap my head around this I can the possibilities really open up! Thanks again!

BitsAndDroids commented 4 months ago

Exactly! If you change the ID, you have to regenerate the library to match the IDs. so connector.send(6666) //or another id. For outputs connector.getOutput6666()// or another id.

elliotth30 commented 4 months ago

Hey there Dave, super it! Sorry I've only just had some time to get back on this, when I last tried the custom send seemed to work (but didn't have the WASM installed - so couldn't tell for sure, but got the logs to show that it was recieved.)

Regarding the calibrated altitude mind, it didn't get any readings what so ever when I implemented the connector.getIndicatedAltitudeCalibrated(); which made me think this was not the correct ID for at least this particular aircraft. I am just downloading a 15GB update so will test it again shortly.

I was wondering if you could reccomend any tutorials, process or tools that would allow me to sniff the output being used by a particular display so that I can match the same custom ID?

Thanks again!

elliotth30 commented 4 months ago

Okay so! Using Spad.next I've managed to use their data monitor to see that it is linked directly to INDICATED ALTITUDE:2, alongside the readings for the button inputs, now just to work out how to map them!

Receiving data from instruments: alt_test_1 alt_test_2

Adjusting the dial: alt_test_3

elliotth30 commented 4 months ago

Okay, so after quite a disappointing day of trial and error, this where I am at.

My first question is, does the connector support SIMCONNECT commands?

After some investigation the target variable I would like to read and write to (both are possible with this variable) is SIMCONNECT:KOHLSMAN SETTING MB

As can be seen here, when I alter the value it updates in the game just as I'd like.

adjusting-calibration_1 adjusting-calibration_2

However when applying this to two custom commands, I just can't seem to get it to do anything:

adjusting-calibration_3

it does get registered and have tested with different custom commands that the signal is being read from the arduino and changing the game, but just can't get these commands to work - as can be seen in the connector logs:

data-sending

Any idea on how I could fix this as this would definitely be the command route that I would like to go for as its so simple:

(SIMCONNECT:KOHLSMAN SETTING MB, Number) 1 + (>SIMCONNECT:KOHLSMAN SETTING MB)

(SIMCONNECT:KOHLSMAN SETTING MB, Number) 1 - (>SIMCONNECT:KOHLSMAN SETTING MB)

I'm really hoping that the SIMCONNECT can work as I've also managed to find my VARIO reading that I would need also:

SIMCONNECT:VARIOMETER RATE

Any ideas would be greatly appreciated. I am hoping that I have just not formatted it correctly!

BitsAndDroids commented 4 months ago

The simconnect sdk doesn't have variables that are prefixed with SIMCONNECT. I'm assuming spad.next translates these to the plain simconnect commands. I believe the correct command would be (A:KOHLSMAN SETTING MB:index, Millibars) and {val} (>A:KOHLSMAN SETTING MB:index, Millibars) to set the value (I'd have to check later to see if this is the correct command).

I know for sure these work: 2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 + 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 - 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

I'll add some screenshots on how to check these commands in game as well. Plus this site has loads of premade commands made by others https://hubhop.mobiflight.com/presets/

elliotth30 commented 4 months ago

Just to confirm I have tried the commands you recommended me:

2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 + 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

2 (L:INSTRUMENT_Altimeter_2, Number) 0.3125 - 914 max 1083 min s0 16 * (>K:2:KOHLSMAN_SET) l0 (>L:INSTRUMENT_Altimeter_2)

but neither worked. But does pickup as readings in the MSFS2020 dev panel.

adjusting-calibration_4

The connector.send(sendKohlmanDec) & connector.send(sendKohlmanInc) control a seperate parameter as I believe you already worked out.

Any idea as to why this could be if it worked for you? I am starting to wonder if any of the custom commands have worked at all.

BitsAndDroids commented 4 months ago

what does it show if you open the console under the debug tab i believe (top of that menu) it should show the events being registered when you start the connection. Or at least it should show that the module is properly installed.

elliotth30 commented 4 months ago

I've loaded up the console and searched "bits" and nothing has come up.

1

fiddling with inputs, nothing appears. Thanks for your help - i did not get anywhere near as much as I wanted to get done today haha

BitsAndDroids commented 4 months ago

That might explain the issues. In your mfs community folder. Is there a folder called BitsAndDroidsModule.

BitsAndDroids commented 4 months ago

The path should look something like this: C:\Users{YOUR NAME}\AppData\Local\Packages\Microsoft.FlightSimulator_8wekyb3d8bbwe\LocalCache\Packages\Community

elliotth30 commented 4 months ago

Can confirm it should be in the right place, this is where it was/is installed:

2

But to confirm, do I have to resinstall the folder every time, as I can't see my custom commands in the events.txt

BitsAndDroids commented 4 months ago

No the events.txt is an old remain that isn't used anymore. But the updater has it stored somewhere so places it in the folder. But it does no harm being there. Just to rule things out. Did you install it with the sim open (and haven't restarted since)? The sim only loads the modules on startup. There's also the WASM debug window that shows if the module is installed correctly image

The correct boot logs should be image

And last the structure of the folder should be: BitsAndDroidsModule -> [modules folder, layout.json, manifest.json] -> modules folder has 2 files event and .wasm

elliotth30 commented 4 months ago

I think I have found something that could perhaps be an issue, it appears to be reading a completely different community folder so will try installing the bits and droids wasm there in addition and check back - will see if theres a way of seeing whre MSFS2020 is expecting it

3

Heres the WASM menu 🤦🏻‍♂️

4

BitsAndDroids commented 4 months ago

That's an interesting find. Never seen that path used before.

BitsAndDroids commented 4 months ago

That little dropdown in the menu is empty if you click on it?

elliotth30 commented 4 months ago

It's weird as it definitely populated with bitsanddroids a couple of hours ago, but restarted the game before taking that screenshot and yes is an empty drop down. but even earlier when it was popupulated, it was litterally just the name and no other detail. I've installed it there too, just reloading the game now. fingers crossed!

BitsAndDroids commented 4 months ago

I believe the path screenshot might be the missing link. On mine it shows the full community folder path. So perhaps on your machine it has to be in the xbox/comunnity path. image

elliotth30 commented 4 months ago

IT FUCKING WORKS!

5 6

to think i've been writing different commands all day hahah - well now I am happy.

One last thing to ask for now - sorry about this, really really appreciate your help by the way.

My next task is to attempt to read the readings from SIMCONNECT:VARIOMETER RATE and INDICATED ALTITUDE 2 as this is the reading that works for this aircraft. Any idea on that or a better way to do this?

I assume the command for INDICATED ALTITUDE 2 would be similar to the first one?

You can see the difference in value on this one: 7

6

BitsAndDroids commented 4 months ago

Pfew glad to hear. Will update the docs to indicate there are multiple possible locations. The (A:VARIOMETER RATE,Feet per second) should be the variometer. I believe you can just swap out the part after the A:.

BitsAndDroids commented 4 months ago

Will check tomorrow if those are default outputs as well that I can add.

BitsAndDroids commented 4 months ago

Btw yesterday somebody told me that making changes to the outputs might sometimes require a restart of the Sim. I'm currently looking into the cause of that.

elliotth30 commented 4 months ago

Thanks again and thats good to know! I've managed to get my correct speed coming in now which is great and the dial so that a whole instrument finished haha, now just multiple more. Really pleased with this so far and genuinely really appreciate all your help and efforts!

BitsAndDroids commented 4 months ago

Release 0.3.17 will be out in a few minutes. It contains new outputs for the indicated altitude:2 and variometer rate. The library has received these functions as well (they are in the release notes). If any other variables are missing, please let me know. I usually add them on demand (there are so many outputs that I can't judge them all if they are useful). I'll close this issue for now, but if you have any further questions, feel free to open a new issue! I love the feedback and questions.