void DS3_ScanPads()
{
    if (!ss_is_connected(&first))
    {
        psPressed = false;
        ss_initialize(&first);
        if (ss_open(&first) > 0)
        {
            ss_start_reading(&first);
            ss_set_led(&first, 0);
        }
    }
    else if (first.pad.buttons.PS && !psPressed)
    {
        psPressed = true;
        ss_set_led(&first, 1);
    }
}
Exemplo n.º 2
0
int ss_open(struct ss_device *dev)
{
   usb_device_entry dev_entry[8];
   unsigned char dev_count;
   if (!_ss_inited)
      return -1;
   if (dev->connected)
      ss_close(dev);

   if (USB_GetDeviceList(dev_entry, 8, USB_CLASS_HID, &dev_count) < 0)
      return -2;

   int i;
   for (i = 0; i < dev_count; ++i)
   {
      if ((dev_entry[i].vid == SS_VENDOR_ID) && 
            (dev_entry[i].pid == SS_PRODUCT_ID))
      {
         if (!_ss_dev_id_list_exists(dev_entry[i].device_id))
         {
            if (USB_OpenDevice(dev_entry[i].device_id, 
                     SS_VENDOR_ID, SS_PRODUCT_ID, &dev->fd) < 0)
               return -3;

            dev->device_id = dev_entry[i].device_id;
            dev->connected = 1;
            dev->enabled = 0;
            dev->reading = 0;

            _ss_set_operational(dev);
            ss_set_led(dev, _ss_dev_number);

            _ss_dev_id_list_add(dev_entry[i].device_id);
            _ss_dev_number++;

            USB_DeviceRemovalNotifyAsync(dev->fd, &_ss_removal_cb, dev);
            return 1;
         }
      }
   }
   return -4;
}
Exemplo n.º 3
0
int ss_is_ready(struct ss_device *dev) {

	/* if a device is detected, try to connect it. */
	if (_dev_detected) {
		/* As we are processing the detected device, we turn off the flag. */
		_dev_detected = 0;
		int i;
		for(i = 0; i < _slots; i++)	{
			if (_ss_dev_list[i].device_id < 0) { /* found an empty slot? */
				if (_ss_open(&_ss_dev_list[i]) > 0) {
					ss_set_led(&_ss_dev_list[i], i+1);
				}
				break;
			}
		}
	}

	if (dev->connected && dev->enabled)
		return 1;

	return 0;
}