Subversion Repositories group.electronics

Rev

Rev 114 | Rev 116 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 114 Rev 115
Line 31... Line 31...
31
 
31
 
32
 
32
 
33
 
33
 
34
#define		BUTTONS_COM1	0
34
#define		BUTTONS_COM1	0
35
#define		BUTTONS_COM2	1
35
#define		BUTTONS_COM2	1
36
#define		BUTTONS_BOTH	2
36
#define		BUTTONS_COMB	2
37
#define		BUTTONS_NAV1	3
37
#define		BUTTONS_NAV1	3
38
#define		BUTTONS_NAV2	4
38
#define		BUTTONS_NAV2	4
39
#define		BUTTONS_MKR 	5
39
#define		BUTTONS_MKR 	5
40
#define		BUTTONS_DME 	6
40
#define		BUTTONS_DME 	6
41
#define		BUTTONS_ADF 	7
41
#define		BUTTONS_ADF 	7
Line 45... Line 45...
45
 
45
 
46
static usb_dev_handle * usbOpenDevice(int vendor, char *vendorName, int product, char *productName);
46
static usb_dev_handle * usbOpenDevice(int vendor, char *vendorName, int product, char *productName);
47
static int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen);
47
static int usbGetDescriptorString(usb_dev_handle *dev, int index, int langid, char *buf, int buflen);
48
void testCode(usb_dev_handle *handle);
48
void testCode(usb_dev_handle *handle);
49
 
49
 
-
 
50
void setLed(double value, int bit);
-
 
51
 
50
void CALLBACK dispatchProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext);
52
void CALLBACK dispatchProc(SIMCONNECT_RECV *pData, DWORD cbData, void *pContext);
51
 
53
 
52
void Process_Exception(SIMCONNECT_RECV* pData);
54
void Process_Exception(SIMCONNECT_RECV* pData);
53
void Process_Connected();
55
void Process_Connected();
54
void Process_FSX_Quit();
56
void Process_FSX_Quit();
Line 59... Line 61...
59
char* Format_SOL(char* Direction, char* Importance);
61
char* Format_SOL(char* Direction, char* Importance);
60
 
62
 
61
void Connect();
63
void Connect();
62
void Disconnect();
64
void Disconnect();
63
 
65
 
64
 
-
 
-
 
66
usb_dev_handle *handle = NULL;
65
HANDLE  hSimConnect = NULL;
67
HANDLE  hSimConnect = NULL;
66
bool    keep_going = false;
68
bool    keep_going = false;
67
bool	Paused = true;
69
bool	Paused = true;
68
char 	string[80];
70
char 	string[80];
69
bool	updateLeds = true;
71
bool	updateLeds = true;
70
char 	ledStatus = 0x00;
72
char 	ledStatus = 0x00;
71
int		nBytes = 0;
73
int		nBytes = 0;
72
char	buffer[16];
74
char	buffer[16];
73
 
75
 
74
struct CommSelectData {
76
struct CommSelectData {
75
	double	comm1;
77
	double	com1;
76
	double	comm2;
78
	double	com2;
77
	double	commb;
79
	double	comb;
78
	double	vor1;
80
	double	vor1;
79
	double	vor2;
81
	double	vor2;
80
	double	mkr;
82
	double	mkr;
81
	double	dme;
83
	double	dme;
82
	double	adf;
84
	double	adf;
Line 95... Line 97...
95
static enum EVENT_ID {
97
static enum EVENT_ID {
96
	EVENT_COM1_TRANSMIT_SELECT,
98
	EVENT_COM1_TRANSMIT_SELECT,
97
	EVENT_COM2_TRANSMIT_SELECT,
99
	EVENT_COM2_TRANSMIT_SELECT,
98
	EVENT_COM_RECEIVE_ALL_TOGGLE,
100
	EVENT_COM_RECEIVE_ALL_TOGGLE,
99
	EVENT_RADIO_VOR1_IDENT_TOGGLE,
101
	EVENT_RADIO_VOR1_IDENT_TOGGLE,
100
	EVENT_RADIO_VOR2_IDENT_TOGGLE
102
	EVENT_RADIO_VOR2_IDENT_TOGGLE,
101
	EVENT_MARKER_SOUND_TOGGLE,
103
	EVENT_MARKER_SOUND_TOGGLE,
102
	EVENT_RADIO_DME1_IDENT_TOGGLE,
104
	EVENT_RADIO_DME1_IDENT_TOGGLE,
103
	EVENT_RADIO_ADF_IDENT_TOGGLE,
105
	EVENT_RADIO_ADF_IDENT_TOGGLE,
104
};
106
};
105
 
107
 
Line 113... Line 115...
113
 
115
 
114
 
116
 
115
 
117
 
116
 
118
 
117
int main(int argc, char **argv) {
119
int main(int argc, char **argv) {
118
	usb_dev_handle *handle = NULL;
-
 
119
    
120
 
120
    handle = usbOpenDevice(0x4242, "newioit.com.au", 0xe231, "Comm Selector");
121
    handle = usbOpenDevice(0x4242, "newioit.com.au", 0xe231, "Comm Selector");
121
 
122
 
122
    if(handle == NULL) {
123
    if(handle == NULL) {
123
            fprintf(stderr, "Could not find USB device\n");
124
            fprintf(stderr, "Could not find USB device\n");
124
            exit(1);
125
            exit(1);
Line 155... Line 156...
155
			
156
			
156
			unsigned int buttons = (unsigned int)buffer[1];
157
			unsigned int buttons = (unsigned int)buffer[1];
157
			
158
			
158
			
159
			
159
			
160
			
160
			for (i=-; i<7; i++) {
161
			for (i=0; i<7; i++) {
161
					if (rbi(buttons, i) && rbi(lastButtons, i) == 0) {
162
					if (rbi(buttons, i) && rbi(lastButtons, i) == 0) {
162
						sbi(lastButtons, i);
163
						sbi(lastButtons, i);
163
						hr = SimConnect_TransmitClientEvent(hSimConnect,0, i, 1 ,
164
						hr = SimConnect_TransmitClientEvent(hSimConnect,0, i, 1 ,
164
								SIMCONNECT_GROUP_PRIORITY_STANDARD,SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
165
								SIMCONNECT_GROUP_PRIORITY_STANDARD,SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
165
					}
166
					}
166
					
167
					
167
					if (rbi(lastButtons, i) && ! rbi(buttons, i)
168
					if (rbi(lastButtons, i) && ! rbi(buttons, i))
168
						cbi(lastButtons, i);
169
						cbi(lastButtons, i);
169
			}
170
			}
170
 
171
 
171
            SimConnect_CallDispatch(hSimConnect, dispatchProc, NULL);
172
            SimConnect_CallDispatch(hSimConnect, dispatchProc, NULL);
172
            Sleep(1);
173
            Sleep(1);
Line 231... Line 232...
231
			Process_Connected();
232
			Process_Connected();
232
			break;
233
			break;
233
 
234
 
234
		case SIMCONNECT_RECV_ID_EVENT: {
235
		case SIMCONNECT_RECV_ID_EVENT: {
235
			SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
236
			SIMCONNECT_RECV_EVENT *evt = (SIMCONNECT_RECV_EVENT*)pData;
-
 
237
			/*
236
			switch (evt->uEventID) {
238
			switch (evt->uEventID) {
237
				default:
239
				default:
238
					break;
240
					break;
239
			}
241
			}
-
 
242
			*/
240
			break;
243
			break;
241
		}
244
		}
242
 
245
 
243
		case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
246
		case SIMCONNECT_RECV_ID_SIMOBJECT_DATA: {
244
			SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;
247
			SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE *pObjData = (SIMCONNECT_RECV_SIMOBJECT_DATA_BYTYPE*)pData;
Line 246... Line 249...
246
			switch(pObjData->dwRequestID) {
249
			switch(pObjData->dwRequestID) {
247
				case REQUEST_1: {
250
				case REQUEST_1: {
248
					DWORD ObjectID = pObjData->dwObjectID;
251
					DWORD ObjectID = pObjData->dwObjectID;
249
					CommSelectData *ps = (CommSelectData*)&pObjData->dwData;
252
					CommSelectData *ps = (CommSelectData*)&pObjData->dwData;
250
					
253
					
251
					hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_1, DEFINITION_1, ObjectID, 
-
 
252
														   SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED);
-
 
253
 
-
 
254
					setLed(ps->com1, &ledStatus, BUTTONS_COM1);
254
					setLed(ps->com1, BUTTONS_COM1);
255
					setLed(ps->com2, &ledStatus, BUTTONS_COM2);
255
					setLed(ps->com2, BUTTONS_COM2);
256
					setLed(ps->comb, &ledStatus, BUTTONS_COMB);
256
					setLed(ps->comb, BUTTONS_COMB);
257
					setLed(ps->vor1, &ledStatus, BUTTONS_NAV1);
257
					setLed(ps->vor1, BUTTONS_NAV1);
258
					setLed(ps->vor2, &ledStatus, BUTTONS_NAV2);
258
					setLed(ps->vor2, BUTTONS_NAV2);
259
					setLed(ps->mkr, &ledStatus, BUTTONS_MKR);
259
					setLed(ps->mkr, BUTTONS_MKR);
260
					setLed(ps->dme, &ledStatus, BUTTONS_DME);
260
					setLed(ps->dme, BUTTONS_DME);
261
					setLed(ps->adf, &ledStatus, BUTTONS_ADF);
261
					setLed(ps->adf, BUTTONS_ADF);
262
					
262
					
263
					nBytes = usb_control_msg(handle,
263
					nBytes = usb_control_msg(handle,
264
						USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
264
						USB_TYPE_VENDOR | USB_RECIP_DEVICE | USB_ENDPOINT_IN,
265
						USB_LEDS_SET, ledStatus, 0, (char *)buffer, sizeof(buffer), 5000);
265
						USB_LEDS_SET, ledStatus, 0, (char *)buffer, sizeof(buffer), 5000);
266
 
266
 
267
					printf("\nSIMOBJECT_DATA %d LED Update",  );
267
					printf("\nSIMOBJECT_DATA %d LED Update" );
268
					break;
268
					break;
269
				}
269
				}
270
			}
270
			}
271
			break;	
271
			break;	
272
		}
272
		}
Line 277... Line 277...
277
			switch(pObjData->dwRequestID) {
277
			switch(pObjData->dwRequestID) {
278
				case REQUEST_1: {
278
				case REQUEST_1: {
279
					DWORD ObjectID = pObjData->dwObjectID;
279
					DWORD ObjectID = pObjData->dwObjectID;
280
					CommSelectData *pS = (CommSelectData*)&pObjData->dwData;
280
					CommSelectData *pS = (CommSelectData*)&pObjData->dwData;
281
					
281
					
-
 
282
					HRESULT hr;
282
					hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_1, DEFINITION_1, ObjectID, 
283
					hr = SimConnect_RequestDataOnSimObject(hSimConnect, REQUEST_1, DEFINITION_1, ObjectID, 
283
														   SIMCONNECT_PERIOD_SECOND, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED);
284
														   SIMCONNECT_PERIOD_SIM_FRAME, SIMCONNECT_DATA_REQUEST_FLAG_CHANGED);
284
					break;
285
					break;
285
				}
286
				}
286
			}
287
			}
287
			break;
288
			break;
288
		}
289
		}
Line 300... Line 301...
300
		case SIMCONNECT_RECV_ID_EVENT_RACE_END:
301
		case SIMCONNECT_RECV_ID_EVENT_RACE_END:
301
		case SIMCONNECT_RECV_ID_EVENT_RACE_LAP: */
302
		case SIMCONNECT_RECV_ID_EVENT_RACE_LAP: */
302
 
303
 
303
		case SIMCONNECT_RECV_ID_EXCEPTION:
304
		case SIMCONNECT_RECV_ID_EXCEPTION:
304
        case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
305
        case SIMCONNECT_RECV_ID_EVENT_OBJECT_ADDREMOVE:
305
		case SIMCONNECT_RECV_ID_SIMOBJECT_DATA:
-
 
306
		case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
306
		case SIMCONNECT_RECV_ID_ASSIGNED_OBJECT_ID:
307
		case SIMCONNECT_RECV_ID_EVENT_FILENAME:
307
		case SIMCONNECT_RECV_ID_EVENT_FILENAME:
308
		case SIMCONNECT_RECV_ID_EVENT_FRAME:
308
		case SIMCONNECT_RECV_ID_EVENT_FRAME:
309
		case SIMCONNECT_RECV_ID_WEATHER_OBSERVATION:
309
		case SIMCONNECT_RECV_ID_WEATHER_OBSERVATION:
310
		case SIMCONNECT_RECV_ID_CLOUD_STATE:
310
		case SIMCONNECT_RECV_ID_CLOUD_STATE:
Line 318... Line 318...
318
		default:
318
		default:
319
			printf("\n%s Message ignored (Unknown RECV_ID)", Format_SOL(M_IN, I_NEX));
319
			printf("\n%s Message ignored (Unknown RECV_ID)", Format_SOL(M_IN, I_NEX));
320
    }
320
    }
321
}
321
}
322
 
322
 
323
void setLed(double value, char* ledS, int bit) {
323
void setLed(double value, int bit) {
324
	if (value)
324
	if (value)
325
		sbi(ledS, bit);
325
		sbi(ledStatus, bit);
326
	else
326
	else
327
		cbi(ledS, bit);
327
		cbi(ledStatus, bit);
328
}
328
}
329
 
329
 
330
void Process_Exception(SIMCONNECT_RECV* pData) {
330
void Process_Exception(SIMCONNECT_RECV* pData) {
331
	// SimConnect cannot process a client request
331
	// SimConnect cannot process a client request
332
	SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION *) pData;
332
	SIMCONNECT_RECV_EXCEPTION *except = (SIMCONNECT_RECV_EXCEPTION *) pData;
Line 335... Line 335...
335
		Exception_String(except->dwException));
335
		Exception_String(except->dwException));
336
}
336
}
337
 
337
 
338
void Process_Connected() {
338
void Process_Connected() {
339
	printf("\n%s Connected.", Format_SOL(M_IN));
339
	printf("\n%s Connected.", Format_SOL(M_IN));
340
 
-
 
341
	EVENT_COM1_TRANSMIT_SELECT,
-
 
342
	EVENT_COM2_TRANSMIT_SELECT,
-
 
343
	EVENT_COM_RECEIVE_ALL_TOGGLE,
-
 
344
	EVENT_RADIO_VOR1_IDENT_TOGGLE,
-
 
345
	EVENT_RADIO_VOR2_IDENT_TOGGLE
-
 
346
	EVENT_MARKER_SOUND_TOGGLE,
-
 
347
	RADIO_DME1_IDENT_TOGGLE,
-
 
348
	RADIO_ADF_IDENT_TOGGLE,	
-
 
349
	
340
	
350
	HRESULT hr;
341
	HRESULT hr;
351
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM1_TRANSMIT_SELECT, "COM1_TRANSMIT_SELECT");
342
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM1_TRANSMIT_SELECT, "COM1_TRANSMIT_SELECT");
352
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM2_TRANSMIT_SELECT, "COM2_TRANSMIT_SELECT");
343
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM2_TRANSMIT_SELECT, "COM2_TRANSMIT_SELECT");
353
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM_RECEIVE_ALL_TOGGLE, "COM_RECEIVE_ALL_TOGGLE");
344
	hr = SimConnect_MapClientEventToSimEvent(hSimConnect, EVENT_COM_RECEIVE_ALL_TOGGLE, "COM_RECEIVE_ALL_TOGGLE");