Esempio n. 1
0
void kbdms_open_dev(void){
  int ret = -1;
  ret = setup_uinput_device("/dev/uinput");
  if(ret < 0){
	  __android_log_print(ANDROID_LOG_INFO, "syo", "call setup_uinput_device failure");
      return;
  }
}
Esempio n. 2
0
int main(int argc, char *argv[])
{ 
    setup_uinput_device();
 
    sleep(5);
    int key;
    int i;
    /*for (i = 1; i < argc; i++)
    {
        key = atoi(argv[i]);
        simulate_key(key, 1);
        if (check_valid_control_key(key) == 0)
        //if not control key, release it
        {
            simulate_key(key, 0);
        }
    }
    //The code is so nice!
    for (i=1; i < argc; i++)
    {
        key = atoi(argv[i]);
        if (check_valid_control_key(key) == 1)
        {
            simulate_key(key, 0);
        }
    }*/
    //KEY_1 corresponding to 2! Look /usr/include/linux/input.h
    //KEY_2 corresponding to 3!
    key = 2;
    simulate_key(key, 1);
    simulate_key(key, 0);

    key = 3;
    simulate_key(key, 1);
    simulate_key(key, 0);
 
    simulate_key_end();
    if(ioctl(fd, UI_DEV_DESTROY) < 0)
        die("error: ioctl");
    close(fd);
 
    return 0;
}
Esempio n. 3
0
int main()
{
	char* buff = (char *)malloc(1024 * sizeof(char));
	char key;
	FILE* usb_fd = fopen("/dev/input/by-id/usb-P.I._Engineering_Xkeys-event-if00", "r");
	// Return an error if device not found.
	if (setup_uinput_device() < 0)
	{
		printf("Unable to find uinput device\n");
		return -1;
	}
	while (1)
	{
		bzero(buff, 1024);
		fread(buff, sizeof(char), 144, usb_fd);
	//	printf("%c\n", buff[20] + '0');
		key = buff[12] + '0';
		switch (key)
		{
			case '1':
	//			printf("1 is pressed ...\n");
				send_key_code(KEY_1);
				break;
			case '9':
				send_key_code(KEY_2);
				break;
			case 'A':
				send_key_code(KEY_3);
				break;
			case 'I':
				send_key_code(KEY_4);
				break;
			case 'Q':
				send_key_code(KEY_5);
				break;
		}
	}
}
int main()
{
    if( setup_uinput_device() < 0 )
    {
        printf("Unable to find uinput device\n");
        return -1;
    }

    printf("opened device");

   /* 
    while( 0 )
    {
	read(0, &event, sizeof(event));

//		printf(&event);
        write(uinp_fd, &event, sizeof(event));
		usleep( 1000 );
		fflush(stdout);
		
    }
    */

    /*
    static int uinp_fd = -1;
    uinp_fd = open("/dev/uinput", O_WRONLY | O_NDELAY | O_NONBLOCK);
    if (uinp_fd == NULL)
    {
        printf("Unable to open /dev/uinput\n");
        return -1;
    }
*/
    //ioctl(uinp_fd, UI_DEV_DESTROY);
    close(uinp_fd);
    
}
int main(int argc, const char *argv[])
{
  nfc_device *pnd;
  nfc_target nt;
  const nfc_target ntbis;

  // Allocate only a pointer to nfc_context
  nfc_context *context;

  // Initialize libnfc and set the nfc_context
  nfc_init(&context);
  if (context == NULL) {
    printf("Unable to init libnfc (malloc)\n");
    exit(EXIT_FAILURE);
  }

  // Display libnfc version
  const char *acLibnfcVersion = nfc_version();
  (void)argc;
  printf("%s utilise libnfc v%s\n", argv[0], acLibnfcVersion);

  // Open, using the first available NFC device which can be in order of selection:
  //   - default device specified using environment variable or
  //   - first specified device in libnfc.conf (/etc/nfc) or
  //   - first specified device in device-configuration directory (/etc/nfc/devices.d) or
  //   - first auto-detected (if feature is not disabled in libnfc.conf) device
  pnd = nfc_open(context, NULL);

  if (pnd == NULL) {
    printf("ERROR: %s\n", "Unable to open NFC device.");
    exit(EXIT_FAILURE);
  }
  // Set opened NFC device to initiator mode
  if (nfc_initiator_init(pnd) < 0) {
    nfc_perror(pnd, "nfc_initiator_init");
    exit(EXIT_FAILURE);
  }

  printf("Lecteur NFC: %s \n", nfc_device_get_name(pnd));

  // Poll for a ISO14443A (MIFARE) tag
  const nfc_modulation nmMifare = {
    .nmt = NMT_ISO14443A,
    .nbr = NBR_106,
  };

  int uinp_fd;
  if ((uinp_fd = setup_uinput_device()) < 0) {
  printf("Unable to find uinput device\n");
  return -1;
  }
  sleep(1);
  



  long int uid = 0;
  int i = 0;
  int check = 1;
  while (1) {
    if (nfc_initiator_list_passive_targets(pnd, nmMifare, &nt, 1) > 0) {
      if (uid != parse_dex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen)) {
        //printf("%s\n", strtol(*nt.nti.nai.abtUid, 16));
        i++;
        printf("\nmotherfucker %d\n", i);
        printf("Uid : ");
        print_hex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
        printf("Parse dex : ");
        printf("%ld\n",parse_dex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen));
        uid = parse_dex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen);
        //printf("Before x : ");
        //printf("%s\n", before_x(uid));
        printf("Do x : ");
        do_x(uinp_fd, uid);
      } else {
        //printf("i: %d uid:%ld nt:%ld\n",i, uid, parse_dex(nt.nti.nai.abtUid, nt.nti.nai.szUidLen));
        //i++;
      }
    } else {
      check = 0;
      uid = 0;
    }
  }
    /* Destroy the input device */
  ioctl(uinp_fd, UI_DEV_DESTROY);
  /* Close the UINPUT device */
  close(uinp_fd);
  // Close NFC device
  nfc_close(pnd);
  // Release the context
  nfc_exit(context);
  exit(EXIT_SUCCESS);
}
Esempio n. 6
0
int main(int argc, char *argv[]) {

    buttonstates padButtons;
	snespad pads;
	pollButton = 1;
	pollPads = 1;
	doRun = 1;

	// check command line arguments
	if (argc > 1) {
		// argv[1]==1 poll controllers only
		// argv[1]==2 poll button only
		// argv[1]==3 poll controllers and button
		switch ( atoi(argv[argc-1]) ) {
			case 1:
				printf("[SNESDev-Rpi] Polling only controllers.\n");
				pollButton = 0;
				pollPads = 1;
			break;
			case 2:
				printf("[SNESDev-Rpi] Polling button only.\n");
				pollButton = 1;
				pollPads = 0;
			break;
			case 3:
				printf("[SNESDev-Rpi] Polling controllers and button.\n");
				pollButton = 1;
				pollPads = 1;
			break;
			default:
				return -1;
		}
    } else {
    	printf("[SNESDev-Rpi] Polling controllers and button.\n");
    }

    if (!bcm2835_init())
        return 1;

	// initialize button and LEDs
    bcm2835_gpio_fsel(BUTTONPIN,  BCM2835_GPIO_FSEL_INPT);

    /* initialize controller structures with GPIO pin assignments */

    // pin out used in SNESDev article on blog
	// pads.clock  = RPI_GPIO_P1_18;
	// pads.strobe = RPI_GPIO_P1_16;
	// pads.data1  = RPI_GPIO_P1_22;
	// pads.data2  = RPI_GPIO_P1_15;

    // pin out used pi gamecon GPIO driver
	pads.clock  = RPI_GPIO_P1_19;
	pads.strobe = RPI_GPIO_P1_23;
	pads.data1  = RPI_GPIO_P1_07;
	pads.data2  = RPI_GPIO_P1_05;

	/* set GPIO pins as input or output pins */
	initializePads( &pads );

	/* intialize virtual input device */
	if ((uinp_fd = setup_uinput_device()) < 0) {
		printf("[SNESDev-Rpi] Unable to find uinput device\n");
		return -1;
	}

	if (signal(SIGINT, sig_handler) == SIG_ERR)
  		printf("\n[SNESDev-Rpi] Cannot catch SIGINT\n");

	/* enter the main loop */
	while ( doRun ) {

		if (pollButton) {
			/* Check state of button. */
			checkButton(uinp_fd);
		}

		if (pollPads) {
			/* read states of the buttons */
			updateButtons(&pads, &padButtons);

			/* send an event (pressed or released) for each button */
			/* key events for first controller */
	        processPadBtn(padButtons.buttons1, SNES_A,     KEY_X,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_B,     KEY_Z,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_X,     KEY_S,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_Y,     KEY_A,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_L,     KEY_Q,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_R,     KEY_W,          uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_SELECT,KEY_RIGHTSHIFT, uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_START, KEY_ENTER,      uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_LEFT,  KEY_LEFT,       uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_RIGHT, KEY_RIGHT,      uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_UP,    KEY_UP,         uinp_fd);
	        processPadBtn(padButtons.buttons1, SNES_DOWN,  KEY_DOWN,       uinp_fd);

			// key events for second controller 
	        processPadBtn(padButtons.buttons2, SNES_A,     KEY_E, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_B,     KEY_R, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_X,     KEY_T, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_Y,     KEY_Y, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_L,     KEY_U, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_R,     KEY_I, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_SELECT,KEY_O, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_START, KEY_P, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_LEFT,  KEY_C, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_RIGHT, KEY_B, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_UP,    KEY_F, uinp_fd);
	        processPadBtn(padButtons.buttons2, SNES_DOWN,  KEY_V, uinp_fd);
		}

		/* wait for some time to keep the CPU load low */
		delay(FRAMEWAIT);
	}

	return 0;
}