Exemple #1
0
static bool linuxraw_joypad_init(void *data)
{
   unsigned i;
   settings_t *settings = config_get_ptr();

   g_epoll              = epoll_create(MAX_USERS + 1);
   if (g_epoll < 0)
      return false;

   (void)data;

   for (i = 0; i < MAX_USERS; i++)
   {
      char path[PATH_MAX_LENGTH]  = {0};
      autoconfig_params_t params  = {{0}};
      struct linuxraw_joypad *pad = (struct linuxraw_joypad*)&linuxraw_pads[i];

      if (!pad)
         continue;

      params.idx = i;

      pad->fd    = -1;
      pad->ident = settings->input.device_names[i];
      
      snprintf(path, sizeof(path), "/dev/input/js%u", i);

      if (linuxraw_joypad_init_pad(path, pad))
      {
         strlcpy(params.name,   pad->ident, sizeof(params.name)); 
         strlcpy(params.driver, "linuxraw", sizeof(params.driver));

         /* TODO - implement VID/PID? */
         input_config_autoconfigure_joypad(&params);
         linuxraw_poll_pad(pad);
      }
      else
         input_config_autoconfigure_joypad(&params);
   }

   g_notify = inotify_init();
   if (g_notify >= 0)
   {
      struct epoll_event event;

      linuxraw_joypad_setup_notify();

      event.events = EPOLLIN;
      event.data.ptr = NULL;
      epoll_ctl(g_epoll, EPOLL_CTL_ADD, g_notify, &event);
   }

   g_hotplug = true;

   return true;
}
static bool linuxraw_joypad_init(void)
{
   g_epoll = epoll_create(MAX_PLAYERS + 1);
   if (g_epoll < 0)
      return false;

   for (unsigned i = 0; i < MAX_PLAYERS; i++)
   {
      struct linuxraw_joypad *pad = &g_pads[i];
      pad->fd = -1;
      pad->ident = g_settings.input.device_names[i];
      
      char path[PATH_MAX];
      snprintf(path, sizeof(path), "/dev/input/js%u", i);

      if (linuxraw_joypad_init_pad(path, pad))
      {
         input_config_autoconfigure_joypad(i, pad->ident, "linuxraw");
         poll_pad(pad);
      }
      else
         input_config_autoconfigure_joypad(i, NULL, NULL);
   }

   g_notify = inotify_init();
   if (g_notify >= 0)
   {
      linuxraw_joypad_setup_notify();

      struct epoll_event event;
      event.events = EPOLLIN;
      event.data.ptr = NULL;
      epoll_ctl(g_epoll, EPOLL_CTL_ADD, g_notify, &event);
   }

   g_hotplug = true;

   return true;
}