Jump to content
The simFlight Network Forums

Trigger macros via API


 Share

Recommended Posts

Hi,

I'm currently developing with the Java-API and this is working really fine :-) Also i'm using the macro function to connect Goflight-modules with special aircraft functions.

Quick question: Could I trigger these macros from the API? I'm currently developing a checklist manager which should do also some automations with lights/TCAS and so on. But not all aircrafts are able to deal with the standart-API. Triggering macros via the API could solve the problem.

Regards

Stefan

Link to comment
Share on other sites

Quick question: Could I trigger these macros from the API? I'm currently developing a checklist manager which should do also some automations with lights/TCAS and so on. But not all aircrafts are able to deal with the standart-API. Triggering macros via the API could solve the problem.

I think this is the same question answered in an earlier thread, here:

viewtopic.php?f=54&t=72264

Can you check and see if that helps?

Regards

Pete

Link to comment
Share on other sites

If somebody would like to trigger the virtual buttons with the Java-API, this works:

    public void setButton(int joystick, int button) {

        // joystick 64-72
        // button 0-31

        byte[] data = new byte[36];
        joystick -= 64;
        int offset = joystick * 4;
        data[((button) / 8) + offset] = (byte) Math.pow(2, button % 8);
        fsuipc_wrapper.WriteData(0x3340, 36, data);

    }

Link to comment
Share on other sites

If somebody would like to trigger the virtual buttons with the Java-API, this works:

It would do, but it appears to only switch one button on and all the other 287 off. And if another application is also using virtual buttons you could easily interfere with their operations quite severely, because you are writing all 288 button bits.

I don't know Java, but wouldn't something like this be better, just to change the one byte you need to?

    public void setButton(int joystick, int button) {

        // joystick 64-72
        // button 0-31

        byte data = new byte;
        joystick -= 64;
        int offset = 0x3340 + (joystick * 4) + (button / 8);

        fsuipc_wrapper.ReadData(offset, 1, data);
        data = data | (byte) Math.pow(2, button % 8);
          // Here I am assuming logical "OR" is '|' as in C -- if not change it
          // If you have shifts in Java then it would be more efficient to comput the value by "1 << (button%8)" where << is left shift
        fsuipc_wrapper.WriteData(offset, 1, data);
    }

The clear button routine would be the same except you'd use Logical AND instead of OR, with the logicl NOT of the computed value, and you could have a Toggle gacility by using "Exclusive Or" with the computed value.

I'm assuming Java has some Logical facilities in its repetoire, else you'd need to do everything using maths which is pretty horrible.

If you know you have exlusive use of a range of 8 buttons then you wouldn't need to read them and manipulate them this way, you could simply set whatever combination you liked the way you are doing it but for 1 byte not 36. Writing all 288 buttons every time is not only uncooperative but it also prevents you using more than one button in your own program, at least without some changes.

Regards

Pete

Link to comment
Share on other sites

    public void setButton(int joystick, int button) {

        // joystick 64-72
        // button 0-31

        joystick -= 64;
        int offset = 0x3340 + (joystick * 4) + (button / 8);
        byte[] data = new byte[1];
        fsuipc_wrapper.ReadData(offset, 1, data);
        data[0] = (byte) (data[0] | 1 << (button % 8));
        fsuipc_wrapper.WriteData(offset, 1, data);

    }

Based on your comments I have rewritten the code and it's working really fine! :-) It was not clear for me that I have no exclusive area to write the buttons. I will keep this in mind.

Thank you for support!

Stefan

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
 Share

×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use. Guidelines Privacy Policy We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.