Subversion Repositories group.electronics

Rev

Rev 116 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 116 Rev 118
Line 132... Line 132...
132
		buffer[i] = 0x00;
132
		buffer[i] = 0x00;
133
	}
133
	}
134
	
134
	
135
	usbPushLeds();	
135
	usbPushLeds();	
136
 
136
 
-
 
137
	while (hSimConnect == NULL) {
137
	Connect();
138
		Connect();
-
 
139
		if (hSimConnect == NULL)
-
 
140
			Sleep(10000);
-
 
141
	}
138
 
142
 
139
	if (hSimConnect != NULL) {
-
 
140
		keep_going = true;
143
	keep_going = true;
141
 
144
 
142
		unsigned int lastButtons = 0;
145
	unsigned int lastButtons = 0;
143
 
146
 
144
		while(keep_going) {
147
	while(keep_going) {
145
			HRESULT hr;
148
		HRESULT hr;
146
				
149
				
147
			usbGetState();		
150
		usbGetState();		
148
			unsigned char buttons = (unsigned char)buffer[1];
151
		unsigned char buttons = (unsigned char)buffer[1];
149
 
152
 
150
			for (i=0; i<=7; i++) {
153
		for (i=0; i<=7; i++) {
151
					if (rbi(buttons, i) && rbi(lastButtons, i) == 0) {
154
				if (rbi(buttons, i) && rbi(lastButtons, i) == 0) {
152
						sbi(lastButtons, i);
155
					sbi(lastButtons, i);
153
						hr = SimConnect_TransmitClientEvent(hSimConnect,0, i, 1 ,
156
					hr = SimConnect_TransmitClientEvent(hSimConnect,0, i, 1 ,
154
								SIMCONNECT_GROUP_PRIORITY_STANDARD,SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
157
							SIMCONNECT_GROUP_PRIORITY_STANDARD,SIMCONNECT_EVENT_FLAG_GROUPID_IS_PRIORITY);
155
					}
158
				}
156
					
159
					
157
					if (rbi(lastButtons, i) && ! rbi(buttons, i))
160
				if (rbi(lastButtons, i) && ! rbi(buttons, i))
158
						cbi(lastButtons, i);
161
					cbi(lastButtons, i);
159
			}
162
		}
160
 
163
 
161
            SimConnect_CallDispatch(hSimConnect, dispatchProc, NULL);
164
        SimConnect_CallDispatch(hSimConnect, dispatchProc, NULL);
162
            Sleep(1);
165
        Sleep(1);
163
        }
166
    }
164
        Disconnect();
167
    Disconnect();
165
    } else {
-
 
166
		// Implement retrying
-
 
167
	}
-
 
168
 
168
 
169
 
169
 
170
    usb_close(handle);
170
    usb_close(handle);
171
 
171
 
172
	return 0;
172
	return 0;
Line 178... Line 178...
178
	if (hSimConnect == NULL) {
178
	if (hSimConnect == NULL) {
179
		printf("\n%s Requesting a SimConnect connection", Format_SOL(M_OUT));
179
		printf("\n%s Requesting a SimConnect connection", Format_SOL(M_OUT));
180
		hr = SimConnect_Open(&hSimConnect, "Comm Selector", NULL, 0, 0, 0);
180
		hr = SimConnect_Open(&hSimConnect, "Comm Selector", NULL, 0, 0, 0);
181
		if (hr != S_OK)	{
181
		if (hr != S_OK)	{
182
			// FSX may be inactive, or there is a problem
182
			// FSX may be inactive, or there is a problem
183
			printf("\n%s Error %d while opening a SimConnect connection", Format_SOL(M_IN, I_OK), hr);
183
			printf("\n%s Error %d:  Sleeping 10 seconds and retrying", Format_SOL(M_IN, I_OK), hr);
184
		} else {
184
		} else {
185
			// Connection to FSX initialized
185
			// Connection to FSX initialized
186
			printf("\n%s Connection request being processed (%d)", Format_SOL(M_IN), hSimConnect);
186
			printf("\n%s Connection request being processed (%d)", Format_SOL(M_IN), hSimConnect);
187
			// (When connection process completes, an OPEN message will be received)
187
			// (When connection process completes, an OPEN message will be received)
188
		}
188
		}