Guest rodrigowindows@gmail.com Posted June 12, 2015 Share Posted June 12, 2015 Hello, I am trying to set waypoints through SimConnect_SetDataOnSimObject but it is not working. What I already did is when pressed the key “ctrl+shift+A†I set a init position(It is working), but when I press the key “ctrl+shift+B†it is supposed to set the waypoints and then fly. This is my code: #include "stdafx.h" #include #include #include #include "SimConnect.h" #include #include int quit = 0; HANDLE hSimConnect = NULL; static enum GROUP_ID { GROUP_67, }; static enum INPUT_ID { INPUT_67, }; static enum EVENT_ID{ EVENT_SIM_START, EVENT_6, EVENT_7, }; static enum DATA_DEFINE_ID { DEFINITION_6, DEFINITION_WAYPOINT, }; static enum DATA_REQUEST_ID { REQUEST_6, }; void CALLBACK MyDispatchProcSD(SIMCONNECT_RECV* pData, DWORD cbData, void *pContext) { HRESULT hr; switch(pData->dwID) { case SIMCONNECT_RECV_ID_EVENT: { SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData; switch(evt->uEventID) { case EVENT_SIM_START: { // Turn the ctrl-shift-u input event on now hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_67, SIMCONNECT_STATE_ON); } break; case EVENT_6: { SIMCONNECT_DATA_INITPOSITION Init; Init.Altitude = 433.0; // Altitude of Sea-tac is 433 feet Init.Latitude = 47 + (25.91/60); // Convert from 47 25.90 N Init.Longitude = -122 - (18.48/60); // Convert from 122 18.48 W Init.Pitch = 0.0; Init.Bank = 0.0; Init.Heading = 360.0; Init.OnGround = 1; Init.Airspeed = 1; hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_6, SIMCONNECT_OBJECT_ID_USER, 0, 0, sizeof(Init), &Init ); printf("\nEVENT_6 received and data sent"); } break; case EVENT_7: { hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_WAYPOINT,"AI Waypoint List", "number", SIMCONNECT_DATATYPE_WAYPOINT); SIMCONNECT_DATA_WAYPOINT wp[3]; wp[0].Flags = SIMCONNECT_WAYPOINT_SPEED_REQUESTED; wp[0].Altitude = 800; wp[0].Latitude = 47 + (27.79/60); wp[0].Longitude = -122 - (18.46/60); wp[0].ktsSpeed = 100; wp[1].Flags = SIMCONNECT_WAYPOINT_SPEED_REQUESTED; wp[1].Altitude = 600; wp[1].Latitude = 47 + (27.79/60); wp[1].Longitude = -122 - (17.37/60); wp[1].ktsSpeed = 100; wp[2].Flags = SIMCONNECT_WAYPOINT_WRAP_TO_FIRST | SIMCONNECT_WAYPOINT_SPEED_REQUESTED; wp[2].Altitude = 800; wp[2].Latitude = 47 + (27.79/60); wp[2].Longitude = -122 - (19.92/60); wp[2].ktsSpeed = 100; hr = SimConnect_SetDataOnSimObject(hSimConnect, DEFINITION_WAYPOINT, SIMCONNECT_OBJECT_ID_USER, 0, ARRAYSIZE(wp), sizeof(wp[0]), wp); } break; default: break; } break; } case SIMCONNECT_RECV_ID_QUIT: { quit = 1; break; } default: printf("\nReceived:%d",pData->dwID); break; } } void testDataSet() { HRESULT hr; if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Set Data", NULL, 0, 0, 0))) { printf("\nConnected to Prepar3D!"); // Set up a data definition for positioning data hr = SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_6, "Initial Position", NULL, SIMCONNECT_DATATYPE_INITPOSITION); // Request a simulation start event hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart"); // Create a custom event hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_6, "My.CTRLSHIFTA"); hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_7, "My.CTRLSHIFTB"); // Link the custom event to some keyboard keys, and turn the input event off hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_67, "ctrl+shift+A", EVENT_6); hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT_67, "ctrl+shift+B", EVENT_7); hr = SimConnect_SetInputGroupState(hSimConnect, INPUT_67, SIMCONNECT_STATE_OFF); // Sign up for notifications for EVENT_6 hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_67, EVENT_6); hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_67, EVENT_7); while( 0 == quit ) { SimConnect_CallDispatch(hSimConnect, MyDispatchProcSD, NULL); Sleep(1); } hr = SimConnect_Close(hSimConnect); } } int __cdecl _tmain(int argc, _TCHAR* argv[]) { testDataSet(); return 0; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.