Changeset 290 in flair-src for trunk/tools


Ignore:
Timestamp:
01/08/19 17:45:23 (5 years ago)
Author:
Sanahuja Guillaume
Message:

support for multiple ds3 in usb

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/tools/Controller/DualShock3/src/DualShock3.cpp

    r214 r290  
    3939#include <bluetooth/hci.h>
    4040#include <bluetooth/hci_lib.h>
     41#include <sys/file.h>
    4142
    4243#define USB_DIR_IN 0x80
     
    156157      dev_name << "/dev/hidraw" << i;
    157158      if ((usb_fd = open(dev_name.str().c_str(), O_RDONLY)) >= 0) {
    158         int res = 0;
     159        int res=flock(usb_fd, LOCK_EX|LOCK_NB);
     160        if(res<0) {
     161          Thread::Warn("%s seems to be locked by another application\n", dev_name.str().c_str());
     162          close(usb_fd);
     163          continue;
     164        }
     165       
    159166        struct hidraw_devinfo info;
    160 
    161167        res = ioctl(usb_fd, HIDIOCGRAWINFO, &info);
    162168        if (res < 0) {
    163           Thread::Err("ioctl error (HIDIOCGRAWINFO) on %s\n",
    164                       dev_name.str().c_str());
     169          Thread::Err("ioctl error (HIDIOCGRAWINFO) on %s\n",dev_name.str().c_str());
    165170        } else {
    166171          // Printf("%x %x\n", info.vendor, info.product);
     
    171176          }
    172177        }
     178        flock(usb_fd, LOCK_UN);
    173179        close(usb_fd);
    174180      }
     
    193199DualShock3::~DualShock3() {
    194200  if (connectionType == Usb) {
     201    flock(usb_fd, LOCK_UN);
    195202    close(usb_fd);
    196203  }
Note: See TracChangeset for help on using the changeset viewer.