Rev 125 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 125 | Rev 127 | ||
---|---|---|---|
Line -... | Line 1... | ||
- | 1 | /************************************************** |
|
- | 2 | * |
|
- | 3 | * |
|
- | 4 | * Riddim |
|
1 | #include <confuse.h> |
5 | * Remote Interactive Digital Drone Interface Mashup |
- | 6 | * |
|
2 | #include <string.h> |
7 | * 2007-2008 Marcus -LiGi- Bueschleb |
- | 8 | * |
|
- | 9 | * |
|
- | 10 | **************************************************/ |
|
Line 3... | Line -... | ||
3 | - | ||
4 | #include <stdio.h> |
11 | |
5 | #include <stdlib.h> |
- | |
6 | #include <string.h> |
- | |
7 | #include <fcntl.h> |
- | |
8 | #include "lib/x52/x52.h" |
- | |
9 | #include <unistd.h> |
- | |
10 | #include <sys/socket.h> |
- | |
11 | #include <bluetooth/bluetooth.h> |
- | |
12 | #include <bluetooth/hci.h> |
- | |
Line 13... | Line -... | ||
13 | #include <bluetooth/hci_lib.h> |
- | |
14 | - | ||
15 | #include <sys/time.h> |
- | |
16 | - | ||
17 | - | ||
18 | #include <bluetooth/rfcomm.h> |
- | |
19 | - | ||
20 | - | ||
21 | #include <linux/joystick.h> |
- | |
22 | #define JOY_DEV "/dev/input/js0" |
12 | #include "riddim.h" |
23 | - | ||
24 | #define MAX_BT_DEVICES 3 |
- | |
25 | - | ||
26 | - | ||
27 | #define STATEID_SCANNING 0 |
- | |
28 | #define STATEID_CONNECTING 1 |
- | |
29 | - | ||
30 | #define BUTTON_SELECT 26 |
13 | |
31 | #define BUTTON_DOWN 28 |
- | |
32 | #define BUTTON_UP 27 |
- | |
33 | - | ||
34 | - | ||
35 | // #define AXIS_ROLL 0 |
- | |
36 | // #define AXIS_NICK 1 |
- | |
Line -... | Line 14... | ||
- | 14 | #define FALSE 0 |
|
Line -... | Line 15... | ||
- | 15 | #define TRUE 1 |
|
Line 37... | Line -... | ||
37 | // #define AXIS_GIER 5 |
- | |
38 | // #define AXIS_GAS 2 |
- | |
39 | - | ||
40 | - | ||
41 | - | ||
42 | // for x52 |
- | |
Line 43... | Line 16... | ||
43 | /* |
16 | |
44 | #define AXIS_ROLL 4 |
17 | #define test_bit(bit, array) (array[bit/8] & (1<<(bit%8))) |
45 | #define AXIS_NICK 3 |
18 | |
46 | #define AXIS_GIER 5 |
19 | int state=STATEID_SCANNING; |
47 | #define AXIS_GAS 2 |
- | |
Line 48... | Line -... | ||
48 | - | ||
49 | #define INVERT_ROLL -1 |
- | |
50 | #define INVERT_NICK -1 |
- | |
51 | #define INVERT_GIER 1 |
- | |
Line 52... | Line -... | ||
52 | #define INVERT_GAS -1 |
- | |
53 | */ |
- | |
54 | - | ||
55 | #define AXIS_ROLL 0 |
- | |
Line -... | Line 20... | ||
- | 20 | ||
- | 21 | ||
- | 22 | // from config |
|
- | 23 | char *input_evdev_name; |
|
Line 56... | Line -... | ||
56 | #define AXIS_NICK 1 |
- | |
57 | #define AXIS_GIER 3 |
- | |
58 | #define AXIS_GAS 2 |
- | |
59 | - | ||
60 | #define INVERT_ROLL 1 |
- | |
61 | #define INVERT_NICK -1 |
- | |
62 | #define INVERT_GIER 1 |
- | |
Line -... | Line 24... | ||
- | 24 | int mk_socket_port=0; |
|
- | 25 | int loop_delay=0; |
|
- | 26 | ||
- | 27 | ||
Line 63... | Line -... | ||
63 | #define INVERT_GAS -1 |
- | |
64 | - | ||
65 | - | ||
Line 66... | Line -... | ||
66 | #include <stdio.h> |
- | |
67 | #include <errno.h> |
- | |
68 | #include <string.h> |
28 | |
Line 69... | Line 29... | ||
69 | #include <sys/socket.h> |
29 | double nick_mul=0.3f; |
70 | #include <sys/types.h> |
30 | double roll_mul=0.3f; |
71 | #include <netinet/in.h> |
31 | double gier_mul=0.3f; |
Line 72... | Line -... | ||
72 | #include <unistd.h>//for close() for socket |
- | |
73 | - | ||
74 | - | ||
75 | #define INPUT_NONE 0 |
- | |
76 | #define INPUT_JOYDEV 1 |
- | |
77 | #define INPUT_EVDEV 2 |
- | |
78 | - | ||
79 | - | ||
80 | // from config |
- | |
81 | char *input_evdev_name; |
- | |
82 | - | ||
83 | // time struct for measuring |
- | |
84 | struct timeval time_struct1; |
- | |
85 | struct timeval time_struct2; |
- | |
86 | - | ||
87 | 32 | double gas_mul=0.3f; |
|
Line -... | Line 33... | ||
- | 33 | ||
- | 34 | ||
- | 35 | int rel_axis_nick=1; |
|
- | 36 | int rel_axis_roll=0; |
|
- | 37 | int rel_axis_gier=5; |
|
88 | int act_nick=0; |
38 | int rel_axis_gas=2; |
89 | int act_roll=0; |
39 | |
Line 90... | Line 40... | ||
90 | int act_gier=0; |
40 | |
Line 91... | Line 41... | ||
91 | int act_gas=0; |
41 | cfg_bool_t exit_after_init = cfg_false; |
92 | int act_mode=0; |
42 | |
Line 93... | Line 43... | ||
93 | 43 | // time struct for measuring |
|
Line 94... | Line -... | ||
94 | int bt_device_count=0; |
- | |
95 | - | ||
96 | char names[MAX_BT_DEVICES][248]; |
- | |
97 | char addrs[MAX_BT_DEVICES][19]; |
- | |
98 | - | ||
99 | int s, status; |
- | |
100 | unsigned char TxBuffer[150]; |
- | |
101 | unsigned char _TxBuffer[150]; |
- | |
102 | - | ||
103 | char RxBuffer[150]; |
- | |
104 | - | ||
105 | - | ||
106 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
- | |
107 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
- | |
108 | - | ||
109 | struct js_event x52_event_struct; |
- | |
110 | - | ||
111 | int engines_on=0; |
- | |
112 | int old_engines_on=0; |
- | |
113 | - | ||
114 | char in_char; |
44 | struct timeval time_struct1; |
Line 115... | Line 45... | ||
115 | 45 | struct timeval time_struct2; |
|
116 | struct ExternControl_s |
- | |
117 | { |
- | |
118 | unsigned char Digital[2]; // (noch unbenutzt) |
- | |
119 | unsigned char RemoteTasten; //(gab es schon für das virtuelle Display) |
- | |
120 | signed char Nick; |
- | |
121 | signed char Roll; |
- | |
122 | signed char Gier; |
- | |
123 | unsigned char Gas; //(es wird das Stick-Gas auf diesen Wert begrenzt; --> StickGas ist das Maximum) |
- | |
124 | signed char Higt; //(Höhenregler) |
- | |
125 | unsigned char free; // (unbenutzt) |
- | |
126 | unsigned char Frame; // (Bestätigung) |
- | |
127 | unsigned char Config; |
- | |
128 | }; |
- | |
129 | - | ||
130 | - | ||
131 | struct ExternControl_s ExternControl ; |
- | |
132 | - | ||
133 | int state=STATEID_SCANNING; |
- | |
134 | - | ||
135 | - | ||
136 | struct x52 *x52_output; |
- | |
137 | - | ||
138 | int selected_bt_device=0; |
- | |
139 | void scan_bt() |
- | |
140 | { |
- | |
141 | inquiry_info *ii = NULL; |
- | |
142 | - | ||
143 | int dev_id, sock, len, flags; |
- | |
144 | int i; |
- | |
145 | char addr[19] = { 0 }; |
- | |
146 | char name[248] = { 0 }; |
- | |
147 | - | ||
148 | dev_id = hci_get_route(NULL); |
- | |
149 | sock = hci_open_dev( dev_id ); |
- | |
150 | if (dev_id < 0 || sock < 0) { |
- | |
151 | perror("opening socket"); |
- | |
152 | exit(1); |
- | |
153 | } |
- | |
154 | - | ||
155 | len = 8; |
- | |
156 | - | ||
157 | flags = IREQ_CACHE_FLUSH; |
- | |
Line 158... | Line 46... | ||
158 | ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info)); |
46 | |
159 | 47 | ||
160 | bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags); |
48 | char RxBuffer[150]; |
Line 161... | Line 49... | ||
161 | if( bt_device_count < 0 ) perror("hci_inquiry"); |
49 | |
- | 50 | ||
- | 51 | int status; |
|
- | 52 | ||
- | 53 | ||
162 | 54 | ||
163 | for (i = 0; i < bt_device_count; i++) { |
55 | |
- | 56 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
|
- | 57 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
|
- | 58 | ||
- | 59 | struct js_event x52_event_struct; |
|
- | 60 | ||
- | 61 | int engines_on=0; |
|
- | 62 | int old_engines_on=0; |
|
- | 63 | ||
- | 64 | char in_char; |
|
- | 65 | ||
- | 66 | struct x52 *x52_output; |
|
- | 67 | ||
- | 68 | int selected_bt_device=0; |
|
- | 69 | ||
164 | ba2str(&(ii+i)->bdaddr, addr); |
70 | int yalv; /* loop counter */ |
- | 71 | size_t read_bytes; /* how many bytes were read */ |
|
165 | sprintf(addrs[i],"%s",addr); |
72 | struct input_event ev[64]; /* the events (up to 64 at once) */ |
166 | 73 | ||
167 | memset(name, 0, sizeof(name)); |
74 | int evdev_fd; |
- | 75 | int evdev_out_fd; |
|
- | 76 | ||
- | 77 | int evdev_rw=TRUE; |
|
- | 78 | ||
- | 79 | int connect_evdev() |
|
- | 80 | { |
|
Line 168... | Line -... | ||
168 | - | ||
Line -... | Line 81... | ||
- | 81 | ||
- | 82 | struct input_devinfo { |
|
- | 83 | uint16_t bustype; |
|
- | 84 | uint16_t vendor; |
|
- | 85 | uint16_t product; |
|
- | 86 | uint16_t version; |
|
- | 87 | }; |
|
- | 88 | struct input_devinfo device_info; |
|
- | 89 | ||
- | 90 | if ((evdev_out_fd = open(input_evdev_name, O_WRONLY)) < 0) |
|
- | 91 | { |
|
- | 92 | printf(" cant open evdev read/write - trying readonly\n"); |
|
- | 93 | evdev_rw=FALSE; |
|
- | 94 | } |
|
- | 95 | if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0) |
|
- | 96 | { |
|
- | 97 | printf(" cant open evdev !"); |
|
- | 98 | return 0; |
|
- | 99 | } |
|
- | 100 | ||
- | 101 | ioctl(evdev_fd,EVIOCGID,&device_info); |
|
- | 102 | ||
- | 103 | printf("vendor 0x%04hx product 0x%04hx version 0x%04hx \n", |
|
- | 104 | device_info.vendor, device_info.product, |
|
- | 105 | device_info.version); |
|
- | 106 | ||
- | 107 | ||
- | 108 | char name[256]= "Unknown"; |
|
- | 109 | ||
- | 110 | if(ioctl(evdev_fd, EVIOCGNAME(sizeof(name)), name) < 0) { |
|
- | 111 | perror("evdev ioctl"); |
|
- | 112 | } |
|
- | 113 | ||
- | 114 | printf("EVDEV reports name: %s\n", name); |
|
- | 115 | ||
- | 116 | /* this macro is used to tell if "bit" is set in "array" |
|
- | 117 | * it selects a byte from the array, and does a boolean AND |
|
- | 118 | * operation with a byte that only has the relevant bit set. |
|
- | 119 | * eg. to check for the 12th bit, we do (array[1] & 1<<4) |
|
- | 120 | */ |
|
- | 121 | ||
- | 122 | ||
- | 123 | uint8_t evtype_bitmask[EV_MAX/8 + 1]; |
|
- | 124 | ||
- | 125 | if(ioctl(evdev_fd, EVIOCGBIT(0, sizeof(evtype_bitmask)), evtype_bitmask) < 0) |
|
- | 126 | perror("evdev ioctl"); |
|
- | 127 | ||
- | 128 | printf("Supported event types:\n"); |
|
- | 129 | for (yalv = 0; yalv < EV_MAX; yalv++) { |
|
- | 130 | if (test_bit(yalv, evtype_bitmask)) { |
|
- | 131 | /* this means that the bit is set in the event types list */ |
|
Line -... | Line 132... | ||
- | 132 | printf(" Event type 0x%02x ", yalv); |
|
169 | if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), |
133 | switch ( yalv) |
Line 170... | Line 134... | ||
170 | name, 0) < 0) |
134 | { |
171 | sprintf(names[i],"[unknown]"); |
135 | case EV_KEY : |
Line 231... | Line 195... | ||
231 | } |
195 | } |
Line 232... | Line -... | ||
232 | - | ||
233 | - | ||
234 | - | ||
235 | - | ||
236 | void AddCRC(unsigned int wieviele) |
- | |
237 | { |
- | |
238 | unsigned int tmpCRC = 0,i; |
- | |
239 | for(i = 0; i < wieviele;i++) |
- | |
240 | { |
- | |
241 | tmpCRC += TxBuffer[i]; |
- | |
242 | } |
- | |
243 | tmpCRC %= 4096; |
- | |
244 | TxBuffer[i++] = '=' + tmpCRC / 64; |
- | |
245 | TxBuffer[i++] = '=' + tmpCRC % 64; |
- | |
246 | TxBuffer[i++] = '\r'; |
- | |
247 | } |
- | |
248 | - | ||
249 | - | ||
250 | void SendOutData(unsigned char cmd,unsigned char modul, unsigned char *snd, unsigned char len) |
- | |
251 | { |
- | |
252 | unsigned int pt = 0; |
- | |
253 | unsigned char a,b,c; |
- | |
254 | unsigned char ptr = 0; |
- | |
255 | - | ||
256 | TxBuffer[pt++] = '#'; // Startzeichen |
- | |
257 | TxBuffer[pt++] = modul; // Adresse (a=0; b=1,...) |
- | |
258 | TxBuffer[pt++] = cmd; // Commando |
- | |
259 | - | ||
260 | while(len) |
- | |
261 | { |
- | |
262 | if(len) { a = snd[ptr++]; len--;} else a = 0; |
- | |
263 | if(len) { b = snd[ptr++]; len--;} else b = 0; |
- | |
264 | if(len) { c = snd[ptr++]; len--;} else c = 0; |
- | |
265 | TxBuffer[pt++] = '=' + (a >> 2); |
- | |
266 | TxBuffer[pt++] = '=' + (((a & 0x03) << 4) | ((b & 0xf0) >> 4)); |
- | |
267 | TxBuffer[pt++] = '=' + (((b & 0x0f) << 2) | ((c & 0xc0) >> 6)); |
- | |
268 | TxBuffer[pt++] = '=' + ( c & 0x3f); |
- | |
269 | } |
- | |
270 | - | ||
271 | - | ||
272 | - | ||
273 | AddCRC(pt); |
- | |
274 | printf("Sending to MK %d \n" , pt); |
- | |
275 | - | ||
276 | status = send(s,"\r" , 1, 0); |
- | |
277 | - | ||
278 | - | ||
279 | // for (c=0;c<pt+2;c++) |
- | |
280 | // { |
- | |
281 | status = write(s,&TxBuffer , pt+3); |
- | |
282 | // printf("Send to MK %d \n" , TxBuffer[c] ); |
- | |
283 | // } |
- | |
284 | /*while(TxBuffer[i] !='\r' && i<150) |
- | |
285 | { |
- | |
286 | // TxBuffer[i]='#'; |
- | |
Line 287... | Line -... | ||
287 | status = send(s,&TxBuffer[i] , 1, 0); |
- | |
288 | printf(" +%d%c ",i,TxBuffer[i]); |
- | |
289 | i++; |
- | |
290 | } |
- | |
291 | - | ||
Line 292... | Line 196... | ||
292 | status = send(s,"\r" , 1, 0); |
196 | |
293 | */ |
197 | |
294 | // status = send(s,"\r" , 1, 0); |
198 | |
Line 325... | Line 229... | ||
325 | write_display(i,disp_txt); |
229 | write_display(i,disp_txt); |
326 | } |
230 | } |
327 | } |
231 | } |
328 | } |
232 | } |
Line 329... | Line -... | ||
329 | - | ||
330 | int connect_mk(char dest[18]) |
- | |
331 | { |
- | |
332 | - | ||
333 | struct sockaddr_rc addr ; |
- | |
334 | struct sockaddr_in sa; |
- | |
335 | - | ||
336 | sa.sin_family = AF_INET; |
- | |
337 | sa.sin_addr.s_addr = htonl(0x0); |
- | |
338 | sa.sin_port = htons(54321); |
- | |
339 | - | ||
340 | // allocate a socket |
- | |
341 | // s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
- | |
342 | s = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP); |
- | |
343 | //); |
- | |
344 | - | ||
345 | // set the connection parameters (who to connect to) |
- | |
346 | addr.rc_family = AF_BLUETOOTH; |
- | |
347 | addr.rc_channel = 1; |
- | |
348 | str2ba( dest, &addr.rc_bdaddr ); |
- | |
349 | - | ||
350 | // connect to server |
- | |
351 | // status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
- | |
352 | status = connect(s,(struct sockaddr*) &sa, sizeof(struct sockaddr_in)); |
- | |
353 | - | ||
354 | return status; |
- | |
355 | - | ||
356 | /* |
- | |
357 | struct sockaddr_rc addr ; |
- | |
358 | - | ||
359 | // allocate a socket |
- | |
360 | s = socket(AF_BLUETOOTH, SOCK_STREAM, BTPROTO_RFCOMM); |
- | |
361 | |
- | |
362 | // set the connection parameters (who to connect to) |
- | |
363 | addr.rc_family = AF_BLUETOOTH; |
- | |
364 | addr.rc_channel = 1; |
- | |
365 | str2ba( dest, &addr.rc_bdaddr ); |
- | |
366 | - | ||
367 | // connect to server |
- | |
Line 368... | Line 233... | ||
368 | status = connect(s, (struct sockaddr *)&addr, sizeof(addr)); |
233 | |
- | 234 | ||
369 | 235 | void print_device_list() |
|
- | 236 | { |
|
- | 237 | int i; |
|
370 | return status; |
238 | for(i=0;i<bt_device_count;i++) |
Line 371... | Line -... | ||
371 | */ |
- | |
372 | } |
- | |
373 | 239 | printf("device%i->%s\n",i,names[i]); |
|
374 | 240 | } |
|
375 | 241 | ||
Line 385... | Line 251... | ||
385 | int main(int argc, char**argv) |
251 | int main(int argc, char**argv) |
386 | { |
252 | { |
Line 387... | Line 253... | ||
387 | 253 | ||
388 | printf("Starting Riddim \n"); |
254 | printf("Starting Riddim \n"); |
- | 255 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
|
- | 256 | printf("\nusage:\n"); |
|
Line 389... | Line -... | ||
389 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
- | |
390 | 257 | printf("\t riddim [config_file]\n\n"); |
|
- | 258 | ||
- | 259 | ||
391 | 260 | cfg_opt_t opts[] = { |
|
- | 261 | ||
- | 262 | CFG_SIMPLE_BOOL("exit_after_init", &exit_after_init), |
|
- | 263 | CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
|
- | 264 | CFG_SIMPLE_INT("loop_delay", &loop_delay), |
|
- | 265 | CFG_SIMPLE_INT("mk_socket_port", &mk_socket_port), |
|
- | 266 | ||
- | 267 | CFG_SIMPLE_FLOAT("nick_mul", &nick_mul), |
|
- | 268 | CFG_SIMPLE_FLOAT("roll_mul", &roll_mul), |
|
- | 269 | CFG_SIMPLE_FLOAT("gier_mul", &gier_mul), |
|
- | 270 | CFG_SIMPLE_FLOAT("gas_mul", &gas_mul), |
|
- | 271 | ||
- | 272 | CFG_SIMPLE_INT("rel_axis_nick", &rel_axis_nick), |
|
- | 273 | CFG_SIMPLE_INT("rel_axis_roll", &rel_axis_roll), |
|
392 | 274 | CFG_SIMPLE_INT("rel_axis_gier", &rel_axis_gier), |
|
393 | cfg_opt_t opts[] = { |
275 | CFG_SIMPLE_INT("rel_axis_gas", &rel_axis_gas), |
Line 394... | Line 276... | ||
394 | CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
276 | |
Line 395... | Line 277... | ||
395 | CFG_END() |
277 | CFG_END() |
396 | }; |
278 | }; |
Line 397... | Line 279... | ||
397 | 279 | ||
398 | cfg_t *cfg; |
- | |
399 | - | ||
Line 400... | Line -... | ||
400 | // input_evdev_name=strdup("/dev/event0"); |
- | |
401 | printf("Parsing config file"); |
280 | cfg_t *cfg; |
402 | 281 | ||
403 | cfg = cfg_init(opts, 0); |
282 | // input_evdev_name=strdup("/dev/event0"); |
404 | cfg_parse(cfg, "/etc/riddim.conf"); |
- | |
405 | printf("input %s:",input_evdev_name); |
- | |
406 | - | ||
407 | // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips ) |
- | |
408 | if (argv[1]) |
283 | printf("Parsing config file "); |
409 | { |
- | |
410 | if (connect_mk(argv[1])==-1) |
284 | |
- | 285 | cfg = cfg_init(opts, 0); |
|
411 | { |
286 | |
- | 287 | if (argv[1]) |
|
- | 288 | { |
|
412 | printf("cant connect to QC at adress: %s\n",argv[1]); |
289 | printf("%s\n ",argv[1]); |
- | 290 | cfg_parse(cfg, argv[1]); |
|
Line -... | Line 291... | ||
- | 291 | } |
|
Line -... | Line 292... | ||
- | 292 | else |
|
- | 293 | { |
|
- | 294 | printf("/etc/riddim.conf\n"); |
|
413 | return 0; |
295 | cfg_parse(cfg, "/etc/riddim.conf"); |
- | 296 | } |
|
- | 297 | printf("input %s:\n",input_evdev_name); |
|
- | 298 | ||
- | 299 | // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips ) |
|
- | 300 | ||
- | 301 | if (mk_socket_port) |
|
- | 302 | { |
|
- | 303 | printf("connecting to local port: %i\n",mk_socket_port); |
|
Line -... | Line 304... | ||
- | 304 | ||
Line 414... | Line 305... | ||
414 | } |
305 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
415 | printf("connected to QC at adress: %s\n",argv[1]); |
306 | printf("cant connect !!"); |
416 | connected=1; |
307 | else |
417 | } |
308 | { |
Line 452... | Line 343... | ||
452 | if (x52_output) |
343 | if (x52_output) |
453 | printf(" done \n"); |
344 | printf(" done \n"); |
454 | else |
345 | else |
455 | printf(" not found \n"); |
346 | printf(" not found \n"); |
Line -... | Line 347... | ||
- | 347 | ||
456 | 348 | /* |
|
457 | if (!connected) |
349 | if (!connected) |
458 | { |
350 | { |
459 | printf("Scanning for Bluetooth Devices ..\n"); |
351 | printf("Scanning for Bluetooth Devices ..\n"); |
460 | write_display(1,"Bluetooth Scan"); |
352 | write_display(1,"Bluetooth Scan"); |
461 | scan_bt(); |
353 | scan_bt(); |
462 | printf(" done \n"); |
354 | printf(" done \n"); |
- | 355 | printf(" %d Devices found \n",bt_device_count); |
|
463 | printf(" %d Devices found \n",bt_device_count); |
356 | print_device_list() ; |
464 | } |
357 | } |
Line 465... | Line 358... | ||
465 | 358 | */ |
|
466 | 359 | ||
- | 360 | int v_old; |
|
- | 361 | int polls=0; |
|
- | 362 | ||
- | 363 | int retval; |
|
467 | int v_old; |
364 | if (exit_after_init) |
Line -... | Line 365... | ||
- | 365 | exit(0); |
|
- | 366 | printf("starting loop ..\n"); |
|
Line -... | Line 367... | ||
- | 367 | ||
- | 368 | struct input_event led_event; |
|
- | 369 | led_event.type=EV_LED; |
|
- | 370 | ||
- | 371 | int complete_misses=0; |
|
- | 372 | if (evdev_out_fd) |
|
- | 373 | { |
|
Line -... | Line 374... | ||
- | 374 | led_event.code = LED_MISC; |
|
468 | int polls=0; |
375 | led_event.value = 1; |
469 | printf("starting loop ..\n"); |
376 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
Line -... | Line 377... | ||
- | 377 | } |
|
- | 378 | ||
- | 379 | int confirm_misses; |
|
- | 380 | while( 1 ) |
|
- | 381 | { |
|
- | 382 | ||
- | 383 | if (evdev_out_fd) |
|
- | 384 | { |
|
- | 385 | if (led_event.value) |
|
- | 386 | led_event.value = 0; |
|
470 | 387 | else |
|
471 | 388 | led_event.value = 1 ; |
|
- | 389 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
|
Line 472... | Line 390... | ||
472 | 390 | } |
|
473 | while( 1 ) |
391 | |
474 | { |
- | |
475 | - | ||
476 | switch (input) |
392 | usleep(loop_delay); |
Line 477... | Line 393... | ||
477 | { |
393 | switch (input) |
478 | 394 | { |
|
479 | case INPUT_NONE: |
- | |
480 | printf("input none\n"); |
- | |
481 | usleep(10000); |
- | |
482 | - | ||
483 | break; |
- | |
484 | - | ||
485 | case INPUT_EVDEV: |
- | |
486 | printf("input evdev\n"); |
- | |
487 | usleep(30000); |
- | |
Line 488... | Line 395... | ||
488 | 395 | ||
489 | 396 | ||
490 | read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64); |
397 | case INPUT_NONE: |
491 | printf("read done\n"); |
398 | printf("starting input none\n"); |
- | 399 | break; |
|
- | 400 | ||
492 | if (read_bytes < (int) sizeof(struct input_event)) { |
401 | case INPUT_EVDEV: |
- | 402 | printf("input evdev\n"); |
|
- | 403 | ||
- | 404 | struct timeval tv; |
|
- | 405 | int retval; |
|
493 | perror("evtest: short read"); |
406 | fd_set rfds; |
494 | exit (1); |
407 | FD_ZERO(&rfds); |
- | 408 | FD_SET(evdev_fd,&rfds); |
|
- | 409 | ||
- | 410 | tv.tv_sec = 0; |
|
495 | } |
411 | tv.tv_usec = 5; |
496 | 412 | ||
497 | for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++) |
413 | retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv); |
- | 414 | ||
- | 415 | if (retval==-1) |
|
- | 416 | printf("error in select!!!!!!!!\n"); |
|
- | 417 | else if (retval) |
|
- | 418 | { |
|
- | 419 | read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64); |
|
498 | { |
420 | |
499 | // 1 -> nick |
421 | if (read_bytes < (int) sizeof(struct input_event)) { |
500 | // 2 -> gas |
422 | perror("evtest: short read"); |
501 | // 4->roll |
423 | exit (1); |
- | 424 | } |
|
- | 425 | ||
- | 426 | for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++) |
|
- | 427 | { |
|
- | 428 | ||
- | 429 | printf("%d type:%d code:%d val:%d \n",yalv,ev[yalv].type,ev[yalv].code,ev[yalv].value); |
|
- | 430 | if (ev[yalv].type==EV_REL) axis[ ev[yalv].code]= ev[yalv].value; |
|
- | 431 | if (ev[yalv].type==EV_KEY) button[ ev[yalv].code-256]= ev[yalv].value; |
|
- | 432 | } |
|
502 | // 5-> gier |
433 | |
- | 434 | ||
- | 435 | for (yalv=0;yalv<10;yalv++) |
|
Line -... | Line 436... | ||
- | 436 | printf("A%d %d -" , yalv, axis[yalv] ); |
|
Line 503... | Line -... | ||
503 | axis[ ev[yalv].code]= ev[yalv].value; |
- | |
504 | 437 | printf("\n"); |
|
505 | printf("nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]); |
438 | |
506 | /*if ( ev[yalv].code==5) |
439 | for (yalv=0;yalv<10;yalv++) |
Line 507... | Line 440... | ||
507 | printf("Event: time %ld.%06ld, type %d, code %d, value %d\n", |
440 | printf("B%d %d -" , yalv, button[yalv] ); |
Line 568... | Line 501... | ||
568 | ExternControl.Config=1; |
501 | ExternControl.Config=1; |
Line 569... | Line 502... | ||
569 | 502 | ||
Line 570... | Line 503... | ||
570 | printf("sending data\n"); |
503 | printf("sending data\n"); |
571 | 504 | ||
Line 572... | Line 505... | ||
572 | 505 | ||
573 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
506 | if (connected)SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
574 | gettimeofday(&time_struct1,NULL); |
507 | gettimeofday(&time_struct1,NULL); |
575 | 508 | ||
576 | if (button_trigger[BUTTON_SELECT]==1) |
509 | if (button_trigger[BUTTON_SELECT]==1) |
577 | { |
510 | { |
578 | state=STATEID_CONNECTING; |
511 | state=STATEID_CONNECTING; |
579 | clear_display(); |
512 | clear_display(); |
580 | write_display(0,"connecting to"); |
513 | write_display(0,"connecting to"); |
Line 581... | Line 514... | ||
581 | write_display(1,names[selected_bt_device]); |
514 | write_display(1,names[selected_bt_device]); |
582 | connect_mk(addrs[selected_bt_device]); |
515 | //connect_mk(addrs[selected_bt_device]); |
Line 589... | Line 522... | ||
589 | if (button_trigger[BUTTON_DOWN]==1) |
522 | if (button_trigger[BUTTON_DOWN]==1) |
590 | if (selected_bt_device>0) selected_bt_device--; |
523 | if (selected_bt_device>0) selected_bt_device--; |
591 | if (button_trigger[BUTTON_UP]==1) |
524 | if (button_trigger[BUTTON_UP]==1) |
592 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
525 | if (selected_bt_device<bt_device_count-1) selected_bt_device++; |
Line 593... | Line -... | ||
593 | - | ||
- | 526 | ||
594 | output_device_list() ; |
527 | |
595 | } |
528 | } |
Line 596... | Line 529... | ||
596 | break; |
529 | break; |
- | 530 | ||
Line 597... | Line 531... | ||
597 | 531 | case STATEID_CONNECTING: |
|
- | 532 | ||
- | 533 | ||
- | 534 | confirm_misses=0; |
|
Line -... | Line 535... | ||
- | 535 | printf("connected:%d",connected); |
|
- | 536 | if (connected) while (RxBuffer[1]!='t') |
|
- | 537 | { |
|
- | 538 | ||
- | 539 | RxBuffer[1]=0; |
|
- | 540 | ||
Line 598... | Line -... | ||
598 | case STATEID_CONNECTING: |
- | |
599 | - | ||
600 | RxBuffer[1]=0; |
- | |
601 | - | ||
Line 602... | Line -... | ||
602 | - | ||
603 | // ftime(&time_struct); |
- | |
Line 604... | Line 541... | ||
604 | printf("waiting for confirm frame\n"); |
541 | |
605 | RxBuffer[2]=0; |
542 | // ftime(&time_struct); |
Line 606... | Line 543... | ||
606 | int confirm_misses=0; |
543 | printf("waiting for confirm frame ( misses:%d )\n",confirm_misses); |
607 | 544 | RxBuffer[2]=0; |
|
608 | while (RxBuffer[2]!='t') |
545 | |
609 | { |
546 | |
610 | 547 | ||
611 | r=0; |
548 | r=0; |
612 | in_char='#'; |
549 | in_char='#'; |
613 | 550 | ||
Line 623... | Line 560... | ||
623 | RxBuffer[r++]='0'; |
560 | RxBuffer[r++]='0'; |
624 | } |
561 | } |
625 | // printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char); |
562 | // printf("\ncount:%d r:%d %d %c \n",count , r, in_char, in_char); |
626 | } |
563 | } |
627 | RxBuffer[r++]='\0'; |
564 | RxBuffer[r++]='\0'; |
628 | printf("--->%s\n",RxBuffer); |
565 | printf("%d--->%s\n",complete_misses,RxBuffer); |
629 | // new |
566 | // new |
630 | if (button_trigger[12]>1) |
567 | if (button_trigger[12]>1) |
631 | { |
568 | { |
632 | SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
569 | SendOutData('s', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
633 | button_trigger[12]=0; |
570 | button_trigger[12]=0; |
634 | } |
571 | } |
635 | if (++confirm_misses>4) |
572 | if (++confirm_misses>4) |
- | 573 | { |
|
- | 574 | complete_misses++; |
|
- | 575 | printf("sending again\n"); |
|
636 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
576 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
637 | 577 | } |
|
638 | } |
578 | } |
- | 579 | else |
|
- | 580 | printf("not connected to mk\n"); |
|
639 | gettimeofday(&time_struct2,NULL); |
581 | gettimeofday(&time_struct2,NULL); |
Line 640... | Line 582... | ||
640 | 582 | ||
641 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
583 | printf("last trip: %d",(int)(time_struct1.tv_usec-time_struct2.tv_usec)); |
Line -... | Line 584... | ||
- | 584 | act_mode=button[24] | (button[25]<<1); |
|
- | 585 | ||
- | 586 | ||
- | 587 | ||
- | 588 | // Step converting axis data to nick/roll/gier/gas/.. |
|
- | 589 | ||
- | 590 | act_nick=axis[rel_axis_nick]*nick_mul; |
|
- | 591 | act_roll=axis[rel_axis_roll]*roll_mul; |
|
- | 592 | act_gier=axis[rel_axis_gier]*gier_mul; |
|
- | 593 | act_gas=axis[rel_axis_gas]*gas_mul; |
|
- | 594 | act_gas=255; |
|
- | 595 | ||
642 | act_mode=button[24] | (button[25]<<1); |
596 | |
643 | 597 | /* |
|
644 | switch (act_mode) |
598 | switch (act_mode) |
Line 645... | Line 599... | ||
645 | { |
599 | { |
646 | case 0: |
600 | case 0: |
647 | 601 | ||
648 | 602 | ||
Line 649... | Line 603... | ||
649 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK); |
603 | act_nick=(axis[AXIS_NICK])*(INVERT_NICK); |
650 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL); |
604 | act_roll=(axis[AXIS_ROLL])*(INVERT_ROLL); |
Line 651... | Line 605... | ||
651 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER); |
605 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
Line 675... | Line 629... | ||
675 | 629 | ||
Line 676... | Line 630... | ||
676 | 630 | ||
677 | break; |
631 | break; |
678 | 632 | ||
679 | } |
633 | } |
680 | 634 | */ |
|
681 | ExternControl.Digital[0]=0; |
635 | ExternControl.Digital[0]=0; |
682 | ExternControl.Digital[1]=0; |
636 | ExternControl.Digital[1]=0; |
Line 696... | Line 650... | ||
696 | ExternControl.Config=1; |
650 | ExternControl.Config=1; |
697 | printf("---+++act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick , act_roll , act_gier , act_gas); |
651 | printf("---+++act_mode %d , act_nick %d , act_roll %d , act_gier %d , act_gas %d",act_mode , act_nick , act_roll , act_gier , act_gas); |
Line -... | Line 652... | ||
- | 652 | ||
- | 653 | ||
698 | 654 | ||
699 | 655 | if (connected) |
|
700 | 656 | { |
|
701 | printf("sending data\n"); |
657 | printf("sending data\n"); |
702 | 658 | ||
703 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
659 | SendOutData('b', 0, (unsigned char *)&ExternControl, sizeof(ExternControl)); |
Line 704... | Line 660... | ||
704 | gettimeofday(&time_struct1,NULL); |
660 | gettimeofday(&time_struct1,NULL); |
705 | printf("sent data\n"); |
661 | printf("sent data\n"); |
706 | 662 | } |
|
707 | 663 | ||
708 | // printf("sleeping\n"); |
664 | // printf("sleeping\n"); |
709 | // for (polls=0;polls<100;polls++) // FIXME - better Polling |
665 | // for (polls=0;polls<100;polls++) // FIXME - better Polling |
710 | // printf("end_sleep\n"); |
666 | // printf("end_sleep\n"); |
Line 711... | Line 667... | ||
711 | 667 | ||
712 | int v=axis[6]/655+50; |
668 | int v=axis[6]/655+50; |
713 | if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
669 | if (v!=v_old)if (x52_output) x52_setbri(x52_output, 0,v ); |
714 | v_old=v; |
670 | v_old=v; |
715 | 671 | ||
Line 716... | Line 672... | ||
716 | printf("v: %d \n",v); |
672 | printf("v: %d \n",v); |
Line 717... | Line 673... | ||
717 | 673 | ||
718 | 674 | ||
719 | for (i=0;i<num_of_axis;i++) |
675 | for (i=0;i<num_of_axis;i++) |
720 | printf("A%d: %d ", i,axis[i]>>8 ); |
676 | printf("A%d: %d ", i,axis[i]>>8 ); |
721 | 677 | ||
722 | for( x=0 ; x<num_of_buttons ; ++x ) |
678 | for( x=0 ; x<num_of_buttons ; ++x ) |
723 | 679 | ||
724 | printf("B%d: %d ", x, button[x] ); |
680 | printf("B%d: %d ", x, button[x] ); |
Line 725... | Line 681... | ||
725 | 681 | ||
Line 726... | Line 682... | ||
726 | break; |
682 | break; |
727 | } |
683 | } |
728 | 684 | ||
Line 729... | Line 685... | ||
729 | printf("\n"); |
685 | printf("\n"); |
730 | fflush(stdout); |
686 | fflush(stdout); |
731 | printf("loop fin"); |
687 | printf("loop fin ( misses:%d)\n",complete_misses); |