charliefoxtwo / TouchDCS

An application for interfacing with DCS-BIOS using TouchOSC (or potentially other OSC applications).
GNU General Public License v3.0
35 stars 2 forks source link

Adding multiple OSC devices to the config.json #14

Closed ghost closed 2 years ago

ghost commented 2 years ago

I am having trouble adding more devices to the config.json. My programing skills are 0, sorry. How could I add a second device here? I tried various things but always results in crashing and errors.

"osc": {
    "devices": [
      {
        "ipAddress": "192.168.3.78",
        "sendPort": 9000,
        "receivePort": 8000
      }
          ]

Thank you, awesome software :D already creating my second template and I love it.

charliefoxtwo commented 2 years ago

Just add another block inside of the square brackets, and make sure there's a comma between them. Something like the below example should work. Of course you can make the ports whatever you want, as long as they match in TouchOSC.

"osc": {
    "devices": [
        {
            "ipAddress": "192.168.3.78",
            "sendPort": 9000,
            "receivePort": 8000
        },
        {
            "ipAddress": "192.168.3.123",
            "sendPort": 9001,
            "receivePort": 8001
        }
    ]
} 
ghost commented 2 years ago

Oh, that missing comma was my fault. Perfect now. Thank you for answering so fast.

Sorry for the off topic I’m about to type.

I am trying to display the altitude in meters for a warbird. Since DCS-BIOS seems to only output feet, I’m a little bit lost.

Is it possible to convert the received string with simple math before displaying it?

Like, the received string is 6000 ft, before displaying X, X= string * 0.3048. Probably I just typed an atrocity…

charliefoxtwo commented 2 years ago

Sure, you can absolutely do a conversion in TouchOSC! I'll post an example in a little bit.

charliefoxtwo commented 2 years ago

Untested, but something like this in the script box for the label I think will work?

function onReceiveOSC(msg)
  local input = msg[2][1].value -- get the input
  local converted = tonumber(input) * 0.3048 -- convert it to metric
  self.values.text = converted -- set the label to our new value
  return true -- needed so the label doesn't set its own value
end
ghost commented 2 years ago

Works perfectly! Thank you so much for this! I even managed to check Lua.org in order to find a function to round the result.

function onReceiveOSC(msg)
  local input = msg[2][1].value
  local converted = tonumber(input) * 0.3048
  self.values.text = math.floor (converted) // Rounding the result so the meter indicator value is easily readable.
  return true
end

I am sharing the templates at the DCS forum, what an awesome thing you created.

charliefoxtwo commented 2 years ago

Ah yeah rounding the result seems like what you'd want there, glad you got that sorted.

Happy to help :)

A couple of people have shared their templates in the discord as well (link in the badge in the readme) so feel free to share there as well. Glad it's working out for you!

As an aside, you can use triple backticks to create the code block like I did, like so:

```lua
-- code goes here
ghost commented 2 years ago

Oh thanks! I was wondering how did you create the code block...

I have to make a Discord account, last time I tried they didn't allow me without giving out my phone number. Maybe it is a lost cause.

Thank you again so much for all your help :D