Hardware Reference
In-Depth Information
367
/
368 int
369 main(int argc,char
argv) {
370 int fd, need_sync, init = 3;
371 int rel_x=0, rel_y = 0;
372 nunchuk_t data0, data, last;
373
374 if ( argc > 1 && !strcmp(argv [1]," −d") )
375 f_debug = 1; /
∗∗
Enable debug messages
/
376
377 (void)uinput_postkey; /
Suppress compiler warning about unused
/
378
379 i2c_init("/dev/i2c−1"); /
Open I2C controller
/
380 nunchuk_init(); /
Turn off encrypt ion
/
381
382 signal(SIGINT,sigint_handler); /
Trap on SIGINT
/
383 fd = uinput_open(); /
Open/dev/uinput
/
384
385 while ( !is_signaled ) {
386 if ( nunchuk_read(&data) < 0 )
387 continue;
388
389 if ( f_debug )
390 dump_data(&data); /
Dump nunchuk data
/
391
392 if ( init > 0 && !data0.stick_x && !data0.stick_y ) {
393 data0 = data; /
Save initial values
/
394 last = data;
395 −−init;
396 continue;
397 }
398
399 need_sync = 0;
400 if ( abs(data.stick_x − data0.stick_x) > 2
401 || abs(data.stick_y − data0.stick_y) > 2) {
402 rel_x = curve (data.stick_x − data0.stick_x);
403 rel_y = curve (data.stick_y − data0.stick_y);
404 if ( rel_x || rel_y ) {
405 uinput_movement(fd,rel_x,−rel_y);
406 need_sync = 1;
407 }
408 }
409
410 if ( last.z_button != data.z_button ) {
411 uinput_click(fd, data.z_button,1);
412 need_sync = 1;
413 }
414
Search WWH ::




Custom Search