Rev 125 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 125 | Rev 127 | ||
---|---|---|---|
- | 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 | **************************************************/ |
|
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> |
- | |
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 |
- | |
- | 14 | #define FALSE 0 |
|
- | 15 | #define TRUE 1 |
|
37 | // #define AXIS_GIER 5 |
- | |
38 | // #define AXIS_GAS 2 |
- | |
39 | - | ||
40 | - | ||
41 | - | ||
42 | // for x52 |
- | |
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 |
- | |
48 | - | ||
49 | #define INVERT_ROLL -1 |
- | |
50 | #define INVERT_NICK -1 |
- | |
51 | #define INVERT_GIER 1 |
- | |
52 | #define INVERT_GAS -1 |
- | |
53 | */ |
- | |
54 | - | ||
55 | #define AXIS_ROLL 0 |
- | |
- | 20 | ||
- | 21 | ||
- | 22 | // from config |
|
- | 23 | char *input_evdev_name; |
|
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 |
- | |
- | 24 | int mk_socket_port=0; |
|
- | 25 | int loop_delay=0; |
|
- | 26 | ||
- | 27 | ||
63 | #define INVERT_GAS -1 |
- | |
64 | - | ||
65 | - | ||
66 | #include <stdio.h> |
- | |
67 | #include <errno.h> |
- | |
68 | #include <string.h> |
28 | |
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; |
72 | #include <unistd.h>//for close() for socket |
32 | double gas_mul=0.3f; |
73 | 33 | ||
74 | 34 | ||
75 | #define INPUT_NONE 0 |
35 | int rel_axis_nick=1; |
76 | #define INPUT_JOYDEV 1 |
36 | int rel_axis_roll=0; |
77 | #define INPUT_EVDEV 2 |
37 | int rel_axis_gier=5; |
78 | 38 | int rel_axis_gas=2; |
|
79 | 39 | ||
80 | // from config |
40 | |
81 | char *input_evdev_name; |
41 | cfg_bool_t exit_after_init = cfg_false; |
82 | 42 | ||
83 | // time struct for measuring |
43 | // time struct for measuring |
84 | struct timeval time_struct1; |
44 | struct timeval time_struct1; |
85 | struct timeval time_struct2; |
45 | struct timeval time_struct2; |
86 | 46 | ||
87 | - | ||
88 | int act_nick=0; |
- | |
89 | int act_roll=0; |
- | |
90 | int act_gier=0; |
- | |
91 | int act_gas=0; |
- | |
92 | int act_mode=0; |
- | |
93 | - | ||
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 | 47 | ||
103 | char RxBuffer[150]; |
48 | char RxBuffer[150]; |
104 | 49 | ||
- | 50 | ||
- | 51 | int status; |
|
- | 52 | ||
- | 53 | ||
- | 54 | ||
105 | 55 | ||
106 | int x52_input_fd, *axis=NULL, num_of_axis=0, num_of_buttons=0, x; |
56 | 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]; |
57 | char *button=NULL,*button_trigger=NULL, name_of_joystick[80]; |
108 | 58 | ||
109 | struct js_event x52_event_struct; |
59 | struct js_event x52_event_struct; |
110 | 60 | ||
111 | int engines_on=0; |
61 | int engines_on=0; |
112 | int old_engines_on=0; |
62 | int old_engines_on=0; |
113 | 63 | ||
114 | char in_char; |
64 | char in_char; |
115 | - | ||
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 | 65 | ||
136 | struct x52 *x52_output; |
66 | struct x52 *x52_output; |
137 | 67 | ||
138 | int selected_bt_device=0; |
68 | 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; |
- | |
158 | ii = (inquiry_info*)malloc(MAX_BT_DEVICES * sizeof(inquiry_info)); |
- | |
159 | - | ||
160 | bt_device_count = hci_inquiry(dev_id, len, MAX_BT_DEVICES, NULL, &ii, flags); |
- | |
161 | if( bt_device_count < 0 ) perror("hci_inquiry"); |
- | |
162 | - | ||
163 | for (i = 0; i < bt_device_count; i++) { |
- | |
164 | ba2str(&(ii+i)->bdaddr, addr); |
- | |
165 | sprintf(addrs[i],"%s",addr); |
- | |
166 | - | ||
167 | memset(name, 0, sizeof(name)); |
- | |
168 | - | ||
169 | if (hci_read_remote_name(sock, &(ii+i)->bdaddr, sizeof(name), |
- | |
170 | name, 0) < 0) |
- | |
171 | sprintf(names[i],"[unknown]"); |
- | |
172 | else |
- | |
173 | sprintf(names[i],"%s",name); |
- | |
174 | - | ||
175 | } |
- | |
176 | - | ||
177 | - | ||
178 | free( ii ); |
- | |
179 | close( sock ); |
- | |
180 | } |
- | |
181 | 69 | ||
182 | int yalv; /* loop counter */ |
70 | int yalv; /* loop counter */ |
183 | size_t read_bytes; /* how many bytes were read */ |
71 | size_t read_bytes; /* how many bytes were read */ |
184 | struct input_event ev[64]; /* the events (up to 64 at once) */ |
72 | struct input_event ev[64]; /* the events (up to 64 at once) */ |
185 | 73 | ||
186 | int evdev_fd; |
74 | int evdev_fd; |
- | 75 | int evdev_out_fd; |
|
- | 76 | ||
- | 77 | int evdev_rw=TRUE; |
|
- | 78 | ||
187 | int connect_evdev() |
79 | int connect_evdev() |
188 | { |
80 | { |
- | 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 | } |
|
189 | if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0) { |
95 | if ((evdev_fd = open(input_evdev_name, O_RDONLY)) < 0) |
- | 96 | { |
|
190 | printf(" cant open evdev "); |
97 | printf(" cant open evdev !"); |
191 | return 0; |
98 | return 0; |
192 | } |
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); |
|
193 | - | ||
- | 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 */ |
|
- | 132 | printf(" Event type 0x%02x ", yalv); |
|
- | 133 | switch ( yalv) |
|
- | 134 | { |
|
- | 135 | case EV_KEY : |
|
- | 136 | printf(" (Keys or Buttons)\n"); |
|
- | 137 | break; |
|
- | 138 | case EV_ABS : |
|
- | 139 | printf(" (Absolute Axes)\n"); |
|
- | 140 | break; |
|
- | 141 | case EV_LED : |
|
- | 142 | printf(" (LEDs)\n"); |
|
- | 143 | break; |
|
- | 144 | case EV_REP : |
|
- | 145 | printf(" (Repeat)\n"); |
|
- | 146 | break; |
|
- | 147 | case EV_SYN : |
|
- | 148 | printf(" (Sync?)\n"); |
|
- | 149 | break; |
|
- | 150 | case EV_REL : |
|
- | 151 | printf(" (Relative Axis)\n"); |
|
- | 152 | break; |
|
- | 153 | case EV_MSC : |
|
- | 154 | printf(" (Misc)\n"); |
|
- | 155 | break; |
|
- | 156 | default: |
|
- | 157 | printf(" (Unknown event type: 0x%04hx)\n", yalv); |
|
194 | return 1; |
158 | }}} |
195 | 159 | ||
196 | 160 | return 1; |
|
197 | } |
161 | } |
198 | 162 | ||
199 | int connect_joy() |
163 | int connect_joy() |
200 | { |
164 | { |
201 | 165 | ||
202 | axis = (int *) calloc( 100, sizeof( int ) ); |
166 | axis = (int *) calloc( 100, sizeof( int ) ); |
203 | button = (char *)calloc( 100, sizeof( char ) ); |
167 | button = (char *)calloc( 100, sizeof( char ) ); |
204 | button_trigger = (char *) calloc( 100, sizeof( char ) ); |
168 | button_trigger = (char *) calloc( 100, sizeof( char ) ); |
205 | 169 | ||
206 | 170 | ||
207 | // axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
171 | // axis = (int *) calloc( num_of_axis, sizeof( int ) ); |
208 | // button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
172 | // button = (char *)calloc( num_of_buttons, sizeof( char ) ); |
209 | // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
173 | // button_trigger = (char *) calloc( num_of_buttons, sizeof( char ) ); |
210 | 174 | ||
211 | 175 | ||
212 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
176 | if( ( x52_input_fd = open( JOY_DEV, O_RDONLY ) ) < 0 ) |
213 | { |
177 | { |
214 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
178 | printf( "Couldn't open joystick device %s\n", JOY_DEV ); |
215 | printf( "try modprobe joydev\n" ); |
179 | printf( "try modprobe joydev\n" ); |
216 | return 0; |
180 | return 0; |
217 | } |
181 | } |
218 | 182 | ||
219 | ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
183 | ioctl( x52_input_fd, JSIOCGAXES, &num_of_axis ); |
220 | ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
184 | ioctl( x52_input_fd, JSIOCGBUTTONS, &num_of_buttons ); |
221 | ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
185 | ioctl( x52_input_fd, JSIOCGNAME(80), &name_of_joystick ); |
222 | 186 | ||
223 | printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
187 | printf("Joystick detected: %s\n\t%d axis\n\t%d buttons\n\n" |
224 | , name_of_joystick |
188 | , name_of_joystick |
225 | , num_of_axis |
189 | , num_of_axis |
226 | , num_of_buttons ); |
190 | , num_of_buttons ); |
227 | 191 | ||
228 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
192 | fcntl( x52_input_fd, F_SETFL, O_NONBLOCK ); /* use non-blocking mode */ |
229 | 193 | ||
230 | return 1; |
194 | return 1; |
231 | } |
195 | } |
232 | 196 | ||
233 | 197 | ||
234 | 198 | ||
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]='#'; |
- | |
287 | status = send(s,&TxBuffer[i] , 1, 0); |
- | |
288 | printf(" +%d%c ",i,TxBuffer[i]); |
- | |
289 | i++; |
- | |
290 | } |
- | |
291 | - | ||
292 | status = send(s,"\r" , 1, 0); |
- | |
293 | */ |
- | |
294 | // status = send(s,"\r" , 1, 0); |
- | |
295 | printf("\n"); |
199 | |
296 | } |
200 | |
297 | 201 | ||
298 | 202 | ||
299 | void write_display(int line,char* text) |
203 | void write_display(int line,char* text) |
300 | { |
204 | { |
301 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
205 | if (x52_output) x52_settext(x52_output, line , text, strlen(text)); |
302 | } |
206 | } |
303 | 207 | ||
304 | void clear_display() |
208 | void clear_display() |
305 | { |
209 | { |
306 | write_display(0,""); |
210 | write_display(0,""); |
307 | write_display(1,""); |
211 | write_display(1,""); |
308 | write_display(2,""); |
212 | write_display(2,""); |
309 | } |
213 | } |
310 | 214 | ||
311 | 215 | ||
312 | void output_device_list() |
216 | void output_device_list() |
313 | { |
217 | { |
314 | int i; |
218 | int i; |
315 | char disp_txt[20]; |
219 | char disp_txt[20]; |
316 | for(i=0;i<bt_device_count;i++) |
220 | for(i=0;i<bt_device_count;i++) |
317 | { |
221 | { |
318 | if (i<3) |
222 | if (i<3) |
319 | { |
223 | { |
320 | 224 | ||
321 | if (selected_bt_device==i) |
225 | if (selected_bt_device==i) |
322 | sprintf(disp_txt,"#%s",names[i]); |
226 | sprintf(disp_txt,"#%s",names[i]); |
323 | else |
227 | else |
324 | sprintf(disp_txt," %s",names[i]); |
228 | sprintf(disp_txt," %s",names[i]); |
325 | write_display(i,disp_txt); |
229 | write_display(i,disp_txt); |
326 | } |
230 | } |
327 | } |
231 | } |
328 | } |
232 | } |
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 |
- | |
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++) |
371 | */ |
239 | printf("device%i->%s\n",i,names[i]); |
372 | } |
240 | } |
373 | 241 | ||
374 | - | ||
375 | - | ||
376 | 242 | ||
377 | int r=0; |
243 | int r=0; |
378 | int count=0; |
244 | int count=0; |
379 | int connected=0; |
245 | int connected=0; |
380 | 246 | ||
381 | 247 | ||
382 | int input=INPUT_NONE; |
248 | int input=INPUT_NONE; |
383 | 249 | ||
384 | 250 | ||
385 | int main(int argc, char**argv) |
251 | int main(int argc, char**argv) |
386 | { |
252 | { |
387 | 253 | ||
388 | printf("Starting Riddim \n"); |
254 | printf("Starting Riddim \n"); |
389 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
255 | printf("\tRemote Interactive Digital Drone Interface Mashup\n"); |
- | 256 | printf("\nusage:\n"); |
|
- | 257 | printf("\t riddim [config_file]\n\n"); |
|
390 | - | ||
391 | 258 | ||
- | 259 | ||
- | 260 | cfg_opt_t opts[] = { |
|
392 | 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), |
|
- | 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), |
394 | CFG_SIMPLE_STR("input_evdev", &input_evdev_name), |
276 | |
395 | CFG_END() |
277 | CFG_END() |
396 | }; |
278 | }; |
397 | 279 | ||
398 | cfg_t *cfg; |
280 | cfg_t *cfg; |
399 | 281 | ||
400 | // input_evdev_name=strdup("/dev/event0"); |
282 | // input_evdev_name=strdup("/dev/event0"); |
401 | printf("Parsing config file"); |
283 | printf("Parsing config file "); |
402 | 284 | ||
403 | cfg = cfg_init(opts, 0); |
- | |
404 | cfg_parse(cfg, "/etc/riddim.conf"); |
- | |
405 | printf("input %s:",input_evdev_name); |
- | |
406 | 285 | cfg = cfg_init(opts, 0); |
|
407 | // 1st argument -> Bluetooth adrees to bypass scanning ( takes to long for short testing roundtrips ) |
286 | |
408 | if (argv[1]) |
287 | if (argv[1]) |
409 | { |
- | |
410 | if (connect_mk(argv[1])==-1) |
- | |
411 | { |
- | |
412 | printf("cant connect to QC at adress: %s\n",argv[1]); |
- | |
413 | return 0; |
288 | { |
414 | } |
- | |
415 | printf("connected to QC at adress: %s\n",argv[1]); |
289 | printf("%s\n ",argv[1]); |
- | 290 | cfg_parse(cfg, argv[1]); |
|
416 | connected=1; |
291 | } |
- | 292 | else |
|
- | 293 | { |
|
417 | } |
294 | printf("/etc/riddim.conf\n"); |
- | 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 ) |
|
418 | int i; |
300 | |
- | 301 | if (mk_socket_port) |
|
- | 302 | { |
|
- | 303 | printf("connecting to local port: %i\n",mk_socket_port); |
|
- | 304 | ||
- | 305 | if (connect_mk_localhost_socket(mk_socket_port)==-1) |
|
- | 306 | printf("cant connect !!"); |
|
- | 307 | else |
|
- | 308 | { |
|
- | 309 | printf("connected to QC at adress: %s\n",argv[1]); |
|
419 | 310 | connected=TRUE; |
|
420 | 311 | } |
|
421 | 312 | } |
|
422 | 313 | ||
423 | 314 | int i; |
|
424 | 315 | ||
425 | printf("\nInitializing X-52 input ..\n"); |
316 | printf("\nInitializing X-52 input ..\n"); |
426 | if (connect_joy()) |
317 | if (connect_joy()) |
427 | { |
318 | { |
428 | printf(".. done");// |
319 | printf(".. done");// |
429 | input=INPUT_JOYDEV; |
320 | input=INPUT_JOYDEV; |
430 | } |
321 | } |
431 | else |
322 | else |
432 | printf(".. ERROR ");// |
323 | printf(".. ERROR ");// |
433 | 324 | ||
434 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
325 | printf("\nInitializing evdev input (%s) ..\n",input_evdev_name); |
435 | if (connect_evdev()) |
326 | if (connect_evdev()) |
436 | { |
327 | { |
437 | printf(".. done");// |
328 | printf(".. done");// |
438 | input=INPUT_EVDEV; |
329 | input=INPUT_EVDEV; |
439 | } |
330 | } |
440 | else |
331 | else |
441 | printf(".. ERROR ");// |
332 | printf(".. ERROR ");// |
442 | 333 | ||
443 | printf("\nInitializing X-52 output .."); |
334 | printf("\nInitializing X-52 output .."); |
444 | 335 | ||
445 | x52_output = x52_init(); |
336 | x52_output = x52_init(); |
446 | 337 | ||
447 | clear_display(); |
338 | clear_display(); |
448 | 339 | ||
449 | write_display(0, "RIDDIM active"); |
340 | write_display(0, "RIDDIM active"); |
450 | 341 | ||
451 | if (x52_output) x52_setbri(x52_output, 1,128); |
342 | if (x52_output) x52_setbri(x52_output, 1,128); |
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"); |
- | 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"); |
463 | printf(" %d Devices found \n",bt_device_count); |
355 | printf(" %d Devices found \n",bt_device_count); |
- | 356 | print_device_list() ; |
|
464 | } |
357 | } |
465 | 358 | */ |
|
466 | 359 | ||
467 | int v_old; |
360 | int v_old; |
468 | int polls=0; |
361 | int polls=0; |
- | 362 | ||
- | 363 | int retval; |
|
- | 364 | if (exit_after_init) |
|
- | 365 | exit(0); |
|
469 | printf("starting loop ..\n"); |
366 | printf("starting loop ..\n"); |
- | 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 | { |
|
- | 374 | led_event.code = LED_MISC; |
|
- | 375 | led_event.value = 1; |
|
- | 376 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
|
470 | 377 | } |
|
471 | 378 | ||
472 | 379 | int confirm_misses; |
|
473 | while( 1 ) |
380 | while( 1 ) |
474 | { |
381 | { |
- | 382 | ||
- | 383 | if (evdev_out_fd) |
|
- | 384 | { |
|
- | 385 | if (led_event.value) |
|
- | 386 | led_event.value = 0; |
|
- | 387 | else |
|
- | 388 | led_event.value = 1 ; |
|
- | 389 | retval = write(evdev_out_fd, &led_event, sizeof(struct input_event)); |
|
- | 390 | } |
|
- | 391 | ||
475 | 392 | usleep(loop_delay); |
|
476 | switch (input) |
393 | switch (input) |
- | 394 | { |
|
477 | { |
395 | |
478 | 396 | ||
479 | case INPUT_NONE: |
- | |
480 | printf("input none\n"); |
- | |
481 | usleep(10000); |
397 | case INPUT_NONE: |
482 | 398 | printf("starting input none\n"); |
|
483 | break; |
399 | break; |
484 | 400 | ||
485 | case INPUT_EVDEV: |
401 | case INPUT_EVDEV: |
486 | printf("input evdev\n"); |
402 | printf("input evdev\n"); |
487 | usleep(30000); |
- | |
488 | - | ||
489 | - | ||
490 | read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64); |
- | |
491 | printf("read done\n"); |
- | |
492 | if (read_bytes < (int) sizeof(struct input_event)) { |
- | |
493 | perror("evtest: short read"); |
- | |
494 | exit (1); |
- | |
495 | } |
- | |
496 | 403 | ||
497 | for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++) |
404 | struct timeval tv; |
498 | { |
405 | int retval; |
499 | // 1 -> nick |
406 | fd_set rfds; |
- | 407 | FD_ZERO(&rfds); |
|
- | 408 | FD_SET(evdev_fd,&rfds); |
|
500 | // 2 -> gas |
409 | |
- | 410 | tv.tv_sec = 0; |
|
- | 411 | tv.tv_usec = 5; |
|
- | 412 | ||
- | 413 | retval = select(evdev_fd+1, &rfds, NULL, NULL, &tv); |
|
501 | // 4->roll |
414 | |
502 | // 5-> gier |
415 | if (retval==-1) |
- | 416 | printf("error in select!!!!!!!!\n"); |
|
- | 417 | else if (retval) |
|
- | 418 | { |
|
503 | axis[ ev[yalv].code]= ev[yalv].value; |
419 | read_bytes = read(evdev_fd, ev, sizeof(struct input_event) * 64); |
504 | 420 | ||
505 | printf("nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]); |
421 | if (read_bytes < (int) sizeof(struct input_event)) { |
- | 422 | perror("evtest: short read"); |
|
- | 423 | exit (1); |
|
- | 424 | } |
|
- | 425 | ||
- | 426 | for (yalv = 0; yalv < (int) (read_bytes / sizeof(struct input_event)); yalv++) |
|
- | 427 | { |
|
506 | /*if ( ev[yalv].code==5) |
428 | |
507 | printf("Event: time %ld.%06ld, type %d, code %d, value %d\n", |
429 | printf("%d type:%d code:%d val:%d \n",yalv,ev[yalv].type,ev[yalv].code,ev[yalv].value); |
508 | ev[yalv].time.tv_sec, ev[yalv].time.tv_usec, ev[yalv].type, |
430 | if (ev[yalv].type==EV_REL) axis[ ev[yalv].code]= ev[yalv].value; |
509 | ev[yalv].code, ev[yalv].value); |
431 | if (ev[yalv].type==EV_KEY) button[ ev[yalv].code-256]= ev[yalv].value; |
- | 432 | } |
|
- | 433 | ||
- | 434 | ||
- | 435 | for (yalv=0;yalv<10;yalv++) |
|
- | 436 | printf("A%d %d -" , yalv, axis[yalv] ); |
|
- | 437 | printf("\n"); |
|
- | 438 | ||
- | 439 | for (yalv=0;yalv<10;yalv++) |
|
- | 440 | printf("B%d %d -" , yalv, button[yalv] ); |
|
510 | */ |
441 | // printf("input read done: nick:%d roll:%d gier:%d gas:%d\n",axis[3] , axis[4] , axis[5] , axis[2]); |
- | 442 | } |
|
- | 443 | else |
|
- | 444 | printf("no data from evdev data from evdev: \n"); |
|
511 | } |
- | |
512 | 445 | ||
513 | 446 | break; |
|
514 | break; |
447 | |
515 | case INPUT_JOYDEV: |
448 | case INPUT_JOYDEV: |
516 | printf("input joydev\n"); |
449 | printf("input joydev\n"); |
517 | // poll values from input device |
450 | // poll values from input device |
518 | 451 | ||
519 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
452 | for (polls=0;polls<100;polls++) // FIXME - better Polling |
520 | { |
453 | { |
521 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
454 | read(x52_input_fd, &x52_event_struct, sizeof(struct js_event)); |
522 | 455 | ||
523 | 456 | ||
524 | /* see what to do with the event */ |
457 | /* see what to do with the event */ |
525 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
458 | switch (x52_event_struct.type & ~JS_EVENT_INIT) |
526 | { |
459 | { |
527 | case JS_EVENT_AXIS: |
460 | case JS_EVENT_AXIS: |
528 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
461 | axis [ x52_event_struct.number ] = x52_event_struct.value; |
529 | break; |
462 | break; |
530 | case JS_EVENT_BUTTON: |
463 | case JS_EVENT_BUTTON: |
531 | button [ x52_event_struct.number ] = x52_event_struct.value; |
464 | button [ x52_event_struct.number ] = x52_event_struct.value; |
532 | break; |
465 | break; |
533 | } |
466 | } |
534 | } |
467 | } |
535 | 468 | ||
536 | for( x=0 ; x<num_of_buttons ; ++x ) |
469 | for( x=0 ; x<num_of_buttons ; ++x ) |
537 | if( button[x]==0) |
470 | if( button[x]==0) |
538 | button_trigger[x]=0; |
471 | button_trigger[x]=0; |
539 | else |
472 | else |
540 | { |
473 | { |
541 | if (button_trigger[x]<100)button_trigger[x]++; |
474 | if (button_trigger[x]<100)button_trigger[x]++; |
542 | } |
475 | } |
543 | break; |
476 | break; |
544 | } |
477 | } |
545 | 478 | ||
546 | printf("input done\n"); |
479 | printf("input done\n"); |
547 | 480 | ||
548 | switch(state) |
481 | switch(state) |
549 | { |
482 | { |
550 | 483 | ||
551 | 484 | ||
552 | case STATEID_SCANNING: |
485 | case STATEID_SCANNING: |
553 | 486 | ||
554 | state=STATEID_CONNECTING; |
487 | state=STATEID_CONNECTING; |
555 | 488 | ||
556 | ExternControl.Digital[0]=0; |
489 | ExternControl.Digital[0]=0; |
557 | ExternControl.Digital[1]=0; |
490 | ExternControl.Digital[1]=0; |
558 | ExternControl.RemoteTasten=0; |
491 | ExternControl.RemoteTasten=0; |
559 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
492 | ExternControl.Nick=(axis[1]>>8)*(-1)+127;; |
560 | 493 | ||
561 | printf("nick%d\n",ExternControl.Nick); |
494 | printf("nick%d\n",ExternControl.Nick); |
562 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
495 | ExternControl.Roll=(axis[0]>>8)*(-1)+127;; |
563 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
496 | ExternControl.Gier=(axis[5]>>8)*(-1)+127;; |
564 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
497 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
565 | ExternControl.Higt=0; |
498 | ExternControl.Higt=0; |
566 | ExternControl.free=0; |
499 | ExternControl.free=0; |
567 | ExternControl.Frame='t'; |
500 | ExternControl.Frame='t'; |
568 | ExternControl.Config=1; |
501 | ExternControl.Config=1; |
569 | 502 | ||
570 | printf("sending data\n"); |
503 | printf("sending data\n"); |
571 | 504 | ||
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"); |
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]); |
583 | write_display(0,"connected to"); |
516 | write_display(0,"connected to"); |
584 | } |
517 | } |
585 | 518 | ||
586 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
519 | if ((button_trigger[BUTTON_UP]+button_trigger[BUTTON_DOWN])==1) |
587 | { |
520 | { |
588 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
521 | printf("-> sel_dev %d - %d\n",selected_bt_device,button_trigger[19]); |
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++; |
593 | - | ||
- | 526 | ||
594 | output_device_list() ; |
527 | |
595 | } |
528 | } |
596 | break; |
529 | break; |
597 | 530 | ||
598 | case STATEID_CONNECTING: |
531 | case STATEID_CONNECTING: |
- | 532 | ||
599 | 533 | ||
- | 534 | confirm_misses=0; |
|
- | 535 | printf("connected:%d",connected); |
|
- | 536 | if (connected) while (RxBuffer[1]!='t') |
|
- | 537 | { |
|
- | 538 | ||
- | 539 | RxBuffer[1]=0; |
|
- | 540 | ||
- | 541 | ||
- | 542 | // ftime(&time_struct); |
|
600 | RxBuffer[1]=0; |
- | |
601 | - | ||
602 | - | ||
603 | // ftime(&time_struct); |
- | |
604 | printf("waiting for confirm frame\n"); |
- | |
605 | RxBuffer[2]=0; |
- | |
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 | ||
614 | while(in_char!='\n') |
551 | while(in_char!='\n') |
615 | { |
552 | { |
616 | count=read(s,&in_char,1); |
553 | count=read(mk_socket,&in_char,1); |
617 | if (in_char!=0) |
554 | if (in_char!=0) |
618 | { |
555 | { |
619 | RxBuffer[r++]=in_char; |
556 | RxBuffer[r++]=in_char; |
620 | } |
557 | } |
621 | else |
558 | else |
622 | { |
559 | { |
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); |
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)); |
642 | act_mode=button[24] | (button[25]<<1); |
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 | ||
- | 596 | ||
643 | 597 | /* |
|
644 | switch (act_mode) |
598 | switch (act_mode) |
645 | { |
599 | { |
646 | case 0: |
600 | case 0: |
647 | 601 | ||
648 | 602 | ||
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); |
651 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER); |
605 | act_gier=(axis[AXIS_GIER])*(INVERT_GIER); |
652 | act_gas=((axis[AXIS_GAS]>>8)-128)*(-1); |
606 | act_gas=((axis[AXIS_GAS])-128)*(-1); |
653 | 607 | |
|
654 | // clip gas |
608 | // clip gas |
655 | if (act_gas<0) act_gas=0; |
609 | if (act_gas<0) act_gas=0; |
656 | 610 | ||
657 | if (act_gas>250) act_gas=250; |
611 | if (act_gas>250) act_gas=250; |
658 | 612 | ||
659 | //////// act_gas=0; |
613 | //////// act_gas=0; |
660 | break; |
614 | break; |
661 | 615 | ||
662 | case 1: |
616 | case 1: |
663 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
617 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/2; |
664 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
618 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/2; |
665 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
619 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/2; |
666 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
620 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
667 | 621 | ||
668 | break; |
622 | break; |
669 | 623 | |
|
670 | case 2: |
624 | case 2: |
671 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
625 | act_nick=(axis[AXIS_NICK]>>8)*(INVERT_NICK)/3; |
672 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
626 | act_roll=(axis[AXIS_ROLL]>>8)*(INVERT_ROLL)/3; |
673 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
627 | act_gier=(axis[AXIS_GIER]>>8)*(INVERT_GIER)/3; |
674 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
628 | act_gas=(axis[AXIS_GAS]>>8)*(INVERT_GAS); |
675 | 629 | ||
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; |
683 | ExternControl.RemoteTasten=0; |
637 | ExternControl.RemoteTasten=0; |
684 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
638 | ExternControl.Nick=act_nick; //(axis[1]>>8)*(-1)/2; |
685 | // printf("nick%d\n",ExternControl.Nick); |
639 | // printf("nick%d\n",ExternControl.Nick); |
686 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
640 | ExternControl.Roll=act_roll*(-1); //(axis[0]>>8)*(-1)/2; |
687 | ExternControl.Gier=(axis[5]>>8); |
641 | ExternControl.Gier=(axis[5]>>8); |
688 | ExternControl.Gier=act_gier; // ************ |
642 | ExternControl.Gier=act_gier; // ************ |
689 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
643 | ExternControl.Gas=(axis[2]>>8)*(-1)+127; |
690 | ExternControl.Gas=act_gas; // ************ |
644 | ExternControl.Gas=act_gas; // ************ |
691 | // ExternControl.Gas=0; // ************ |
645 | // ExternControl.Gas=0; // ************ |
692 | ExternControl.Higt=0; |
646 | ExternControl.Higt=0; |
693 | ExternControl.free=0; |
647 | ExternControl.free=0; |
694 | ExternControl.Frame='t'; |
648 | ExternControl.Frame='t'; |
695 | 649 | ||
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); |
698 | 652 | ||
699 | 653 | ||
- | 654 | ||
- | 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)); |
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"); |
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 | ||
716 | printf("v: %d \n",v); |
672 | printf("v: %d \n",v); |
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] ); |
725 | 681 | ||
726 | break; |
682 | break; |
727 | } |
683 | } |
728 | 684 | ||
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); |
732 | 688 | ||
733 | } |
689 | } |
734 | 690 | ||
735 | 691 | ||
736 | /******************** Cleanup **********************/ |
692 | /******************** Cleanup **********************/ |
737 | close(x52_input_fd); |
693 | close(x52_input_fd); |
738 | close(s); |
694 | close(mk_socket); |
739 | 695 | ||
740 | if (x52_output) x52_close(x52_output); |
696 | if (x52_output) x52_close(x52_output); |
741 | return 0; |
697 | return 0; |
742 | } |
698 | } |
743 | 699 |