Ejemplo n.º 1
0
static void emit_mouse (int dx, int dy)
{
  if (dx != 0 || dy != 0) {
      const int maxcoord = 65535;
      static int x = maxcoord / 2;
      static int y = maxcoord / 2;
      x += dx * 64;
      y += dy * 64;
      if (x < 0)
        x = 0;
      if (y < 0)
        y = 0;
      if (x > maxcoord)
        x = maxcoord;
      if (y > maxcoord)
        y = maxcoord;
      msg("## mouse dx %d, dy %d -- x %d y %d\n", dx, dy, x, y);
      xbmc.SendMOUSE(x, y);
  }
}
Ejemplo n.º 2
0
static void xbmc_button_up (const char *button)
{
  if (debug) printf("NEC send up [%s]\n", button);
  xbmc.SendButton(button, "R1", BTN_UP);
}
Ejemplo n.º 3
0
static void xbmc_button_down (const char *button)
{
  if (debug) printf("NEC send down [%s]\n", button);
  xbmc.SendButton(button, "R1", BTN_DOWN);
}
Ejemplo n.º 4
0
static void xbmc_button (const char *button)
{
  if (debug) printf("NEC send [%s]\n", button);
  xbmc.SendButton(button, "R1", BTN_DOWN | BTN_QUEUE | BTN_NO_REPEAT);
}
Ejemplo n.º 5
0
static void xbmc_release_button ()
{
  msg("## send key released\n");
  xbmc.SendButton(0x01, BTN_UP);
}
Ejemplo n.º 6
0
static void xbmc_keyr (const char *key)
{
  msg("## send repeat key (R1) '%s'\n", key);
  xbmc.SendButton(key, "R1", BTN_DOWN);
}
Ejemplo n.º 7
0
static void xbmc_key (const char *key)
{
  msg("## send key (R1) '%s'\n", key);
  xbmc.SendButton(key, "R1", BTN_NO_REPEAT);
}
Ejemplo n.º 8
0
static void xbmc_action_button (const char *btn)
{
  msg("## send action '%s' (button)\n", btn);
  xbmc.SendACTION(btn, ACTION_BUTTON);
}
Ejemplo n.º 9
0
int main (int argc, char **argv)
{
  bool daemonize = false;

  while (true) {
      int c;
      static struct option long_options[] =
          {
              {"help",    no_argument, NULL, 'h'},
              {"version", no_argument, NULL, 'v'},
              {"daemon",  no_argument, NULL, 'd'},
              {"fork",    no_argument, NULL, 'f'},
              {0, 0, 0, 0}
          };

      c = getopt_long(argc, argv, "hvd", long_options, NULL);
      if (c == -1)
        break;
      switch (c) {
      case 'h':
        print_usage(argv[0]);
        exit(EXIT_SUCCESS);
      case 'v':
        msg("HAMA MCE remote event client v%s for XBMC\n", VERSION);
        exit(EXIT_SUCCESS);
      case 'd':
        daemonize = true;
        break;
      default:
        print_usage(argv[0]);
        exit(EXIT_FAILURE);
      }
  }

  if (optind < (argc - 1)) {
      err("%s: too many arguments\n", argv[0]);
      exit(EXIT_FAILURE);
  }

  struct sigaction sa;
  sigemptyset(&sa.sa_mask);
  sa.sa_handler = handle_exit;
  PCHK(sigaction(SIGINT,  &sa, NULL));
  PCHK(sigaction(SIGTERM, &sa, NULL));

  libusb_context *ctx;
  libusb_device_handle *dev;
  struct libusb_transfer *transfer0x81 = libusb_alloc_transfer(0);
  struct libusb_transfer *transfer0x82 = libusb_alloc_transfer(0);
  unsigned char buf0x81 [8];
  unsigned char buf0x82 [5];

  UCHK(libusb_init(&ctx));

  if (!(dev = libusb_open_device_with_vid_pid(ctx, 0x05a4, 0x9881))) {
      err("%s: No HAMA MCE remote control found.\n", argv[0]);
      exit(EXIT_FAILURE);
  }

  int exit_code = EXIT_SUCCESS;

  if (libusb_kernel_driver_active(dev, 0))
    UCHK(libusb_detach_kernel_driver(dev, 0));
  if (libusb_kernel_driver_active(dev, 1))
    UCHK(libusb_detach_kernel_driver(dev, 1));
  UCHK(libusb_claim_interface(dev, 0));
  UCHK(libusb_claim_interface(dev, 1));

  libusb_fill_interrupt_transfer(transfer0x81, dev, 0x81, buf0x81, sizeof(buf0x81), transfer0x81_cb, NULL, 215);
  UCHK(libusb_submit_transfer(transfer0x81));

  libusb_fill_interrupt_transfer(transfer0x82, dev, 0x82, buf0x82, sizeof(buf0x82), transfer0x82_cb, NULL, 200);
  UCHK(libusb_submit_transfer(transfer0x82));

  msg("Connected HAMA MCE Remote\n");
  xbmc.SendHELO("HAMA MCE Remote", ICON_NONE);

  if (daemonize) {
      if (daemon(0,0) == -1) {
          err("Failed to fork\n");
          perror(argv[0]);
          exit_code = EXIT_FAILURE;
          goto exit;
      }
  }

  while (!(disconnected || quit)) {
      UCHK(libusb_handle_events(ctx));
  }
  exit:
  if (disconnected) {
      msg("Disconnected HAMA MCE Remote\n");
      xbmc.SendNOTIFICATION("Disconnected", "HAMA MCE Remote", ICON_NONE);
  }
  else {
      msg("Closing HAMA MCE Remote\n");
      xbmc.SendNOTIFICATION("Closing", "HAMA MCE Remote", ICON_NONE);
  }

  libusb_free_transfer(transfer0x81);
  libusb_free_transfer(transfer0x82);

  if (!disconnected) {
      // Release the remote back to the system
      UCHK(libusb_release_interface(dev, 0));
      UCHK(libusb_release_interface(dev, 1));
      UCHK(libusb_attach_kernel_driver(dev, 0));
      UCHK(libusb_attach_kernel_driver(dev, 1));
  }

  libusb_close(dev);
  libusb_exit(ctx);

  exit(exit_code);
}