예제 #1
0
void testCockpitCamera()
{
	if (SUCCEEDED(SimConnect_Open(&hSimConnect, "Cockpit Camera", NULL, 0, 0, 0)))
	{
		cameraConfig = configLoader.load();

		SimConnect_AddToDataDefinition(hSimConnect, DEFINITION_1, "title", NULL, SIMCONNECT_DATATYPE_STRINGV);

		SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");
		SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_AIRCRAFT_CHANGED, "AircraftLoaded");

		SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP0, SIMCONNECT_GROUP_PRIORITY_STANDARD);

		REGISTER_CAMERA_BUTTON(1, "Num_1", "ctrl+Num_1");
		REGISTER_CAMERA_BUTTON(2, "Num_2", "ctrl+Num_2");
		REGISTER_CAMERA_BUTTON(3, "Num_3", "ctrl+Num_3");
		REGISTER_CAMERA_BUTTON(4, "Num_4", "ctrl+Num_4");
		REGISTER_CAMERA_BUTTON(5, "Num_5", "ctrl+Num_5");
		REGISTER_CAMERA_BUTTON(6, "Num_6", "ctrl+Num_6");
		REGISTER_CAMERA_BUTTON(7, "Num_7", "ctrl+Num_7");
		REGISTER_CAMERA_BUTTON(8, "Num_8", "ctrl+Num_8");
		REGISTER_CAMERA_BUTTON(9, "Num_9", "ctrl+Num_9");

		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_LEFT);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_RIGHT);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_UP);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_DOWN);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_FORWARD);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_BACK);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_HEADING_LEFT);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_HEADING_RIGHT);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_CENTER);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_PITCH_UP);
		SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_PITCH_DOWN);

		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_LEFT);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_RIGHT);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_UP);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_DOWN);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_FORWARD);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_BACK);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_HEADING_LEFT);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_HEADING_RIGHT);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_CENTER);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_PITCH_UP);
		SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP0, EVENT_PITCH_DOWN);

		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_4", EVENT_LEFT);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_6", EVENT_RIGHT);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_8", EVENT_UP);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_2", EVENT_DOWN);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_7", EVENT_FORWARD);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_1", EVENT_BACK);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_0", EVENT_HEADING_LEFT);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_Del", EVENT_HEADING_RIGHT);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_5", EVENT_CENTER);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_9", EVENT_PITCH_UP);
		SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+Num_3", EVENT_PITCH_DOWN);

		SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON);

		while (0 == quit)
		{
			SimConnect_CallDispatch(hSimConnect, MyDispatchProcCC, NULL);
			Sleep(1);
		}

		SimConnect_Close(hSimConnect);
	}

}
예제 #2
0
void testCommunication()
{
	HRESULT hr;
	printf("Connecting to Flight Simulator!\n");

	if (SUCCEEDED(SimConnect_Open(&hSimConnect, "PMDG 777X Test", NULL, 0, 0, 0)))
	{
		printf("Connected to Flight Simulator!\n");

		// 1) Set up data connection

		// Associate an ID with the PMDG data area name
		hr = SimConnect_MapClientDataNameToID(hSimConnect, PMDG_777X_DATA_NAME, PMDG_777X_DATA_ID);

		// Define the data area structure - this is a required step
		hr = SimConnect_AddToClientDataDefinition(hSimConnect, PMDG_777X_DATA_DEFINITION, 0, sizeof(PMDG_777X_Data), 0, 0);

		// Sign up for notification of data change.  
		// SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED flag asks for the data to be sent only when some of the data is changed.
		hr = SimConnect_RequestClientData(hSimConnect, PMDG_777X_DATA_ID, DATA_REQUEST, PMDG_777X_DATA_DEFINITION,
			SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED, 0, 0, 0);


		// 2) Set up control connection

		// First method: control data area
		Control.Event = 0;
		Control.Parameter = 0;

		// Associate an ID with the PMDG control area name
		hr = SimConnect_MapClientDataNameToID(hSimConnect, PMDG_777X_CONTROL_NAME, PMDG_777X_CONTROL_ID);

		// Define the control area structure - this is a required step
		hr = SimConnect_AddToClientDataDefinition(hSimConnect, PMDG_777X_CONTROL_DEFINITION, 0, sizeof(PMDG_777X_Control), 0, 0);

		// Sign up for notification of control change.  
		hr = SimConnect_RequestClientData(hSimConnect, PMDG_777X_CONTROL_ID, CONTROL_REQUEST, PMDG_777X_CONTROL_DEFINITION,
			SIMCONNECT_CLIENT_DATA_PERIOD_ON_SET, SIMCONNECT_CLIENT_DATA_REQUEST_FLAG_CHANGED, 0, 0, 0);

		// Second method: Create event IDs for controls that we are going to operate
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_LOGO_LIGHT_SWITCH, "#69748");		//EVT_OH_LIGHTS_LOGO
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_FLIGHT_DIRECTOR_SWITCH, "#69834");	//EVT_MCP_FD_SWITCH_L


																										// 3) Request current aircraft .air file path
		hr = SimConnect_RequestSystemState(hSimConnect, AIR_PATH_REQUEST, "AircraftLoaded");
		// also request notifications on sim start and aircraft change
		hr = SimConnect_SubscribeToSystemEvent(hSimConnect, EVENT_SIM_START, "SimStart");


		// 4) Assign keyboard shortcuts
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_KEYBOARD_A);
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_KEYBOARD_B);
		hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_KEYBOARD_C);

		hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYBOARD, EVENT_KEYBOARD_A);
		hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYBOARD, EVENT_KEYBOARD_B);
		hr = SimConnect_AddClientEventToNotificationGroup(hSimConnect, GROUP_KEYBOARD, EVENT_KEYBOARD_C);

		hr = SimConnect_SetNotificationGroupPriority(hSimConnect, GROUP_KEYBOARD, SIMCONNECT_GROUP_PRIORITY_HIGHEST);

		hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+ctrl+a", EVENT_KEYBOARD_A);
		hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+ctrl+b", EVENT_KEYBOARD_B);
		hr = SimConnect_MapInputEventToClientEvent(hSimConnect, INPUT0, "shift+ctrl+c", EVENT_KEYBOARD_C);

		hr = SimConnect_SetInputGroupState(hSimConnect, INPUT0, SIMCONNECT_STATE_ON);

		printf("entering main loop\n");
		// 5) Main loop
		while (quit == 0)
		{
			//printf("running main loop\n");
			// receive and process the 777X data
			SimConnect_CallDispatch(hSimConnect, MyDispatchProc, NULL);

			Sleep(1);
		}

		hr = SimConnect_Close(hSimConnect);
	}
	else
		printf("Unable to connect!\n\n");
}