Rev 47 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 47 | Rev 48 | ||
---|---|---|---|
1 | #include <stdio.h> |
1 | #include <stdio.h> |
2 | #include <stdlib.h> |
2 | #include <stdlib.h> |
3 | #include <string.h> |
3 | #include <string.h> |
4 | #include <fcntl.h> |
4 | #include <fcntl.h> |
5 | #include "lib/x52/x52.h" |
5 | #include "lib/x52/x52.h" |
6 | #include <unistd.h> |
6 | #include <unistd.h> |
7 | #include <sys/socket.h> |
7 | #include <sys/socket.h> |
8 | #include <bluetooth/bluetooth.h> |
8 | #include <bluetooth/bluetooth.h> |
9 | #include <bluetooth/hci.h> |
9 | #include <bluetooth/hci.h> |
10 | #include <bluetooth/hci_lib.h> |
10 | #include <bluetooth/hci_lib.h> |
11 | 11 | ||
12 | 12 | ||
13 | #include <bluetooth/rfcomm.h> |
13 | #include <bluetooth/rfcomm.h> |
14 | 14 | ||
15 | 15 | ||
16 | #include <linux/joystick.h> |
16 | #include <linux/joystick.h> |
17 | #define JOY_DEV "/dev/input/js0" |
17 | #define JOY_DEV "/dev/input/js0" |
18 | 18 | ||
19 | #define MAX_BT_DEVICES 3 |
19 | #define MAX_BT_DEVICES 3 |
20 | 20 | ||
21 | 21 | ||
22 | #define STATEID_SCANNING 0 |
22 | #define STATEID_SCANNING 0 |
23 | #define STATEID_CONNECTING 1 |
23 | #define STATEID_CONNECTING 1 |
24 | 24 | ||
25 | #define BUTTON_SELECT 26 |
25 | #define BUTTON_SELECT 26 |
26 | #define BUTTON_DOWN 28 |
26 | #define BUTTON_DOWN 28 |
27 | #define BUTTON_UP 27 |
27 | #define BUTTON_UP 27 |
28 | 28 | ||
29 | int bt_device_count=0; |
29 | int bt_device_count=0; |
30 | 30 | ||
31 | char names[MAX_BT_DEVICES][248]; |
31 | char names[MAX_BT_DEVICES][248]; |
32 | char addrs[MAX_BT_DEVICES][19]; |
32 | char addrs[MAX_BT_DEVICES][19]; |
33 | 33 | ||
34 | int s, status; |
34 | int s, status; |
35 | unsigned char TxBuffer[150]; |
35 | unsigned char TxBuffer[150]; |
36 | unsigned char _TxBuffer[150]; |
36 | unsigned char _TxBuffer[150]; |
- | 37 | ||
- | 38 | char RxBuffer[150]; |
|
- | 39 | ||
37 | 40 | ||
38 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
41 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
39 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
42 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
40 | 43 | ||
41 | struct js_event x52_event_struct; |
44 | struct js_event x52_event_struct; |
- | 45 | ||
- | 46 | ||
- | 47 | int engines_on=0; |
|
- | 48 | int old_engines_on=0; |
|
- | 49 | ||
- | 50 | char in_char; |
|
42 | 51 | ||
43 | struct |
52 | struct |
44 | { |
53 | { |
45 | char val[4]; |
54 | char val[4]; |
46 | } MotortestParam; |
55 | } MotortestParam; |
47 | 56 | ||
48 | struct |
57 | struct |
49 | { |
58 | { |
50 | unsigned char Digital[2]; // (noch unbenutzt) |
59 | unsigned char Digital[2]; // (noch unbenutzt) |
51 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
60 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
52 | signed char Nick; |
61 | signed char Nick; |
53 | signed char Roll; |
62 | signed char Roll; |
54 | signed char Gier; |
63 | signed char Gier; |
55 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
64 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
56 | signed char Hight; //(Höhenregler) |
65 | signed char Higt; //(Höhenregler) |
57 | unsigned char free; // (unbenutzt) |
66 | unsigned char free; // (unbenutzt) |
58 | unsigned char Frame; // (Bestätigung) |
67 | unsigned char Frame; // (Bestätigung) |
59 | unsigned char Config; |
68 | unsigned char Config; |
60 | } ExternControl; |
69 | } ExternControl; |
61 | 70 | ||
62 | 71 | ||
63 | 72 | ||
64 | int state=STATEID_SCANNING; |
73 | int state=STATEID_SCANNING; |
65 | 74 | ||
66 | 75 | ||
67 | struct x52 *x52_output; |
76 | struct x52 *x52_output; |
68 | 77 | ||
69 | int selected_bt_device=0; |
78 | int selected_bt_device=0; |
70 | void scan_bt() |
79 | void scan_bt() |
71 | { |
80 | { |
72 | inquiry_info *ii = NULL; |
81 | inquiry_info *ii = NULL; |
73 | 82 | ||
74 | int dev_id, sock, len, flags; |
83 | int dev_id, sock, len, flags; |
75 | int i; |
84 | int i; |
76 | char addr[19] = { 0 }; |
85 | char addr[19] = { 0 }; |
77 | char name[248] = { 0 }; |
86 | char name[248] = { 0 }; |
78 | 87 | ||
79 | dev_id = hci_get_route(NULL); |
88 | dev_id = hci_get_route(NULL); |
80 | sock = hci_open_dev( dev_id ); |
89 | sock = hci_open_dev( dev_id ); |
81 | if (dev_id < 0 || sock < 0) { |
90 | if (dev_id < 0 || sock < 0) { |
82 | perror("opening socket"); |
91 | perror("opening socket"); |
83 | exit(1); |
92 | exit(1); |
84 | } |
93 | } |
85 | 94 | ||
86 | len = 8; |
95 | len = 8; |
87 | 96 | ||
88 | flags = IREQ_CACHE_FLUSH; |
97 | flags = IREQ_CACHE_FLUSH; |
89 | ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info)); |
98 | ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info)); |
90 | 99 | ||
91 | bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags); |
100 | bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags); |
92 | if( bt_device_count < 0 ) perror("hci_inquiry"); |
101 | if( bt_device_count < 0 ) perror("hci_inquiry"); |
93 | 102 | ||
94 | for (i = 0; i < bt_device_count; i++) { |
103 | for (i = 0; i < bt_device_count; i++) { |
95 | ba2str(&(ii+i)->bdaddr, addr); |
104 | ba2str(&(ii+i)->bdaddr, addr); |
96 | sprintf(addrs[i],"%s",addr); |
105 | sprintf(addrs[i],"%s",addr); |
97 | 106 | ||
98 | memset(name, 0, sizeof(name)); |
107 | memset(name, 0, sizeof(name)); |
99 | 108 | ||
100 | if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), |
109 | if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), |
101 | name, 0) < 0) |
110 | name, 0) < 0) |
102 | sprintf(names[i],"[unknown]"); |
111 | sprintf(names[i],"[unknown]"); |
103 | else |
112 | else |
104 | sprintf(names[i],"%s",name); |
113 | sprintf(names[i],"%s",name); |
105 | 114 | ||
106 | } |
115 | } |
107 | 116 | ||
108 | 117 | ||
109 | free( ii ); |
118 | free( ii ); |
110 | close( sock ); |
119 | close( sock ); |
111 | } |
120 | } |
112 | 121 | ||
113 | 122 | ||
114 | void connect_joy() |
123 | void connect_joy() |
115 | { |
124 | { |
116 | 125 | ||
117 | 126 | ||
118 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
127 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
119 | { |
128 | { |
120 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
129 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
121 | return ; |
130 | return ; |
122 | } |
131 | } |
123 | 132 | ||
124 | ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
133 | ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
125 | ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
134 | ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
126 | ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
135 | ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
127 | 136 | ||
128 | axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
137 | axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
129 | button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
138 | button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
130 | button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
139 | button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
131 | 140 | ||
132 | printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
141 | printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
133 | , name_of_joystick |
142 | , name_of_joystick |
134 | , num_of_axis |
143 | , num_of_axis |
135 | , num_of_buttons ); |
144 | , num_of_buttons ); |
136 | 145 | ||
137 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
146 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
138 | 147 | ||
139 | } |
148 | } |
140 | 149 | ||
141 | 150 | ||
142 | 151 | ||
143 | 152 | ||
144 | void AddCRC(unsigned int wieviele) |
153 | void AddCRC(unsigned int wieviele) |
145 | { |
154 | { |
146 | unsigned int tmpCRC = 0,i; |
155 | unsigned int tmpCRC = 0,i; |
147 | for(i = 0; i < wieviele;i++) |
156 | for(i = 0; i < wieviele;i++) |
148 | { |
157 | { |
149 | tmpCRC += TxBuffer[i]; |
158 | tmpCRC += TxBuffer[i]; |
150 | } |
159 | } |
151 | tmpCRC %= 4096; |
160 | tmpCRC %= 4096; |
152 | TxBuffer[i++] = '=' + tmpCRC / 64; |
161 | TxBuffer[i++] = '=' + tmpCRC / 64; |
153 | TxBuffer[i++] = '=' + tmpCRC % 64; |
162 | TxBuffer[i++] = '=' + tmpCRC % 64; |
154 | TxBuffer[i++] = '\r'; |
163 | TxBuffer[i++] = '\r'; |
155 | } |
164 | } |
156 | - | ||
157 | void SendOutData(unsigned char cmd,unsigned char modul, int len) |
- | |
158 | { |
- | |
159 | unsigned int pt = 0,ptr=0,i; |
- | |
160 | int a,b,c; |
- | |
161 | TxBuffer[pt++] = '#'; // Startzeichen |
- | |
162 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
- | |
- | 165 | ||
- | 166 | ||
- | 167 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
|
- | 168 | { |
|
- | 169 | unsigned int pt = 0; |
|
- | 170 | unsigned char a,b,c; |
|
- | 171 | unsigned char ptr = 0; |
|
- | 172 | ||
- | 173 | TxBuffer[pt++] = '#'; // Startzeichen |
|
- | 174 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
|
163 | TxBuffer[pt++] = cmd; // Commando |
175 | TxBuffer[pt++] = cmd; // Commando |
164 | 176 | ||
165 | while(len) |
177 | while(len) |
166 | { |
178 | { |
167 | if(len) { a = _TxBuffer[ptr++]; len--;} else a = 0; |
179 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
168 | if(len) { b = _TxBuffer[ptr++]; len--;} else b = 0; |
180 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
169 | if(len) { c = _TxBuffer[ptr++]; len--;} else c = 0; |
181 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
170 | TxBuffer[pt++] = '=' + (a >> 2); |
182 | TxBuffer[pt++] = '=' + (a >> 2); |
171 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
183 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
172 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
184 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
- | 185 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
|
- | 186 | } |
|
- | 187 | ||
- | 188 | ||
- | 189 | ||
173 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
190 | AddCRC(pt); |
- | 191 | printf("Sending to MK %d \n" , pt); |
|
- | 192 | ||
- | 193 | status = send(s,"\r" , 1, 0); |
|
174 | } |
194 | |
- | 195 | ||
- | 196 | // for (c=0;c<pt+2;c++) |
|
- | 197 | // { |
|
175 | 198 | status = write(s,&TxBuffer , pt+3); |
|
176 | status = send(s,"\r" , 1, 0); |
199 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
177 | i=0; |
200 | // } |
178 | while(TxBuffer[i] !='\r' && i<150) |
201 | /*while(TxBuffer[i] !='\r' && i<150) |
179 | { |
202 | { |
180 | // TxBuffer[i]='#'; |
203 | // TxBuffer[i]='#'; |
181 | status = send(s,&TxBuffer[i] , 1, 0); |
204 | status = send(s,&TxBuffer[i] , 1, 0); |
182 | printf(" +%d%c ",i,TxBuffer[i]); |
205 | printf(" +%d%c ",i,TxBuffer[i]); |
183 | i++; |
206 | i++; |
184 | } |
207 | } |
185 | 208 | ||
186 | status = send(s,"\r" , 1, 0); |
209 | status = send(s,"\r" , 1, 0); |
187 | 210 | */ |
|
- | 211 | // status = send(s,"\r" , 1, 0); |
|
188 | printf("\n"); |
212 | printf("\n"); |
189 | AddCRC(pt); |
- | |
190 | printf("Sending to MK\n"); |
- | |
191 | - | ||
192 | } |
213 | } |
193 | 214 | ||
194 | - | ||
195 | int engines_on=0; |
- | |
196 | int old_engines_on=0; |
- | |
197 | - | ||
198 | 215 | ||
199 | void write_display(int line,char* text) |
216 | void write_display(int line,char* text) |
200 | { |
217 | { |
201 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
218 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
202 | } |
219 | } |
203 | 220 | ||
204 | void clear_display() |
221 | void clear_display() |
205 | { |
222 | { |
206 | write_display(0,""); |
223 | write_display(0,""); |
207 | write_display(1,""); |
224 | write_display(1,""); |
208 | write_display(2,""); |
225 | write_display(2,""); |
209 | } |
226 | } |
210 | 227 | ||
211 | 228 | ||
212 | void output_device_list() |
229 | void output_device_list() |
213 | { |
230 | { |
214 | int i; |
231 | int i; |
215 | char disp_txt[20]; |
232 | char disp_txt[20]; |
216 | for(i=0;i<bt_device_count;i++) |
233 | for(i=0;i<bt_device_count;i++) |
217 | { |
234 | { |
218 | if (i<3) |
235 | if (i<3) |
219 | { |
236 | { |
220 | 237 | ||
221 | if (selected_bt_device==i) |
238 | if (selected_bt_device==i) |
222 | sprintf(disp_txt,"#%s",names[i]); |
239 | sprintf(disp_txt,"#%s",names[i]); |
223 | else |
240 | else |
224 | sprintf(disp_txt," %s",names[i]); |
241 | sprintf(disp_txt," %s",names[i]); |
225 | write_display(i,disp_txt); |
242 | write_display(i,disp_txt); |
226 | } |
243 | } |
227 | } |
244 | } |
228 | } |
245 | } |
229 | 246 | ||
230 | void connect_mk(char dest[18]) |
247 | void connect_mk(char dest[18]) |
231 | { |
248 | { |
232 | struct sockaddr_rc addr ; |
249 | struct sockaddr_rc addr ; |
233 | 250 | ||
234 | // allocate a socket |
251 | // allocate a socket |
235 | s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
252 | s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
236 | 253 | ||
237 | // set the connection parameters (who to connect to) |
254 | // set the connection parameters (who to connect to) |
238 | addr.rc_family = AF_BLUETOOTH; |
255 | addr.rc_family = AF_BLUETOOTH; |
239 | addr.rc_channel = 1; |
256 | addr.rc_channel = 1; |
240 | str2ba( dest, &addr.rc_bdaddr ); |
257 | str2ba( dest, &addr.rc_bdaddr ); |
241 | 258 | ||
242 | // connect to server |
259 | // connect to server |
243 | status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
260 | status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
244 | 261 | ||
245 | } |
262 | } |
246 | 263 | ||
247 | 264 | ||
248 | 265 | ||
- | 266 | ||
- | 267 | int r=0; |
|
249 | 268 | int count=0; |
|
250 | 269 | ||
251 | int main(int argc, char**argv) |
270 | int main(int argc, char**argv) |
252 | { |
271 | { |
253 | printf("Starting Riddim \n"); |
272 | printf("Starting Riddim \n"); |
254 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
273 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
255 | 274 | ||
256 | //int tmp=2; |
275 | //int tmp=2; |
257 | // connect_mk("00:0B:CE:01:6B:4F"); |
276 | connect_mk("00:0B:CE:01:6B:4F"); |
258 | 277 | ||
259 | 278 | ||
260 | 279 | ||
261 | 280 | ||
262 | int i; |
281 | int i; |
263 | 282 | ||
264 | printf("\nInitializing X-52 input ..\n"); |
283 | printf("\nInitializing X-52 input ..\n"); |
265 | connect_joy(); |
284 | connect_joy(); |
266 | printf(".. done"); |
285 | printf(".. done"); |
267 | 286 | ||
268 | printf("\nInitializing X-52 output .."); |
287 | printf("\nInitializing X-52 output .."); |
269 | 288 | ||
270 | x52_output = x52_init(); |
289 | x52_output = x52_init(); |
271 | 290 | ||
272 | clear_display(); |
291 | clear_display(); |
273 | 292 | ||
274 | write_display(0, "RIDDIM active"); |
293 | write_display(0, "RIDDIM active"); |
275 | 294 | ||
276 | if (x52_output) x52_setbri(x52_output, 1,128); |
295 | if (x52_output) x52_setbri(x52_output, 1,128); |
277 | if (x52_output) |
296 | if (x52_output) |
278 | printf(" done \n"); |
297 | printf(" done \n"); |
279 | else |
298 | else |
280 | printf(" not found \n"); |
299 | printf(" not found \n"); |
281 | 300 | ||
282 | printf("Scanning for Bluetooth Devices ..\n"); |
301 | printf("Scanning for Bluetooth Devices ..\n"); |
283 | write_display(1,"Bluetooth Scan"); |
302 | write_display(1,"Bluetooth Scan"); |
284 | 303 | ||
285 | scan_bt(); |
304 | // scan_bt(); |
286 | printf(" done \n"); |
305 | printf(" done \n"); |
287 | printf(" %d Devices found \n",bt_device_count); |
306 | printf(" %d Devices found \n",bt_device_count); |
288 | 307 | ||
289 | 308 | ||
290 | for(i=0;i<bt_device_count;i++) |
309 | /* for(i=0;i<bt_device_count;i++) |
291 | { |
310 | { |
292 | printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
311 | printf(" %d -> %s (%s) \n",i,names[i],addrs[i]); |
293 | if (i<3) write_display(i,names[i]); |
312 | if (i<3) write_display(i,names[i]); |
294 | } |
313 | } |
295 | 314 | |
|
296 | output_device_list() ; |
315 | output_device_list() ; |
297 | 316 | */ |
|
298 | 317 | ||
299 | int v_old; |
318 | int v_old; |
300 | while( 1 ) |
319 | while( 1 ) |
301 | { |
320 | { |
302 | int polls=0; |
321 | int polls=0; |
303 | for (polls=0;polls<1000;polls++) // FIXME - better Polling |
322 | for (polls=0;polls<1000;polls++) // FIXME - better Polling |
304 | { |
323 | { |
305 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
324 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
306 | 325 | ||
307 | 326 | ||
308 | /* see what to do with the event */ |
327 | /* see what to do with the event */ |
309 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
328 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
310 | { |
329 | { |
311 | case JS_EVENT_AXIS: |
330 | case JS_EVENT_AXIS: |
312 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
331 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
313 | break; |
332 | break; |
314 | case JS_EVENT_BUTTON: |
333 | case JS_EVENT_BUTTON: |
315 | button [ x52_event_struct.number ] = x52_event_struct.value; |
334 | button [ x52_event_struct.number ] = x52_event_struct.value; |
316 | break; |
335 | break; |
317 | } |
336 | } |
318 | } |
337 | } |
319 | 338 | ||
320 | for( x=0 ; x<num_of_buttons ; ++x ) |
339 | for( x=0 ; x<num_of_buttons ; ++x ) |
321 | if( button[x]==0) |
340 | if( button[x]==0) |
322 | button_trigger[x]=0; |
341 | button_trigger[x]=0; |
323 | else |
342 | else |
324 | { |
343 | { |
325 | if (button_trigger[x]<100)button_trigger[x]++; |
344 | if (button_trigger[x]<100)button_trigger[x]++; |
326 | } |
345 | } |
327 | 346 | ||
328 | 347 | ||
329 | 348 | ||
330 | switch(state) |
349 | switch(state) |
331 | { |
350 | { |
- | 351 | ||
- | 352 | ||
332 | case STATEID_SCANNING: |
353 | case STATEID_SCANNING: |
- | 354 | ||
- | 355 | state=STATEID_CONNECTING; //e |
|
- | 356 | ||
- | 357 | ExternControl.Digital[0]=0; |
|
- | 358 | ExternControl.Digital[1]=0; |
|
- | 359 | ExternControl.RemoteTasten=0; |
|
- | 360 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
|
- | 361 | ||
- | 362 | printf("nick%d\n",ExternControl.Nick); |
|
- | 363 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
|
- | 364 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
|
- | 365 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
|
- | 366 | ExternControl.Higt=0; |
|
- | 367 | ExternControl.free=0; |
|
- | 368 | ExternControl.Frame='t'; |
|
- | 369 | ExternControl.Config=1; |
|
- | 370 | ||
- | 371 | ||
- | 372 | ||
- | 373 | printf("sending data\n"); |
|
- | 374 | ||
- | 375 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
|
- | 376 | ||
- | 377 | ||
333 | if (button_trigger[BUTTON_SELECT]==1) |
378 | if (button_trigger[BUTTON_SELECT]==1) |
334 | { |
379 | { |
335 | state=STATEID_CONNECTING; |
380 | state=STATEID_CONNECTING; |
336 | clear_display(); |
381 | clear_display(); |
337 | write_display(0,"connecting to"); |
382 | write_display(0,"connecting to"); |
338 | write_display(1,names[selected_bt_device]); |
383 | write_display(1,names[selected_bt_device]); |
339 | connect_mk(addrs[selected_bt_device]); |
384 | connect_mk(addrs[selected_bt_device]); |
340 | write_display(0,"connected to"); |
385 | write_display(0,"connected to"); |
341 | } |
386 | } |
342 | 387 | ||
343 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
388 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
344 | { |
389 | { |
345 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
390 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
346 | if (button_trigger[BUTTON_DOWN]==1) |
391 | if (button_trigger[BUTTON_DOWN]==1) |
347 | if (selected_bt_device>0) selected_bt_device--; |
392 | if (selected_bt_device>0) selected_bt_device--; |
348 | if (button_trigger[BUTTON_UP]==1) |
393 | if (button_trigger[BUTTON_UP]==1) |
349 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
394 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
350 | 395 | ||
351 | output_device_list() ; |
396 | output_device_list() ; |
352 | } |
397 | } |
353 | break; |
398 | break; |
- | 399 | ||
354 | case STATEID_CONNECTING: |
400 | case STATEID_CONNECTING: |
- | 401 | // for (polls=0;polls<10;polls++) // FIXME - better Polling |
|
- | 402 | RxBuffer[1]=0; |
|
- | 403 | while (RxBuffer[1]!='t') |
|
- | 404 | { |
|
- | 405 | ||
- | 406 | r=0; |
|
- | 407 | in_char='#'; |
|
- | 408 | ||
- | 409 | while(in_char!='\r') |
|
- | 410 | { |
|
- | 411 | count=read(s,&in_char,1); |
|
- | 412 | if (in_char!=0) |
|
- | 413 | { |
|
- | 414 | RxBuffer[r++]=in_char; |
|
- | 415 | } |
|
- | 416 | else |
|
- | 417 | { |
|
- | 418 | RxBuffer[r++]='0'; |
|
- | 419 | } |
|
- | 420 | // printf("count:%d r:%d %d %c \n",count , r, in_char, in_char); |
|
- | 421 | } |
|
- | 422 | RxBuffer[r++]='\0'; |
|
- | 423 | printf("--->%s\n",RxBuffer); |
|
- | 424 | ||
- | 425 | } |
|
- | 426 | ||
- | 427 | ExternControl.Digital[0]=0; |
|
- | 428 | ExternControl.Digital[1]=0; |
|
- | 429 | ExternControl.RemoteTasten=0; |
|
- | 430 | ExternControl.Nick=(axis[1]>>8)*(-1); |
|
- | 431 | printf("nick%d\n",ExternControl.Nick); |
|
- | 432 | ExternControl.Roll=(axis[0]>>8)*(-1); |
|
- | 433 | ExternControl.Gier=(axis[5]>>8); |
|
- | 434 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
|
- | 435 | ExternControl.Higt=0; |
|
- | 436 | ExternControl.free=0; |
|
- | 437 | ExternControl.Frame='t'; |
|
- | 438 | ExternControl.Config=1; |
|
355 | 439 | ||
356 | - | ||
357 | _TxBuffer[0]=(axis[2]>>8)*(-1)+127; |
- | |
358 | if (button[7]!=1)_TxBuffer[0] =0; |
- | |
359 | - | ||
360 | _TxBuffer[1]=_TxBuffer[0]; |
- | |
361 | _TxBuffer[2]=_TxBuffer[0]; |
- | |
362 | _TxBuffer[3]=_TxBuffer[0]; |
- | |
363 | - | ||
364 | SendOutData('t', 0, 4); |
- | |
365 | - | ||
366 | - | ||
- | 440 | ||
- | 441 | ||
- | 442 | printf("sending data\n"); |
|
- | 443 | ||
- | 444 | SendOutData('b', 0, &ExternControl, sizeof(ExternControl)); |
|
- | 445 | ||
- | 446 | printf("sent data\n"); |
|
- | 447 | ||
- | 448 | ||
- | 449 | printf("sleeping\n"); |
|
367 | sleep(0.05); |
450 | // usleep(10000); |
368 | 451 | ||
369 | 452 | printf("end_sleep\n"); |
|
370 | 453 | ||
371 | int v=axis[6]/655+50; |
454 | int v=axis[6]/655+50; |
372 | if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
455 | if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
373 | v_old=v; |
456 | v_old=v; |
374 | 457 | ||
375 | printf("v: %d \r",v); |
458 | printf("v: %d \n",v); |
376 | 459 | ||
377 | 460 | ||
378 | for (i=0;i<num_of_axis;i++) |
461 | for (i=0;i<num_of_axis;i++) |
379 | printf("A%d: %d ", i,axis[i]>>8 ); |
462 | printf("A%d: %d ", i,axis[i]>>8 ); |
380 | 463 | ||
381 | for( x=0 ; x<num_of_buttons ; ++x ) |
464 | for( x=0 ; x<num_of_buttons ; ++x ) |
382 | 465 | ||
383 | printf("B%d: %d ", x, button[x] ); |
466 | printf("B%d: %d ", x, button[x] ); |
384 | 467 | ||
385 | break; |
468 | break; |
386 | } |
469 | } |
387 | 470 | ||
388 | printf("\r"); |
471 | printf("\n"); |
389 | fflush(stdout); |
- | |
- | 472 | fflush(stdout); |
|
390 | 473 | printf("loop fin"); |
|
391 | 474 | ||
392 | } |
475 | } |
393 | 476 | ||
394 | 477 | ||
395 | /******************** Cleanup **********************/ |
478 | /******************** Cleanup **********************/ |
396 | close(x52_input_fd); |
479 | close(x52_input_fd); |
397 | close(s); |
480 | close(s); |
398 | 481 | ||
399 | if (x52_output) x52_close(x52_output); |
482 | if (x52_output) x52_close(x52_output); |
400 | return 0; |
483 | return 0; |
401 | } |
484 | } |
402 | 485 |