HeliosVirtualCockpit / Helios

Helios Distribution
https://github.com/HeliosVirtualCockpit/Helios/wiki
GNU General Public License v3.0
196 stars 34 forks source link

M-2000C Interface for TACAN channel, UHF and VHF presets #82

Open derammo opened 4 years ago

derammo commented 4 years ago

This is a basic interface for the Mirage 2000

Comments:

comment by @BlueFinBima on 2018-08-05 17:49:24 +0000 UTC

https://github.com/BlueFinBima/helios/commit/510370cc6f21b32e617d62d9f75a80a0737e8709 now contains an M2000C interface that can be pulled into profiles, but this is just the start of the journey because most of the definitions will not be quite right.

comment by @Phar71 on 2019-08-18 19:19:08 +0000 UTC

Hello,

Many thanks BlueFinBima for your answer. I hope I will be able to help. I will try to do a pull request as soon as possible, at least to begin the project.

But before that, I would like to resolve the problem I’m facing.

So, I’m struggling to find the issue on Tacan channel, preset U/VHF channel displays. I thought I had to listen at another id but after a lot of researches, work, headaches, I think I know why I’m not getting the good value but I don’t know how to get it. It’s why I’m asking to know if you have an idea on the problem.

For example, trying to display the TACAN channel, I’m not able to catch some changes when I turn the knob. The id of the value is 623 to have the tens and the hundreds from 0-12. The value of the step seems to be 0.070769237, so I need at least 2 digits after the dot to evaluate each value (0.00; 0.08 0.15; 0.23; 0.31; 0.38; 0.46; 0.54; 0.62; 0.69; 0.77; 0.85; 0.92), rounded to two digits. But when I read the value, I only have one digit that is not enough to evaluate a 13 positions knob. Because if I rounded to 1 digit, I have two "0.2", two "0.5" and two "0.8"

I tried to change the format value from "%.1f" to "%.5f" but I still have a one digit value. Do you think that’s coming from DCS, the interface, my function, a bad use of C# (it’s a long time from the last time I used it).

I have the same problem with the preset channel for the U/VHF radio. That’s a 20 positions knob, using the values 0.00; 0.05; 0.10; 0.15; 0.20; 0.25; … I’m not able to see the second digit too.

Sorry to take your time. I’ve not a lot of time too so I understand that you won’t be able to always help me. I hope to had more value to the software rather than just asking questions.

BlueFinBima, how do you want I give you my email? I updated my profile. Is it enough?

 public class TACANChannel : NetworkFunction
    {
        private static DCSDataElement[] _dataElements = new DCSDataElement[] { new DCSDataElement("623", "%.5f", false), new DCSDataElement("625", "%.1f", false) };

        private double _tens;
        private double _ones;

        private HeliosValue _channel;

        public TACANChannel(BaseUDPInterface sourceInterface)
            : base(sourceInterface)
        {
            _channel = new HeliosValue(sourceInterface, BindingValue.Empty, "TACAN", "Channel", "Currently tuned TACAN channel.", "", BindingValueUnits.Numeric);
            Values.Add(_channel);
            Triggers.Add(_channel);
        }

        public override ExportDataElement[] GetDataElements()
        {
            return _dataElements;
        }

        public override void ProcessNetworkData(string id, string value)
        {
            switch (id)
            {
                case "623":
                    switch (value) //get only a 0.x value
                    {
                        case "0.00":
                            _tens = 0.0;
                            break;
                        case "0.08":
                            _tens = 10.0;
                            break;
                        case "0.15":
                            _tens = 20.0;
                            break;
                        case "0.23":
                            _tens = 30.0;
                            break;
                        case "0.31":
                            _tens = 40.0;
                            break;
                        case "0.38":
                            _tens = 50.0;
                            break;
                        case "0.46":
                            _tens = 60.0;
                            break;
                        case "0.54":
                            _tens = 70.0;
                            break;
                        case "0.62":
                            _tens = 80.0;
                            break;
                        case "0.69":
                            _tens = 90.0;
                            break;
                        case "0.77":
                            _tens = 100.0;
                            break;
                        case "0.85":
                            _tens = 110.0;
                            break;
                        case "0.92":
                            _tens = 120.0;
                            break;
                    }
                    break;
                case "625":

comment by @BlueFinBima on 2019-08-19 19:40:08 +0000 UTC

@Phar71 I've sent you an invitation to Slack. Interestingly Ikarus thinks the TACAN display for the Mirage is 620-622. We can discuss further when you appear in Slack.

-- TACAN
    [620] = "%.1f", --  X/Y
    [621] = "%.4f", --  Drum XX0 left (--;1-12;--)
    [622] = "%.4f", --  Drum 00X right  (0;1-9;0)

comment by @BlueFinBima on 2019-09-04 15:36:32 +0000 UTC

https://github.com/BlueFinBima/Helios/commit/191fa79c60715ee04ee8ecb2c32c618fde99a204 adds a number of components.

migrated from https://github.com/BlueFinBima/Helios/issues/82

please make sure to close upstream issue when this item is closed

derammo commented 4 years ago

@damien022: @Phar71 has not communicated for a long time and isn't a member of the new repo. So right now you are the only one assigned to look into this. Not sure if you want to work on the Mirage? If you do, I have the harmony database available with code information to answer questions like the ones above.

norsetto commented 3 years ago

Hi,

I'm trying to do a simple M2000C profile, with VTB, Fuel and Engine panels. I noticed that the VTB buttons and detot bindings are missing; I see commented out code in M2000CInterface.cs for the VTB buttons but nothing for the detot one. What would be needed to have these bindings available?

derammo commented 3 years ago

basically someone has to take over developing that interface. Since you have already read the code, are you game to give it a try?

norsetto commented 3 years ago

Let me first try to pull the repo and try a build. If I can manage that I can certainly give it a shot...

derammo commented 3 years ago

sweet. The build is a bit messy because we have submodules and Visual Studio doesn't understand those. So the first build goes in a few phases. I wrote it up on the wiki. Please read some of these pages so you don't waste all your time and end up hating it :)

https://github.com/HeliosVirtualCockpit/Helios/wiki/Information-for-Helios-Developers

norsetto commented 3 years ago

Yes, I hated it :) But seriously, I modified the interface code with the attached patch. Now I can see the bindings but they do nothing, so I guess there is some more stuff that needs editing too? patch.txt

derammo commented 3 years ago

this patch seems to just change the names of a bunch of controls, and the device name under which they appear?

to make it work, you have to instantiate the right sort of control (Switch, Axis, etc.) with the right "arguments" and "device IDs" and "command IDs" that match the internal codes of DCS

to find out the correct ones to use for a particular control, look at a working interface made by someone else, like DCS-BIOS https://github.com/DCSFlightpanels/dcs-bios/blob/master/Scripts/DCS-BIOS/lib/M-2000C.lua

This will have the "argument" number, which is the index into device "0" where the value can be read from DCS. This will be an integer. If the switch or whatever can also be set to something, it will have a "device ID" and one or more "commands" with specific values that need to be sent. All these can be gleaned from the DCS-BIOS Lua and plugged into the Helios code.

So, for a two position switch, you have:

derammo commented 3 years ago

oh I just realized you DID add some stuff... sorry patch is hard to read :)

yeah if 203 isn't working, check the DCS-BIOS code for the same argument and see how they have it declared

derammo commented 3 years ago

the declarations you have there should correctly work if you operate the switch in the DCS cockpit, but Helios can't control DCS because none of the switch positions are declared. e.g. for 203, it would have to also have the { device 5, command 3203 } information, like in the commented out declaration in the original code (search for CreateToggleSwitch). I have no idea why all that was removed and replaced with dummies that are basically read-only access? This is abandoned code, maybe check git blame for clues why it was ripped out? It looks like someone was going backwards?

norsetto commented 3 years ago

Thanks for the tips, they were really helpful. I concocted the following:

AddFunction(new Switch(this, VTH_VTB, "213", new SwitchPosition[] {
                                                                    new SwitchPosition("1.0", "-", "3213"),
                                                                    new SwitchPosition("0.0", "+", "3213"),
                                                                    new SwitchPosition("-1.0", "Neutre", "3213")
                                                                   }, "HUD/VTB", "Target Data Manual Entry Begin/End", "%0.1f"));  // elements["PTN_213"] = default_2_way_spring_switch(_("Target Data Manual Entry Begin/End"), devices.VTH_VTB, device_commands.Button_213, 213, true)
AddFunction(new Switch(this, VTH_VTB, "214", new SwitchPosition[] {
                                                                     new SwitchPosition("1.0", "-", "3214"),
                                                                     new SwitchPosition("0.0", "+", "3214"),
                                                                     new SwitchPosition("-1.0", "Neutre", "3214")
                                                                    }, "HUD/VTB", "Bullseye Waypoint Selector", "%0.1f"));    // elements["PTN_214"] = default_2_way_spring_switch(_("Bullseye Waypoint Selector"), devices.VTH_VTB, device_commands.Button_214, 214, true)
AddFunction(new Switch(this, VTH_VTB, "215", new SwitchPosition[] {
                                                                    new SwitchPosition("1.0", "-", "3215"),
                                                                    new SwitchPosition("0.0", "+", "3215"),
                                                                    new SwitchPosition("-1.0", "Neutre", "3215")
                                                                    }, "HUD/VTB", "Target Range from Bullseye", "%0.1f"));    // elements["PTN_215"] = default_2_way_spring_switch(_("Target Range from Bullseye"), devices.VTH_VTB, device_commands.Button_215, 215, true)
AddFunction(new Switch(this, VTH_VTB, "216", new SwitchPosition[] {
                                                                     new SwitchPosition("1.0", "-", "3216"),
                                                                     new SwitchPosition("0.0", "+", "3216"),
                                                                     new SwitchPosition("-1.0", "Neutre", "3216")
                                                                    }, "HUD/VTB", "Target Bearing from Bullseye", "%0.1f"));    // elements["PTN_216"] = default_2_way_spring_switch(_("Target Bearing from Bullseye"), devices.VTH_VTB, device_commands.Button_216, 216, true)
AddFunction(new Switch(this, VTH_VTB, "217", new SwitchPosition[] {
                                                                     new SwitchPosition("1.0", "-", "3217"),
                                                                     new SwitchPosition("0.0", "+", "3217"),
                                                                     new SwitchPosition("-1.0", "Neutre", "3217")
                                                                    }, "HUD/VTB", "Target Heading", "%0.1f"));    // elements["PTN_217"] = default_2_way_spring_switch(_("Target Heading"), devices.VTH_VTB, device_commands.Button_217, 217, true)
AddFunction(new Switch(this, VTH_VTB, "218", new SwitchPosition[] {
                                                                    new SwitchPosition("1.0", "-", "3218"),
                                                                    new SwitchPosition("0.0", "+", "3218"),
                                                                    new SwitchPosition("-1.0", "Neutre", "3218")
                                                                    }, "HUD/VTB", "Target Altitude", "%0.1f"));    // elements["PTN_218"] = default_2_way_spring_switch(_("Target Altitude"), devices.VTH_VTB, device_commands.Button_218, 218, true)
AddFunction(new Switch(this, VTH_VTB, "219", new SwitchPosition[] {
                                                                     new SwitchPosition("1.0", "-", "3219"),
                                                                     new SwitchPosition("0.0", "+", "3219"),
                                                                     new SwitchPosition("-1.0", "Neutre", "3219")
                                                                     }, "HUD/VTB", "Target Mach Number", "%0.1f"));    // elements["PTN_219"] = default_2_way_spring_switch(_("Target Mach Number"), devices.VTH_VTB, device_commands.Button_219, 219, true)
AddFunction(new Switch(this, VTH_VTB, "220", new SwitchPosition[] {                                                                                
                                                                     new SwitchPosition("1.0", "-", "3220"),
                                                                     new SwitchPosition("0.0", "+", "3220"),
                                                                     new SwitchPosition("-1.0", "Neutre", "3220")
                                                                     }, "HUD/VTB", "Target Age", "%0.1f"));    // elements["PTN_220"] = default_2_way_spring_switch(_("Target Age"), devices.VTH_VTB, device_commands.Button_220, 220, true)
AddFunction(new PushButton(this, VTH_VTB, "3221", "221", "HUD/VTB", "VTB Power Switch"));    // elements["PTN_221"] = default_2_position_tumb(_("VTB Power Switch"), devices.VTH_VTB, device_commands.Button_221, 221)
AddFunction(new PushButton(this, VTH_VTB, "3222", "222", "HUD/VTB", "VTB Declutter"));    // elements["PTN_222"] = default_2_way_spring_switch(_("VTB Declutter"), devices.VTH_VTB, device_commands.Button_222, 222, true)
AddFunction(new PushButton(this, VTH_VTB, "3223", "223", "HUD/VTB", "VTB Orientation Selector (Inop)"));    // elements["PTN_223"] = default_2_position_tumb(_("VTB Orientation Selector (Inop)"), devices.VTH_VTB, device_commands.Button_223, 223)

The fuel detot switch should work similarly to these but I'd rather wait for 2.7 to test it since it is not yet implemented in the current stable release. This code works well in my profile and shouldn't break compatibility with older profiles (needs to be tested). I tried to make it compatible with the current coding style, but, to be completely honest, I don't quite like it:

  1. two way switches are defined as push buttons
  2. three way switches positions makes little sense to me
  3. it doesn't use CreateThreeWaySwitch or CreateToggleSwitch but implements it its own way (to be fair the switch method is public, so why not...)

Perhaps the whole interface needs refactoring?

derammo commented 3 years ago

I consider all these interfaces "hacked up scripts." Anyone is free to contribute anything they can, because we desperately need people who can even perform the task of gathering the codes and testing them out. So I don't care at all how horrible the code is :)

So yeah, the M-2000C interface has always been a draft contributed by someone who didn't finish it and then left. But that's what we got...

So if you want to make it nice, go ahead. Just please fork the repo so I can review stuff as a PR instead of a patch. That's just more efficient. If there is a way to create a PR from patch in github, I don't know it. Careful when you make the PR, because github will target Gadroc's old abandoned upstream repo by default, so you need to change that to this repo.

Also, if you want to fix up the Switch class to allow object initializers and appropriate Add(...) functions to make it look nicer, that's totally fine too. Nobody here is opposed to people who can code making the code base better :)

That said, when it is done, I need to review to make sure it doesn't break things backwards. For example, your changes to the device names you had in your previous patch you already figured out. I would just read over the PR to make sure there isn't anything subtle.

derammo commented 3 years ago

Oh and yes, of course use CreateToggleSwitch and CreateThreeWaySwitch if you think that is clearer. I certainly like it better.

nitpick: please change "Neutre" to something English

norsetto commented 3 years ago

I've deleted the pull request, let me clone the fork and redo the changes cleanly.

norsetto commented 3 years ago

Built and tested successfully.

derammo commented 3 years ago

@norsetto thank you for the contribution. Please review this to make sure the name is as you want it: https://github.com/HeliosVirtualCockpit/Helios/commit/02e4e882664c2b0b5863ddd0c5074378e8e659c4

norsetto commented 3 years ago

@norsetto thank you for the contribution. Please review this to make sure the name is as you want it: 02e4e88

Glad I could contribute, even if minimally!

derammo commented 3 years ago

just realized this issue was actually for something else entirely. So the issue stays.