• Which the release of FS2020 we see an explosition of activity on the forun and of course we are very happy to see this. But having all questions about FS2020 in one forum becomes a bit messy. So therefore we would like to ask you all to use the following guidelines when posting your questions:

    • Tag FS2020 specific questions with the MSFS2020 tag.
    • Questions about making 3D assets can be posted in the 3D asset design forum. Either post them in the subforum of the modelling tool you use or in the general forum if they are general.
    • Questions about aircraft design can be posted in the Aircraft design forum
    • Questions about airport design can be posted in the FS2020 airport design forum. Once airport development tools have been updated for FS2020 you can post tool speciifc questions in the subforums of those tools as well of course.
    • Questions about terrain design can be posted in the FS2020 terrain design forum.
    • Questions about SimConnect can be posted in the SimConnect forum.

    Any other question that is not specific to an aspect of development or tool can be posted in the General chat forum.

    By following these guidelines we make sure that the forums remain easy to read for everybody and also that the right people can find your post to answer it.

Help for a simple problem I think?

Messages
3
Country
unitedkingdom
Can anyone take a look at the code below, I cannot firgure out for the life of me why I am getting random values?

Code:
#include <windows.h>
#include <tchar.h>
#include <stdio.h>
#include <strsafe.h>
#include "SimConnect.h"

HANDLE hSimConnect = NULL;
int quit = 0;

static enum CONTROLS_DATA_ID {
    DEFINITION_CONTROLS
};

static enum CONTROLS_REQUEST_ID {
    REQUEST_CONTROLS
};

struct controls
{
    double ypos;
    double xpos;
};

//callback procedure
void CALLBACK MyDispatchProc(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext)
{
    HRESULT hr;
    //check events
    switch (pData->dwID)
    {
        case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
        {
            SIMCONNECT_RECV_SIMOBJECT_DATA *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA*)pData;
            switch (pObjData->dwRequestID)
            {
                case REQUEST_CONTROLS:
                {
                    controls *pS = (controls*)&pObjData->dwData;
                    system("CLS");
                    printf("x value: %d\n", pS->xpos);
                    printf("y value: %d\n", pS->ypos);
                    break;
                }
                default:
                    break;
            }
            break;
        }
    }
}

int __cdecl _tmain(int argc, _TCHAR* argv[])
{
    //create connection to FSX and error check
    HRESULT hr = SimConnect_Open(&hSimConnect,"Steve's Autopilot",NULL,0,0,0);
    if (hr == S_OK)
    {
        printf("Connected to FSX!\n");
    }
    else
    {
        printf("Failed to connect to FSX!\n");
        return 1;
    }

    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_CONTROLS, "YOKE Y POSITION", "percent");
    hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_CONTROLS, "YOKE X POSITION", "percent");

    //request data from throttle position
    hr = SimConnect_RequestDataOnSimObject(hSimConnect,
        REQUEST_CONTROLS,
        DEFINITION_CONTROLS, 
        SIMCONNECT_OBJECT_ID_USER,
        SIMCONNECT_PERIOD_VISUAL_FRAME);
    if (hr != S_OK)
    {
        printf("Could not receive aircraft data!\n");
    }

    //loop until quit message
    while (quit == 0)
    {
        SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL);
        Sleep(1);
    }

    //close connection to FSX
    hr = SimConnect_Close(hSimConnect);   
    return 0;
}
 
Sorry chaps but solved it...

I thought from reading the sdk that all values were as doubles or char[] arrays but no!

how I fixed it was...

Code:
printf("y value: %d\n", (int)floor(pS->ypos));

for some reason I had to cast it to an int to get the values that I wanted between -100<0>100

still not sure why I have had to do this but at least its working!
 
Not a waste! Always good for future reference in case someone else makes the same mistake. :)
 
Back
Top