c-true / FsConnect

Wrapper for Flight Simulator 2020 SimConnect library
59 stars 19 forks source link

Unable to set heading bug #14

Closed markusbuschhoff closed 3 years ago

markusbuschhoff commented 3 years ago

Hi,

I successfully connected to FS2020 and received the heading bug setting using RequestData on FsSimVar.AutopilotHeadingLockDir. However, I was unable to set the value using a client event. I basically followed the example in the README. After successful connection I call:

        fsConnect.MapClientEventToSimEvent(ev.group, ev.setHeadingBug, FsEventNameId.HeadingBugSet);
        fsConnect.SetNotificationGroupPriority(ev.group);
        fsConnect.TransmitClientEvent(ev.setHeadingBug, (uint) 0, ev.group);

I expected the AP heading selector to switch to 0, but it stays at the heading dialed in. I tried several alternatives (e.g. binding my event to FsEventNameId.HeadingBugInc, FsEventNameId.FlapsIncr), but none worked. However, a call to SetText does show a text popup in MSFS (so, it's probably not a connection issue).

Any help appreciated.

EDIT: Inserted 2nd code line

TimianHeber commented 3 years ago

Hi! I'll look into it this weekend.

TimianHeber commented 3 years ago

HI, I made a quick integration test and the following works for me. But it seems to be the same as your example, so there may be something else wrong. Please see if the FsError event is raised, maybe something interesting will be reported there, such as duplicate IDs. Good luck and please let me know if you still have problems!

    [TestFixture, Explicit]
    public class FsConnectIntegrationTest
    {
        enum TestEnums
        {
            GroupId=1234,
            EventId=1235
        }

        [Test]
        public void Test()
        {
            // Arrange
            AutoResetEvent resetEvent = new AutoResetEvent(false);
            int errorCount = 0;

            FsConnect fsConnect = new FsConnect();
            fsConnect.ConnectionChanged += (sender, b) =>
            {
                if (b) resetEvent.Set();
            };
            fsConnect.FsError += (sender, args) =>
            {
                errorCount++;
                Console.WriteLine($"Error: {args.ExceptionDescription}");
            };

            fsConnect.Connect("FsConnectIntegrationTest", 0);

            bool res = resetEvent.WaitOne(2000);
            if (!res) Assert.Fail("Not connected to MSFS within timeout");

            // Act
            fsConnect.MapClientEventToSimEvent(TestEnums.GroupId, TestEnums.EventId, FsEventNameId.HeadingBugSet);
            fsConnect.SetNotificationGroupPriority(TestEnums.GroupId);

            fsConnect.TransmitClientEvent(TestEnums.EventId, (uint)DateTime.Now.Second*6, TestEnums.GroupId);

            // Assert
            Assert.That(errorCount, Is.Zero);

            // Teardown
            fsConnect?.Disconnect();
        }
    }