static void DeviceConnectedEvent(USBH_Device device) { //Check if device is a PS3 Controller if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID) { if (device.TYPE == USBH_DeviceType.Hub) { WriteSerial("Hub Connected"); } else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)//Check if it is the bluetooth dongle { WriteSerial("Bluetooth Dongle Connected"); BT = new Bluetooth(device); } else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID) { WriteSerial("PS3 Move Controller Connected"); Move = new PS3Move(device); } else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID) { WriteSerial("PS3 Navigation Controller Connected"); Navigation = new PS3Navigation(device); } else { WriteSerial("Unknown Device Connected"); } return; } if (PS3Connected == PS3Max)//Check if the maximum number of controller is exceeded { WriteSerial(PS3Max + " Controllers are already connected"); return; } PS3[PS3Connected] = new PS3Controller(device); //Connect the PS3 Controller PS3Device[PS3Connected] = device; //Store the device see "DeviceDisconnectedEvent" PS3SetLED(PS3Connected); //Set the specific LED on runThread[PS3Connected] = true; //Start the loop WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Connected"); PS3Connected++; }
static void DeviceDisconnectedEvent(USBH_Device device) { //Check if device is a PS3 Controller if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID) { if (device.TYPE == USBH_DeviceType.Hub) { WriteSerial("Hub Disconnected"); for (byte i = 0; i < PS3Connected; i++)//All controllers has to be stopped { runThread[i] = false; PS3[i].Abort(); BT.Abort(); } } else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID) { WriteSerial("Bluetooth Dongle Disconnected"); PS3RumbleBT = false; BT.Abort(); } else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID) { WriteSerial("PS3 Move Controller Disconnected"); Move.Abort(); } else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID) { WriteSerial("PS3 Navigation Disconnected"); Navigation.Abort(); } else { WriteSerial("Unknown Device Disconnected"); } return; } PS3Connected--; if (device.ID == PS3Device[PS3Connected].ID) //Check if it is the last one { runThread[PS3Connected] = false; //Stop the loop for the last controller PS3Rumble[PS3Connected] = false; //Also stop the rumble thread if active PS3[PS3Connected].Abort(); //Abort the reading thread WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Disconnected"); } else { byte PS3number; for (PS3number = 0; PS3number < PS3Connected; PS3number++)//Check which number that was disconnected { if (device.ID == PS3Device[PS3number].ID) { break; } } runThread[PS3number] = false; PS3Rumble[PS3number] = false;//Also stop the rumble thread if active PS3[PS3number].Abort(); WriteSerial("PS3 Controller: " + (PS3number + 1) + " - Disconnected"); //Move all the controllers from that point one down for (byte i = PS3number; i < PS3Connected; i++)//Does not include the last one, as it is allways moved one down { //Stop that thread including the next one runThread[i] = false; PS3[i].Abort(); runThread[i + 1] = false; PS3[i + 1].Abort(); //Move one down PS3[i] = new PS3Controller(PS3Device[i + 1]); PS3Device[i] = PS3Device[i + 1]; PS3SetLED(i); runThread[i] = true; WriteSerial("PS3 Controller: " + (i + 2) + " - Changed to " + (i + 1)); } } }
//public PS3Controller Controller { get { return _controller; } } #endregion #region Awake private void Awake() { _controller = gameObject.AddComponent <PS3Controller>(); }
static void DeviceDisconnectedEvent(USBH_Device device) { //Check if device is a PS3 Controller if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID) { if (device.TYPE == USBH_DeviceType.Hub) { WriteSerial("Hub Disconnected"); for (byte i = 0; i < PS3Connected; i++)//All controllers has to be stopped { runThread[i] = false; PS3[i].Abort(); BT.Abort(); } } else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID) { WriteSerial("Bluetooth Dongle Disconnected"); PS3RumbleBT = false; BT.Abort(); } else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID) { WriteSerial("PS3 Move Controller Disconnected"); Move.Abort(); } else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID) { WriteSerial("PS3 Navigation Disconnected"); Navigation.Abort(); } else WriteSerial("Unknown Device Disconnected"); return; } PS3Connected--; if (device.ID == PS3Device[PS3Connected].ID)//Check if it is the last one { runThread[PS3Connected] = false;//Stop the loop for the last controller PS3Rumble[PS3Connected] = false;//Also stop the rumble thread if active PS3[PS3Connected].Abort();//Abort the reading thread WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Disconnected"); } else { byte PS3number; for (PS3number = 0; PS3number < PS3Connected; PS3number++)//Check which number that was disconnected if (device.ID == PS3Device[PS3number].ID) break; runThread[PS3number] = false; PS3Rumble[PS3number] = false;//Also stop the rumble thread if active PS3[PS3number].Abort(); WriteSerial("PS3 Controller: " + (PS3number + 1) + " - Disconnected"); //Move all the controllers from that point one down for (byte i = PS3number; i < PS3Connected; i++)//Does not include the last one, as it is allways moved one down { //Stop that thread including the next one runThread[i] = false; PS3[i].Abort(); runThread[i + 1] = false; PS3[i + 1].Abort(); //Move one down PS3[i] = new PS3Controller(PS3Device[i + 1]); PS3Device[i] = PS3Device[i + 1]; PS3SetLED(i); runThread[i] = true; WriteSerial("PS3 Controller: " + (i + 2) + " - Changed to " + (i + 1)); } } }
static void DeviceConnectedEvent(USBH_Device device) { //Check if device is a PS3 Controller if (device.VENDOR_ID != PS3Controller.PS3_VENDOR_ID || device.PRODUCT_ID != PS3Controller.PS3_PRODUCT_ID) { if (device.TYPE == USBH_DeviceType.Hub) WriteSerial("Hub Connected"); else if (device.PRODUCT_ID == Bluetooth.CSR_PRODUCT_ID && device.VENDOR_ID == Bluetooth.CSR_VENDOR_ID)//Check if it is the bluetooth dongle { WriteSerial("Bluetooth Dongle Connected"); BT = new Bluetooth(device); } else if (device.VENDOR_ID == PS3Move.PS3MOVE_VENDOR_ID && device.PRODUCT_ID == PS3Move.PS3MOVE_PRODUCT_ID) { WriteSerial("PS3 Move Controller Connected"); Move = new PS3Move(device); } else if (device.VENDOR_ID == PS3Navigation.PS3NAVIGATION_VENDOR_ID && device.PRODUCT_ID == PS3Navigation.PS3NAVIGATION_PRODUCT_ID) { WriteSerial("PS3 Navigation Controller Connected"); Navigation = new PS3Navigation(device); } else WriteSerial("Unknown Device Connected"); return; } if (PS3Connected == PS3Max)//Check if the maximum number of controller is exceeded { WriteSerial(PS3Max + " Controllers are already connected"); return; } PS3[PS3Connected] = new PS3Controller(device);//Connect the PS3 Controller PS3Device[PS3Connected] = device;//Store the device see "DeviceDisconnectedEvent" PS3SetLED(PS3Connected);//Set the specific LED on runThread[PS3Connected] = true;//Start the loop WriteSerial("PS3 Controller: " + (PS3Connected + 1) + " - Connected"); PS3Connected++; }
public virtual bool GetButtonUp(PS3Controller.ePS3ButtonId buttonId) { return GetButtonUp((BaseController.eButtonId)buttonId); }
protected void AddJoystickButtonMap(PS3Controller.ePS3ButtonId buttonId, int inputKey) { AddJoystickButtonMap((BaseController.eButtonId)buttonId, inputKey); }